Skip to content

Registry-driven WKT CRS matching and coder/tile test coverage - #240

Closed
trasch wants to merge 1 commit into
add-epsg3395-epsg32662from
registry-driven-wkt
Closed

trasch wants to merge 1 commit into
add-epsg3395-epsg32662from
registry-driven-wkt

Conversation

@trasch

@trasch trasch commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of making the projection system generic. Stacks on #239 (phase 3: EPSG:3395/32662) — review/merge the chain in order. Completes the remaining phase 4 items; the WKB/WKT/TWKB coordinate-constructor simplification was already done in #239.

Registry-driven CRS matching

  • ProjectionDefinition gains wktMatchers: [[String]] — each inner list is one alternative fragment set, and every fragment of a set must be contained for the alternative to match. This preserves the previous A && (B || C) semantics exactly (e.g. "WGS 84" or "WGS_1984")
  • ProjectionRegistry.definition(matchingWkt:) probes definitions in registry order — specific patterns first (EPSG:3857 "Pseudo-Mercator" before EPSG:3395 "Mercator") — and Projection.init?(wkt:) now delegates to it
  • No more hand-written if/else chains: future projections register their WKT patterns in their own definition. noSRID registers no patterns and never matches

Test coverage

  • MapTile (already worked generically, tests added per review decision): tile bounding boxes in EPSG:3395/EPSG:32662 verified against manual reprojection of the EPSG:4326 bounds; centerCoordinate round trips. EPSG:32662 longitudes asserted as exactly linear (tile width = 360/2ᶻ)
  • Coders: WKT round trips with the SRID embedded in the string, TWKB decode fixtures for the new projections (TWKB is decode-only, no encoder exists)
  • ProjectionWktMatcherTests: 3857/3395 disambiguation, both geographic fragment alternatives, unrecognized strings (PROJCS["Something Else"], GEOGCS["ETRS89"] → nil)
  • Test files renamed per projection (Epsg3395Tests.swift, Epsg32662Tests.swift) so the names stay meaningful as projections accumulate

Behavior note (documented, unchanged behavior)

WKTCoder.decode(wkt:sourceSrid:targetProjection:) with an explicit sourceSrid does not consume an embedded SRID=...; prefix — decoding strings produced by WKTCoder.encode (which always writes the prefix) requires sourceSrid: nil so the SRID is detected from the string. Surfaced by the new round-trip tests.

Testing

Full suite: 2450 tests in 175 suites, zero warnings (+8 vs. phase 3).

Phase 4 of making the projection system generic: move WKT CRS
identification into the projection registry and round out test
coverage for the coder and MapTile paths.

- ProjectionDefinition gains wktMatchers: [[String]] - each inner
  list is an alternative fragment set, every fragment of one set
  must be contained for a match. This preserves the previous
  A && (B || C) semantics (e.g. "WGS 84" or "WGS_1984") exactly.
- ProjectionRegistry probes definitions in registry order
  (specific patterns first: EPSG:3857 "Pseudo-Mercator" before
  EPSG:3395 "Mercator"); Projection.init?(wkt:) now delegates to
  it. noSRID registers no patterns and never matches.
- MapTile tests: tile bounding boxes in EPSG:3395/EPSG:32662
  verified against manual reprojection of the EPSG:4326 bounds,
  plus centerCoordinate round trips (the generic pixel-projection
  path already handles the new projections).
- Coder tests: WKT round trips with SRID embedded in the string,
  TWKB decode fixtures for the new projections (decode-only API),
  and ProjectionWktMatcherTests covering the 3857/3395
  disambiguation, both geographic fragment alternatives and
  unrecognized strings (GEOGCS["ETRS89"] -> nil).
- Test rename: NewProjectionAlgorithmTests.swift split into
  projection-named files (Epsg3395Tests.swift, Epsg32662Tests.swift)
  so the names stay meaningful as more projections are added.

Behavior note: WKTCoder.decode with an explicit sourceSrid does not
consume an embedded "SRID=...;" prefix - decoders of strings
produced by WKTCoder.encode must use sourceSrid: nil so the SRID is
detected from the string.
@trasch

trasch commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #250, which consolidates the full projection-genericity chain into a single reviewable PR. All commits are unchanged in #250.

@trasch trasch closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant