From a7a46886877803b64d72578ffe3b38b2a1a13e2a Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Fri, 6 Aug 2021 19:11:58 +0200 Subject: [PATCH] Add Mul2D to Point{,F,F32}. --- point.go | 7 ++++++- pointf.go | 7 ++++++- pointf32.go | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/point.go b/point.go index 73813f6..bcbf314 100644 --- a/point.go +++ b/point.go @@ -80,11 +80,16 @@ func (p Point) Less(q Point) bool { return p.Y < q.Y } -// Mul multiplier the X and Y values of point p with t and returns the result. +// Mul multiplies 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) } +// Mul2D multiplies the X and Y values of point p with x and y and returns the result. +func (p Point) Mul2D(x, y int) Point { + return Pt(p.X*x, p.Y*y) +} + // Norm returns the point with both X and Y normalized. func (p Point) Norm() Point { return Pt(ints.Norm(p.X), ints.Norm(p.Y)) diff --git a/pointf.go b/pointf.go index 437dc58..86ef9b8 100644 --- a/pointf.go +++ b/pointf.go @@ -132,11 +132,16 @@ 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. +// Mul multiplies 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) } +// Mul2D multiplies the X and Y values of point p with x and y and returns the result. +func (p PointF) Mul2D(x, y float64) PointF { + return PtF(p.X*x, p.Y*y) +} + // Rect returns a rectangle starting from point p to given point q func (p PointF) Rect(q PointF) RectangleF { return RectangleF{Min: p, Max: q} diff --git a/pointf32.go b/pointf32.go index f63bad3..8b5b1ae 100644 --- a/pointf32.go +++ b/pointf32.go @@ -132,11 +132,16 @@ 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. +// Mul multiplies 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) } +// Mul2D multiplies the X and Y values of point p with x and y and returns the result. +func (p PointF32) Mul2D(x, y float32) PointF32 { + return PtF32(p.X*x, p.Y*y) +} + // Rect returns a rectangle starting from point p to given point q func (p PointF32) Rect(q PointF32) RectangleF32 { return RectangleF32{Min: p, Max: q}