diff --git a/point.go b/point.go index 2e3d092..bd5c54d 100644 --- a/point.go +++ b/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) diff --git a/pointf.go b/pointf.go index d81b147..c7d6a9b 100644 --- a/pointf.go +++ b/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} diff --git a/pointf32.go b/pointf32.go index 00c76a0..ad4d920 100644 --- a/pointf32.go +++ b/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}