Skip to content

Finish the NewEnvelopeXY constructor - #711

Merged
peterstace merged 3 commits into
masterfrom
710_EnvelopeXY
Aug 13, 2026
Merged

Finish the NewEnvelopeXY constructor#711
peterstace merged 3 commits into
masterfrom
710_EnvelopeXY

Conversation

@peterstace

Copy link
Copy Markdown
Owner

Description

NewEnvelopeXY is already on master. It landed as part of the test helper
consolidation in #707, which needed it for the envelope tests, and it went in
without the finishing that the rest of the XY constructor family has. So this
PR completes #710 by tidying up the existing function rather than adding it.

Two things about the constructor itself:

  • It sat between NewPolygonXYZM and NewSingleRingPolygonXY, separating the
    two halves of the Polygon block. It now sits after the geometry type
    constructors, since an Envelope isn't one of them.

  • Its doc comment didn't mention that the result is the smallest Envelope
    containing all of the coordinates, which the xys ...float64 signature
    doesn't convey. It was also missing the note about validation that every
    sibling constructor carries. Envelope has a Validate method, so the note
    applies here too.

The second commit uses the constructor where envelopes were being built from
literals:

  • The ClipByRect test cases each spelled out two XY literals with named
    fields per rectangle, which is the verbosity NewEnvelopeXY exists to avoid.

  • The TWKB bbox header and the zig zag ring benchmark had already computed their
    bounds as float64s, so they were wrapping them in XY values only to hand
    them to NewEnvelope.

Call sites that hold XY values already are left alone, including the
type_envelope tests that exercise NewEnvelope itself.

Check List

Have you:

  • Added unit tests? TestNewEnvelopeXY came in with Consolidate test helpers into internal/test package #707 and covers the
    no-argument, single pair, two point, reversed order, three point, and odd
    count panic cases. This change needed no new cases.

  • Add cmprefimpl tests? (if appropriate?) Not appropriate. There is no PostGIS
    or GEOS counterpart to compare a Go constructor against.

  • Updated release notes? (if appropriate?) Yes. The existing Unreleased entry
    is expanded to describe the coordinate ordering, the empty and point envelope
    cases, and the panic.

  • Updated the README.md (if new functionality is added?) Not appropriate. The
    README doesn't enumerate constructors.

Related Issue

Benchmark Results

Not applicable, so no benchmark run is included. The twkb_parser.go change
passes the same four float64s to NewEnvelopeXY instead of packing them into
two XY values first, and the remaining changes are in test and benchmark
setup.

NewEnvelopeXY landed early as part of the test helper consolidation in
#707, without the finishing that the rest of the XY constructor family
has.

Move it out of the middle of the Polygon block, where it separated
NewPolygonXYZM from NewSingleRingPolygonXY, to sit after the geometry
type constructors.

Document that the result is the smallest Envelope containing all of the
coordinates, which the variadic signature doesn't convey, and add the
note about validation that every sibling constructor carries. Envelope
has a Validate method, so the note applies here too.

Closes #710
The ClipByRect test cases spelled out two XY literals with named fields
for each rectangle, which is the verbosity NewEnvelopeXY exists to
avoid. The TWKB bbox header and the zig zag ring benchmark had already
computed their bounds as float64s, so they were wrapping them in XY
values only to hand them to NewEnvelope.

Call sites that hold XY values already, such as the type_envelope tests
that exercise NewEnvelope itself, are left alone.
@peterstace peterstace self-assigned this Aug 12, 2026
"Joins the other XY constructors" could be read as joining or combining
data, which is a plausible meaning in a geometry library. Say that the
constructor follows the same convention instead.
@peterstace
peterstace merged commit c4e4515 into master Aug 13, 2026
1 check passed
@peterstace
peterstace deleted the 710_EnvelopeXY branch August 13, 2026 01:14
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.

Add a NewEnvelopeXY constructor

1 participant