Skip to content

Commit 4a2ab4d

Browse files
author
peng.li24
committed
refactor: merge linearring.h into polygon.h, move geos_utils.h to base.h
- LinearRing class (polygon.py L23-L107) now lives alongside Polygon in polygon.h - detail:: helpers moved from shapely/detail/geos_utils.h to shapely/geometry/base.h - Aligns with Python shapely source: base.py BaseGeometry, polygon.py LinearRing+Polygon - All 142 tests pass
1 parent 7e88739 commit 4a2ab4d

7 files changed

Lines changed: 286 additions & 195 deletions

File tree

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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
2633
inline 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
3240
inline 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
4251
inline 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
4757
inline 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
5263
inline 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
5769
inline 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
6275
inline 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
6781
inline 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
7287
inline 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
7793
inline 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
8299
inline 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
88106
inline 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
94113
inline 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
99119
inline 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
106127
inline 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
111133
inline 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
115138
inline 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
119143
inline 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
123148
inline 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
127153
inline 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
131158
inline 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
135163
inline 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
140169
inline 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();

shapely/geometry/linearring.h

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)