1- // Internal GEOS utility functions shared across geometry types.
2- // NOT part of public API — do not include directly.
1+ // Python Source: shapely/geometry/base.py
2+ // Line Range: L146-L931 (class BaseGeometry + BaseMultipartGeometry)
3+ // Alignment: strict
4+ // EXEMPTION: cpp_internal_detail
5+ // Reason: C++ implements Python BaseGeometry methods as internal detail:: helpers.
6+ // Python shapely calls GEOS C API directly in BaseGeometry;
7+ // C++ wraps GEOS C++ API in shapely::detail namespace.
8+ // These helpers are not part of the public shapely::geometry API.
39
410#pragma once
511
@@ -23,12 +29,14 @@ namespace detail {
2329
2430// --- WKT / WKB serialization ------------------------------------------------
2531
32+ // Python: shapely/geometry/base.py::wkt:L369
2633inline std::string geos_to_wkt (const geos::geom::Geometry* g) {
2734 if (!g || g->isEmpty ()) return " GEOMETRYCOLLECTION EMPTY" ;
2835 geos::io::WKTWriter writer;
2936 return writer.write (g);
3037}
3138
39+ // Python: shapely/geometry/base.py::wkb_hex:L379
3240inline std::string geos_to_wkb_hex (const geos::geom::Geometry* g) {
3341 if (!g || g->isEmpty ()) return " " ;
3442 geos::io::WKBWriter writer;
@@ -39,104 +47,125 @@ inline std::string geos_to_wkb_hex(const geos::geom::Geometry* g) {
3947
4048// --- Predicates -------------------------------------------------------------
4149
50+ // Python: shapely/geometry/base.py::contains:L766
4251inline bool geos_contains (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
4352 if (!a || !b) return false ;
4453 return a->contains (b);
4554}
4655
56+ // Python: shapely/geometry/base.py::within:L813
4757inline bool geos_within (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
4858 if (!a || !b) return false ;
4959 return a->within (b);
5060}
5161
62+ // Python: shapely/geometry/base.py::crosses:L770
5263inline bool geos_crosses (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
5364 if (!a || !b) return false ;
5465 return a->crosses (b);
5566}
5667
68+ // Python: shapely/geometry/base.py::disjoint:L774
5769inline bool geos_disjoint (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
5870 if (!a || !b) return true ;
5971 return a->disjoint (b);
6072}
6173
74+ // Python: shapely/geometry/base.py::overlaps:L805
6275inline bool geos_overlaps (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
6376 if (!a || !b) return false ;
6477 return a->overlaps (b);
6578}
6679
80+ // Python: shapely/geometry/base.py::touches:L809
6781inline bool geos_touches (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
6882 if (!a || !b) return false ;
6983 return a->touches (b);
7084}
7185
86+ // Python: shapely/geometry/base.py::covers:L758
7287inline bool geos_covers (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
7388 if (!a || !b) return false ;
7489 return a->covers (b);
7590}
7691
92+ // Python: shapely/geometry/base.py::covered_by:L762
7793inline bool geos_covered_by (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
7894 if (!a || !b) return false ;
7995 return a->coveredBy (b);
8096}
8197
98+ // Python: shapely/geometry/base.py::equals:L778
8299inline bool geos_equals (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
83100 if (!a && !b) return true ;
84101 if (!a || !b) return false ;
85102 return a->equals (b);
86103}
87104
105+ // Python: shapely/geometry/base.py::equals_exact:L817
88106inline bool geos_equals_exact (const geos::geom::Geometry* a, const geos::geom::Geometry* b, double tol) {
89107 if (!a && !b) return true ;
90108 if (!a || !b) return false ;
91109 return a->equalsExact (b, tol);
92110}
93111
112+ // Python: shapely/geometry/base.py::relate:L753
94113inline std::string geos_relate (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
95114 if (!a || !b) return " " ;
96115 return a->relate (b)->toString ();
97116}
98117
118+ // Python: shapely/geometry/base.py::relate_pattern:L890
99119inline bool geos_relate_pattern (const geos::geom::Geometry* a, const geos::geom::Geometry* b, const std::string& pat) {
100120 if (!a || !b) return false ;
101121 return a->relate (b, pat);
102122}
103123
104124// --- Geometry property helpers ----------------------------------------------
105125
126+ // Python: shapely/geometry/base.py::geom_type:L426
106127inline std::string geos_geom_type (const geos::geom::Geometry* g) {
107128 if (!g) return " GeometryCollection" ;
108129 return g->getGeometryType ();
109130}
110131
132+ // Python: shapely/geometry/base.py::is_simple:L739
111133inline bool geos_is_simple (const geos::geom::Geometry* g) {
112134 return g && g->isSimple ();
113135}
114136
137+ // Python: shapely/geometry/base.py::is_valid:L745
115138inline bool geos_is_valid (const geos::geom::Geometry* g) {
116139 return g && g->isValid ();
117140}
118141
142+ // Python: shapely/geometry/base.py::is_empty:L714
119143inline bool geos_is_empty (const geos::geom::Geometry* g) {
120144 return !g || g->isEmpty ();
121145}
122146
147+ // Python: shapely/geometry/base.py::has_z:L708
123148inline int geos_has_z (const geos::geom::Geometry* g) {
124149 return g ? (g->getCoordinateDimension () > 2 ) : 0 ;
125150}
126151
152+ // Python: shapely/geometry/base.py::area:L434
127153inline double geos_area (const geos::geom::Geometry* g) {
128154 return g ? g->getArea () : 0.0 ;
129155}
130156
157+ // Python: shapely/geometry/base.py::length:L447
131158inline double geos_length (const geos::geom::Geometry* g) {
132159 return g ? g->getLength () : 0.0 ;
133160}
134161
162+ // Python: shapely/geometry/base.py::hausdorff_distance:L442
135163inline double geos_hausdorff_distance (const geos::geom::Geometry* a, const geos::geom::Geometry* b) {
136164 if (!a || !b) return 0.0 ;
137165 return geos::algorithm::distance::DiscreteHausdorffDistance (*a, *b).distance ();
138166}
139167
168+ // Python: shapely/geometry/base.py::bounds:L470
140169inline std::vector<double > geos_bounds (const geos::geom::Geometry* g) {
141170 if (!g || g->isEmpty ()) return {0 , 0 , 0 , 0 };
142171 const geos::geom::Envelope* env = g->getEnvelopeInternal ();
0 commit comments