Skip to content

Commit 2b33452

Browse files
committed
Fix extrusion bug that removed the last element in a user-supplied list representing a shape.
1 parent 317b188 commit 2b33452

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/glow/extrude.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,14 @@ function extrusion(args) {
795795
var slist = []
796796
for (var i=0; i<contour.length; i++) slist.push(vec(contour[i][0], contour[i][1], 0))
797797
var shape_closed = slist[slist.length-1].equals(slist[0])
798-
if (!shape_closed) new Error("An extrusion shape must be a closed curve.")
798+
if (!shape_closed) throw new Error("An extrusion shape must be a closed curve.")
799799
shapeinfo = []
800800
var out = vec(0,0,1)
801801
var L = slist.length
802802
var firstsharp = null
803803
var totallength = 0
804804
var vs = [], lengths=[], i, v
805805

806-
807806
// Identify that corner of the shape that is the lowest point (minimum y)
808807
var miny, minyi
809808
for (i=0; i<L-1; i++) { // create list of vectors, calculate total length of the shape
@@ -980,10 +979,10 @@ function extrusion(args) {
980979
function tessellate(contours) {
981980
// Use the poly2tri.js library to divide a 2D shape with possible holes into triangles.
982981
// Not called if the path is closed (so no end caps need to be displayed).
983-
var i, j
982+
var i, j, endsave=null
984983
var c = contours[0]
985984
// poly2tri.js does not accept duplicate points:
986-
if (c[0][0] === c[c.length-1][0] && c[0][1] === c[c.length-1][1]) c.pop()
985+
if (c[0][0] === c[c.length-1][0] && c[0][1] === c[c.length-1][1]) endsave = c.pop()
987986

988987
// Create poly2tri.js element for outer contour:
989988
var pts = []
@@ -998,6 +997,7 @@ function extrusion(args) {
998997
for (i=0; i<contours[j].length; i++) pts.push(new Point(c[i][0], c[i][1]))
999998
swctx.addHole(pts)
1000999
}
1000+
if (endsave !== null) c.push(endsave) // restore last contour point
10011001

10021002
function texpos(p) { // evalulate texture coordinates, using bounding box info
10031003
var x=p.x, y=p.y

0 commit comments

Comments
 (0)