Skip to content

Commit

Permalink
Remove error from Envelope's TransformXY method
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Sep 15, 2023
1 parent 73e2723 commit 71e0813
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions geom/type_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,12 @@ func (e Envelope) Distance(o Envelope) (float64, bool) {
}

// TransformXY transforms this Envelope into another Envelope according to fn.
// TODO: remove the error here as well.
func (e Envelope) TransformXY(fn func(XY) XY) (Envelope, error) {
func (e Envelope) TransformXY(fn func(XY) XY) Envelope {
min, max, ok := e.MinMaxXYs()
if !ok {
return Envelope{}, nil
return Envelope{}
}
return NewEnvelope([]XY{fn(min), fn(max)})
return newUncheckedEnvelope(fn(min), fn(max))
}

// AsBox converts this Envelope to an rtree.Box.
Expand Down
6 changes: 2 additions & 4 deletions geom/type_envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@ func TestEnvelopeTransformXY(t *testing.T) {
{twoPtEnv(1, 2, 3, 4), twoPtEnv(1.5, 5, 4.5, 10)},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
got, err := tc.input.TransformXY(transform)
expectNoErr(t, err)
got := tc.input.TransformXY(transform)
expectEnvEq(t, got, tc.want)
})
}
Expand All @@ -577,10 +576,9 @@ func BenchmarkEnvelopeTransformXY(b *testing.B) {
input := twoPtEnv(1, 2, 3, 4)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := input.TransformXY(func(in XY) XY {
input.TransformXY(func(in XY) XY {
return XY{in.X * 1.5, in.Y * 2.5}
})
expectNoErr(b, err)
}
}

Expand Down

0 comments on commit 71e0813

Please sign in to comment.