ShapeUtils.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /**
  2. * @author zz85 / http://www.lab4games.net/zz85/blog
  3. */
  4. var ShapeUtils = {
  5. // calculate area of the contour polygon
  6. area: function ( contour ) {
  7. var n = contour.length;
  8. var a = 0.0;
  9. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  10. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  11. }
  12. return a * 0.5;
  13. },
  14. triangulate: ( function () {
  15. /**
  16. * This code is a quick port of code written in C++ which was submitted to
  17. * flipcode.com by John W. Ratcliff // July 22, 2000
  18. * See original code and more information here:
  19. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20. *
  21. * ported to actionscript by Zevan Rosser
  22. * www.actionsnippet.com
  23. *
  24. * ported to javascript by Joshua Koo
  25. * http://www.lab4games.net/zz85/blog
  26. *
  27. */
  28. function snip( contour, u, v, w, n, verts ) {
  29. var p;
  30. var ax, ay, bx, by;
  31. var cx, cy, px, py;
  32. ax = contour[ verts[ u ] ].x;
  33. ay = contour[ verts[ u ] ].y;
  34. bx = contour[ verts[ v ] ].x;
  35. by = contour[ verts[ v ] ].y;
  36. cx = contour[ verts[ w ] ].x;
  37. cy = contour[ verts[ w ] ].y;
  38. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  39. var aX, aY, bX, bY, cX, cY;
  40. var apx, apy, bpx, bpy, cpx, cpy;
  41. var cCROSSap, bCROSScp, aCROSSbp;
  42. aX = cx - bx; aY = cy - by;
  43. bX = ax - cx; bY = ay - cy;
  44. cX = bx - ax; cY = by - ay;
  45. for ( p = 0; p < n; p ++ ) {
  46. px = contour[ verts[ p ] ].x;
  47. py = contour[ verts[ p ] ].y;
  48. if ( ( ( px === ax ) && ( py === ay ) ) ||
  49. ( ( px === bx ) && ( py === by ) ) ||
  50. ( ( px === cx ) && ( py === cy ) ) ) continue;
  51. apx = px - ax; apy = py - ay;
  52. bpx = px - bx; bpy = py - by;
  53. cpx = px - cx; cpy = py - cy;
  54. // see if p is inside triangle abc
  55. aCROSSbp = aX * bpy - aY * bpx;
  56. cCROSSap = cX * apy - cY * apx;
  57. bCROSScp = bX * cpy - bY * cpx;
  58. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  59. }
  60. return true;
  61. }
  62. // takes in an contour array and returns
  63. return function triangulate( contour, indices ) {
  64. var n = contour.length;
  65. if ( n < 3 ) return null;
  66. var result = [],
  67. verts = [],
  68. vertIndices = [];
  69. /* we want a counter-clockwise polygon in verts */
  70. var u, v, w;
  71. if ( ShapeUtils.area( contour ) > 0.0 ) {
  72. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  73. } else {
  74. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  75. }
  76. var nv = n;
  77. /* remove nv - 2 vertices, creating 1 triangle every time */
  78. var count = 2 * nv; /* error detection */
  79. for ( v = nv - 1; nv > 2; ) {
  80. /* if we loop, it is probably a non-simple polygon */
  81. if ( ( count -- ) <= 0 ) {
  82. //** Triangulate: ERROR - probable bad polygon!
  83. //throw ( "Warning, unable to triangulate polygon!" );
  84. //return null;
  85. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  86. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  87. if ( indices ) return vertIndices;
  88. return result;
  89. }
  90. /* three consecutive vertices in current polygon, <u,v,w> */
  91. u = v; if ( nv <= u ) u = 0; /* previous */
  92. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  93. w = v + 1; if ( nv <= w ) w = 0; /* next */
  94. if ( snip( contour, u, v, w, nv, verts ) ) {
  95. var a, b, c, s, t;
  96. /* true names of the vertices */
  97. a = verts[ u ];
  98. b = verts[ v ];
  99. c = verts[ w ];
  100. /* output Triangle */
  101. result.push( [ contour[ a ],
  102. contour[ b ],
  103. contour[ c ] ] );
  104. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  105. /* remove v from the remaining polygon */
  106. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  107. verts[ s ] = verts[ t ];
  108. }
  109. nv --;
  110. /* reset error detection counter */
  111. count = 2 * nv;
  112. }
  113. }
  114. if ( indices ) return vertIndices;
  115. return result;
  116. };
  117. } )(),
  118. triangulateShape: function ( contour, holes ) {
  119. function removeDupEndPts( points ) {
  120. var l = points.length;
  121. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  122. points.pop();
  123. }
  124. }
  125. removeDupEndPts( contour );
  126. holes.forEach( removeDupEndPts );
  127. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  128. // inOtherPt needs to be collinear to the inSegment
  129. if ( inSegPt1.x !== inSegPt2.x ) {
  130. if ( inSegPt1.x < inSegPt2.x ) {
  131. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  132. } else {
  133. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  134. }
  135. } else {
  136. if ( inSegPt1.y < inSegPt2.y ) {
  137. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  138. } else {
  139. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  140. }
  141. }
  142. }
  143. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  144. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  145. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  146. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  147. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  148. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  149. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  150. if ( Math.abs( limit ) > Number.EPSILON ) {
  151. // not parallel
  152. var perpSeg2;
  153. if ( limit > 0 ) {
  154. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  155. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  156. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  157. } else {
  158. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  159. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  160. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  161. }
  162. // i.e. to reduce rounding errors
  163. // intersection at endpoint of segment#1?
  164. if ( perpSeg2 === 0 ) {
  165. if ( ( inExcludeAdjacentSegs ) &&
  166. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  167. return [ inSeg1Pt1 ];
  168. }
  169. if ( perpSeg2 === limit ) {
  170. if ( ( inExcludeAdjacentSegs ) &&
  171. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  172. return [ inSeg1Pt2 ];
  173. }
  174. // intersection at endpoint of segment#2?
  175. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  176. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  177. // return real intersection point
  178. var factorSeg1 = perpSeg2 / limit;
  179. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx, y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  180. } else {
  181. // parallel or collinear
  182. if ( ( perpSeg1 !== 0 ) ||
  183. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  184. // they are collinear or degenerate
  185. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  186. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  187. // both segments are points
  188. if ( seg1Pt && seg2Pt ) {
  189. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  190. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  191. return [ inSeg1Pt1 ]; // they are the same point
  192. }
  193. // segment#1 is a single point
  194. if ( seg1Pt ) {
  195. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  196. return [ inSeg1Pt1 ];
  197. }
  198. // segment#2 is a single point
  199. if ( seg2Pt ) {
  200. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  201. return [ inSeg2Pt1 ];
  202. }
  203. // they are collinear segments, which might overlap
  204. var seg1min, seg1max, seg1minVal, seg1maxVal;
  205. var seg2min, seg2max, seg2minVal, seg2maxVal;
  206. if ( seg1dx !== 0 ) {
  207. // the segments are NOT on a vertical line
  208. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  209. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  210. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  211. } else {
  212. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  213. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  214. }
  215. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  216. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  217. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  218. } else {
  219. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  220. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  221. }
  222. } else {
  223. // the segments are on a vertical line
  224. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  225. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  226. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  227. } else {
  228. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  229. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  230. }
  231. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  232. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  233. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  234. } else {
  235. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  236. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  237. }
  238. }
  239. if ( seg1minVal <= seg2minVal ) {
  240. if ( seg1maxVal < seg2minVal ) return [];
  241. if ( seg1maxVal === seg2minVal ) {
  242. if ( inExcludeAdjacentSegs ) return [];
  243. return [ seg2min ];
  244. }
  245. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  246. return [ seg2min, seg2max ];
  247. } else {
  248. if ( seg1minVal > seg2maxVal ) return [];
  249. if ( seg1minVal === seg2maxVal ) {
  250. if ( inExcludeAdjacentSegs ) return [];
  251. return [ seg1min ];
  252. }
  253. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  254. return [ seg1min, seg2max ];
  255. }
  256. }
  257. }
  258. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  259. // The order of legs is important
  260. // translation of all points, so that Vertex is at (0,0)
  261. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  262. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  263. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  264. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  265. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  266. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  267. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  268. // angle != 180 deg.
  269. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  270. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  271. if ( from2toAngle > 0 ) {
  272. // main angle < 180 deg.
  273. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  274. } else {
  275. // main angle > 180 deg.
  276. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  277. }
  278. } else {
  279. // angle == 180 deg.
  280. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  281. return ( from2otherAngle > 0 );
  282. }
  283. }
  284. function removeHoles( contour, holes ) {
  285. var shape = contour.concat(); // work on this shape
  286. var hole;
  287. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  288. // Check if hole point lies within angle around shape point
  289. var lastShapeIdx = shape.length - 1;
  290. var prevShapeIdx = inShapeIdx - 1;
  291. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  292. var nextShapeIdx = inShapeIdx + 1;
  293. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  294. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  295. if ( ! insideAngle ) {
  296. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  297. return false;
  298. }
  299. // Check if shape point lies within angle around hole point
  300. var lastHoleIdx = hole.length - 1;
  301. var prevHoleIdx = inHoleIdx - 1;
  302. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  303. var nextHoleIdx = inHoleIdx + 1;
  304. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  305. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  306. if ( ! insideAngle ) {
  307. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  308. return false;
  309. }
  310. return true;
  311. }
  312. function intersectsShapeEdge( inShapePt, inHolePt ) {
  313. // checks for intersections with shape edges
  314. var sIdx, nextIdx, intersection;
  315. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  316. nextIdx = sIdx + 1; nextIdx %= shape.length;
  317. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  318. if ( intersection.length > 0 ) return true;
  319. }
  320. return false;
  321. }
  322. var indepHoles = [];
  323. function intersectsHoleEdge( inShapePt, inHolePt ) {
  324. // checks for intersections with hole edges
  325. var ihIdx, chkHole,
  326. hIdx, nextIdx, intersection;
  327. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  328. chkHole = holes[ indepHoles[ ihIdx ] ];
  329. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  330. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  331. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  332. if ( intersection.length > 0 ) return true;
  333. }
  334. }
  335. return false;
  336. }
  337. var holeIndex, shapeIndex,
  338. shapePt, holePt,
  339. holeIdx, cutKey, failedCuts = [],
  340. tmpShape1, tmpShape2,
  341. tmpHole1, tmpHole2;
  342. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  343. indepHoles.push( h );
  344. }
  345. var minShapeIndex = 0;
  346. var counter = indepHoles.length * 2;
  347. while ( indepHoles.length > 0 ) {
  348. counter --;
  349. if ( counter < 0 ) {
  350. console.log( 'THREE.ShapeUtils: Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!' );
  351. break;
  352. }
  353. // search for shape-vertex and hole-vertex,
  354. // which can be connected without intersections
  355. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  356. shapePt = shape[ shapeIndex ];
  357. holeIndex = - 1;
  358. // search for hole which can be reached without intersections
  359. for ( var h = 0; h < indepHoles.length; h ++ ) {
  360. holeIdx = indepHoles[ h ];
  361. // prevent multiple checks
  362. cutKey = shapePt.x + ':' + shapePt.y + ':' + holeIdx;
  363. if ( failedCuts[ cutKey ] !== undefined ) continue;
  364. hole = holes[ holeIdx ];
  365. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  366. holePt = hole[ h2 ];
  367. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  368. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  369. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  370. holeIndex = h2;
  371. indepHoles.splice( h, 1 );
  372. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  373. tmpShape2 = shape.slice( shapeIndex );
  374. tmpHole1 = hole.slice( holeIndex );
  375. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  376. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  377. minShapeIndex = shapeIndex;
  378. // Debug only, to show the selected cuts
  379. // glob_CutLines.push( [ shapePt, holePt ] );
  380. break;
  381. }
  382. if ( holeIndex >= 0 ) break; // hole-vertex found
  383. failedCuts[ cutKey ] = true; // remember failure
  384. }
  385. if ( holeIndex >= 0 ) break; // hole-vertex found
  386. }
  387. }
  388. return shape; /* shape with no holes */
  389. }
  390. var i, il, f, face,
  391. key, index,
  392. allPointsMap = {};
  393. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  394. var allpoints = contour.concat();
  395. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  396. Array.prototype.push.apply( allpoints, holes[ h ] );
  397. }
  398. //console.log( "allpoints",allpoints, allpoints.length );
  399. // prepare all points map
  400. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  401. key = allpoints[ i ].x + ':' + allpoints[ i ].y;
  402. if ( allPointsMap[ key ] !== undefined ) {
  403. console.warn( 'THREE.ShapeUtils: Duplicate point', key, i );
  404. }
  405. allPointsMap[ key ] = i;
  406. }
  407. // remove holes by cutting paths to holes and adding them to the shape
  408. var shapeWithoutHoles = removeHoles( contour, holes );
  409. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  410. //console.log( "triangles",triangles, triangles.length );
  411. // check all face vertices against all points map
  412. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  413. face = triangles[ i ];
  414. for ( f = 0; f < 3; f ++ ) {
  415. key = face[ f ].x + ':' + face[ f ].y;
  416. index = allPointsMap[ key ];
  417. if ( index !== undefined ) {
  418. face[ f ] = index;
  419. }
  420. }
  421. }
  422. return triangles.concat();
  423. },
  424. isClockWise: function ( pts ) {
  425. return ShapeUtils.area( pts ) < 0;
  426. }
  427. };
  428. export { ShapeUtils };