fix 0 vector len + fix imdraw polyline

This commit is contained in:
faiface 2017-03-23 19:15:06 +01:00
parent 0585b0af8c
commit 4619398b9e
2 changed files with 3 additions and 12 deletions

View File

@ -85,6 +85,9 @@ func (u Vec) Angle() float64 {
// Unit returns a vector of length 1 facing the direction of u (has the same angle).
func (u Vec) Unit() Vec {
if u == 0 {
return 1
}
return u / V(u.Len(), 0)
}

View File

@ -433,18 +433,6 @@ func (imd *IMDraw) outlineEllipseArc(radius pixel.Vec, low, high, thickness floa
func (imd *IMDraw) polyline(thickness float64, closed bool) {
points := imd.getAndClearPoints()
// filter identical adjacent points
filtered := points[:0]
for i := 0; i < len(points); i++ {
if closed || i+1 < len(points) {
j := (i + 1) % len(points)
if points[i].pos != points[j].pos {
filtered = append(filtered, points[i])
}
}
}
points = filtered
if len(points) < 2 {
return
}