Skip to content

Commit b7cc2ad

Browse files
author
peng.li24
committed
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)
1 parent 3d9769f commit b7cc2ad

5 files changed

Lines changed: 1031 additions & 1037 deletions

File tree

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ We created `shapelycpp` to keep Shapely's familiar API while letting C++ break t
1515

1616
`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.
1717

18+
## Precision Alignment
19+
20+
### `double` (C++) ↔ Python shapely: Bit-identical
21+
22+
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).
36+
1837
## Quick Start
1938

2039
### Dependencies
@@ -83,8 +102,9 @@ shapelycpp/
83102
│ └── main.cpp
84103
├── tests/ # Python precision alignment tests
85104
│ ├── module.cpp # pybind11 test module
86-
│ ├── test_geometry.py
87-
│ └── test_ops.py
105+
│ ├── conftest.py # pytest fixtures (float64/float32 make, CppFactory)
106+
│ ├── utils.py # coordinate generators & comparison helpers
107+
│ └── test_api.py # unified precision alignment tests (float64/float32)
88108
├── CMakeLists.txt # build & .deb packaging
89109
└── README.md
90110
```

0 commit comments

Comments
 (0)