chore: correct hemisphere letter for negative coords in demo#2027
Merged
Conversation
Rewrite formatDegrees without the in-expression param mutation and the `0 | x` floor hacks. The mutation reassigned `degrees` to its absolute value before getDirection ran, so negative coordinates always rendered as E/N. Passing the original signed value fixes the direction (W/S). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleans up
formatDegreesin the demo and fixes a latent bug it was hiding.The old one-liner mutated its parameter mid-expression (
degrees = -degrees) to take the absolute value for the minutes calc. BecausegetDirection(degrees, …)is evaluated last in the template string, it saw the already-mutated (positive) value — so every negative coordinate rendered E/N regardless of hemisphere.Rewritten with
Math.abs/Math.trunc/Math.floor(no mutation, no0 | xfloor hacks) andgetDirectionnow receives the original signed value.Effect
Degrees/minutes/seconds are byte-for-byte identical (verified across positive and negative samples). Only the direction letter changes — and only for negatives, where it was wrong:
-122.6789(lon)-122° 40' 44" E❌-122° 40' 44" W✅-20.123(lat)-20° 7' 22" N❌-20° 7' 22" S✅Verification
npm run docs:build→ cleannpm test→ 4/4 pass🤖 Generated with Claude Code