Skip to content

Add EPSG:3395 and EPSG:32662 projections - #239

Closed
trasch wants to merge 1 commit into
generic-projection-registryfrom
add-epsg3395-epsg32662
Closed

trasch wants to merge 1 commit into
generic-projection-registryfrom
add-epsg3395-epsg32662

Conversation

@trasch

@trasch trasch commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 3 of making the projection system generic. Stacks on #238 (phase 2: ProjectionDefinition registry) — review/merge that one first.

Adds two new WGS84 projections to prove the registry architecture makes new projections cheap to add.

New projections

EPSG:3395 — WGS 84 / World Mercator (ellipsoidal)

  • Snyder ellipsoidal Mercator forward formulas; iterative inverse solving the conformal latitude
  • Unlike EPSG:3857 (spherical formulas), y values differ away from the equator; identical at the equator
  • Wraps at ±originShift like EPSG:3857; valid y extent is the EPSG-registered bound of ±20_048_966.104014604

EPSG:32662 — WGS 84 / Plate Carree

  • Identity: longitude/latitude used directly as x/y in degrees
  • Wraps at ±180°

Registration

  • Projection enum cases with raw SRID values, init?(srid:) entries, description
  • WKT patterns: "Pseudo-Mercator" → 3857 vs. "Mercator" → 3395 now disambiguated; "Plate Carree" → 32662
  • ProjectionKind.planar, wraparound extents via the existing capability API

What this proved

Adding two projections touched only: the enum, two definition structs, the registry, and tests. All algorithms, BoundingBox, MapTile and pixel conversions picked them up automatically through the Phase 1/2 abstractions.

Coder simplification (early phase 4 work)

The WKB/WKT/TWKB coordinate constructors had per-projection nested switches; collapsed into one generic expression (Coordinate3D(x:y:) + projected(to:)). Behavior-identical for all existing cases; new projections now decode/encode correctly with embedded SRIDs.

Testing

  • Conversion values computed independently with the Snyder formulas (including explicit sign verification of the inverse, after catching a conformal-latitude sign error during development)
  • Round trips across all five projections, antimeridian cutting in 3395/32662, distance/boundingBox/contains, normalize/clamp, destination/bearing via the EPSG:4326 pivot, WKB round trips
  • Full suite: 2442 tests in 174 suites, zero warnings

Phase 3 of making the projection system generic: prove the registry
architecture by adding two new WGS84 projections.

- EPSG:3395 (WGS 84 / World Mercator): ellipsoidal Mercator with
  Snyder forward formulas and an iterative inverse (the conformal
  latitude iteration). Wraps at ±originShift like EPSG:3857, but y
  values differ away from the equator. Valid y extent is the
  EPSG-registered bound of ±20_048_966.104014604.
- EPSG:32662 (WGS 84 / Plate Carree): identity x/y in degrees,
  wraps at ±180°.

Both are registered with SRID lookup, description, WKT patterns
("Pseudo-Mercator" vs. "Mercator" now disambiguated between 3857
and 3395), planar ProjectionKind and wraparound extents. All
algorithms, BoundingBox, MapTile and the pixel conversions pick
them up automatically through the ProjectionKind/registry
abstractions - no per-algorithm changes needed.

The WKB/WKT/TWKB coordinate constructors collapsed their per-
projection nested switches into one generic expression (behavior-
identical for all existing cases); new projections now decode and
encode correctly with embedded SRIDs.

Tests: conversion values computed independently with the Snyder
formulas, round trips across all five projections, antimeridian
cutting, distance/boundingBox/contains, normalize/clamp,
destination/bearing via the EPSG:4326 pivot, and WKB round trips
in the new projections.
@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