Skip to content

[GH-3592] Stop envelope polygons from sharing their closing coordinate - #3593

Merged
jiayuasu merged 1 commit into
apache:masterfrom
vera-rubin:fix/envelope-closing-coordinate
Nov 27, 2026
Merged

jiayuasu merged 1 commit into
apache:masterfrom
vera-rubin:fix/envelope-closing-coordinate

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Constructors.polygonFromEnvelope (used by ST_MakeEnvelope, ST_PolygonFromEnvelope and the 2D ST_Expand) put the same Coordinate object at the first and the last position of the ring. Functions that edit coordinates in place then move that point twice. translate(makeEnvelope(0, 0, 2, 1), 10, 20) returns POLYGON ((20 40, 10 21, 12 21, 12 20, 20 40)) with area 23 instead of POLYGON ((10 20, 10 21, 12 21, 12 20, 10 20)) with area 2; affine and flipCoordinates are hit the same way.

The closing point is now a copy of the first coordinate.

How was this patch tested?

Added ConstructorsTest.envelopeCoordinatesAreEditedOnce, which checks translate, affine (with an SRID) and flipCoordinates on envelope polygons. It fails without the fix (POLYGON ((20 40, 10 21, 12 21, 12 20, 20 40))) and passes with it.

mvn -pl common -am test -Dtest='FunctionsTest,ConstructorsTest' passes (416 tests), and mvn -pl common spotless:check is clean.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

Nathan, ChipLab

polygonFromEnvelope used the same Coordinate object for the first and
the last point of the ring. Functions that edit coordinates in place,
such as translate, affine and flipCoordinates, then changed that point
twice: translate(makeEnvelope(0, 0, 2, 1), 10, 20) returned
POLYGON ((20 40, 10 21, 12 21, 12 20, 20 40)) with area 23 instead of
POLYGON ((10 20, 10 21, 12 21, 12 20, 10 20)) with area 2.

Use a copy of the first coordinate as the closing point.
@vera-rubin
vera-rubin requested a review from jiayuasu as a code owner November 26, 2026 09:14
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 27, 2026

@jiayuasu jiayuasu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jiayuasu
jiayuasu merged commit 81f292f into apache:master Nov 27, 2026
@jiayuasu

Copy link
Copy Markdown
Member

@vera-rubin, would you be willing to fix the same issue in 3D ST_Expand in a follow-up PR? It builds its own ring and still uses the first Coordinate object to close it. 3D ring construction

I reproduced it by expanding POINT Z (2 4 8) by (1, 2, 3) and then translating by (10, 20, 2). The first corner starts at (1, 2, 5) and should land at (11, 22, 7). It moves twice and lands at (21, 42, 9), changing the polygon’s XY area from 8 to 32. The same coordinate copy you used here should fix it. This example would make a good regression test.

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.

Envelope polygons share their closing coordinate, so ST_Translate/ST_Affine/ST_FlipCoordinates move it twice

2 participants