Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
MinMaxXYs
method to the Envelope
type
The following pattern was frequently employed by users of the library: envMin, minOK := env.Min().XY() envMax, maxOK := env.Max().XY() if !minOK || !maxOK { // envelope is empty, special handling } // finally do something with envMin and envMax This works, but has some downsides: - There is a lot of "min"/"max" stutter in the first three lines. - It feels a little more verbose than it could be. - It can be easy for subtle bugs to occur if the mins and maxes don't all line up (e.g. min is used in place of max in a single place). - The predicate in the if statement is awkward because `minOK` and `maxOK` should always have the same value. It doesn't feel right to ignore one of them though due to the asymmetry. ORing them together isn't quite correct either, since it might imply that they could be different. ANDing them together also implies that they might be different too. The problem is that there are 2 sources of truth for one logical boolean value. The new method changes this pattern to: envMin, envMax, ok := env.MinMaxXYs() if !ok { // envelope is empty, special handling } // finally do something with envMin and envMax There's still a _tiny_ bit of stutter between `envMin`, `envMax`, and `MinMaxXYs`, but there's less chance for bugs to slip in. It's one line shorter, and there are less variables overall, and there is just one boolean so the if statement is much simpler.
- Loading branch information