implementing pre 1.8 sortslice solution
This commit is contained in:
parent
b8bb00a161
commit
0092d6a577
15
geometry.go
15
geometry.go
|
@ -3,7 +3,6 @@ package pixel
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clamp returns x clamped to the interval [min, max].
|
// Clamp returns x clamped to the interval [min, max].
|
||||||
|
@ -629,7 +628,11 @@ func (r Rect) IntersectionPoints(l Line) []Vec {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order the points
|
// 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
|
return points
|
||||||
}
|
}
|
||||||
|
@ -966,10 +969,10 @@ func (c Circle) IntersectionPoints(l Line) []Vec {
|
||||||
first := closestToCenter.Add(closestToCenter.To(l.A).Unit().Scaled(a))
|
first := closestToCenter.Add(closestToCenter.To(l.A).Unit().Scaled(a))
|
||||||
second := closestToCenter.Add(closestToCenter.To(l.B).Unit().Scaled(a))
|
second := closestToCenter.Add(closestToCenter.To(l.B).Unit().Scaled(a))
|
||||||
|
|
||||||
points := []Vec{first, second}
|
if first.To(l.A).Len() < second.To(l.A).Len() {
|
||||||
sort.Slice(points, func(i, j int) bool { return points[i].To(l.A).Len() < points[j].To(l.A).Len() })
|
return []Vec{first, second}
|
||||||
|
}
|
||||||
return points
|
return []Vec{second, first}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such
|
// Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such
|
||||||
|
|
Loading…
Reference in New Issue