Skip to content

feat(geojson): encode Polygon geometries and validate ring orientation - #22

Merged
Alexandre-T merged 1 commit into
mainfrom
feat/13-geojson-polygon
Sep 21, 2026
Merged

Alexandre-T merged 1 commit into
mainfrom
feat/13-geojson-polygon

Conversation

@Alexandre-T

Copy link
Copy Markdown
Contributor

Closes #13.

GeoJsonStrategy now encodes Geometry and Geography Polygons in XY/XYZ, including EMPTY, preserving rings, positions, Z and coordinates without reference metadata. For example, [[[0,0],[2,0],[0,2],[0,0]]] produces {"type":"Polygon","coordinates":[[[0,0],[2,0],[0,2],[0,0]]]}. XYM/XYZM remain rejected, including EMPTY.

Every ring is checked using signed XY area: exterior area must be positive, interior area negative, and zero area raises UnsupportedGeometryStructureException. This implements the approved normative decision for RFC 7946 section 3.1.6. Rings are never repaired or reversed. No separate simplicity/self-intersection validation is added; general topology remains the caller's responsibility. Antimeridian coordinates are unchanged, with the deliberate non-application of RFC 7946 section 3.1.9 and interoperability implications documented.

An internal GeoJson/GeometryEncoder now contains the geometry dispatch and private encoding methods. This necessary extraction keeps the existing PHPMD coupling threshold satisfied without weakening rules. GeoJsonStrategy retains dimension checks and JSON exception wrapping. Existing public APIs, exceptions and other strategy behavior remain unchanged; no breaking changes or dependency changes.

Added 36 explicit Polygon examples across both families plus Polygon interface and JSON-failure tests (38 new tests total). Existing GeoJSON tests only gain coverage metadata for the internal extraction. Updated docs/strategies.md and tests/README.md with usage, EMPTY, dimensions, caller responsibilities, invariant findings and the approved policy.

Validation:

  • vendor/bin/phpunit --no-coverage --filter GeoJson: 194 tests, 656 assertions passed before the internal extraction.
  • composer test: final code passes 914 tests, 1428 assertions with PCOV.
  • composer quality: PHP CS Fixer, PHPStan level 9, PHPMD and PHPCS pass. Existing PHPMD/PDepend dependency deprecation messages remain non-fatal.
  • git diff --cached --check: passed.

The normative gate is resolved by the linked approval; no unresolved implementation gate. Signed-area checks are not a general topology validator. No reviewer has been launched or requested, per Alexandre's instruction. Independent review and merge remain outstanding; the Story is not declared Done.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (745a906) to head (b15225f).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #22   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       161       173   +12     
===========================================
  Files             14        15    +1     
  Lines            296       317   +21     
===========================================
+ Hits             296       317   +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Alexandre-T
Alexandre-T merged commit 9ae1e3c into main Sep 21, 2026
3 checks passed
@Alexandre-T
Alexandre-T deleted the feat/13-geojson-polygon branch September 21, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Story: Encode Polygon geometries and validate ring orientation

2 participants