@faicad/faijs 0.32.3 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/dist/api/api-namespace.js +3 -3
  2. package/dist/api/api-namespace.js.map +1 -1
  3. package/dist/api/assembly/index.d.ts +1 -0
  4. package/dist/api/assembly/index.d.ts.map +1 -1
  5. package/dist/api/assembly/index.js +1 -0
  6. package/dist/api/assembly/index.js.map +1 -1
  7. package/dist/api/assembly/lower.d.ts.map +1 -1
  8. package/dist/api/assembly/lower.js +7 -0
  9. package/dist/api/assembly/lower.js.map +1 -1
  10. package/dist/api/assembly/normalize.d.ts.map +1 -1
  11. package/dist/api/assembly/normalize.js +2 -1
  12. package/dist/api/assembly/normalize.js.map +1 -1
  13. package/dist/api/assembly/solve-tree.d.ts +46 -0
  14. package/dist/api/assembly/solve-tree.d.ts.map +1 -0
  15. package/dist/api/assembly/solve-tree.js +135 -0
  16. package/dist/api/assembly/solve-tree.js.map +1 -0
  17. package/dist/api/assembly/solve.d.ts +7 -0
  18. package/dist/api/assembly/solve.d.ts.map +1 -1
  19. package/dist/api/assembly/solve.js.map +1 -1
  20. package/dist/api/assembly/solvers/assembly-tree.d.ts +4 -0
  21. package/dist/api/assembly/solvers/assembly-tree.d.ts.map +1 -1
  22. package/dist/api/assembly/solvers/assembly-tree.js +1 -0
  23. package/dist/api/assembly/solvers/assembly-tree.js.map +1 -1
  24. package/dist/api/assembly/solvers/global-solver.d.ts.map +1 -1
  25. package/dist/api/assembly/solvers/global-solver.js +210 -3
  26. package/dist/api/assembly/solvers/global-solver.js.map +1 -1
  27. package/dist/api/assembly/solvers/types.d.ts +8 -0
  28. package/dist/api/assembly/solvers/types.d.ts.map +1 -1
  29. package/dist/api/assembly/solvers/types.js.map +1 -1
  30. package/dist/api/assembly/types.d.ts +32 -1
  31. package/dist/api/assembly/types.d.ts.map +1 -1
  32. package/dist/api/assembly/types.js.map +1 -1
  33. package/dist/api/assembly/validate.d.ts +2 -2
  34. package/dist/api/assembly/validate.d.ts.map +1 -1
  35. package/dist/api/assembly/validate.js +24 -2
  36. package/dist/api/assembly/validate.js.map +1 -1
  37. package/dist/api/cadquery-selectors/edge.js +1 -1
  38. package/dist/api/cadquery-selectors/edge.js.map +1 -1
  39. package/dist/api/cadquery-selectors/entity.d.ts +29 -20
  40. package/dist/api/cadquery-selectors/entity.d.ts.map +1 -1
  41. package/dist/api/cadquery-selectors/entity.js +26 -20
  42. package/dist/api/cadquery-selectors/entity.js.map +1 -1
  43. package/dist/api/cadquery-selectors/face.d.ts +4 -2
  44. package/dist/api/cadquery-selectors/face.d.ts.map +1 -1
  45. package/dist/api/cadquery-selectors/face.js +8 -7
  46. package/dist/api/cadquery-selectors/face.js.map +1 -1
  47. package/dist/api/cadquery-selectors/resolve.d.ts +7 -6
  48. package/dist/api/cadquery-selectors/resolve.d.ts.map +1 -1
  49. package/dist/api/cadquery-selectors/resolve.js +13 -11
  50. package/dist/api/cadquery-selectors/resolve.js.map +1 -1
  51. package/dist/api/chamfer.js +1 -1
  52. package/dist/api/chamfer.js.map +1 -1
  53. package/dist/api/draft.js +1 -1
  54. package/dist/api/draft.js.map +1 -1
  55. package/dist/api/edge-ref.js +2 -2
  56. package/dist/api/edge-ref.js.map +1 -1
  57. package/dist/api/engrave.js +1 -1
  58. package/dist/api/engrave.js.map +1 -1
  59. package/dist/api/export-3mf.js +1 -1
  60. package/dist/api/export-3mf.js.map +1 -1
  61. package/dist/api/export-brep.js +1 -1
  62. package/dist/api/export-brep.js.map +1 -1
  63. package/dist/api/export-step.d.ts +12 -13
  64. package/dist/api/export-step.d.ts.map +1 -1
  65. package/dist/api/export-step.js +19 -17
  66. package/dist/api/export-step.js.map +1 -1
  67. package/dist/api/extrude.js +3 -3
  68. package/dist/api/extrude.js.map +1 -1
  69. package/dist/api/face-ref.js +2 -2
  70. package/dist/api/face-ref.js.map +1 -1
  71. package/dist/api/feature-repair.js +2 -2
  72. package/dist/api/feature-repair.js.map +1 -1
  73. package/dist/api/fillet-variable.js +1 -1
  74. package/dist/api/fillet-variable.js.map +1 -1
  75. package/dist/api/fillet.js +1 -1
  76. package/dist/api/fillet.js.map +1 -1
  77. package/dist/api/geom.js +1 -1
  78. package/dist/api/geom.js.map +1 -1
  79. package/dist/api/import-step.d.ts.map +1 -1
  80. package/dist/api/import-step.js +4 -2
  81. package/dist/api/import-step.js.map +1 -1
  82. package/dist/api/pattern.js +1 -1
  83. package/dist/api/pattern.js.map +1 -1
  84. package/dist/api/place.js +1 -1
  85. package/dist/api/place.js.map +1 -1
  86. package/dist/api/punch-hole.js +1 -1
  87. package/dist/api/punch-hole.js.map +1 -1
  88. package/dist/api/replicate.js +1 -1
  89. package/dist/api/replicate.js.map +1 -1
  90. package/dist/api/revolve.js +1 -1
  91. package/dist/api/revolve.js.map +1 -1
  92. package/dist/api/section-by-plane.js +1 -1
  93. package/dist/api/section-by-plane.js.map +1 -1
  94. package/dist/api/shell.js +1 -1
  95. package/dist/api/shell.js.map +1 -1
  96. package/dist/api/sketch-on-face.js +1 -1
  97. package/dist/api/sketch-on-face.js.map +1 -1
  98. package/dist/api/split-by-plane.js +1 -1
  99. package/dist/api/split-by-plane.js.map +1 -1
  100. package/dist/api/split.js +1 -1
  101. package/dist/api/split.js.map +1 -1
  102. package/dist/api/thicken.js +1 -1
  103. package/dist/api/thicken.js.map +1 -1
  104. package/dist/api/topo-resolve.js +4 -4
  105. package/dist/api/topo-resolve.js.map +1 -1
  106. package/dist/api/transform.js +1 -1
  107. package/dist/api/transform.js.map +1 -1
  108. package/dist/api/view/view-projection.d.ts +8 -0
  109. package/dist/api/view/view-projection.d.ts.map +1 -1
  110. package/dist/api/view/view-projection.js +73 -2
  111. package/dist/api/view/view-projection.js.map +1 -1
  112. package/dist/boolean/cross-section.d.ts.map +1 -1
  113. package/dist/boolean/cross-section.js +3 -1
  114. package/dist/boolean/cross-section.js.map +1 -1
  115. package/dist/brep/brep-ops.d.ts +26 -0
  116. package/dist/brep/brep-ops.d.ts.map +1 -1
  117. package/dist/brep/brep-ops.js +45 -0
  118. package/dist/brep/brep-ops.js.map +1 -1
  119. package/dist/brep/brep-topology.js +1 -1
  120. package/dist/brep/brep-topology.js.map +1 -1
  121. package/dist/brep/engine/adapters/brep-mock.d.ts.map +1 -1
  122. package/dist/brep/engine/adapters/brep-mock.js +2 -0
  123. package/dist/brep/engine/adapters/brep-mock.js.map +1 -1
  124. package/dist/brep/engine/primitives.d.ts +17 -0
  125. package/dist/brep/engine/primitives.d.ts.map +1 -1
  126. package/dist/brep/engine/primitives.js.map +1 -1
  127. package/dist/brep/export/export-model.d.ts.map +1 -1
  128. package/dist/brep/export/export-model.js +36 -11
  129. package/dist/brep/export/export-model.js.map +1 -1
  130. package/dist/brep/export/step-flat.d.ts +35 -0
  131. package/dist/brep/export/step-flat.d.ts.map +1 -0
  132. package/dist/brep/export/step-flat.js +94 -0
  133. package/dist/brep/export/step-flat.js.map +1 -0
  134. package/dist/brep/export/step.d.ts.map +1 -1
  135. package/dist/brep/export/step.js +42 -21
  136. package/dist/brep/export/step.js.map +1 -1
  137. package/dist/brep/handle-bridge.d.ts +4 -4
  138. package/dist/brep/handle-bridge.js +4 -4
  139. package/dist/brep/handle-bridge.js.map +1 -1
  140. package/dist/brep/svg/svg-to-solid.d.ts +3 -17
  141. package/dist/brep/svg/svg-to-solid.d.ts.map +1 -1
  142. package/dist/brep/svg/svg-to-solid.js +16 -317
  143. package/dist/brep/svg/svg-to-solid.js.map +1 -1
  144. package/dist/brepkit-kernel/brepkitKernel.d.ts.map +1 -1
  145. package/dist/brepkit-kernel/brepkitKernel.js +10 -0
  146. package/dist/brepkit-kernel/brepkitKernel.js.map +1 -1
  147. package/dist/brepkit-kernel/brepkitWasm.d.ts +1 -1
  148. package/dist/brepkit-kernel/brepkitWasm.d.ts.map +1 -1
  149. package/dist/brepkit-kernel/brepkitWasm.js +7 -6
  150. package/dist/brepkit-kernel/brepkitWasm.js.map +1 -1
  151. package/dist/brepkit-kernel/multi-version-test.d.ts +7 -7
  152. package/dist/brepkit-kernel/multi-version-test.d.ts.map +1 -1
  153. package/dist/brepkit-kernel/multi-version-test.js +10 -10
  154. package/dist/brepkit-kernel/multi-version-test.js.map +1 -1
  155. package/dist/cad-runtime/direct-executor.js +2 -2
  156. package/dist/cad-runtime/direct-executor.js.map +1 -1
  157. package/dist/cad-runtime/runtime.js +5 -5
  158. package/dist/cad-runtime/runtime.js.map +1 -1
  159. package/dist/geometry2d/curve2d.js +42 -1
  160. package/dist/geometry2d/curve2d.js.map +1 -1
  161. package/dist/math3d/Box3.js.map +1 -1
  162. package/dist/math3d/Euler.js.map +1 -1
  163. package/dist/math3d/Mat4.js.map +1 -1
  164. package/dist/math3d/Plane.js.map +1 -1
  165. package/dist/math3d/Quat.js.map +1 -1
  166. package/dist/math3d/Vec2.js.map +1 -1
  167. package/dist/math3d/Vec3.js.map +1 -1
  168. package/dist/math3d/index.js.map +1 -1
  169. package/dist/mesh/meshdata/contour.d.ts +34 -0
  170. package/dist/mesh/meshdata/contour.d.ts.map +1 -0
  171. package/dist/mesh/meshdata/contour.js +39 -0
  172. package/dist/mesh/meshdata/contour.js.map +1 -0
  173. package/dist/mesh/meshdata/extrude.d.ts +25 -0
  174. package/dist/mesh/meshdata/extrude.d.ts.map +1 -0
  175. package/dist/mesh/meshdata/extrude.js +198 -0
  176. package/dist/mesh/meshdata/extrude.js.map +1 -0
  177. package/dist/mesh/meshdata/index.js.map +1 -1
  178. package/dist/mesh/meshdata/ops.js.map +1 -1
  179. package/dist/mesh/meshdata/parametric.js.map +1 -1
  180. package/dist/mesh/meshdata/weld.js.map +1 -1
  181. package/dist/node-host/cli.d.ts.map +1 -1
  182. package/dist/node-host/cli.js +3 -2
  183. package/dist/node-host/cli.js.map +1 -1
  184. package/dist/occt-kernel/occt-primitives.d.ts.map +1 -1
  185. package/dist/occt-kernel/occt-primitives.js +2 -0
  186. package/dist/occt-kernel/occt-primitives.js.map +1 -1
  187. package/dist/primitives/svg/svg-path.d.ts +192 -0
  188. package/dist/primitives/svg/svg-path.d.ts.map +1 -0
  189. package/dist/primitives/svg/svg-path.js +776 -0
  190. package/dist/primitives/svg/svg-path.js.map +1 -0
  191. package/dist/third-party/earcut.d.ts +19 -0
  192. package/dist/third-party/earcut.d.ts.map +1 -0
  193. package/dist/third-party/earcut.js +575 -0
  194. package/dist/third-party/earcut.js.map +1 -0
  195. package/package.json +10 -3
@@ -0,0 +1,575 @@
1
+ // Vendored earcut@2.2.4 as ESM (ISC license).
2
+ // The npm package ships CJS only; Vite dev (with @faicad/faijs excluded from
3
+ // optimizeDeps) serves node_modules raw and cannot import it. Vendoring the
4
+ // byte-identical algorithm as ESM keeps behavior the same in every environment.
5
+ //
6
+ // ISC License
7
+ // Copyright (c) 2016, Mapbox
8
+ //
9
+ // Permission to use, copy, modify, and/or distribute this software for any
10
+ // purpose with or without fee is hereby granted, provided that the above
11
+ // copyright notice and this permission notice appear in all copies.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14
+ // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15
+ // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16
+ // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
+ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18
+ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19
+ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
+ /* eslint-disable -- vendored third-party code (upstream uses var); keep byte-faithful */
21
+ // @ts-nocheck — vendored third-party code; keep byte-faithful to upstream.
22
+ 'use strict';
23
+ /**
24
+ * Triangulates a polygon (with optional holes) into triangle vertex indices.
25
+ * Vendored byte-faithful from npm earcut@2.2.4 (ISC license); do not edit the body.
26
+ * @param data - flat coordinate array (dim coordinates per vertex)
27
+ * @param holeIndices - start vertex index of each hole ring, if any
28
+ * @param dim - number of coordinates per vertex (default 2)
29
+ * @returns {number[]} flat triangle index array (3 indices per triangle)
30
+ */
31
+ function earcut(data, holeIndices, dim) {
32
+ dim = dim || 2;
33
+ var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = linkedList(data, 0, outerLen, dim, true), triangles = [];
34
+ if (!outerNode || outerNode.next === outerNode.prev)
35
+ return triangles;
36
+ var minX, minY, maxX, maxY, x, y, invSize;
37
+ if (hasHoles)
38
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
39
+ // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
40
+ if (data.length > 80 * dim) {
41
+ minX = maxX = data[0];
42
+ minY = maxY = data[1];
43
+ for (var i = dim; i < outerLen; i += dim) {
44
+ x = data[i];
45
+ y = data[i + 1];
46
+ if (x < minX)
47
+ minX = x;
48
+ if (y < minY)
49
+ minY = y;
50
+ if (x > maxX)
51
+ maxX = x;
52
+ if (y > maxY)
53
+ maxY = y;
54
+ }
55
+ // minX, minY and invSize are later used to transform coords into integers for z-order calculation
56
+ invSize = Math.max(maxX - minX, maxY - minY);
57
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
58
+ }
59
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
60
+ return triangles;
61
+ }
62
+ // create a circular doubly linked list from polygon points in the specified winding order
63
+ function linkedList(data, start, end, dim, clockwise) {
64
+ var i, last;
65
+ if (clockwise === (signedArea(data, start, end, dim) > 0)) {
66
+ for (i = start; i < end; i += dim)
67
+ last = insertNode(i, data[i], data[i + 1], last);
68
+ }
69
+ else {
70
+ for (i = end - dim; i >= start; i -= dim)
71
+ last = insertNode(i, data[i], data[i + 1], last);
72
+ }
73
+ if (last && equals(last, last.next)) {
74
+ removeNode(last);
75
+ last = last.next;
76
+ }
77
+ return last;
78
+ }
79
+ // eliminate colinear or duplicate points
80
+ function filterPoints(start, end) {
81
+ if (!start)
82
+ return start;
83
+ if (!end)
84
+ end = start;
85
+ var p = start, again;
86
+ do {
87
+ again = false;
88
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
89
+ removeNode(p);
90
+ p = end = p.prev;
91
+ if (p === p.next)
92
+ break;
93
+ again = true;
94
+ }
95
+ else {
96
+ p = p.next;
97
+ }
98
+ } while (again || p !== end);
99
+ return end;
100
+ }
101
+ // main ear slicing loop which triangulates a polygon (given as a linked list)
102
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
103
+ if (!ear)
104
+ return;
105
+ // interlink polygon nodes in z-order
106
+ if (!pass && invSize)
107
+ indexCurve(ear, minX, minY, invSize);
108
+ var stop = ear, prev, next;
109
+ // iterate through ears, slicing them one by one
110
+ while (ear.prev !== ear.next) {
111
+ prev = ear.prev;
112
+ next = ear.next;
113
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
114
+ // cut off the triangle
115
+ triangles.push(prev.i / dim | 0);
116
+ triangles.push(ear.i / dim | 0);
117
+ triangles.push(next.i / dim | 0);
118
+ removeNode(ear);
119
+ // skipping the next vertex leads to less sliver triangles
120
+ ear = next.next;
121
+ stop = next.next;
122
+ continue;
123
+ }
124
+ ear = next;
125
+ // if we looped through the whole remaining polygon and can't find any more ears
126
+ if (ear === stop) {
127
+ // try filtering points and slicing again
128
+ if (!pass) {
129
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
130
+ // if this didn't work, try curing all small self-intersections locally
131
+ }
132
+ else if (pass === 1) {
133
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
134
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
135
+ // as a last resort, try splitting the remaining polygon into two
136
+ }
137
+ else if (pass === 2) {
138
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
139
+ }
140
+ break;
141
+ }
142
+ }
143
+ }
144
+ // check whether a polygon node forms a valid ear with adjacent nodes
145
+ function isEar(ear) {
146
+ var a = ear.prev, b = ear, c = ear.next;
147
+ if (area(a, b, c) >= 0)
148
+ return false; // reflex, can't be an ear
149
+ // now make sure we don't have other points inside the potential ear
150
+ var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
151
+ // triangle bbox; min & max are calculated like this for speed
152
+ var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx), y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy), x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx), y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);
153
+ var p = c.next;
154
+ while (p !== a) {
155
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
156
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
157
+ area(p.prev, p, p.next) >= 0)
158
+ return false;
159
+ p = p.next;
160
+ }
161
+ return true;
162
+ }
163
+ function isEarHashed(ear, minX, minY, invSize) {
164
+ var a = ear.prev, b = ear, c = ear.next;
165
+ if (area(a, b, c) >= 0)
166
+ return false; // reflex, can't be an ear
167
+ var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
168
+ // triangle bbox; min & max are calculated like this for speed
169
+ var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx), y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy), x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx), y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);
170
+ // z-order range for the current triangle bbox;
171
+ var minZ = zOrder(x0, y0, minX, minY, invSize), maxZ = zOrder(x1, y1, minX, minY, invSize);
172
+ var p = ear.prevZ, n = ear.nextZ;
173
+ // look for points inside the triangle in both directions
174
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
175
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
176
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
177
+ return false;
178
+ p = p.prevZ;
179
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
180
+ pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
181
+ return false;
182
+ n = n.nextZ;
183
+ }
184
+ // look for remaining points in decreasing z-order
185
+ while (p && p.z >= minZ) {
186
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
187
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
188
+ return false;
189
+ p = p.prevZ;
190
+ }
191
+ // look for remaining points in increasing z-order
192
+ while (n && n.z <= maxZ) {
193
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
194
+ pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
195
+ return false;
196
+ n = n.nextZ;
197
+ }
198
+ return true;
199
+ }
200
+ // go through all polygon nodes and cure small local self-intersections
201
+ function cureLocalIntersections(start, triangles, dim) {
202
+ var p = start;
203
+ do {
204
+ var a = p.prev, b = p.next.next;
205
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
206
+ triangles.push(a.i / dim | 0);
207
+ triangles.push(p.i / dim | 0);
208
+ triangles.push(b.i / dim | 0);
209
+ // remove two nodes involved
210
+ removeNode(p);
211
+ removeNode(p.next);
212
+ p = start = b;
213
+ }
214
+ p = p.next;
215
+ } while (p !== start);
216
+ return filterPoints(p);
217
+ }
218
+ // try splitting polygon into two and triangulate them independently
219
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
220
+ // look for a valid diagonal that divides the polygon into two
221
+ var a = start;
222
+ do {
223
+ var b = a.next.next;
224
+ while (b !== a.prev) {
225
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
226
+ // split the polygon in two by the diagonal
227
+ var c = splitPolygon(a, b);
228
+ // filter colinear points around the cuts
229
+ a = filterPoints(a, a.next);
230
+ c = filterPoints(c, c.next);
231
+ // run earcut on each half
232
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
233
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
234
+ return;
235
+ }
236
+ b = b.next;
237
+ }
238
+ a = a.next;
239
+ } while (a !== start);
240
+ }
241
+ // link every hole into the outer loop, producing a single-ring polygon without holes
242
+ function eliminateHoles(data, holeIndices, outerNode, dim) {
243
+ var queue = [], i, len, start, end, list;
244
+ for (i = 0, len = holeIndices.length; i < len; i++) {
245
+ start = holeIndices[i] * dim;
246
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
247
+ list = linkedList(data, start, end, dim, false);
248
+ if (list === list.next)
249
+ list.steiner = true;
250
+ queue.push(getLeftmost(list));
251
+ }
252
+ queue.sort(compareX);
253
+ // process holes from left to right
254
+ for (i = 0; i < queue.length; i++) {
255
+ outerNode = eliminateHole(queue[i], outerNode);
256
+ }
257
+ return outerNode;
258
+ }
259
+ function compareX(a, b) {
260
+ return a.x - b.x;
261
+ }
262
+ // find a bridge between vertices that connects hole with an outer ring and and link it
263
+ function eliminateHole(hole, outerNode) {
264
+ var bridge = findHoleBridge(hole, outerNode);
265
+ if (!bridge) {
266
+ return outerNode;
267
+ }
268
+ var bridgeReverse = splitPolygon(bridge, hole);
269
+ // filter collinear points around the cuts
270
+ filterPoints(bridgeReverse, bridgeReverse.next);
271
+ return filterPoints(bridge, bridge.next);
272
+ }
273
+ // David Eberly's algorithm for finding a bridge between hole and outer polygon
274
+ function findHoleBridge(hole, outerNode) {
275
+ var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;
276
+ // find a segment intersected by a ray from the hole's leftmost point to the left;
277
+ // segment's endpoint with lesser x will be potential connection point
278
+ do {
279
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
280
+ var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
281
+ if (x <= hx && x > qx) {
282
+ qx = x;
283
+ m = p.x < p.next.x ? p : p.next;
284
+ if (x === hx)
285
+ return m; // hole touches outer segment; pick leftmost endpoint
286
+ }
287
+ }
288
+ p = p.next;
289
+ } while (p !== outerNode);
290
+ if (!m)
291
+ return null;
292
+ // look for points inside the triangle of hole point, segment intersection and endpoint;
293
+ // if there are no points found, we have a valid connection;
294
+ // otherwise choose the point of the minimum angle with the ray as connection point
295
+ var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;
296
+ p = m;
297
+ do {
298
+ if (hx >= p.x && p.x >= mx && hx !== p.x &&
299
+ pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
300
+ tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
301
+ if (locallyInside(p, hole) &&
302
+ (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
303
+ m = p;
304
+ tanMin = tan;
305
+ }
306
+ }
307
+ p = p.next;
308
+ } while (p !== stop);
309
+ return m;
310
+ }
311
+ // whether sector in vertex m contains sector in vertex p in the same coordinates
312
+ function sectorContainsSector(m, p) {
313
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
314
+ }
315
+ // interlink polygon nodes in z-order
316
+ function indexCurve(start, minX, minY, invSize) {
317
+ var p = start;
318
+ do {
319
+ if (p.z === 0)
320
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
321
+ p.prevZ = p.prev;
322
+ p.nextZ = p.next;
323
+ p = p.next;
324
+ } while (p !== start);
325
+ p.prevZ.nextZ = null;
326
+ p.prevZ = null;
327
+ sortLinked(p);
328
+ }
329
+ // Simon Tatham's linked list merge sort algorithm
330
+ // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
331
+ function sortLinked(list) {
332
+ var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
333
+ do {
334
+ p = list;
335
+ list = null;
336
+ tail = null;
337
+ numMerges = 0;
338
+ while (p) {
339
+ numMerges++;
340
+ q = p;
341
+ pSize = 0;
342
+ for (i = 0; i < inSize; i++) {
343
+ pSize++;
344
+ q = q.nextZ;
345
+ if (!q)
346
+ break;
347
+ }
348
+ qSize = inSize;
349
+ while (pSize > 0 || (qSize > 0 && q)) {
350
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
351
+ e = p;
352
+ p = p.nextZ;
353
+ pSize--;
354
+ }
355
+ else {
356
+ e = q;
357
+ q = q.nextZ;
358
+ qSize--;
359
+ }
360
+ if (tail)
361
+ tail.nextZ = e;
362
+ else
363
+ list = e;
364
+ e.prevZ = tail;
365
+ tail = e;
366
+ }
367
+ p = q;
368
+ }
369
+ tail.nextZ = null;
370
+ inSize *= 2;
371
+ } while (numMerges > 1);
372
+ return list;
373
+ }
374
+ // z-order of a point given coords and inverse of the longer side of data bbox
375
+ function zOrder(x, y, minX, minY, invSize) {
376
+ // coords are transformed into non-negative 15-bit integer range
377
+ x = (x - minX) * invSize | 0;
378
+ y = (y - minY) * invSize | 0;
379
+ x = (x | (x << 8)) & 0x00FF00FF;
380
+ x = (x | (x << 4)) & 0x0F0F0F0F;
381
+ x = (x | (x << 2)) & 0x33333333;
382
+ x = (x | (x << 1)) & 0x55555555;
383
+ y = (y | (y << 8)) & 0x00FF00FF;
384
+ y = (y | (y << 4)) & 0x0F0F0F0F;
385
+ y = (y | (y << 2)) & 0x33333333;
386
+ y = (y | (y << 1)) & 0x55555555;
387
+ return x | (y << 1);
388
+ }
389
+ // find the leftmost node of a polygon ring
390
+ function getLeftmost(start) {
391
+ var p = start, leftmost = start;
392
+ do {
393
+ if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y))
394
+ leftmost = p;
395
+ p = p.next;
396
+ } while (p !== start);
397
+ return leftmost;
398
+ }
399
+ // check if a point lies within a convex triangle
400
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
401
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&
402
+ (ax - px) * (by - py) >= (bx - px) * (ay - py) &&
403
+ (bx - px) * (cy - py) >= (cx - px) * (by - py);
404
+ }
405
+ // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
406
+ function isValidDiagonal(a, b) {
407
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
408
+ (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
409
+ (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
410
+ equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
411
+ }
412
+ // signed area of a triangle
413
+ function area(p, q, r) {
414
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
415
+ }
416
+ // check if two points are equal
417
+ function equals(p1, p2) {
418
+ return p1.x === p2.x && p1.y === p2.y;
419
+ }
420
+ // check if two segments intersect
421
+ function intersects(p1, q1, p2, q2) {
422
+ var o1 = sign(area(p1, q1, p2));
423
+ var o2 = sign(area(p1, q1, q2));
424
+ var o3 = sign(area(p2, q2, p1));
425
+ var o4 = sign(area(p2, q2, q1));
426
+ if (o1 !== o2 && o3 !== o4)
427
+ return true; // general case
428
+ if (o1 === 0 && onSegment(p1, p2, q1))
429
+ return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
430
+ if (o2 === 0 && onSegment(p1, q2, q1))
431
+ return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
432
+ if (o3 === 0 && onSegment(p2, p1, q2))
433
+ return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
434
+ if (o4 === 0 && onSegment(p2, q1, q2))
435
+ return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
436
+ return false;
437
+ }
438
+ // for collinear points p, q, r, check if point q lies on segment pr
439
+ function onSegment(p, q, r) {
440
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
441
+ }
442
+ function sign(num) {
443
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
444
+ }
445
+ // check if a polygon diagonal intersects any polygon segments
446
+ function intersectsPolygon(a, b) {
447
+ var p = a;
448
+ do {
449
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
450
+ intersects(p, p.next, a, b))
451
+ return true;
452
+ p = p.next;
453
+ } while (p !== a);
454
+ return false;
455
+ }
456
+ // check if a polygon diagonal is locally inside the polygon
457
+ function locallyInside(a, b) {
458
+ return area(a.prev, a, a.next) < 0 ?
459
+ area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
460
+ area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
461
+ }
462
+ // check if the middle point of a polygon diagonal is inside the polygon
463
+ function middleInside(a, b) {
464
+ var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
465
+ do {
466
+ if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
467
+ (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
468
+ inside = !inside;
469
+ p = p.next;
470
+ } while (p !== a);
471
+ return inside;
472
+ }
473
+ // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
474
+ // if one belongs to the outer ring and another to a hole, it merges it into a single ring
475
+ function splitPolygon(a, b) {
476
+ var a2 = new Node(a.i, a.x, a.y), b2 = new Node(b.i, b.x, b.y), an = a.next, bp = b.prev;
477
+ a.next = b;
478
+ b.prev = a;
479
+ a2.next = an;
480
+ an.prev = a2;
481
+ b2.next = a2;
482
+ a2.prev = b2;
483
+ bp.next = b2;
484
+ b2.prev = bp;
485
+ return b2;
486
+ }
487
+ // create a node and optionally link it with previous one (in a circular doubly linked list)
488
+ function insertNode(i, x, y, last) {
489
+ var p = new Node(i, x, y);
490
+ if (!last) {
491
+ p.prev = p;
492
+ p.next = p;
493
+ }
494
+ else {
495
+ p.next = last.next;
496
+ p.prev = last;
497
+ last.next.prev = p;
498
+ last.next = p;
499
+ }
500
+ return p;
501
+ }
502
+ function removeNode(p) {
503
+ p.next.prev = p.prev;
504
+ p.prev.next = p.next;
505
+ if (p.prevZ)
506
+ p.prevZ.nextZ = p.nextZ;
507
+ if (p.nextZ)
508
+ p.nextZ.prevZ = p.prevZ;
509
+ }
510
+ function Node(i, x, y) {
511
+ // vertex index in coordinates array
512
+ this.i = i;
513
+ // vertex coordinates
514
+ this.x = x;
515
+ this.y = y;
516
+ // previous and next vertex nodes in a polygon ring
517
+ this.prev = null;
518
+ this.next = null;
519
+ // z-order curve value
520
+ this.z = 0;
521
+ // previous and next nodes in z-order
522
+ this.prevZ = null;
523
+ this.nextZ = null;
524
+ // indicates whether this is a steiner point
525
+ this.steiner = false;
526
+ }
527
+ // return a percentage difference between the polygon area and its triangulation area;
528
+ // used to verify correctness of triangulation
529
+ earcut.deviation = function (data, holeIndices, dim, triangles) {
530
+ var hasHoles = holeIndices && holeIndices.length;
531
+ var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
532
+ var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
533
+ if (hasHoles) {
534
+ for (var i = 0, len = holeIndices.length; i < len; i++) {
535
+ var start = holeIndices[i] * dim;
536
+ var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
537
+ polygonArea -= Math.abs(signedArea(data, start, end, dim));
538
+ }
539
+ }
540
+ var trianglesArea = 0;
541
+ for (i = 0; i < triangles.length; i += 3) {
542
+ var a = triangles[i] * dim;
543
+ var b = triangles[i + 1] * dim;
544
+ var c = triangles[i + 2] * dim;
545
+ trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
546
+ (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
547
+ }
548
+ return polygonArea === 0 && trianglesArea === 0 ? 0 :
549
+ Math.abs((trianglesArea - polygonArea) / polygonArea);
550
+ };
551
+ function signedArea(data, start, end, dim) {
552
+ var sum = 0;
553
+ for (var i = start, j = end - dim; i < end; i += dim) {
554
+ sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
555
+ j = i;
556
+ }
557
+ return sum;
558
+ }
559
+ // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
560
+ earcut.flatten = function (data) {
561
+ var dim = data[0][0].length, result = { vertices: [], holes: [], dimensions: dim }, holeIndex = 0;
562
+ for (var i = 0; i < data.length; i++) {
563
+ for (var j = 0; j < data[i].length; j++) {
564
+ for (var d = 0; d < dim; d++)
565
+ result.vertices.push(data[i][j][d]);
566
+ }
567
+ if (i > 0) {
568
+ holeIndex += data[i - 1].length;
569
+ result.holes.push(holeIndex);
570
+ }
571
+ }
572
+ return result;
573
+ };
574
+ export default earcut;
575
+ //# sourceMappingURL=earcut.js.map