2020-05-10 10:21:51 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import "github.com/veandco/go-sdl2/sdl"
|
|
|
|
|
|
|
|
type Rectangle struct {
|
|
|
|
sdl.Rect
|
|
|
|
}
|
|
|
|
|
|
|
|
func Rect(x1, y1, x2, y2 int32) Rectangle {
|
|
|
|
if x1 > x2 {
|
|
|
|
x1, x2 = x2, x1
|
|
|
|
}
|
|
|
|
if y1 > y2 {
|
|
|
|
y1, y2 = y2, y1
|
|
|
|
}
|
|
|
|
return Rectangle{sdl.Rect{X: x1, Y: y1, W: x2 - x1, H: y2 - y1}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RectSize(x, y, w, h int32) Rectangle { return Rectangle{sdl.Rect{X: x, Y: y, W: w, H: h}} }
|
|
|
|
|
2020-05-10 15:16:18 +00:00
|
|
|
func (r Rectangle) Bottom() int32 { return r.Y + r.H }
|
|
|
|
|
|
|
|
func (r Rectangle) IsPointInside(x, y int32) bool {
|
|
|
|
return x >= r.X && x < r.X+r.W && y >= r.Y && y < r.Y+r.H
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Rectangle) IsPointInsidePt(p Point) bool { return r.IsPointInside(p.X, p.Y) }
|
|
|
|
|
|
|
|
func (r Rectangle) Right() int32 { return r.X + r.W }
|
|
|
|
|
2020-05-10 10:21:51 +00:00
|
|
|
func (r Rectangle) SDL() sdl.Rect { return r.Rect }
|
|
|
|
func (r Rectangle) SDLPtr() *sdl.Rect { return &r.Rect }
|