Elements

Geometric primitives and the Pydantic input-validation models.

Primitives

Immutable geometric primitive classes built on Pydantic v2.

class cgeom.elements.elements.Point(*args, x, y)[source]

Bases: BaseModel

A 2D point with coordinates (x, y).

Parameters:
model_config = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

x: float
y: float
distance_to(other)[source]

Euclidean distance to another point.

Parameters:

other (Point)

Return type:

float

to_numpy()[source]

Return as numpy array [x, y].

Return type:

ndarray

to_list()[source]

Return as [x, y].

Return type:

list[float]

class cgeom.elements.elements.Line(*args, point1, point2)[source]

Bases: BaseModel

An infinite line defined by two distinct points.

Parameters:
model_config = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

point1: Point
point2: Point
property coefficients: tuple[float, float, float]

General form (a, b, c) normalized so a² + b² = 1.

property slope: float | None

Slope of the line, or None if vertical.

property y_intercept: float | None

Y-intercept, or None if vertical.

contains_point(point, tol=1e-10)[source]

Check whether a point lies on this line.

Parameters:
Return type:

bool

class cgeom.elements.elements.Segment(*args, start, end)[source]

Bases: BaseModel

A line segment between two distinct points.

Parameters:
model_config = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

start: Point
end: Point
property length: float

Euclidean length of the segment.

property midpoint: Point

Midpoint of the segment.

to_list()[source]

Return as [[x1, y1], [x2, y2]].

Return type:

list[list[float]]

class cgeom.elements.elements.Circle(*args, center, radius)[source]

Bases: BaseModel

A circle defined by a center point and radius.

Parameters:
model_config = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

center: Point
radius: float
property area: float

Area of the circle.

property circumference: float

Circumference of the circle.

contains_point(point, tol=1e-10)[source]

Check whether a point lies inside or on the circle.

Parameters:
Return type:

bool

to_list()[source]

Return as [[cx, cy], r].

Return type:

list

class cgeom.elements.elements.Polygon(*args, vertices)[source]

Bases: BaseModel

A polygon defined by an ordered sequence of vertices.

Parameters:

vertices (tuple[Point, ...])

model_config = {'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

vertices: tuple[Point, ...]
property num_vertices: int

Number of vertices.

property area: float

Signed area using the shoelace formula (positive for CCW).

property perimeter: float

Perimeter of the polygon.

to_numpy()[source]

Return as numpy array of shape (n, 2).

Return type:

ndarray

to_list()[source]

Return as [[x, y], …].

Return type:

list[list[float]]

Input models

Pydantic validation models for computational geometry algorithm inputs.

class cgeom.elements.models.ConvexHullInput(*, points)[source]

Bases: BaseModel

Validation model for ConvexHull inputs.

Parameters:

points (List[List[float]])

points: List[List[float]]
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cgeom.elements.models.MinimumCircleInput(*, points)[source]

Bases: BaseModel

Validation model for MinimumCircle inputs.

Parameters:

points (List[List[float]])

points: List[List[float]]
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cgeom.elements.models.PolygonTriangulationInput(*, poly, poly_name='Polygon')[source]

Bases: BaseModel

Validation model for PolygonTriangulation inputs.

Parameters:
poly: List[List[float]]
poly_name: str
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cgeom.elements.models.VoronoiDiagramInput(*, points)[source]

Bases: BaseModel

Validation model for VoronoiDiagram inputs.

Parameters:

points (List[List[float]])

points: List[List[float]]
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cgeom.elements.models.SegmentIntersectionInput(*, segments)[source]

Bases: BaseModel

Validation model for SegmentIntersection inputs.

Parameters:

segments (List[List[List[float]]])

segments: List[List[List[float]]]
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cgeom.elements.models.DelaunayTriangulationInput(*, points)[source]

Bases: BaseModel

Validation model for DelaunayTriangulation inputs.

Parameters:

points (List[List[float]])

points: List[List[float]]
classmethod validate_input(data)[source]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].