Skip to content

Domains

A domain is the region of the plane that gets sampled. See the guide for how they compose.

complexplorer.Domain

Domain(real: tuple[float, float], imag: tuple[float, float], square: bool = True)

Bases: ABC

Abstract base class for complex domains.

A domain represents a region in the complex plane defined by a membership function. The domain can generate meshes for visualization and supports set operations (union, intersection).

Attributes:

Name Type Description
window_real tuple[float, float]

Left and right bounds of the viewing window.

window_imag tuple[float, float]

Bottom and top bounds of the viewing window.

square bool

Whether to constrain the viewing window to be square.

Initialize domain with viewing window.

Parameters:

Name Type Description Default
real tuple[float, float]

Left and right edges of the viewing window.

required
imag tuple[float, float]

Bottom and top edges of the viewing window.

required
square bool

If True, constrain viewing window to be square.

True

contains abstractmethod

contains(z: ndarray) -> np.ndarray

Check if points belong to the domain.

Parameters:

Name Type Description Default
z ndarray

Complex values to test.

required

Returns:

Type Description
ndarray

Boolean array indicating membership.

spacing

spacing(n: int) -> float

Calculate mesh point spacing.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

required

Returns:

Type Description
float

Distance between adjacent mesh points.

mesh

mesh(n: int = 500) -> np.ndarray

Generate complex mesh for the viewing window.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

500

Returns:

Type Description
ndarray

2D array of complex values.

inmask

inmask(n: int = 500) -> np.ndarray

Generate boolean mask for points inside the domain.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

500

Returns:

Type Description
ndarray

Boolean mask (True for points inside).

outmask

outmask(n: int = 500) -> np.ndarray

Generate boolean mask for points outside the domain.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

500

Returns:

Type Description
ndarray

Boolean mask (True for points outside).

domain

domain(n: int = 500) -> np.ndarray

Generate mesh with NaN outside the domain.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

500

Returns:

Type Description
ndarray

Complex mesh with NaN for points outside.

union

union(other: Domain) -> CompositeDomain

Create union with another domain.

Parameters:

Name Type Description Default
other Domain

Domain to union with.

required

Returns:

Type Description
CompositeDomain

Union of the two domains.

intersection

intersection(other: Domain) -> CompositeDomain

Create intersection with another domain.

Parameters:

Name Type Description Default
other Domain

Domain to intersect with.

required

Returns:

Type Description
CompositeDomain

Intersection of the two domains.

difference

difference(other: Domain) -> CompositeDomain

Create set difference with another domain.

Parameters:

Name Type Description Default
other Domain

Domain to subtract.

required

Returns:

Type Description
CompositeDomain

Points in this domain but not in other.

complexplorer.Rectangle

Rectangle(re_length: float, im_length: float, center: complex = 0 + 0j, square: bool = True)

Bases: Domain

Rectangular domain in the complex plane.

Parameters:

Name Type Description Default
re_length float

Length along the real axis.

required
im_length float

Length along the imaginary axis.

required
center complex

Center of the rectangle.

0 + 0j
square bool

Whether to use square viewing window.

True

Initialize rectangular domain.

contains

contains(z: ndarray) -> np.ndarray

Check if points are inside the rectangle.

Membership is defined by the rectangle's own re_length/im_length about its center — independent of any square-padding applied to the viewing window for display (so a non-square rectangle does not report the padded strips as inside).

complexplorer.Disk

Disk(radius: float, center: complex = 0 + 0j)

Bases: Domain

Circular domain in the complex plane.

Parameters:

Name Type Description Default
radius float

Radius of the disk.

required
center complex

Center of the disk.

0 + 0j

Initialize disk domain.

contains

contains(z: ndarray) -> np.ndarray

Check if points are inside the disk.

complexplorer.Annulus

Annulus(inner_radius: float, outer_radius: float, center: complex = 0 + 0j)

Bases: Domain

Annular (ring-shaped) domain in the complex plane.

Parameters:

Name Type Description Default
inner_radius float

Inner radius of the annulus.

required
outer_radius float

Outer radius of the annulus.

required
center complex

Center of the annulus.

0 + 0j

Initialize annulus domain.

contains

contains(z: ndarray) -> np.ndarray

Check if points are inside the annulus.

complexplorer.CompositeDomain

CompositeDomain(domain1: Domain, domain2: Domain, operation: str)

Bases: Domain

Domain formed by set operations on other domains.

This class represents domains created by union, intersection, or difference of two existing domains.

Parameters:

Name Type Description Default
domain1 Domain

First domain.

required
domain2 Domain

Second domain.

required
operation (union, intersection, difference)

Set operation to apply.

'union'

Initialize composite domain.

tight_bounds property

tight_bounds

Get tight bounds, calculating if necessary.

contains

contains(z: ndarray) -> np.ndarray

Check if points are in the composite domain.

calculate_tight_bounds

calculate_tight_bounds(sample_density: int = 100) -> tuple[tuple[float, float], tuple[float, float]]

Calculate tight bounds by sampling the actual domain.

Parameters:

Name Type Description Default
sample_density int

Number of sample points along each axis.

100

Returns:

Type Description
real_bounds, imag_bounds : tuple of tuple

Tight bounds for the composite domain.

mesh

mesh(n: int = 500, use_tight_bounds: bool = True) -> np.ndarray

Generate mesh grid of complex numbers.

For composite domains, can use tight bounds for better fit.

Parameters:

Name Type Description Default
n int

Number of points along the longer axis.

500
use_tight_bounds bool

If True, use tight bounds for composite domains.

True

Returns:

Type Description
ndarray

2D array of complex values.