From 390949790e21af72191e58fa7a67453a004f3eb5 Mon Sep 17 00:00:00 2001 From: Wagner Riffel Date: Wed, 13 May 2020 07:06:54 -0300 Subject: [PATCH] f32: implement fmt.Stringer to Point and Rectangle Signed-off-by: Wagner Riffel --- f32/f32.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/f32/f32.go b/f32/f32.go index e6371655..8062055d 100644 --- a/f32/f32.go +++ b/f32/f32.go @@ -9,17 +9,30 @@ corner with the axes extending right and down. */ package f32 +import "strconv" + // A Point is a two dimensional point. type Point struct { X, Y float32 } +// String return a string representation of p. +func (p Point) String() string { + return "(" + strconv.FormatFloat(float64(p.X), 'f', -1, 32) + + "," + strconv.FormatFloat(float64(p.Y), 'f', -1, 32) + ")" +} + // A Rectangle contains the points (X, Y) where Min.X <= X < Max.X, // Min.Y <= Y < Max.Y. type Rectangle struct { Min, Max Point } +// String return a string representation of r. +func (r Rectangle) String() string { + return r.Min.String() + "-" + r.Max.String() +} + // Add return the point p+p2. func (p Point) Add(p2 Point) Point { return Point{X: p.X + p2.X, Y: p.Y + p2.Y}