From 0092d6a577c62a196bf82c2faaf14e0018ced58c Mon Sep 17 00:00:00 2001 From: Ben Cragg Date: Thu, 4 Apr 2019 16:09:25 +0100 Subject: [PATCH] implementing pre 1.8 sortslice solution --- geometry.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/geometry.go b/geometry.go index 83c0638..e6652cd 100644 --- a/geometry.go +++ b/geometry.go @@ -3,7 +3,6 @@ package pixel import ( "fmt" "math" - "sort" ) // Clamp returns x clamped to the interval [min, max]. @@ -629,7 +628,11 @@ func (r Rect) IntersectionPoints(l Line) []Vec { } // Order the points - sort.Slice(points, func(i, j int) bool { return points[i].To(l.A).Len() < points[j].To(l.A).Len() }) + if len(points) == 2 { + if points[1].To(l.A).Len() < points[0].To(l.A).Len() { + return []Vec{points[1], points[2]} + } + } return points } @@ -966,10 +969,10 @@ func (c Circle) IntersectionPoints(l Line) []Vec { first := closestToCenter.Add(closestToCenter.To(l.A).Unit().Scaled(a)) second := closestToCenter.Add(closestToCenter.To(l.B).Unit().Scaled(a)) - points := []Vec{first, second} - sort.Slice(points, func(i, j int) bool { return points[i].To(l.A).Len() < points[j].To(l.A).Len() }) - - return points + if first.To(l.A).Len() < second.To(l.A).Len() { + return []Vec{first, second} + } + return []Vec{second, first} } // Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such