Slightly clean up normal calculations

We never actually need the "normal" value; it's an extra calculation
we didn't need, because ijNormal is the same value early on. It's
totally possible that we could further simplify this; there's a lot
of time going into the normal computations.
This commit is contained in:
Seebs 2017-06-09 20:19:17 -05:00
parent f68301dcd8
commit 678da34fc3
1 changed files with 14 additions and 15 deletions

View File

@ -528,29 +528,28 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
// first point
j, i := 0, 1
normal := points[i].pos.Sub(points[j].pos).Rotated(math.Pi / 2).Unit().Scaled(thickness / 2)
ijNormal := points[1].pos.Sub(points[0].pos).Rotated(math.Pi / 2).Unit().Scaled(thickness / 2)
if !closed {
switch points[j].endshape {
case NoEndShape:
// nothing
case SharpEndShape:
imd.pushPt(points[j].pos.Add(normal), points[j])
imd.pushPt(points[j].pos.Sub(normal), points[j])
imd.pushPt(points[j].pos.Add(normal.Rotated(math.Pi/2)), points[j])
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
imd.pushPt(points[j].pos.Add(ijNormal.Rotated(math.Pi/2)), points[j])
imd.fillPolygon()
case RoundEndShape:
imd.pushPt(points[j].pos, points[j])
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), normal.Angle(), normal.Angle()+math.Pi)
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), ijNormal.Angle(), ijNormal.Angle()+math.Pi)
}
}
imd.pushPt(points[j].pos.Add(normal), points[j])
imd.pushPt(points[j].pos.Sub(normal), points[j])
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
// middle points
// compute "previous" normal:
ijNormal := points[1].pos.Sub(points[0].pos).Rotated(math.Pi / 2).Unit().Scaled(thickness / 2)
for i := 0; i < len(points); i++ {
j, k := i+1, i+2
@ -602,10 +601,10 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
// last point
i, j = len(points)-2, len(points)-1
normal = points[j].pos.Sub(points[i].pos).Rotated(math.Pi / 2).Unit().Scaled(thickness / 2)
ijNormal = points[j].pos.Sub(points[i].pos).Rotated(math.Pi / 2).Unit().Scaled(thickness / 2)
imd.pushPt(points[j].pos.Sub(normal), points[j])
imd.pushPt(points[j].pos.Add(normal), points[j])
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
imd.fillPolygon()
if !closed {
@ -613,13 +612,13 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
case NoEndShape:
// nothing
case SharpEndShape:
imd.pushPt(points[j].pos.Add(normal), points[j])
imd.pushPt(points[j].pos.Sub(normal), points[j])
imd.pushPt(points[j].pos.Add(normal.Rotated(-math.Pi/2)), points[j])
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
imd.pushPt(points[j].pos.Add(ijNormal.Rotated(-math.Pi/2)), points[j])
imd.fillPolygon()
case RoundEndShape:
imd.pushPt(points[j].pos, points[j])
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), normal.Angle(), normal.Angle()-math.Pi)
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), ijNormal.Angle(), ijNormal.Angle()-math.Pi)
}
}