You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: consolidate tests into test_api.py, document float64/float32 precision alignment in README
- Merge test_geometry.py, test_full_api.py, test_ops.py into single test_api.py
- Covers float64/float32, all geometry types (Point/LineString/Polygon/LinearRing)
- Covers all API: accessors, distance, predicates, relate, hausdorff, project, interpolate, centroid, buffer, intersection, nearest_points, serialization
- Document in README: float64 is bit-identical to Python shapely, float32 is NOT (Python shapely has no float32 mode, precision loss during widening)
Copy file name to clipboardExpand all lines: README.md
+22-2Lines changed: 22 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,25 @@ We created `shapelycpp` to keep Shapely's familiar API while letting C++ break t
15
15
16
16
`shapelycpp` is a **header-only C++ library** implementing shapely's core geometry API (`shapely.geometry.*`, `shapely.ops.*`) with pixel-level precision alignment. Template-based design supports both `float` and `double` coordinates. Powered by GEOS for robust computational geometry.
When using `Point<double>`, `LineString<double>`, `Polygon<double>` (the default), all geometry operations produce **bit-identical** results to Python shapely. This is guaranteed because:
23
+
24
+
- Both use the same GEOS engine (`geos::operation::distance::DistanceOp`, `Geometry::intersects()`, etc.).
25
+
- Python shapely calls `GEOSDistance_r()` (C API), which internally invokes the same `DistanceOp::distance()` as the C++ `shapelycpp`.
26
+
-`LinearRing` / `Polygon` / `LineString` constructors both populate `geos::geom::CoordinateSequence` via the same `Coordinate(x, y)` path.
27
+
28
+
### `float` (C++) ↔ Python shapely: NOT bit-identical
29
+
30
+
When using `Point<float>`, `LineString<float>`, `Polygon<float>`:
31
+
32
+
-**Python shapely has no `float32` mode.** All coordinates are automatically promoted to Python `float` (C `double`).
33
+
- The C++ `float` → `double` widening during `Coordinate` construction introduces precision loss (~7 significant digits for `float32` vs ~15 for `float64`).
34
+
- Results may differ from Python shapely by up to `1e-5` in relative/absolute terms for `float32`.
35
+
- Use `float` precision only when bit-identical alignment with Python shapely is NOT required (e.g., GPU-accelerated computation where `float32` throughput matters).
0 commit comments