Skip to content

Fix inverted coordinate conversion in test_top_bottom_point - #108

Merged
lispandfound merged 1 commit into
mainfrom
fix/95-test-point-coordinate-conversion
Sep 9, 2026
Merged

Fix inverted coordinate conversion in test_top_bottom_point#108
lispandfound merged 1 commit into
mainfrom
fix/95-test-point-coordinate-conversion

Conversation

@lispandfound

Copy link
Copy Markdown
Contributor

Fixes #95

Problem

test_top_bottom_point ran the coordinate conversion backwards:

# before
point = Point(
    coordinates.nztm_to_wgs_depth(np.array([-43.0, 172.0, 1000.0])),
    ...
)

Point.bounds is documented as NZTM (sources.py:37-38) and Point.from_lat_lon_depth builds it with coordinates.wgs_depth_to_nztm(...). The literal here is already a WGS lat/lon, so applying nztm_to_wgs_depth to it produces neither valid NZTM nor the intended location:

intended location           : [ -43.  172. 1000.]
old form, point.coordinates : [ -75.81  82.93 1000.]     <- not in New Zealand
fixed,    point.coordinates : [ -43.  172. 1000.]

Why it passed anyway

The test only asserts on point.top_m and point.bottom_m, which depend solely on the depth component — and nztm_to_wgs_depth passes depth through untouched. top_m/bottom_m are byte-identical either way, so the assertions were satisfied no matter how wrong the horizontal position was. The test did not exercise what it appeared to, and the construction is the kind of thing that gets copied into a test that does use the horizontal position.

Changes

  • Use coordinates.wgs_depth_to_nztm(...).
  • Add assert np.allclose(point.coordinates, point_coordinates) so the horizontal components are actually pinned down.

Verification

  • pytest tests/test_sources.py — 64 passed.
  • The new round-trip assertion fails with the old construction, confirming it is not vacuous.
  • ruff check, ruff format clean.

🤖 Generated with Claude Code

Point.bounds is NZTM, but the test built it with nztm_to_wgs_depth applied
to a value that is already a WGS lat/lon, running the conversion
backwards. The resulting point sat at (-75.8, 82.9) rather than
(-43.0, 172.0).

The test still passed because it only asserts on top_m and bottom_m,
which depend solely on the depth component, and nztm_to_wgs_depth leaves
depth untouched. Adds a round-trip assertion on point.coordinates so the
horizontal components are actually checked.

Fixes #95

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lispandfound
lispandfound merged commit 2a9f05a into main Sep 9, 2026
7 checks passed
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.

tests/test_sources.py: test_top_bottom_point converts coordinates in the wrong direction

1 participant