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
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
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
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
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
k
int
Index of the side
required
Returns
JuliaCurve
The k-th side of the polygon
sides
paths.CircularPolygon.sides()
Get all sides of the polygon.
Returns
list of JuliaCurve
List of curves that form the polygon sides
ClosedPath
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
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
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
z
complex
Point to test
required
Returns
bool
True if z is inside the path, False otherwise
winding
paths.ClosedPath.winding(z)
Compute the winding number around point z.
Parameters
z
complex
Point around which to compute winding number
required
Returns
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
julia_obj
juliacall.AnyValue
A Julia path object from ComplexRegions.jl
required
Attributes
julia
juliacall.AnyValue
The underlying Julia path object
Methods
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
Get the turning angles at all vertices.
Returns
numpy.ndarray
Array of turning angles at vertices
arclength
paths.JuliaPath.arclength()
Compute the total arc length of the path.
Returns
float
Total arc length of all curves in the path
arg
Find the parameter value corresponding to point z on the path.
Parameters
z
complex
Point to locate on the path
required
Returns
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
z
complex
Reference point
required
Returns
complex
Closest point on the path to z
conj
Return the complex conjugate of the path.
Returns
JuliaPath
Complex conjugate of this path
curve
Get the k-th curve in the path.
Parameters
k
int
Index of the curve (0-based)
required
Returns
JuliaCurve
The k-th curve in the path
curves
Get all curves that make up the path.
Returns
list of JuliaCurve
List of curve objects that form the path
dist
Compute the distance from point z to the path.
Parameters
z
complex
Reference point
required
Returns
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
field
str
Name of the field to retrieve
required
Returns
Any
The value of the requested field
intersect
paths.JuliaPath.intersect(other)
Find intersection points with another path.
Parameters
other
JuliaPath
Another path to intersect with
required
Returns
numpy.ndarray or other
Array of intersection points or other result
inv
Compute the inversion of the path with respect to the unit circle.
isapprox
paths.JuliaPath.isapprox(other)
Check if this path is approximately equal to another.
Parameters
other
JuliaPath
Another path to compare with
required
Returns
bool
True if paths are approximately equal, False otherwise
isfinite
paths.JuliaPath.isfinite()
Check if the path has finite length.
Returns
bool
True if the path is finite, False otherwise
ispositive
paths.JuliaPath.ispositive()
Check if the path has positive orientation.
Returns
bool
True if positively oriented, False otherwise
isreal
Check if the path lies on the real axis.
Returns
bool
True if the path is real, False otherwise
length
Get the number of curves in the path.
Returns
int
Number of curves in the path
normal
paths.JuliaPath.normal(t= 0.0 )
Compute the normal vector at parameter t.
Parameters
t
float
Parameter value, default is 0
0.0
Returns
complex
Normal vector at parameter t
point
Evaluate the path at parameter value t.
Parameters
t
float
Parameter value, typically in [0, 1]
required
Returns
complex
Point on the path at parameter t
reflect
paths.JuliaPath.reflect(z)
Reflect point z across the path.
Parameters
z
complex
Point to reflect
required
reverse
paths.JuliaPath.reverse()
Return the path with reversed orientation.
Returns
JuliaPath
Path with reversed orientation
tangent
paths.JuliaPath.tangent(t= 0.0 )
Compute the tangent vector at parameter t.
Parameters
t
float
Parameter value, default is 0
0.0
Returns
complex
Tangent vector at parameter t
unittangent
paths.JuliaPath.unittangent(t= 0.0 )
Compute the unit tangent vector at parameter t.
Parameters
t
float
Parameter value, default is 0
0.0
Returns
complex
Unit tangent vector at parameter t
vertex
paths.JuliaPath.vertex(k)
Get the k-th vertex of the path.
Parameters
k
int
Index of the vertex
required
Returns
complex
Coordinates of the k-th vertex
vertices
paths.JuliaPath.vertices()
Get all vertices of the path.
Returns
numpy.ndarray
Array of vertex coordinates
Path
A path composed of connected curves.
This class represents a sequence of curves that form a continuous path.
Parameters
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
A polygon with straight sides.
This class represents a polygon where all sides are straight line segments.
Parameters
arg
list of complex or juliacall.AnyValue
List of vertex coordinates or Julia Polygon object to wrap
required
Attributes
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
side
Get the k-th side of the polygon.
sides
Get all sides of the polygon.
side
Get the k-th side of the polygon.
Parameters
k
int
Index of the side
required
Returns
JuliaCurve
The k-th side of the polygon
sides
Get all sides of the polygon.
Returns
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
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
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
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
Extract the Julia object from a Python wrapper.
Parameters
p
JuliaCurve, JuliaPath, or other
Python wrapper object or raw Julia object
required
Returns
juliacall.AnyValue or other
The underlying Julia object, or the input if not a wrapper
n_gon
Construct a regular n-gon as a Polygon object.
Parameters
n
int
Number of sides
required
Returns
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
Construct a quadrilateral region from a Rectangle.
Parameters
rect
Rectangle
Rectangle to convert to a region
required
Returns
Interior1CRegion
Interior region of the rectangle
Examples
>>> rect = Rectangle(0 + 0j , np.array([1.0 , 0.5 ]))
>>> region = quad(rect)
wrap_jl_path
Wrap a Julia path object in the appropriate Python class.
Parameters
jul
juliacall.AnyValue
A Julia path object from ComplexRegions.jl
required
Returns
Path
The appropriate Python path wrapper
Raises
ValueError
If the argument is not a Julia object or not a recognized path type