paths

paths

Path classes for the cxregions package.

This module contains all path-related classes including the base JuliaPath class and specific path types like Polygon, CircularPolygon, and Rectangle.

Classes

Name Description
CircularPolygon A polygon with circular arc sides.
ClosedPath A closed path that forms a Jordan curve.
JuliaPath Base class for wrapping Julia path objects from ComplexRegions.jl.
Path A path composed of connected curves.
Polygon A polygon with straight sides.
Rectangle A rectangular polygon.

CircularPolygon

paths.CircularPolygon(arg)

A polygon with circular arc sides.

This class represents a polygon where each side can be either a straight line segment or a circular arc.

Parameters

Name Type Description Default
arg list of curves or juliacall.AnyValue List of curves (segments and arcs) that form the polygon sides, or Julia CircularPolygon object to wrap required

Attributes

Name Type Description
path ClosedPath The underlying closed path

Examples

>>> from cxregions.curves import Arc, Segment
>>> arc1 = Arc(1, 2 + 1j, 1j)
>>> seg1 = Segment(1j, -1)
>>> arc2 = Arc(-1, -0.5j, -1j)
>>> seg2 = Segment(-1j, 1)
>>> cpoly = CircularPolygon([arc1, seg1, arc2, seg2])

Methods

Name Description
side Get the k-th side of the polygon.
sides Get all sides of the polygon.
side
paths.CircularPolygon.side(k)

Get the k-th side of the polygon.

Parameters
Name Type Description Default
k int Index of the side required
Returns
Name Type Description
JuliaCurve The k-th side of the polygon
sides
paths.CircularPolygon.sides()

Get all sides of the polygon.

Returns
Name Type Description
list of JuliaCurve List of curves that form the polygon sides

ClosedPath

paths.ClosedPath(curves)

A closed path that forms a Jordan curve.

This class represents a closed sequence of curves that form a continuous closed path, enabling computation of winding numbers and containment tests.

Parameters

Name Type Description Default
curves list of JuliaCurve, Path, or juliacall.AnyValue List of curves that form the closed path, or Julia ClosedPath object to wrap required

Examples

>>> from cxregions.curves import Segment
>>> seg1 = Segment(0, 1)
>>> seg2 = Segment(1, 1+1j)
>>> seg3 = Segment(1+1j, 1j)
>>> seg4 = Segment(1j, 0)
>>> closed_path = ClosedPath([seg1, seg2, seg3, seg4])

Methods

Name Description
isinside Check if point z is inside the closed path.
winding Compute the winding number around point z.
isinside
paths.ClosedPath.isinside(z)

Check if point z is inside the closed path.

Parameters
Name Type Description Default
z complex Point to test required
Returns
Name Type Description
bool True if z is inside the path, False otherwise
winding
paths.ClosedPath.winding(z)

Compute the winding number around point z.

Parameters
Name Type Description Default
z complex Point around which to compute winding number required
Returns
Name Type Description
int Winding number (positive for counterclockwise orientation)

JuliaPath

paths.JuliaPath(julia_obj)

Base class for wrapping Julia path objects from ComplexRegions.jl.

This class provides a Python interface to Julia path objects, which are sequences of connected curves forming a continuous path.

Parameters

Name Type Description Default
julia_obj juliacall.AnyValue A Julia path object from ComplexRegions.jl required

Attributes

Name Type Description
julia juliacall.AnyValue The underlying Julia path object

Methods

Name Description
angles Get the turning angles at all vertices.
arclength Compute the total arc length of the path.
arg Find the parameter value corresponding to point z on the path.
closest Find the closest point on the path to z.
conj Return the complex conjugate of the path.
curve Get the k-th curve in the path.
curves Get all curves that make up the path.
dist Compute the distance from point z to the path.
get Get a field from the underlying Julia object.
intersect Find intersection points with another path.
inv Compute the inversion of the path with respect to the unit circle.
isapprox Check if this path is approximately equal to another.
isfinite Check if the path has finite length.
ispositive Check if the path has positive orientation.
isreal Check if the path lies on the real axis.
length Get the number of curves in the path.
normal Compute the normal vector at parameter t.
point Evaluate the path at parameter value t.
reflect Reflect point z across the path.
reverse Return the path with reversed orientation.
tangent Compute the tangent vector at parameter t.
unittangent Compute the unit tangent vector at parameter t.
vertex Get the k-th vertex of the path.
vertices Get all vertices of the path.
angles
paths.JuliaPath.angles()

Get the turning angles at all vertices.

Returns
Name Type Description
numpy.ndarray Array of turning angles at vertices
arclength
paths.JuliaPath.arclength()

Compute the total arc length of the path.

Returns
Name Type Description
float Total arc length of all curves in the path
arg
paths.JuliaPath.arg(z)

Find the parameter value corresponding to point z on the path.

Parameters
Name Type Description Default
z complex Point to locate on the path required
Returns
Name Type Description
float or None Parameter value if z is on the path, None otherwise
closest
paths.JuliaPath.closest(z)

Find the closest point on the path to z.

Parameters
Name Type Description Default
z complex Reference point required
Returns
Name Type Description
complex Closest point on the path to z
conj
paths.JuliaPath.conj()

Return the complex conjugate of the path.

Returns
Name Type Description
JuliaPath Complex conjugate of this path
curve
paths.JuliaPath.curve(k)

Get the k-th curve in the path.

Parameters
Name Type Description Default
k int Index of the curve (0-based) required
Returns
Name Type Description
JuliaCurve The k-th curve in the path
curves
paths.JuliaPath.curves()

Get all curves that make up the path.

Returns
Name Type Description
list of JuliaCurve List of curve objects that form the path
dist
paths.JuliaPath.dist(z)

Compute the distance from point z to the path.

Parameters
Name Type Description Default
z complex Reference point required
Returns
Name Type Description
float Distance from z to the closest point on the path
get
paths.JuliaPath.get(field)

Get a field from the underlying Julia object.

Parameters
Name Type Description Default
field str Name of the field to retrieve required
Returns
Name Type Description
Any The value of the requested field
intersect
paths.JuliaPath.intersect(other)

Find intersection points with another path.

Parameters
Name Type Description Default
other JuliaPath Another path to intersect with required
Returns
Name Type Description
numpy.ndarray or other Array of intersection points or other result
inv
paths.JuliaPath.inv()

Compute the inversion of the path with respect to the unit circle.

Returns
Name Type Description
JuliaPath Inverted path
isapprox
paths.JuliaPath.isapprox(other)

Check if this path is approximately equal to another.

Parameters
Name Type Description Default
other JuliaPath Another path to compare with required
Returns
Name Type Description
bool True if paths are approximately equal, False otherwise
isfinite
paths.JuliaPath.isfinite()

Check if the path has finite length.

Returns
Name Type Description
bool True if the path is finite, False otherwise
ispositive
paths.JuliaPath.ispositive()

Check if the path has positive orientation.

Returns
Name Type Description
bool True if positively oriented, False otherwise
isreal
paths.JuliaPath.isreal()

Check if the path lies on the real axis.

Returns
Name Type Description
bool True if the path is real, False otherwise
length
paths.JuliaPath.length()

Get the number of curves in the path.

Returns
Name Type Description
int Number of curves in the path
normal
paths.JuliaPath.normal(t=0.0)

Compute the normal vector at parameter t.

Parameters
Name Type Description Default
t float Parameter value, default is 0 0.0
Returns
Name Type Description
complex Normal vector at parameter t
point
paths.JuliaPath.point(t)

Evaluate the path at parameter value t.

Parameters
Name Type Description Default
t float Parameter value, typically in [0, 1] required
Returns
Name Type Description
complex Point on the path at parameter t
reflect
paths.JuliaPath.reflect(z)

Reflect point z across the path.

Parameters
Name Type Description Default
z complex Point to reflect required
Returns
Name Type Description
complex Reflected point
reverse
paths.JuliaPath.reverse()

Return the path with reversed orientation.

Returns
Name Type Description
JuliaPath Path with reversed orientation
tangent
paths.JuliaPath.tangent(t=0.0)

Compute the tangent vector at parameter t.

Parameters
Name Type Description Default
t float Parameter value, default is 0 0.0
Returns
Name Type Description
complex Tangent vector at parameter t
unittangent
paths.JuliaPath.unittangent(t=0.0)

Compute the unit tangent vector at parameter t.

Parameters
Name Type Description Default
t float Parameter value, default is 0 0.0
Returns
Name Type Description
complex Unit tangent vector at parameter t
vertex
paths.JuliaPath.vertex(k)

Get the k-th vertex of the path.

Parameters
Name Type Description Default
k int Index of the vertex required
Returns
Name Type Description
complex Coordinates of the k-th vertex
vertices
paths.JuliaPath.vertices()

Get all vertices of the path.

Returns
Name Type Description
numpy.ndarray Array of vertex coordinates

Path

paths.Path(curves)

A path composed of connected curves.

This class represents a sequence of curves that form a continuous path.

Parameters

Name Type Description Default
curves list of JuliaCurve or juliacall.AnyValue List of curves that form the path, or Julia Path object to wrap required

Examples

>>> from cxregions.curves import Segment
>>> seg1 = Segment(0, 1)
>>> seg2 = Segment(1, 1+1j)
>>> path = Path([seg1, seg2])

Polygon

paths.Polygon(arg)

A polygon with straight sides.

This class represents a polygon where all sides are straight line segments.

Parameters

Name Type Description Default
arg list of complex or juliacall.AnyValue List of vertex coordinates or Julia Polygon object to wrap required

Attributes

Name Type Description
path ClosedPath The underlying closed path

Examples

>>> # Unit square
>>> poly = Polygon([0, 1, 1+1j, 1j])
>>> # More complex polygon
>>> poly2 = Polygon([4, 4 + 3j, 3j, -2j, 6 - 2j, 6])

Methods

Name Description
side Get the k-th side of the polygon.
sides Get all sides of the polygon.
side
paths.Polygon.side(k)

Get the k-th side of the polygon.

Parameters
Name Type Description Default
k int Index of the side required
Returns
Name Type Description
JuliaCurve The k-th side of the polygon
sides
paths.Polygon.sides()

Get all sides of the polygon.

Returns
Name Type Description
list of JuliaCurve List of line segments that form the polygon sides

Rectangle

paths.Rectangle(a, b=None)

A rectangular polygon.

This class represents a rectangle, which is a special case of a polygon with four sides at right angles.

Parameters

Name Type Description Default
a complex, list, or juliacall.AnyValue Center point, list of vertices, or Julia Rectangle object to wrap required
b array - like or complex Radii array (if a is center) or opposite corner (if a is corner) None

Attributes

Name Type Description
center complex Center of the rectangle
radii array - like Half-widths in x and y directions
rotation float Rotation angle of the rectangle
polygon Polygon The underlying polygon representation

Examples

>>> # Rectangle from center and radii
>>> rect1 = Rectangle(0+0j, np.array([1.0, 0.5]))
>>> # Rectangle from opposite corners
>>> rect2 = Rectangle(-1-1j, 1+1j)

Functions

Name Description
get_julia Extract the Julia object from a Python wrapper.
n_gon Construct a regular n-gon as a Polygon object.
quad Construct a quadrilateral region from a Rectangle.
wrap_jl_path Wrap a Julia path object in the appropriate Python class.

get_julia

paths.get_julia(p)

Extract the Julia object from a Python wrapper.

Parameters

Name Type Description Default
p JuliaCurve, JuliaPath, or other Python wrapper object or raw Julia object required

Returns

Name Type Description
juliacall.AnyValue or other The underlying Julia object, or the input if not a wrapper

n_gon

paths.n_gon(n)

Construct a regular n-gon as a Polygon object.

Parameters

Name Type Description Default
n int Number of sides required

Returns

Name Type Description
Polygon Regular n-sided polygon centered at origin with unit circumradius

Examples

>>> # Regular hexagon
>>> hex_poly = n_gon(6)
>>> # Regular triangle
>>> triangle = n_gon(3)

quad

paths.quad(rect)

Construct a quadrilateral region from a Rectangle.

Parameters

Name Type Description Default
rect Rectangle Rectangle to convert to a region required

Returns

Name Type Description
Interior1CRegion Interior region of the rectangle

Examples

>>> rect = Rectangle(0+0j, np.array([1.0, 0.5]))
>>> region = quad(rect)

wrap_jl_path

paths.wrap_jl_path(jul)

Wrap a Julia path object in the appropriate Python class.

Parameters

Name Type Description Default
jul juliacall.AnyValue A Julia path object from ComplexRegions.jl required

Returns

Name Type Description
Path The appropriate Python path wrapper

Raises

Name Type Description
ValueError If the argument is not a Julia object or not a recognized path type