From 352785e1b8558579028e4728ad05af54f5690389 Mon Sep 17 00:00:00 2001 From: Ben Cragg Date: Wed, 3 Apr 2019 12:37:33 +0100 Subject: [PATCH] Supporting pre go1.10 --- geometry_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/geometry_test.go b/geometry_test.go index ef00f33..488a5a3 100644 --- a/geometry_test.go +++ b/geometry_test.go @@ -1202,6 +1202,15 @@ func TestLine_Len(t *testing.T) { } func TestLine_Rotated(t *testing.T) { + // round returns the nearest integer, rounding ties away from zero. + // This is required because `math.Round` wasn't introduced until Go1.10 + round := func(x float64) float64 { + t := math.Trunc(x) + if math.Abs(x-t) >= 0.5 { + return t + math.Copysign(1, x) + } + return t + } type fields struct { A pixel.Vec B pixel.Vec @@ -1244,10 +1253,10 @@ func TestLine_Rotated(t *testing.T) { // Have to round the results, due to floating-point in accuracies. Results are correct to approximately // 10 decimal places. got := l.Rotated(tt.args.around, tt.args.angle) - if math.Round(got.A.X) != tt.want.A.X || - math.Round(got.B.X) != tt.want.B.X || - math.Round(got.A.Y) != tt.want.A.Y || - math.Round(got.B.Y) != tt.want.B.Y { + if round(got.A.X) != tt.want.A.X || + round(got.B.X) != tt.want.B.X || + round(got.A.Y) != tt.want.A.Y || + round(got.B.Y) != tt.want.B.Y { t.Errorf("Line.Rotated() = %v, want %v", got, tt.want) } })