Skip to main content

raygeo.sketch.entities.polygon

Polygon​

A polygon defined in the local frame of center and handle points.

array_copy​

array_copy: bool

Whether the entity was created as part of an array copy.

center_idx​

center_idx: int

Center point id.

closed​

closed: bool

Whether the polygon contour is closed.

constrained​

constrained: bool

Whether the entity is fully constrained, as computed by the solver.

construction​

construction: bool

Whether the entity is construction geometry.

fill_color​

fill_color: Optional[tuple[float, float, float, float]]

Fill color as (r, g, b, a), or None.

handle_idx​

handle_idx: int

Handle point id.

id​

id: types.EntityID

Unique entity id.

invisible​

invisible: bool

Whether the entity is excluded from toolpath output.

rings​

rings: list[list[tuple[float, float]]]

All rings in the local frame (outer contour first, then holes).

type​

type: str

The entity type name (attribute alias).

vertices​

vertices: list[tuple[float, float]]

The outer contour vertices in the local frame.

append_to_geometry()​

append_to_geometry(
geo: geo.Geometry,
registry: protocols.Registry,
forward: bool = True,
) -> None

Appends the entity's outline to the geometry.

ParameterTypeDescription
geogeo.Geometry
registryprotocols.Registry
forwardbool = True
ReturnsNone

build()​

build(
id: int,
center: int,
handle: int,
center_pos: tuple[float, float],
handle_pos: tuple[float, float],
vertices: Sequence[tuple[float, float]],
closed: bool = False,
world_holes: Optional[Sequence[Sequence[tuple[float, float]]]] = None,
) -> tuple[Any, Any, Polygon]

Reference factory: builds a polygon from center/handle point ids, outer vertices and optional world-space hole rings.

ParameterTypeDescription
idint
centerint
handleint
center_postuple[float, float]
handle_postuple[float, float]
verticesSequence[tuple[float, float]]
closedbool = False
world_holesOptional[Sequence[Sequence[tuple[float, float]]]] = None
Returnstuple[Any, Any, Polygon]

characteristic_length()​

characteristic_length(registry: protocols.Registry) -> float

The characteristic length used by equal-length constraints.

ParameterTypeDescription
registryprotocols.Registry
Returnsfloat

characteristic_length_pairs()​

characteristic_length_pairs() -> list[list[int]]

The defining-point pairs of the characteristic length.

ParameterTypeDescription
Returnslist[list[int]]

clear_helper_references()​

clear_helper_references() -> None

Drops this entity's references to its helper entities.

ParameterTypeDescription
ReturnsNone

contains_point()​

contains_point(registry: protocols.Registry, x: float, y: float) -> bool

Whether the model-space point lies inside the entity.

ParameterTypeDescription
registryprotocols.Registry
xfloat
yfloat
Returnsbool

create_fill_geometry()​

create_fill_geometry(registry: protocols.Registry) -> Optional[geo.Geometry]

The fill geometry of the entity, if it supports fills.

ParameterTypeDescription
registryprotocols.Registry
ReturnsOptional[geo.Geometry]

enclosed_signed_area()​

enclosed_signed_area(registry: protocols.Registry) -> Optional[float]

The signed area enclosed by the polygon (outer ring minus holes), or None when the frame points are missing.

ParameterTypeDescription
registryprotocols.Registry
ReturnsOptional[float]

from_dict()​

from_dict(data: dict) -> Polygon

Builds a polygon from its reference dictionary form.

ParameterTypeDescription
datadict
ReturnsPolygon

geometry_signature()​

geometry_signature(registry: protocols.Registry) -> tuple

Returns the geometry signature used for change detection.

ParameterTypeDescription
registryprotocols.Registry
Returnstuple

get_all_frame_point_ids()​

get_all_frame_point_ids(registry: protocols.Registry) -> list[int]

Frame point ids of a text box, for containment checks.

ParameterTypeDescription
registryprotocols.Registry
Returnslist[int]

get_drag_anchor_points()​

get_drag_anchor_points(point_id: int) -> list[int]

Point ids that act as drag anchors for the given point.

ParameterTypeDescription
point_idint
Returnslist[int]

get_endpoint_ids()​

get_endpoint_ids() -> list[int]

The entity ids of the curve endpoints.

ParameterTypeDescription
Returnslist[int]

get_helper_ids()​

get_helper_ids() -> list[int]

Auxiliary/child entity ids belonging to this compound entity.

ParameterTypeDescription
Returnslist[int]

get_ignorable_unconstrained_points()​

get_ignorable_unconstrained_points() -> list[int]

Point ids that can remain unconstrained when this entity is constrained.

ParameterTypeDescription
Returnslist[int]

get_junction_point_ids()​

get_junction_point_ids() -> list[int]

Point ids acting as junction candidates for chaining.

ParameterTypeDescription
Returnslist[int]

get_point_ids()​

get_point_ids() -> list[int]

The point ids the entity is defined by.

ParameterTypeDescription
Returnslist[int]

get_rigidly_connected_points()​

get_rigidly_connected_points(point_id: int) -> list[int]

Point ids that move rigidly with the given point.

ParameterTypeDescription
point_idint
Returnslist[int]

get_state()​

get_state() -> Optional[dict]

Solver-relevant discrete state for undo/redo snapshots.

ParameterTypeDescription
ReturnsOptional[dict]

get_world_rings()​

get_world_rings(
registry: protocols.Registry,
) -> list[list[tuple[float, float]]]

The polygon's rings in world coordinates.

ParameterTypeDescription
registryprotocols.Registry
Returnslist[list[tuple[float, float]]]

get_world_vertices()​

get_world_vertices(registry: protocols.Registry) -> list[tuple[float, float]]

Returns the entity's toolpath geometry in model coordinates. Returns the polygon vertices in world coordinates.

ParameterTypeDescription
registryprotocols.Registry
Returnslist[tuple[float, float]]

hit_test()​

hit_test(
mx: float,
my: float,
threshold: float,
registry: protocols.Registry,
) -> bool

Whether the entity is hit at model coordinates (mx, my).

ParameterTypeDescription
mxfloat
myfloat
thresholdfloat
registryprotocols.Registry
Returnsbool

intersects_rect()​

intersects_rect(
rect: tuple[float, float, float, float],
registry: protocols.Registry,
) -> bool

Whether the entity intersects the given rect.

ParameterTypeDescription
recttuple[float, float, float, float]
registryprotocols.Registry
Returnsbool

is_closed_loop()​

is_closed_loop() -> bool

Whether the polygon is a closed loop.

ParameterTypeDescription
Returnsbool

is_contained_by()​

is_contained_by(
rect: tuple[float, float, float, float],
registry: protocols.Registry,
) -> bool

Whether the polygon is contained by the given (x1, y1, x2, y2) rect.

ParameterTypeDescription
recttuple[float, float, float, float]
registryprotocols.Registry
Returnsbool

is_edge_entity()​

is_edge_entity() -> bool

Whether the entity participates in edge/chaining adjacency for loop detection (line, arc, bezier).

ParameterTypeDescription
Returnsbool

is_radius_entity()​

is_radius_entity() -> bool

Whether the entity has a radius (arc, circle).

ParameterTypeDescription
Returnsbool

normalize_vertices()​

normalize_vertices(
center: tuple[float, float],
handle: tuple[float, float],
world_vertices: Sequence[tuple[float, float]],
) -> list[tuple[float, float]]

Converts world coordinates to frame-local (u, v) pairs.

ParameterTypeDescription
centertuple[float, float]
handletuple[float, float]
world_verticesSequence[tuple[float, float]]
Returnslist[tuple[float, float]]

restore_base_flags()​

restore_base_flags(data: dict) -> None

Restores base flags serialized by to_dict() but not accepted as constructor arguments.

ParameterTypeDescription
datadict
ReturnsNone

set_fill_color()​

set_fill_color(color: Optional[Sequence[float]]) -> bool

Sets the fill color; returns whether the entity supports fills.

ParameterTypeDescription
colorOptional[Sequence[float]]
Returnsbool

set_state()​

set_state(state: dict) -> None

Restores solver-relevant discrete state from a snapshot.

ParameterTypeDescription
statedict
ReturnsNone

signed_distance_to()​

signed_distance_to(
px: float,
py: float,
registry: protocols.Registry,
) -> Optional[float]

Signed distance from the model-space point, if defined.

ParameterTypeDescription
pxfloat
pyfloat
registryprotocols.Registry
ReturnsOptional[float]

supports_fill()​

supports_fill() -> bool

Whether this entity can receive a fill color.

ParameterTypeDescription
Returnsbool

supports_point_on_curve()​

supports_point_on_curve() -> bool

Whether a point can be constrained onto this entity's curve.

ParameterTypeDescription
Returnsbool

tangent_at()​

tangent_at(
registry: protocols.Registry,
point_id: int,
) -> Optional[tuple[float, float]]

Tangent direction at the point nearest the model-space point.

ParameterTypeDescription
registryprotocols.Registry
point_idint
ReturnsOptional[tuple[float, float]]

to_dict()​

to_dict() -> dict

Serializes the entity to the reference dictionary shape.

ParameterTypeDescription
Returnsdict

to_geometry()​

to_geometry(registry: protocols.Registry) -> geo.Geometry
ParameterTypeDescription
registryprotocols.Registry
Returnsgeo.Geometry

to_outline()​

to_outline(
registry: protocols.Registry,
) -> tuple[list[tuple[float, float]], bool]

Returns (world vertices, closed) for offset processing.

ParameterTypeDescription
registryprotocols.Registry
Returnstuple[list[tuple[float, float]], bool]

to_polygon_vertices()​

to_polygon_vertices(
registry: protocols.Registry,
forward: bool = True,
) -> list[tuple[float, float]]

Returns the entity's outline as polygon vertices.

ParameterTypeDescription
registryprotocols.Registry
forwardbool = True
Returnslist[tuple[float, float]]

to_polyline()​

to_polyline(
registry: protocols.Registry,
tolerance: float = 0.1,
) -> list[tuple[float, float]]

Returns the entity's centerline as polyline vertices.

ParameterTypeDescription
registryprotocols.Registry
tolerancefloat = 0.1
Returnslist[tuple[float, float]]

type_name()​

type_name() -> str

The entity type name.

ParameterTypeDescription
Returnsstr

update_constrained_status()​

update_constrained_status(
registry: protocols.Registry,
constraints: Any,
) -> None

Updates the constrained flag from defining-point status and constraints that dimension this entity's radius or length.

ParameterTypeDescription
registryprotocols.Registry
constraintsAny
ReturnsNone

write_back()​

write_back() -> None

Persists in-place edits back to the owning registry, if any.

ParameterTypeDescription
ReturnsNone