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:
parent
f68301dcd8
commit
678da34fc3
|
@ -528,29 +528,28 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
|
||||||
|
|
||||||
// first point
|
// first point
|
||||||
j, i := 0, 1
|
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 {
|
if !closed {
|
||||||
switch points[j].endshape {
|
switch points[j].endshape {
|
||||||
case NoEndShape:
|
case NoEndShape:
|
||||||
// nothing
|
// nothing
|
||||||
case SharpEndShape:
|
case SharpEndShape:
|
||||||
imd.pushPt(points[j].pos.Add(normal), points[j])
|
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Sub(normal), points[j])
|
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Add(normal.Rotated(math.Pi/2)), points[j])
|
imd.pushPt(points[j].pos.Add(ijNormal.Rotated(math.Pi/2)), points[j])
|
||||||
imd.fillPolygon()
|
imd.fillPolygon()
|
||||||
case RoundEndShape:
|
case RoundEndShape:
|
||||||
imd.pushPt(points[j].pos, points[j])
|
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.Add(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Sub(normal), points[j])
|
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
|
||||||
|
|
||||||
// middle points
|
// middle points
|
||||||
// compute "previous" normal:
|
// 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++ {
|
for i := 0; i < len(points); i++ {
|
||||||
j, k := i+1, i+2
|
j, k := i+1, i+2
|
||||||
|
|
||||||
|
@ -602,10 +601,10 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
|
||||||
|
|
||||||
// last point
|
// last point
|
||||||
i, j = len(points)-2, len(points)-1
|
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.Sub(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Add(normal), points[j])
|
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
|
||||||
imd.fillPolygon()
|
imd.fillPolygon()
|
||||||
|
|
||||||
if !closed {
|
if !closed {
|
||||||
|
@ -613,13 +612,13 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
|
||||||
case NoEndShape:
|
case NoEndShape:
|
||||||
// nothing
|
// nothing
|
||||||
case SharpEndShape:
|
case SharpEndShape:
|
||||||
imd.pushPt(points[j].pos.Add(normal), points[j])
|
imd.pushPt(points[j].pos.Add(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Sub(normal), points[j])
|
imd.pushPt(points[j].pos.Sub(ijNormal), points[j])
|
||||||
imd.pushPt(points[j].pos.Add(normal.Rotated(-math.Pi/2)), points[j])
|
imd.pushPt(points[j].pos.Add(ijNormal.Rotated(-math.Pi/2)), points[j])
|
||||||
imd.fillPolygon()
|
imd.fillPolygon()
|
||||||
case RoundEndShape:
|
case RoundEndShape:
|
||||||
imd.pushPt(points[j].pos, points[j])
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue