From c81df8279f22773f2d90bf92d75460485239f2f7 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 17 May 2020 10:38:01 +0200 Subject: [PATCH] Added all missing conversion functions from the different point & rectangle formats. Renamed To{32,64} to To{F32,F} for consistency. --- pointf.go | 4 ++-- pointf32.go | 4 ++-- rectangle.go | 6 ++++++ rectanglef.go | 6 ++++++ rectanglef32.go | 6 ++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pointf.go b/pointf.go index 0a8d206..22b6090 100644 --- a/pointf.go +++ b/pointf.go @@ -142,8 +142,8 @@ func (p PointF) Sub(q PointF) PointF { return PointF{p.X - q.X, p.Y - q.Y} } -// To32 transforms the point p into a PointF32. -func (p PointF) To32() PointF32 { +// ToF32 transforms the point p into a PointF32. +func (p PointF) ToF32() PointF32 { return PointF32{float32(p.X), float32(p.Y)} } diff --git a/pointf32.go b/pointf32.go index 7777961..353e9d8 100644 --- a/pointf32.go +++ b/pointf32.go @@ -142,8 +142,8 @@ func (p PointF32) Sub(q PointF32) PointF32 { return PointF32{p.X - q.X, p.Y - q.Y} } -// To64 transforms the point p into a PointF. -func (p PointF32) To64() PointF { +// ToF transforms the point p into a PointF. +func (p PointF32) ToF() PointF { return PointF{float64(p.X), float64(p.Y)} } diff --git a/rectangle.go b/rectangle.go index 6fc2a7b..5af858a 100644 --- a/rectangle.go +++ b/rectangle.go @@ -51,3 +51,9 @@ func (r Rectangle) Sub(p Point) Rectangle { Point{r.Max.X - p.X, r.Max.Y - p.Y}, } } + +// ToF returns the floating point representation of r. +func (r Rectangle) ToF() RectangleF { return RectangleF{Min: r.Min.ToF(), Max: r.Max.ToF()} } + +// ToF32 returns the floating point representation of r. +func (r Rectangle) ToF32() RectangleF32 { return RectangleF32{Min: r.Min.ToF32(), Max: r.Max.ToF32()} } diff --git a/rectanglef.go b/rectanglef.go index b33d4b0..58d754f 100644 --- a/rectanglef.go +++ b/rectanglef.go @@ -77,3 +77,9 @@ func (r RectangleF) Sub(p PointF) RectangleF { PointF{r.Max.X - p.X, r.Max.Y - p.Y}, } } + +// ToF32 returns the floating point representation of r. +func (r RectangleF) ToF32() RectangleF32 { return RectangleF32{Min: r.Min.ToF32(), Max: r.Max.ToF32()} } + +// ToInt returns the integer point representation of r. +func (r RectangleF) ToInt() Rectangle { return Rectangle{Min: r.Min.ToInt(), Max: r.Max.ToInt()} } diff --git a/rectanglef32.go b/rectanglef32.go index e482fd7..a948d43 100644 --- a/rectanglef32.go +++ b/rectanglef32.go @@ -77,3 +77,9 @@ func (r RectangleF32) Sub(p PointF32) RectangleF32 { PointF32{r.Max.X - p.X, r.Max.Y - p.Y}, } } + +// ToInt returns the integer point representation of r. +func (r RectangleF32) ToInt() Rectangle { return Rectangle{Min: r.Min.ToInt(), Max: r.Max.ToInt()} } + +// ToF returns the floating point representation of r. +func (r RectangleF32) ToF() RectangleF { return RectangleF{Min: r.Min.ToF(), Max: r.Max.ToF()} }