Skip to content

Commit 0e0d32f

Browse files
sabiqusiPrincessGod
authored andcommitted
Update loadObj.js
1 parent 948a132 commit 0e0d32f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lib/loadObj.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,22 @@ function loadObj(objPath, options) {
330330

331331
// Given the cartesian 2 vertices of a polygon, determine if convex
332332
function isConvex(positions2D) {
333+
var length = position2D.length;
333334
var turnDirection = getTurnDirection(positions2D[0], positions2D[1], positions2D[2]);
334-
for (var i=1; i < positions2D.length-2; ++i) {
335+
for (var i=1; i < length-2; ++i) {
335336
var currentTurnDirection = getTurnDirection(positions2D[i], positions2D[i+1], positions2D[i+2]);
336337
if (turnDirection * currentTurnDirection < 0) {
337338
return false;
338339
}
339340
}
341+
var currentTurnDirection = getTurnDirection(position2D[length-2], position2D[length-1], position2D[0]);
342+
if (turnDirection * currentTurnDirection < 0) {
343+
return false;
344+
}
345+
currentTurnDirection = getTurnDirection(position2D[length-1], position2D[0], position2D[1]);
346+
if (turnDirection * currentTurnDirection < 0) {
347+
return false;
348+
}
340349
return true;
341350
}
342351

0 commit comments

Comments
 (0)