geom/rectanglef.go

33 lines
686 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)}
}
// Dx returns the width of r.
func (r RectangleF) Dx() float64 {
return r.Max.X - r.Min.X
}
// Dy returns the height of r.
func (r RectangleF) Dy() float64 {
return r.Max.Y - r.Min.Y
}
// Size returns the size of the rectangle.
func (r RectangleF) Size() PointF {
return PointF{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
}