vibespatial.constructive.snap

GPU-accelerated snap: snap vertices of geometry A to nearest vertices on B.

For each element-wise pair (A[i], B[i]): 1. For each vertex in A, find the nearest vertex of B within the given

tolerance (matches GEOS/Shapely vertex-to-vertex snap semantics).

  1. If a snap target vertex exists within tolerance, move the vertex to the snapped location. Otherwise keep the vertex unchanged.

  2. Deduplicate coincident vertices that resulted from snapping (sequential scan within each ring/linestring).

  3. Ensure ring closure for polygon rings.

  4. Rebuild geometry offsets from modified coordinate counts.

Architecture (ADR-0033): - Tier 1 NVRTC for the per-vertex nearest-vertex search (geometry-specific

inner loop: iterates all vertices of B for each vertex of A).

  • Tier 1 NVRTC for the per-ring sequential dedup pass (same pattern as remove_repeated_points).

  • Tier 3a CCCL for exclusive_sum on per-span kept counts.

  • Tier 2 CuPy for coordinate gather (compact).

Precision (ADR-0002): CONSTRUCTIVE class – stays fp64 on all devices per policy. PrecisionPlan wired through dispatch for observability only.

Bulk D2H pre-transfer of family coordinate ranges before the dispatch loop (bounded by number of geometry families, not data size). Kernel execution and output assembly are fully device-resident via build_device_resident_owned.

Attributes

Functions

snap_owned(→ vibespatial.geometry.owned.OwnedGeometryArray)

Snap vertices of left geometries to nearest vertices on right within tolerance.

Module Contents

vibespatial.constructive.snap.cp = None
vibespatial.constructive.snap.logger
vibespatial.constructive.snap.snap_owned(left: vibespatial.geometry.owned.OwnedGeometryArray, right: vibespatial.geometry.owned.OwnedGeometryArray, tolerance: float, *, dispatch_mode: vibespatial.runtime.ExecutionMode | str = ExecutionMode.AUTO, precision: vibespatial.runtime.precision.PrecisionMode | str = PrecisionMode.AUTO) vibespatial.geometry.owned.OwnedGeometryArray

Snap vertices of left geometries to nearest vertices on right within tolerance.

For each element-wise pair (left[i], right[i]), snaps each vertex of left[i] to the nearest vertex of right[i] within the given tolerance. Matches GEOS/Shapely vertex-to-vertex snap semantics. Deduplicates coincident vertices and preserves ring closure for polygons.

Supports pairwise (N vs N) and broadcast-right (N vs 1) modes.

Parameters

leftOwnedGeometryArray

Source geometries whose vertices will be snapped.

rightOwnedGeometryArray

Target geometries providing snap target vertices.

tolerancefloat

Maximum distance for snapping. Vertices further than this from any vertex of the target geometry are left unchanged.

dispatch_modeExecutionMode or str

Execution mode selection (AUTO / CPU / GPU).

precisionPrecisionMode or str

Precision mode selection (AUTO / FP32 / FP64).

Returns

OwnedGeometryArray

New geometry array with snapped coordinates.