geom icon indicating copy to clipboard operation
geom copied to clipboard

Function for constructing a valid Rect

Open ffigiel opened this issue 7 years ago • 2 comments

I think this library should have a bulletproof Rect constructor, similar to image.Rect

ffigiel avatar Jan 27 '18 13:01 ffigiel

Example:

func NewRect(x0, y0, x1, y1 float64) (r Rect) {
       if x0 > x1 {
               x0, x1 = x1, x0
       }
       if y0 > y1 {
               y0, y1 = y1, y0
       }
       r.Min.X = x0
       r.Min.Y = y0
       r.Max.X = x1
       r.Max.Y = y1
       return
}

ffigiel avatar Jan 27 '18 13:01 ffigiel

For the image package I think that makes sense because the rects only represent things where it doesn't make sense to have reversed coordinates.

I'm not certain that geom should have that restriction. I admit I can't think of a useful case right now but I'm hesitant to add constraints without a really good reason.

On Jan 27, 2018 8:49 AM, "Filip Figiel" [email protected] wrote:

Example: ```go func NewRect(x0, y0, x1, y1 float64) (r Rect) { if x0 > x1 { x0, x1 = x1, x0 } if y0 > y1 { y0, y1 = y1, y0 } r.Min.X = x0 r.Min.Y = y0 r.Max.X = x1 r.Max.Y = y1 return }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/skelterjohn/geom/issues/2#issuecomment-360986085, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUZ1htyXGsYG78XFzBygEgtj-_auAMuks5tOylpgaJpZM4RvTAt .

skelterjohn avatar Jan 27 '18 14:01 skelterjohn