Type Conversions (conversions.py)¶
The conversions module provides precise geometric conversion routines between CGALPY C++ bound types (Point_2, Polygon_2, Segment_2), high-dimensional composite configuration tensors (Point_d), NumPy arrays, and standard Python data structures.
Architectural Role & Composite Tensor Mapping¶
In multi-robot motion planning, individual robots operate in 2D Euclidean space (
or
), while the multi-robot system operates in a composite joint configuration space
or
. The conversions module acts as the core translation bridge:
Single-to-Composite Mapping: Converts lists of single-robot
Point_2configurations into a composite high-dimensionalPoint_dtensor for joint sampling inSamplingSolver.Composite-to-Single De-multiplexing: De-multiplexes a joint
Point_dtensor back into individual 2D robot coordinates for collision checking and visual rendering.Numeric Exactness: Preserves CGAL exact field type arithmetic (
FT) during float-to-exact conversions to prevent precision loss.
Key Conversion Routines¶
Usage Example¶
from discopygal.geometry_utils import conversions
from discopygal.bindings import Point_2, FT
# Convert single-robot 2D points into a joint 4D configuration tensor for 2 robots
p1 = Point_2(FT(1.5), FT(2.0))
p2 = Point_2(FT(5.0), FT(3.5))
tensor_pt = conversions.points_2_to_point_d([p1, p2])
print("Composite Dimension:", tensor_pt.dimension()) # 4
# De-multiplex tensor back into single-robot points
robot_pts = conversions.point_d_to_points_2(tensor_pt)
API Reference¶
- discopygal.geometry_utils.conversions.FT_to_float(f: FT) float¶
Convert CGAL Field Type (FT) to python float
- Parameters:
f (
FT) – float to convert- Returns:
python float
- Return type:
float
- discopygal.geometry_utils.conversions.Point_2_list_to_Point_d(point_2_list: list[Point_2]) Point_d¶
Convert a list of Point_2’s to a high-dimensional Point_d
- discopygal.geometry_utils.conversions.Point_2_to_xy(point: Point_2) tuple[float, float]¶
Convert CGAL Point_2 to (x,y) values
- Parameters:
point (
Point_2) – point to convert- Returns:
x, y values of point
- Return type:
(
float,float)
- discopygal.geometry_utils.conversions.Point_d_to_Point_2_list(point_d: Point_d) Point_2¶
- Convert a high-dimensional Point_d to a list of Point_2’s(We assume that d%2==0)
- discopygal.geometry_utils.conversions.Point_d_to_Point_k_list(point_d: Point_d, k: int) Point_d¶
- Convert a high-dimensional Point_d to a list of Point_k’s(We assume that d%k==0)
- discopygal.geometry_utils.conversions.Point_k_list_to_Point_d(point_k_list: list[Point_d]) Point_d¶
Convert a list of Point_k’s to a single high-dimensional Point_d (sum of all dimensions)
- discopygal.geometry_utils.conversions.Polygon_2_to_array_of_points(poly)¶
Convert a CGAL Polygon_2 to list of points
- Parameters:
poly (
Polygon_2) – polygon to convert- Returns:
list of tuples of (x,y) points
- Return type:
list<(
float,float)>
- discopygal.geometry_utils.conversions.arrangement_from_dict(d)¶
Reconstruct an Arrangement_2 from the simplified dict produced by
.The reconstruction inserts straight segments for the serialized edges and attempts to restore face data by locating a point inside each serialized face and setting the face’s data value.
- discopygal.geometry_utils.conversions.arrangement_to_dict(arr)¶
Serialize an Arrangement_2 into a simple dict of edges and face polygons.
This produces a lightweight representation that can be reconstructed into a new Arrangement_2 in the main process. It trades exact curve geometry for a robust segment-based reconstruction that the UI can display.
- discopygal.geometry_utils.conversions.array_of_points_to_Polygon_2(poly: list[tuple[float, float]]) Polygon_2¶
Convert a list of points to a CGAL Polygon_2
- Parameters:
poly (list<(
float, :class:`float)>) – list of points to convert- Returns:
CGAL polygon
- Return type:
:class:~discopygal.bindings.Polygon_2`
- discopygal.geometry_utils.conversions.float_to_FT(f: float) FT¶
Convert python float value to CGAL Field Type (FT)
- Parameters:
f (
float) – float to convert- Returns:
CGAL FT
- Return type:
- discopygal.geometry_utils.conversions.graph_from_dict(d)¶
Reconstruct a NetworkX graph from the structure produced by
.Returns a NetworkX Graph or None.
- discopygal.geometry_utils.conversions.graph_to_dict(graph)¶
Serialize a NetworkX graph whose nodes are Point_2/Point_d to plain Python structures.
Returns None for a None graph.
- discopygal.geometry_utils.conversions.point_to_coordinate(p: Point_2, coordinate_index: int)¶
For a given point, return the coordinate of given index
- Parameters:
p (Union[Point_2, TPoint]) – Given point
coordinate_index (int) – The index of the coordinate to return
- Returns:
The value of the coordinate