2017-11-01 05:51:41 +00:00
|
|
|
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)}
|
|
|
|
}
|
|
|
|
|
2017-11-01 10:24:33 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2017-11-01 05:51:41 +00:00
|
|
|
// Size returns the size of the rectangle.
|
|
|
|
func (r RectangleF) Size() PointF {
|
2017-11-01 10:24:33 +00:00
|
|
|
return PointF{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
|
2017-11-01 05:51:41 +00:00
|
|
|
}
|