Repository navigation
Respect the stride parameter in deflateCoordinate - #17614
Conversation
fallenmi
left a comment
There was a problem hiding this comment.
The stride clamp fixes the layout inconsistency without regressing supported empty coordinates. With the identical public-API oracle on exact base d2d35d7d, reducing a Point from XYZ to XY left [1, 2, 3], and the same over-length center made a radius-5 Circle report 4.47213595499958. Exact head 0d367d050 returns [1, 2], preserves radius 5, and leaves both empty and shorter-than-stride coordinates at their existing lengths.
I also checked both callers' truncation behavior and a nonzero-offset deflateCoordinate case. The exact head passes the focused Point/Circle/deflate tests (74/74), the full node suite (2,229/2,229), the browser suite (3,063/3,063), TypeScript typecheck, and diff check. The accepted issue contract and sibling deflateCoordinates behavior match this change. There are currently no published GitHub check runs on the PR head; I did not run the rendering image-comparison suite locally.
Reviewed with OpenAI Codex assistance; I reproduced the exact base/head behavior and ran the suites above locally.
|
📦 Preview the website for this branch here: https://deploy-preview-17614--ol-site.netlify.app/. |
codeCraft-Ritik
left a comment
There was a problem hiding this comment.
Very thorough and well-documented fix!
Catching the edge case where deflateCoordinates would pad undefined on empty coordinates was a great catch. The solution with Math.min is clean and elegant.
There was a problem hiding this comment.
@ethanstoner Thanks for the fix. Please take the time to look at other commits and pull requests in this repository to align yours with the culture of the project (one-line commit messages, keep source code comments short if they are necessary; avoid them if the code speaks for itself).
Short but precise pull request descriptions are what maintainers rely on for reviewing your code, and what's important when someone needs to understand why a change was made, even years after it was made.
Most obvious example: Text like this is not helpful — that's the least you should remove when you let an AI write pull request descriptions.
PR: Respect the stride parameter in deflateCoordinate
Title: Respect the stride parameter in deflateCoordinate
Base: openlayers/openlayers:main
Head: ethanstoner:fix-deflate-coordinate-strideThe repo's .github/PULL_REQUEST_TEMPLATE.md is comment-only (a checklist for the author, no
fields to fill in), so the body below is free-form and follows the template's guidance: reference
the issue, keep commits small and clear, cover the fix with regression tests.Body
Ideally, you'd go over the pull request description yourself. Ask yourself what a maintainer needs to know, and write it accordingly.
That said, please improve the pull request (both code and description) according to my comment, then ask for another review.
Note to @codeCraft-Ritik and @fallenmi: before posting a comment on a pull request, please ask yourself if the text of you have in mind is useful for the topic. Useful comments include reports about the pull request having fixed the underlying issue in your application, or additional observations that might help improve the pull request.
0d367d0 to
abc8f57
Compare
|
Done. The commit is one line, the source comment is gone, and the description is rewritten. You're right about the description — the header block you quoted was scaffolding that should never have been in there, and the rest was longer than a reviewer needs. The new one states the defect, the two affected callers, and why the clamp is |
| */ | ||
| export function deflateCoordinate(flatCoordinates, offset, coordinate, stride) { | ||
| for (let i = 0, ii = coordinate.length; i < ii; ++i) { | ||
| const ii = Math.min(coordinate.length, stride); |
There was a problem hiding this comment.
Why math.min? According to how the other deflate functions work, the correct for-loop would be
for (let i = 0; i < stride; ++i) {There was a problem hiding this comment.
I tried that first. It fails two tests that are already on main, in a file this branch doesn't touch:
FAIL test/node/ol/format/GeoJSON.test.js > #readGeometry > works with empty coordinate array
AssertionError: expected [ undefined, undefined ] to deeply equal []
FAIL test/node/ol/format/GeoJSON.test.js > #readGeometry > works with empty coordinate array and reprojection
AssertionError: expected [ NaN, NaN ] to deeply equal []
test/node/ol/format/GeoJSON.test.js:596 and :615.
You're right that {"type": "Point", "coordinates": []} isn't valid GeoJSON. The clamp isn't there to defend the spec, it's there because the reader accepts that input today and those two tests assert what it produces. With i < stride it writes undefined into the flat coordinates instead.
So it's your call which behaviour you want:
- keep
Math.min, and no existing test changes - use
i < stride, and update those two tests to match, treating an empty position as unsupported
Happy to push 2 if that's the direction. I didn't want to change how the GeoJSON reader handles that input without asking first.
There was a problem hiding this comment.
Neither 1 nor 2, but closer to 2 — see my comment below.
There was a problem hiding this comment.
Changed to for (let i = 0; i < stride; ++i).
The two GeoJSON tests for empty coordinate arrays fail on this branch, as you said to expect. Rest of the node suite is green: 2226 passed, 2 failed.
|
|
||
| it('does not pad a coordinate shorter than the stride', function () { | ||
| const offset = deflateCoordinate(flatCoordinates, 0, [], 2); | ||
| assert.strictEqual(offset, 0); | ||
| assert.deepEqual(flatCoordinates, []); | ||
| }); |
There was a problem hiding this comment.
[] is not a valid coordinate, so this test case can be removed.
There was a problem hiding this comment.
That case covers the clamp, so it goes if the clamp goes.
Answered in the other thread: removing the clamp also breaks two existing GeoJSON reader tests on main, so it's a behaviour decision rather than just dropping a test case. Tell me which way you want it and I'll push it.
According to the GeoJSON spec:
and
So
But we don't need to fail on empty coordinates; we can return a |
abc8f57 to
f85320f
Compare
|
Description rewritten. The scaffolding text at the top is gone, and what is left is the issue reference, what the bug is, the reproduction, and what the tests cover. Code now matches your suggestion: the loop bounds on |
|
@ethanstoner Please make sure that prettier does not report any errors: |
f85320f to
438d7a8
Compare
|
Prettier is clean now, thanks for catching it. That blank line was left over from removing the Current CI on this branch: Pre-Test, Build, Browser, Rendering and CodeQL all pass. Node is 2228 passed / 2 failed, and the 2 are the Ready for another look whenever suits. |
5fd6ad5 to
958c4cb
Compare
ahocevar
left a comment
There was a problem hiding this comment.
Thanks, @ethanstoner. Rebased.
Fixes #15754.
deflateCoordinatetakes astridebut loops overcoordinate.length, so a coordinate with more ordinates than the layout allows writes the extras into the flat coordinates. Its callers arePoint#setCoordinatesandCircle#setCenterAndRadius, which are then left with astrideandlayoutthat no longer describe their own data.Circlealso reports a wrong radius and extent, becausesetCenterAndRadiuswrites the radius at the offset the deflate returned.Tests cover
deflateCoordinatedirectly and thePoint#setCoordinatescase.The two
GeoJSONtests for empty coordinate arrays fail on this branch, as expected, and #17615 fixes them.