geom/rectanglef.go
Sander Schobers 26bac636bc Initial version of the geom package
- Includes PointF, RectangleF and PolygonF. Additional it includes the 32 bit floating point PointF32 and wrappers to image.Point and image.Rectangle.
2017-11-01 06:51:41 +01:00

23 lines
490 B
Go

package geom
// RectangleF is defined by two points, the minimum and maximum (floating point).
type RectangleF struct {
Min, Max PointF
}
// RectF is a shorthand function to create a rectangle.
func RectF(x0, y0, x1, y1 float64) RectangleF {
if x0 > x1 {
x0, x1 = x1, x0
}
if y0 > y1 {
y0, y1 = y1, y0
}
return RectangleF{PtF(x0, y0), PtF(x1, y1)}
}
// Size returns the size of the rectangle.
func (r RectangleF) Size() PointF {
return PtF(r.Max.X-r.Min.X, r.Max.Y-r.Min.Y)
}