Added Div and Mul operations for points.
Moved Less method (for Point) to sort alphabetically.
This commit is contained in:
parent
4df2655b53
commit
3eeedf121e
15
point.go
15
point.go
@ -54,6 +54,16 @@ func (p Point) Add2D(x, y int) Point {
|
||||
return Pt(p.X+x, p.Y+y)
|
||||
}
|
||||
|
||||
// Div divides the X and Y values of point p with t and returns the result.
|
||||
func (p Point) Div(t int) Point {
|
||||
return Pt(p.X/t, p.Y/t)
|
||||
}
|
||||
|
||||
// DistInt returns the integer distance between the points p and q.
|
||||
func (p Point) DistInt(q Point) int {
|
||||
return ints.SubAbs(p.X, q.X) + ints.SubAbs(p.Y, q.Y)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if p.Y == q.Y {
|
||||
@ -62,11 +72,6 @@ func (p Point) Less(q Point) bool {
|
||||
return p.Y < q.Y
|
||||
}
|
||||
|
||||
// DistInt returns the integer distance between the points p and q.
|
||||
func (p Point) DistInt(q Point) int {
|
||||
return ints.SubAbs(p.X, q.X) + ints.SubAbs(p.Y, q.Y)
|
||||
}
|
||||
|
||||
// Mul multiplier the X and Y values of point p with t and returns the result.
|
||||
func (p Point) Mul(t int) Point {
|
||||
return Pt(p.X*t, p.Y*t)
|
||||
|
10
pointf.go
10
pointf.go
@ -91,6 +91,11 @@ func (p PointF) DistanceToPolygon(q PolygonF) float64 {
|
||||
return p.DistanceToLines(append(q.Points, q.Points[0]))
|
||||
}
|
||||
|
||||
// Div divides the X and Y values of point p with t and returns the result.
|
||||
func (p PointF) Div(t float64) PointF {
|
||||
return PtF(p.X/t, p.Y/t)
|
||||
}
|
||||
|
||||
// In tests if the point p is inside the rectangle r.
|
||||
func (p PointF) In(r RectangleF) bool {
|
||||
if p.X < r.Min.X || p.X >= r.Max.X || p.Y < r.Min.Y || p.Y >= r.Max.Y {
|
||||
@ -122,6 +127,11 @@ func (p PointF) Invert() PointF {
|
||||
return PointF{-p.X, -p.Y}
|
||||
}
|
||||
|
||||
// Mul multiplier the X and Y values of point p with t and returns the result.
|
||||
func (p PointF) Mul(t float64) PointF {
|
||||
return PtF(p.X*t, p.Y*t)
|
||||
}
|
||||
|
||||
// Sub subtracts q as a vector from p.
|
||||
func (p PointF) Sub(q PointF) PointF {
|
||||
return PointF{p.X - q.X, p.Y - q.Y}
|
||||
|
10
pointf32.go
10
pointf32.go
@ -91,6 +91,11 @@ func (p PointF32) DistanceToPolygon(q PolygonF32) float32 {
|
||||
return p.DistanceToLines(append(q.Points, q.Points[0]))
|
||||
}
|
||||
|
||||
// Div divides the X and Y values of point p with t and returns the result.
|
||||
func (p PointF32) Div(t float32) PointF32 {
|
||||
return PtF32(p.X/t, p.Y/t)
|
||||
}
|
||||
|
||||
// In tests if the point p is inside the rectangle r.
|
||||
func (p PointF32) In(r RectangleF32) bool {
|
||||
if p.X < r.Min.X || p.X >= r.Max.X || p.Y < r.Min.Y || p.Y >= r.Max.Y {
|
||||
@ -122,6 +127,11 @@ func (p PointF32) Invert() PointF32 {
|
||||
return PointF32{-p.X, -p.Y}
|
||||
}
|
||||
|
||||
// Mul multiplier the X and Y values of point p with t and returns the result.
|
||||
func (p PointF32) Mul(t float32) PointF32 {
|
||||
return PtF32(p.X*t, p.Y*t)
|
||||
}
|
||||
|
||||
// Sub subtracts q as a vector from p.
|
||||
func (p PointF32) Sub(q PointF32) PointF32 {
|
||||
return PointF32{p.X - q.X, p.Y - q.Y}
|
||||
|
Loading…
Reference in New Issue
Block a user