Added Union for Rectangle{,F,F32}.
This commit is contained in:
parent
d1c3f6619b
commit
885f27689f
@ -1,5 +1,7 @@
|
||||
package geom
|
||||
|
||||
import "opslag.de/schobers/geom/ints"
|
||||
|
||||
// Rectangle represents a 2-dimensional surface with as boundaries Min (inclusive) and Max (exclusive).
|
||||
type Rectangle struct {
|
||||
Min, Max Point
|
||||
@ -57,3 +59,8 @@ func (r Rectangle) ToF() RectangleF { return RectangleF{Min: r.Min.ToF(), Max: r
|
||||
|
||||
// ToF32 returns the floating point representation of r.
|
||||
func (r Rectangle) ToF32() RectangleF32 { return RectangleF32{Min: r.Min.ToF32(), Max: r.Max.ToF32()} }
|
||||
|
||||
// Union gives back the union of the two rectangles.
|
||||
func (r Rectangle) Union(s Rectangle) Rectangle {
|
||||
return Rect(ints.Min(r.Min.X, s.Min.X), ints.Min(r.Min.Y, s.Min.Y), ints.Max(r.Max.X, s.Max.X), ints.Max(r.Max.Y, s.Max.Y))
|
||||
}
|
||||
|
@ -83,3 +83,8 @@ func (r RectangleF) ToF32() RectangleF32 { return RectangleF32{Min: r.Min.ToF32(
|
||||
|
||||
// ToInt returns the integer point representation of r.
|
||||
func (r RectangleF) ToInt() Rectangle { return Rectangle{Min: r.Min.ToInt(), Max: r.Max.ToInt()} }
|
||||
|
||||
// Union gives back the union of the two rectangles.
|
||||
func (r RectangleF) Union(s RectangleF) RectangleF {
|
||||
return RectF(Min(r.Min.X, s.Min.X), Min(r.Min.Y, s.Min.Y), Max(r.Max.X, s.Max.X), Max(r.Max.Y, s.Max.Y))
|
||||
}
|
||||
|
@ -83,3 +83,8 @@ func (r RectangleF32) ToInt() Rectangle { return Rectangle{Min: r.Min.ToInt(), M
|
||||
|
||||
// ToF returns the floating point representation of r.
|
||||
func (r RectangleF32) ToF() RectangleF { return RectangleF{Min: r.Min.ToF(), Max: r.Max.ToF()} }
|
||||
|
||||
// Union gives back the union of the two rectangles.
|
||||
func (r RectangleF32) Union(s RectangleF32) RectangleF32 {
|
||||
return RectF32(Min32(r.Min.X, s.Min.X), Min32(r.Min.Y, s.Min.Y), Max32(r.Max.X, s.Max.X), Max32(r.Max.Y, s.Max.Y))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user