MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / st_intersects

Function st_intersects

nodedb-spatial/src/predicates/intersects.rs:17–93  ·  view source on GitHub ↗

ST_Intersects(a, b) — do geometries A and B share any space?

(a: &Geometry, b: &Geometry)

Source from the content-addressed store, hash-verified

15
16/// ST_Intersects(a, b) — do geometries A and B share any space?
17pub fn st_intersects(a: &Geometry, b: &Geometry) -> bool {
18 // Bbox pre-filter.
19 let a_bb = geometry_bbox(a);
20 let b_bb = geometry_bbox(b);
21 if !a_bb.intersects(&b_bb) {
22 return false;
23 }
24
25 match (a, b) {
26 // Point–Point: identical within tolerance.
27 (Geometry::Point { coordinates: ca }, Geometry::Point { coordinates: cb }) => {
28 (ca[0] - cb[0]).abs() < 1e-12 && (ca[1] - cb[1]).abs() < 1e-12
29 }
30
31 // Point–LineString: point on any segment.
32 (Geometry::Point { coordinates: pt }, Geometry::LineString { coordinates: line })
33 | (Geometry::LineString { coordinates: line }, Geometry::Point { coordinates: pt }) => {
34 point_on_ring_boundary(*pt, line)
35 }
36
37 // Point–Polygon: point inside OR on boundary.
38 (Geometry::Point { coordinates: pt }, Geometry::Polygon { coordinates: rings })
39 | (Geometry::Polygon { coordinates: rings }, Geometry::Point { coordinates: pt }) => {
40 point_intersects_polygon(*pt, rings)
41 }
42
43 // LineString–LineString: any edge crossing or shared point.
44 (Geometry::LineString { coordinates: la }, Geometry::LineString { coordinates: lb }) => {
45 linestrings_intersect(la, lb)
46 }
47
48 // LineString–Polygon: any edge crossing, or any line point inside polygon.
49 (Geometry::LineString { coordinates: line }, Geometry::Polygon { coordinates: rings })
50 | (Geometry::Polygon { coordinates: rings }, Geometry::LineString { coordinates: line }) => {
51 linestring_intersects_polygon(line, rings)
52 }
53
54 // Polygon–Polygon: edge crossing or one inside the other.
55 (Geometry::Polygon { coordinates: ra }, Geometry::Polygon { coordinates: rb }) => {
56 polygons_intersect(ra, rb)
57 }
58
59 // Multi* types: any component intersects.
60 (Geometry::MultiPoint { coordinates }, other)
61 | (other, Geometry::MultiPoint { coordinates }) => coordinates
62 .iter()
63 .any(|pt| st_intersects(&Geometry::Point { coordinates: *pt }, other)),
64
65 (Geometry::MultiLineString { coordinates }, other)
66 | (other, Geometry::MultiLineString { coordinates }) => coordinates.iter().any(|ls| {
67 st_intersects(
68 &Geometry::LineString {
69 coordinates: ls.clone(),
70 },
71 other,
72 )
73 }),
74

Callers 5

spatial_prefilterFunction · 0.85
spatial_joinFunction · 0.85
st_disjointFunction · 0.85
st_intersectionFunction · 0.85
apply_predicateFunction · 0.85

Calls 9

geometry_bboxFunction · 0.85
point_on_ring_boundaryFunction · 0.85
point_intersects_polygonFunction · 0.85
linestrings_intersectFunction · 0.85
polygons_intersectFunction · 0.85
intersectsMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected