From f2705fcdf81e88c7c4ad3b8888f1596c4a554d81 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Tue, 24 Dec 2019 10:48:49 +0100 Subject: [PATCH] Added Add2D methods for PointF{,32}. - Add2D adds x, y values instead of a point (Add). --- pointf.go | 5 +++++ pointf32.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pointf.go b/pointf.go index c7d6a9b..c7f3d16 100644 --- a/pointf.go +++ b/pointf.go @@ -22,6 +22,11 @@ func (p PointF) Add(q PointF) PointF { return PointF{p.X + q.X, p.Y + q.Y} } +// Add2D adds x and y to X and Y of point p and returns the sum. +func (p PointF) Add2D(x, y float64) PointF { + return PtF(p.X+x, p.Y+y) +} + // AngleTo calculates the angle [0..2*Pi) from point p to point q. func (p PointF) AngleTo(q PointF) float64 { a := math.Atan((p.Y - q.Y) / (p.X - q.X)) diff --git a/pointf32.go b/pointf32.go index ad4d920..a0a986c 100644 --- a/pointf32.go +++ b/pointf32.go @@ -22,6 +22,11 @@ func (p PointF32) Add(q PointF32) PointF32 { return PointF32{p.X + q.X, p.Y + q.Y} } +// Add2D adds x and y to X and Y of point p and returns the sum. +func (p PointF32) Add2D(x, y float32) PointF32 { + return PtF32(p.X+x, p.Y+y) +} + // AngleTo calculates the angle [0..2*Pi) from point p to point q. func (p PointF32) AngleTo(q PointF32) float32 { a := float32(math.Atan(float64((p.Y - q.Y) / (p.X - q.X))))