Added PointF{,32}.ToInt that converts the point to a Point.
Added Point.In(Rectangle).
This commit is contained in:
parent
17af2eb843
commit
18bac571b8
8
point.go
8
point.go
@ -64,6 +64,14 @@ func (p Point) DistInt(q Point) int {
|
|||||||
return ints.SubAbs(p.X, q.X) + ints.SubAbs(p.Y, q.Y)
|
return ints.SubAbs(p.X, q.X) + ints.SubAbs(p.Y, q.Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In tests if the point p is inside the rectangle r.
|
||||||
|
func (p Point) In(r Rectangle) bool {
|
||||||
|
if p.X < r.Min.X || p.X >= r.Max.X || p.Y < r.Min.Y || p.Y >= r.Max.Y {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Less returns true if q is above (Y is smaller) or left (X is smaller) than p. Otherwise returns false.
|
// Less returns true if q is above (Y is smaller) or left (X is smaller) than p. Otherwise returns false.
|
||||||
func (p Point) Less(q Point) bool {
|
func (p Point) Less(q Point) bool {
|
||||||
if p.Y == q.Y {
|
if p.Y == q.Y {
|
||||||
|
@ -147,6 +147,11 @@ func (p PointF) To32() PointF32 {
|
|||||||
return PointF32{float32(p.X), float32(p.Y)}
|
return PointF32{float32(p.X), float32(p.Y)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToInt transforms the point p into a Point.
|
||||||
|
func (p PointF) ToInt() Point {
|
||||||
|
return Point{int(p.X), int(p.Y)}
|
||||||
|
}
|
||||||
|
|
||||||
// MaxPtF returns the point that is at the largest X & Y position of a and b.
|
// MaxPtF returns the point that is at the largest X & Y position of a and b.
|
||||||
func MaxPtF(a, b PointF) PointF {
|
func MaxPtF(a, b PointF) PointF {
|
||||||
return PtF(Max(a.X, b.X), Max(a.Y, b.Y))
|
return PtF(Max(a.X, b.X), Max(a.Y, b.Y))
|
||||||
|
@ -147,6 +147,11 @@ func (p PointF32) To64() PointF {
|
|||||||
return PointF{float64(p.X), float64(p.Y)}
|
return PointF{float64(p.X), float64(p.Y)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToInt transforms the point p into a Point.
|
||||||
|
func (p PointF32) ToInt() Point {
|
||||||
|
return Point{int(p.X), int(p.Y)}
|
||||||
|
}
|
||||||
|
|
||||||
// MaxPtF32 returns the point that is at the largest X & Y position of a and b.
|
// MaxPtF32 returns the point that is at the largest X & Y position of a and b.
|
||||||
func MaxPtF32(a, b PointF32) PointF32 {
|
func MaxPtF32(a, b PointF32) PointF32 {
|
||||||
return PtF32(Max32(a.X, b.X), Max32(a.Y, b.Y))
|
return PtF32(Max32(a.X, b.X), Max32(a.Y, b.Y))
|
||||||
|
Loading…
Reference in New Issue
Block a user