tins2020/point.go

41 lines
820 B
Go
Raw Normal View History

2020-05-08 16:38:26 +00:00
package tins2020
import "github.com/veandco/go-sdl2/sdl"
2020-05-08 16:38:26 +00:00
type Point struct {
sdl.Point
2020-05-08 16:38:26 +00:00
}
func (p Point) Add(q Point) Point { return Pt(p.X+q.X, p.Y+q.Y) }
func (p Point) In(r Rectangle) bool { return r.IsPointInsidePt(p) }
func (p Point) ToPtF() PointF { return PtF(float32(p.X), float32(p.Y)) }
type PointF struct {
sdl.FPoint
}
func (p PointF) Add(q PointF) PointF {
return PtF(p.X+q.X, p.Y+q.Y)
}
func (p PointF) Mul(f float32) PointF {
return PtF(f*p.X, f*p.Y)
}
func (p PointF) Sub(q PointF) PointF { return PtF(p.X-q.X, p.Y-q.Y) }
func Pt(x, y int32) Point { return Point{sdl.Point{X: x, Y: y}} }
func PtF(x, y float32) PointF { return PointF{sdl.FPoint{X: x, Y: y}} }
func PtPtr(x, y int32) *Point {
p := Pt(x, y)
return &p
}
func PtFPtr(x, y float32) *PointF {
p := PtF(x, y)
return &p
}