vibespatial.constructive.polygon

Attributes

Functions

polygon_buffer_owned_array(...)

polygon_centroids_owned(→ tuple[numpy.ndarray, ...)

Compute polygon centroids directly from OwnedGeometryArray coordinate buffers.

Module Contents

vibespatial.constructive.polygon.POLYGON_BUFFER_GPU_THRESHOLD = 50000
vibespatial.constructive.polygon.polygon_buffer_owned_array(polygons: vibespatial.geometry.owned.OwnedGeometryArray, distance: float | numpy.ndarray, *, quad_segs: int = 8, join_style: str = 'round', mitre_limit: float = 5.0, dispatch_mode: vibespatial.runtime.ExecutionMode = ExecutionMode.AUTO) vibespatial.geometry.owned.OwnedGeometryArray
vibespatial.constructive.polygon.polygon_centroids_owned(owned: vibespatial.geometry.owned.OwnedGeometryArray, *, dispatch_mode: vibespatial.runtime.ExecutionMode | str = ExecutionMode.AUTO, precision: vibespatial.runtime.precision.PrecisionMode | str = 'auto', return_owned: bool = False) tuple[numpy.ndarray, numpy.ndarray] | vibespatial.geometry.owned.OwnedGeometryArray

Compute polygon centroids directly from OwnedGeometryArray coordinate buffers.

Uses the shoelace formula on ring coordinates (exterior ring only):

cx = sum((x_i + x_{i+1}) * cross_i) / (6 * area) cy = sum((y_i + y_{i+1}) * cross_i) / (6 * area) where cross_i = x_i * y_{i+1} - x_{i+1} * y_i

When return_owned is False (default), returns (cx, cy) numpy arrays of shape (row_count,).

When return_owned is True, returns a device-resident point OwnedGeometryArray built directly from GPU centroid buffers (zero D->H transfer on the GPU path). On CPU fallback the centroids are computed on host and then uploaded via point_owned_from_xy_device.

GPU path uses ADR-0002 precision dispatch: fp32 with Kahan summation + coordinate centering on consumer GPUs, native fp64 on datacenter GPUs.