Skip to content

Commit

Permalink
Merge e966c8c into d18f93b
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Oct 11, 2021
2 parents d18f93b + e966c8c commit f40be31
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

- Adds a new method `MinMaxXYs (XY, XY, bool)` to the `Envelope` type. The
first two return values are the minimum and maximum XY values in the
envelope, and the third return value indicates whether or not the first two
are defined (they are only defined for non-empty envelopes).

## v0.33.0

2021-10-11
Expand Down
5 changes: 2 additions & 3 deletions geom/alg_point_on_surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ func pointOnAreaSurface(poly Polygon) (Point, float64) {
}

// Create bisector.
envMin, minOK := env.Min().XY()
envMax, maxOK := env.Max().XY()
if !minOK || !maxOK {
envMin, envMax, ok := env.MinMaxXYs()
if !ok {
return Point{}, 0
}

Expand Down
11 changes: 11 additions & 0 deletions geom/type_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ func (e Envelope) Max() Point {
return e.max().asUncheckedPoint()
}

// MinMaxXYs returns the two XY values in the envelope that contain the minimum
// (first return value) and maximum (second return value) X and Y values in the
// envelope. The third return value is true if and only if the Envelope is
// non-empty and thus the first two return values are populated.
func (e Envelope) MinMaxXYs() (XY, XY, bool) {
if e.IsEmpty() {
return XY{}, XY{}, false
}
return e.min(), e.max(), true
}

// ExtendToIncludeXY returns the smallest envelope that contains all of the
// points in this envelope along with the provided point. It gives an error if
// the XY contains NaN or +/- Infinite coordinates.
Expand Down
13 changes: 13 additions & 0 deletions geom/type_envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ func TestEnvelopeAttributes(t *testing.T) {
t.Run("Max", func(t *testing.T) {
expectGeomEqWKT(t, tc.env.Max().AsGeometry(), tc.max)
})
t.Run("MinMaxXYs", func(t *testing.T) {
gotMin, gotMax, gotOK := tc.env.MinMaxXYs()
expectBoolEq(t, gotOK, !tc.isEmpty)
if gotOK {
wantMin, minOK := geomFromWKT(t, tc.min).AsPoint().XY()
expectTrue(t, minOK)
expectXYEq(t, gotMin, wantMin)

wantMax, maxOK := geomFromWKT(t, tc.max).AsPoint().XY()
expectTrue(t, maxOK)
expectXYEq(t, gotMax, wantMax)
}
})
t.Run("AsGeometry", func(t *testing.T) {
expectGeomEqWKT(t, tc.env.AsGeometry(), tc.geom, IgnoreOrder)
})
Expand Down

0 comments on commit f40be31

Please sign in to comment.