diff --git a/dist/path-bool.core.js b/dist/path-bool.core.js index f4e9767..9fd9534 100644 --- a/dist/path-bool.core.js +++ b/dist/path-bool.core.js @@ -1581,6 +1581,7 @@ function findVertices(edges, boundingBox) { } break; case "A": + // TODO: explain if (edge.seg[5] === false) { return []; } @@ -1588,7 +1589,6 @@ function findVertices(edges, boundingBox) { } } const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`; - // TODO: check other direction if (hasOwn(vertexPairIdToEdges, vertexPairId)) { const existingEdge = vertexPairIdToEdges[vertexPairId].find((other) => segmentsEqual(other[0].seg, edge.seg, EPS.point)); if (existingEdge) { @@ -1597,6 +1597,20 @@ function findVertices(edges, boundingBox) { return []; } } + const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`; + if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) { + const reversedSeg = reversePathSegment(edge.seg); + const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find((other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point)); + if (existingEdge) { + if (existingEdge[0].parent === edge.parent) { + // discard "there and back" pairs + return []; + } + existingEdge[1].parent |= edge.parent; + existingEdge[2].parent |= edge.parent; + return []; + } + } const fwdEdge = { ...edge, incidentVertices: [startVertex, endVertex], diff --git a/dist/path-bool.core.js.map b/dist/path-bool.core.js.map index 7c4aa55..fc1cd8a 100644 --- a/dist/path-bool.core.js.map +++ b/dist/path-bool.core.js.map @@ -1 +1 @@ -{"version":3,"file":"path-bool.core.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/PathCommand.ts","../src/primitives/Path.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n // TODO: check other direction\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d.scale","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d"],"mappings":"AAUA;AAEA,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AAEnB,SAAS,OAAO,CAAC,CAAS,EAAE,CAAS,EAAE,WAAiB,EAAA;IACpD,IAAI,IAAI,GAAG,MAAM,CAAC;AAElB,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE;QACtB,IAAI,IAAI,IAAI,CAAC;KAChB;AAAM,SAAA,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE;QAC9B,IAAI,IAAI,KAAK,CAAC;KACjB;AAED,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE;QACrB,IAAI,IAAI,MAAM,CAAC;KAClB;AAAM,SAAA,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE;QAC/B,IAAI,IAAI,GAAG,CAAC;KACf;AAED,IAAA,OAAO,IAAI,CAAC;AAChB,CAAC;AAEe,SAAA,wBAAwB,CAAC,GAAgB,EAAE,WAAiB,EAAA;AACxE,IAAA,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,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ACN,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;AACN,qBAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC;iBACtB,CAAC;gBACF,MAAM;SACb;KACJ;AACL;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file +{"version":3,"file":"path-bool.core.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/PathCommand.ts","../src/primitives/Path.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n // TODO: explain\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {\n const reversedSeg = reversePathSegment(edge.seg);\n const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(\n (other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),\n );\n if (existingEdge) {\n if (existingEdge[0].parent === edge.parent) {\n // discard \"there and back\" pairs\n return [];\n }\n\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d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GAAG;gBACJ,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClD,MAAM;AACV,YAAA,KAAK,GAAG;AACJ,gBAAA,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1C,MAAM;AACV,YAAA,KAAK,GAAG;gBACJ,MAAM;oBACF,GAAG;oBACH,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;oBACN,GAAG,CAAC,CAAC,CAAC;AACN,qBAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC;iBACtB,CAAC;gBACF,MAAM;SACb;KACJ;AACL;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file diff --git a/dist/path-bool.core.umd.js b/dist/path-bool.core.umd.js index 21c039f..2c0baed 100644 --- a/dist/path-bool.core.umd.js +++ b/dist/path-bool.core.umd.js @@ -1,2 +1,2 @@ -var t,n;t=this,n=function(t){const n=0,e=1,o=2,r=4,s=8;function i(t,i,a){let c=n;return ta.right&&(c|=o),ia.bottom&&(c|=s),c}function a(t,n){let[[a,c],[u,f]]=t,g=i(a,c,n),h=i(u,f,n);for(;;){if(!(g|h))return!0;if(g&h)return!1;{const{top:t,right:l,bottom:d,left:p}=n;let m,b;const M=h>g?h:g;M&s?(m=a+(u-a)*(d-c)/(f-c),b=d):M&r?(m=a+(u-a)*(t-c)/(f-c),b=t):M&o?(b=c+(f-c)*(l-a)/(u-a),m=l):M&e&&(b=c+(f-c)*(p-a)/(u-a),m=p),M==g?(a=m,c=b,g=i(a,c,n)):(u=m,f=b,h=i(u,f,n))}}}function c(t,n){return t.left<=n.right&&n.left<=t.right&&t.top<=n.bottom&&n.top<=t.bottom}function u(t,n){return t?{top:Math.min(t.top,n.top),right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom),left:Math.min(t.left,n.left)}:n}function f(t,n){return t?{top:Math.min(t.top,n[1]),right:Math.max(t.right,n[0]),bottom:Math.max(t.bottom,n[1]),left:Math.min(t.left,n[0])}:{top:n[1],right:n[0],bottom:n[1],left:n[0]}}function g(t){return Math.max(t.right-t.left,t.bottom-t.top)}function h(t,n){return{top:t[1]-n,right:t[0]+n,bottom:t[1]+n,left:t[0]-n}}class l{static fromPairs(t,n,e=8){if(0===t.length)throw new Error("QuadTree.fromPairs: at least one pair needed.");let o=t[0][0];for(let n=1;n0&&this.pairs.length>=this.innerNodeCapacity){this.ensureSubtrees();for(let e=0;e{const t=[0,0],n=b(),e=[0,0],o=[0,0];return function([r,s,i,a,c,u,f,g]){if(0===i||0===a)return null;M(n,-I(c)),C(t,s,g),B(t,t,.5),P(t,t,n);let h=i*i,l=a*a;const d=t[0]*t[0],p=t[1]*t[1];i=Math.abs(i),a=Math.abs(a);const m=d/h+p/l+1e-12;if(m>1){const t=Math.sqrt(m);i*=t,a*=t;const n=Math.abs(m);h*=n,l*=n}const b=u===f?-1:1,w=Math.sqrt((h*l-h*p-l*d)/(h*p+l*d)),x=b*w*(i*t[1]/a),y=b*w*(-a*t[0]/i);!function(t,n){if(t===n){var e=n[1];t[1]=n[2],t[2]=e}else t[0]=n[0],t[1]=n[2],t[2]=n[1],t[3]=n[3]}(n,n),v(e,s,g),B(e,e,.5),P(o,[x,y],n),v(o,o,e);const E=[(t[0]-x)/i,(t[1]-y)/a],k=O([1,0],E);let F=O(E,[(-t[0]-x)/i,(-t[1]-y)/a]);return!f&&F>0?F-=A:f&&F<0&&(F+=A),{center:[o[0],o[1]],theta1:k,deltaTheta:F,rx:i,ry:a,phi:c}}})(),D=(()=>{const t=[0,0],n=[0,0],e=b();return function({center:o,theta1:r,deltaTheta:s,rx:i,ry:a,phi:c}){M(e,c),E(t,i*Math.cos(r),a*Math.sin(r)),P(t,t,e),v(t,t,o),E(n,i*Math.cos(r+s),a*Math.sin(r+s)),P(n,n,e),v(n,n,o);const u=Math.abs(s)>Math.PI;return["A",[t[0],t[1]],i,a,c,u,s>0,[n[0],n[1]]]}})(),Z=(()=>{const t=[0,0],n=[0,0],e=[0,0],o=[0,0],r=[0,0],s=[0,0];return function(i,a){switch(i[0]){case"L":k(s,i[1],i[2],a);break;case"C":k(t,i[1],i[2],a),k(n,i[2],i[3],a),k(e,i[3],i[4],a),k(o,t,n,a),k(r,n,e,a),k(s,o,r,a);break;case"Q":k(t,i[1],i[2],a),k(n,i[2],i[3],a),k(s,t,n,a);break;case"A":{const t=q(i);if(!t){k(s,i[1],i[7],a);break}const{deltaTheta:n,phi:e,theta1:o,rx:r,ry:c,center:u}=t,f=o+a*n;E(s,r*Math.cos(f),c*Math.sin(f)),function(t,n,e,o){var r=n[0]-e[0],s=n[1]-e[1],i=Math.sin(o),a=Math.cos(o);t[0]=r*a-s*i+e[0],t[1]=r*i+s*a+e[1]}(s,s,[0,0],e),v(s,s,u);break}}return[s[0],s[1]]}})(),$=(()=>{const t=w(),n=w();return function(e,o=Math.PI/2){const r=q(e);if(!r)return[["L",e[1],e[7]]];const{center:s,theta1:i,deltaTheta:a,rx:c,ry:u}=r,f=Math.ceil(Math.abs(a)/o);!function(t,n){t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=n[0],t[5]=n[1]}(t,s),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=Math.sin(e),f=Math.cos(e);t[0]=o*f+s*u,t[1]=r*f+i*u,t[2]=o*-u+s*f,t[3]=r*-u+i*f,t[4]=a,t[5]=c}(t,t,I(e[4])),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=e[0],f=e[1];t[0]=o*u,t[1]=r*u,t[2]=s*f,t[3]=i*f,t[4]=a,t[5]=c}(t,t,[c,u]);const g=[],h=a/f,l=4/3*Math.tan(h/4),d=Math.sin(h),p=Math.cos(h);for(let e=0;e1-o.param)&&(r[1]1-o.param)?[]:[r]}let r=[[{seg:t,startParam:0,endParam:1,boundingBox:G(t)},{seg:n,startParam:0,endParam:1,boundingBox:G(n)}]];const s=[];for(;r.length;){const t=[];for(const[n,e]of r){if(et(n.seg,e.seg,o.point))continue;const r=g(n.boundingBox)<=o.linear,i=g(e.boundingBox)<=o.linear;if(r&&i){const t=X(tt(n.seg),tt(e.seg),o.param);t&&s.push([Q(n.startParam,n.endParam,t[0]),Q(e.startParam,e.endParam,t[1])])}else{const o=r?[n]:Y(n),s=i?[e]:Y(e);for(const n of o)for(const e of s)nt(n,e)&&t.push([n,e])}}r=t}return e?s:s.filter((([t,n])=>t>o.param&&t<1-o.param||n>o.param&&n<1-o.param))}const rt=Object.hasOwn;function st(t){const n=new WeakMap;return(e,...o)=>{if(n.has(e))return n.get(e);{const r=t(e,...o);return n.set(e,r),r}}}function*it(t,n){let e=0;for(const o of t)yield n(o,e++)}const at=8,ct=8,ut={point:1e-6,linear:1e-4,param:1e-8};var ft,gt;function ht(){let t=0;return st((()=>t++))}function lt(t){return n=>({seg:n,parent:t})}function dt(t){return t.outgoingEdges.length}function pt({directionFlag:t,segments:n}){let e,o;const r=n[0];return t?(e=Z(r,1),o=Z(r,1-ut.param)):(e=Z(r,0),o=Z(r,ut.param)),Math.atan2(o[1]-e[1],o[0]-e[0])}function mt(t){const{outgoingEdges:n}=t.incidentVertices[1],e=n.findIndex((n=>n.twin===t));return n[(e+1)%n.length]}t.PathBooleanOperation=void 0,(ft=t.PathBooleanOperation||(t.PathBooleanOperation={}))[ft.Union=0]="Union",ft[ft.Difference=1]="Difference",ft[ft.Intersection=2]="Intersection",ft[ft.Exclusion=3]="Exclusion",ft[ft.Division=4]="Division",ft[ft.Fracture=5]="Fracture",t.FillRule=void 0,(gt=t.FillRule||(t.FillRule={}))[gt.NonZero=0]="NonZero",gt[gt.EvenOdd=1]="EvenOdd";const bt=st((t=>t.incidentEdges.flatMap((t=>{const n=[];for(const e of t.segments)for(let o=0;o<64;o++){const r=o/64,s=t.directionFlag?1-r:r;n.push(Z(e,s))}return n}))));function Mt(t,n,e){return t>=e==n=e[0]);var o,r,s,i,a}function xt(t,n){if(t.length<=2)return 0;let e=t[t.length-1],o=0;for(const r of t)wt(e,r,n)&&(o+=r[1]>e[1]?-1:1),e=r;return o}function yt(t){const n=bt(t);for(let t=0;t=n[0]}function vt(t,n){const e=G(t);if(!Et(e,n))return 0;let o=[{boundingBox:e,seg:t}],r=0;for(;o.length>0;){const t=[];for(const{boundingBox:e,seg:s}of o)if(g(e)t>0,[t.PathBooleanOperation.Difference]:({flag:t})=>1===t,[t.PathBooleanOperation.Intersection]:({flag:t})=>3===t,[t.PathBooleanOperation.Exclusion]:({flag:t})=>1===t||2===t,[t.PathBooleanOperation.Division]:({flag:t})=>!(1&~t),[t.PathBooleanOperation.Fracture]:({flag:t})=>t>0};function Lt(t,n){return[2*t[0]-n[0],2*t[1]-n[1]]}t.pathBoolean=function(n,e,o,r,s){const i=[...it(n,lt(1)),...it(o,lt(2))];!function(t){for(let n=0;no[1]&&o.reverse();const[r,s]=o;if(Math.abs(r-s)({...t,boundingBox:G(t.seg)}))),e=n.reduce(((t,{boundingBox:n})=>u(t,n)),null);if(!e)return{edges:[],totalBoundingBox:null};const o=new l(e,at),r={};function s(t,n){rt(r,t)||(r[t]=[]),r[t].push(n)}for(let e=0;e1-ut.param)break;const r=(n-a)/(1-a);if(a=n,r1-ut.param)continue;const[c,u]=J(s,r);i.push({seg:c,boundingBox:G(c),parent:e.parent}),s=u}i.push({seg:s,boundingBox:G(s),parent:e.parent})}return{edges:i,totalBoundingBox:e}}(i);if(!c)return[];const f=function(t,n){const e=new l(n,ct),o=[];function r(t){const n=h(t,ut.point),r=e.find(n);if(r.size)return function(t){return t.values().next().value}(r);{const r={point:t,outgoingEdges:[]};return e.insert(n,r),o.push(r),r}}const s=ht(),i={};return{edges:t.flatMap((t=>{const n=r(T(t.seg)),e=r(N(t.seg));if(n===e)switch(t.seg[0]){case"L":return[];case"C":if(S(t.seg[1],t.seg[2],ut.point)&&S(t.seg[3],t.seg[4],ut.point))return[];break;case"Q":if(S(t.seg[1],t.seg[2],ut.point))return[];break;case"A":if(!1===t.seg[5])return[]}const o=`${s(n)}:${s(e)}`;if(rt(i,o)){const n=i[o].find((n=>et(n[0].seg,t.seg,ut.point)));if(n)return n[1].parent|=t.parent,n[2].parent|=t.parent,[]}const a={...t,incidentVertices:[n,e],directionFlag:!1,twin:null},c={...t,incidentVertices:[e,n],directionFlag:!0,twin:a};return a.twin=c,n.outgoingEdges.push(a),e.outgoingEdges.push(c),rt(i,o)?i[o].push([t,a,c]):i[o]=[[t,a,c]],[a,c]})),vertices:o}}(a,c),g=function({vertices:t}){const n=[],e=[],o=st((t=>{const n={outgoingEdges:[]};return e.push(n),n})),r=ht(),s={},i=new WeakSet;for(const e of t){if(2===dt(e))continue;const t=o(e);for(const a of e.outgoingEdges){const e=[];let c=a;for(;c.parent===a.parent&&c.directionFlag===a.directionFlag&&2===dt(c.incidentVertices[1]);){e.push(c.seg),i.add(c.incidentVertices[1]);const[t,n]=c.incidentVertices[1].outgoingEdges;c=t.twin===c?n:t}e.push(c.seg);const u=o(c.incidentVertices[1]),f=`${r(a)}-${r(c)}`,g=s[`${r(c.twin)}-${r(a.twin)}`]??null,h={segments:e,parent:a.parent,incidentVertices:[t,u],directionFlag:a.directionFlag,twin:g};g&&(g.twin=h),s[f]=h,t.outgoingEdges.push(h),n.push(h)}}const a=[];for(const n of t){if(2!==dt(n)||i.has(n))continue;let t=n.outgoingEdges[0];const e={segments:[],parent:t.parent,directionFlag:t.directionFlag};do{e.segments.push(t.seg),i.add(t.incidentVertices[0]);const[n,o]=t.incidentVertices[1].outgoingEdges;t=n.twin===t?o:n}while(t.incidentVertices[0]!==n);a.push(e)}return{edges:n,vertices:e,cycles:a}}(f);!function(t){function n(n){const e=new WeakSet,o=new WeakMap;function r(t,s,i){if(o.has(t))return o.get(t);o.set(t,i);let a=1/0;for(const e of t.outgoingEdges)e.parent&n&&e!==s&&(a=Math.min(a,r(e.incidentVertices[1],e.twin,i+1)));return a<=i&&e.add(t),a}for(const e of t.edges)e.parent&n&&r(e.incidentVertices[0],null,0);return e}const e=n(1),o=n(2);function r(t){return!(1&~t.parent)&&e.has(t.incidentVertices[0])&&e.has(t.incidentVertices[1])||!(2&~t.parent)&&o.has(t.incidentVertices[0])&&o.has(t.incidentVertices[1])}t.vertices=t.vertices.filter((function(t){return e.has(t)||o.has(t)}));for(const n of t.vertices)n.outgoingEdges=n.outgoingEdges.filter(r);t.edges=t.edges.filter(r)}(g),function({vertices:t}){const n=st(pt);for(const e of t)dt(e)>2&&e.outgoingEdges.sort(((t,e)=>n(t)-n(e)))}(g);const d=function(t){let n=[];function e(t,n){let o=!1;for(const r of t){const t=Bt(n,r.component);if(t){if(r.outgoingEdges.has(t)){const o=r.outgoingEdges.get(t);r.outgoingEdges.set(t,e(o,n))}else r.outgoingEdges.set(t,[{component:n,outgoingEdges:new Map}]);o=!0;break}}if(o)return t;{const e={component:n,outgoingEdges:new Map},o=[e];for(const r of t){const t=Bt(r.component,n);t?e.outgoingEdges.has(t)?e.outgoingEdges.get(t).push(r):e.outgoingEdges.set(t,[r]):o.push(r)}return o}}for(const o of t)n=e(n,o);return n}(function({edges:t,cycles:n}){const e=[],o=new WeakMap;for(const n of t){if(o.has(n))continue;const t={incidentEdges:[],flag:0};let r=n;do{const n=o.get(r.twin)??null,e={segments:r.segments,parent:r.parent,incidentVertex:t,directionFlag:r.directionFlag,twin:n};n&&(n.twin=e),o.set(r,e),t.incidentEdges.push(e),r=mt(r)}while(r.incidentVertices[0]!==n.incidentVertices[0]);e.push(t)}for(const t of n){const n={incidentEdges:[],flag:0},o={segments:t.segments,parent:t.parent,incidentVertex:n,directionFlag:t.directionFlag,twin:null},r={incidentEdges:[],flag:0},s={segments:[...t.segments].reverse(),parent:t.parent,incidentVertex:r,directionFlag:!t.directionFlag,twin:o};o.twin=s,n.incidentEdges.push(o),r.incidentEdges.push(s),e.push(n,r)}const r=[],s=new WeakSet,i=new WeakSet;for(const t of e){if(s.has(t))continue;const n=[],e=[],o=t=>{s.has(t)||n.push(t),s.add(t);for(const n of t.incidentEdges){if(i.has(n))continue;const{twin:t}=n;e.push(n,t),i.add(n),i.add(t),o(t.incidentVertex)}};o(t);const a=n.find((t=>yt(t).winding<0));r.push({vertices:n,edges:e,outerFace:a})}return r}(g));!function(t,n,e){function o(t,r,s){const i=new WeakSet;!function r(s,a,c){if(i.has(s))return;i.add(s);const u=kt(a,n),f=kt(c,e);s.flag=u|f<<1;for(const t of s.incidentEdges){const n=t.twin;let e=a;1&t.parent&&(e+=t.directionFlag?-1:1);let o=c;2&t.parent&&(o+=t.directionFlag?-1:1),r(n.incidentVertex,e,o)}if(t.outgoingEdges.has(s)){const n=t.outgoingEdges.get(s);for(const t of n)o(t,a,c)}}(t.component.outerFace,r,s)}for(const n of t)o(n,0,0)}(d,e,r);const m=Ft[s];switch(s){case t.PathBooleanOperation.Division:case t.PathBooleanOperation.Fracture:return function(t,n){const e=[];function o(t){for(const o of t.component.vertices){if(!n(o)||o===t.component.outerFace)continue;const r=[];for(const t of o.incidentEdges)t.directionFlag?r.push(...t.segments.map(W)):r.push(...t.segments);if(t.outgoingEdges.has(o))for(const n of t.outgoingEdges.get(o)){const{outerFace:t}=n.component;for(const n of t.incidentEdges)n.directionFlag?r.push(...n.segments.map(W)):r.push(...n.segments)}e.push(r)}for(const n of t.outgoingEdges.values())for(const t of n)o(t)}for(const n of t)o(n);return e}(d,m);default:{const t=new Set(function*(t,n){function*e(t){for(const e of t.component.vertices)n(e)&&(yield e);for(const n of t.outgoingEdges.values())for(const t of n)yield*e(t)}for(const n of t)yield*e(n)}(d,m));return[[...Pt(t)]]}}},t.pathFromCommands=function*(t){let n=null,e=null,o=null;function r(){throw new Error("Bad SVG path data sequence.")}for(const s of function*(t){let n=[0,0],e=n;for(const o of t)switch(o[0]){case"M":yield o,n=e=o[1];break;case"L":case"T":yield o,n=o[1];break;case"C":yield o,n=o[3];break;case"S":case"Q":yield o,n=o[2];break;case"A":yield o,n=o[6];break;case"Z":case"z":n=e,yield["Z"];break;case"H":n=[o[1],n[1]],yield["L",n];break;case"V":n=[n[0],o[1]],yield["L",n];break;case"m":n=e=[n[0]+o[1],n[1]+o[2]],yield["M",n];break;case"l":n=[n[0]+o[1],n[1]+o[2]],yield["L",n];break;case"h":n=[n[0]+o[1],n[1]],yield["L",n];break;case"v":n=[n[0],n[1]+o[1]],yield["L",n];break;case"c":yield["C",[n[0]+o[1],n[1]+o[2]],[n[0]+o[3],n[1]+o[4]],n=[n[0]+o[5],n[1]+o[6]]];break;case"s":yield["S",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"q":yield["Q",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"t":yield["T",n=[n[0]+o[1],n[1]+o[2]]];break;case"a":yield["A",o[1],o[2],o[3],o[4],o[5],n=[n[0]+o[6],n[1]+o[7]]]}}(t))switch(s[0]){case"M":e=n=s[1],o=null;break;case"L":e||r(),yield["L",e,s[1]],e=s[1],o=null;break;case"C":e||r(),yield["C",e,s[1],s[2],s[3]],e=s[3],o=s[2];break;case"S":e||r(),o||r(),yield["C",e,Lt(e,o),s[1],s[2]],e=s[2],o=s[1];break;case"Q":e||r(),yield["Q",e,s[1],s[2]],e=s[2],o=s[1];break;case"T":e||r(),o||r(),o=Lt(e,o),yield["Q",e,o,s[1]],e=s[1];break;case"A":e||r(),yield["A",e,s[1],s[2],s[3],s[4],s[5],s[6]],e=s[6],o=null;break;case"Z":case"z":e||r(),n||r(),yield["L",e,n],e=n,o=null}},t.pathToCommands=function*(t,n=1e-4){let e=null;for(const o of t)switch(e&&S(o[1],e,n)||(yield["M",o[1]]),o[0]){case"L":yield["L",e=o[2]];break;case"C":yield["C",o[2],o[3],e=o[4]];break;case"Q":yield["Q",o[2],e=o[3]];break;case"A":yield["A",o[2],o[3],o[4],o[5],o[6],e=o[7]]}}},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).PathBool={}); +var t,n;t=this,n=function(t){const n=0,e=1,o=2,r=4,s=8;function i(t,i,a){let c=n;return ta.right&&(c|=o),ia.bottom&&(c|=s),c}function a(t,n){let[[a,c],[u,f]]=t,g=i(a,c,n),h=i(u,f,n);for(;;){if(!(g|h))return!0;if(g&h)return!1;{const{top:t,right:l,bottom:d,left:p}=n;let m,b;const M=h>g?h:g;M&s?(m=a+(u-a)*(d-c)/(f-c),b=d):M&r?(m=a+(u-a)*(t-c)/(f-c),b=t):M&o?(b=c+(f-c)*(l-a)/(u-a),m=l):M&e&&(b=c+(f-c)*(p-a)/(u-a),m=p),M==g?(a=m,c=b,g=i(a,c,n)):(u=m,f=b,h=i(u,f,n))}}}function c(t,n){return t.left<=n.right&&n.left<=t.right&&t.top<=n.bottom&&n.top<=t.bottom}function u(t,n){return t?{top:Math.min(t.top,n.top),right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom),left:Math.min(t.left,n.left)}:n}function f(t,n){return t?{top:Math.min(t.top,n[1]),right:Math.max(t.right,n[0]),bottom:Math.max(t.bottom,n[1]),left:Math.min(t.left,n[0])}:{top:n[1],right:n[0],bottom:n[1],left:n[0]}}function g(t){return Math.max(t.right-t.left,t.bottom-t.top)}function h(t,n){return{top:t[1]-n,right:t[0]+n,bottom:t[1]+n,left:t[0]-n}}class l{static fromPairs(t,n,e=8){if(0===t.length)throw new Error("QuadTree.fromPairs: at least one pair needed.");let o=t[0][0];for(let n=1;n0&&this.pairs.length>=this.innerNodeCapacity){this.ensureSubtrees();for(let e=0;e{const t=[0,0],n=b(),e=[0,0],o=[0,0];return function([r,s,i,a,c,u,f,g]){if(0===i||0===a)return null;M(n,-I(c)),C(t,s,g),B(t,t,.5),P(t,t,n);let h=i*i,l=a*a;const d=t[0]*t[0],p=t[1]*t[1];i=Math.abs(i),a=Math.abs(a);const m=d/h+p/l+1e-12;if(m>1){const t=Math.sqrt(m);i*=t,a*=t;const n=Math.abs(m);h*=n,l*=n}const b=u===f?-1:1,w=Math.sqrt((h*l-h*p-l*d)/(h*p+l*d)),x=b*w*(i*t[1]/a),y=b*w*(-a*t[0]/i);!function(t,n){if(t===n){var e=n[1];t[1]=n[2],t[2]=e}else t[0]=n[0],t[1]=n[2],t[2]=n[1],t[3]=n[3]}(n,n),v(e,s,g),B(e,e,.5),P(o,[x,y],n),v(o,o,e);const E=[(t[0]-x)/i,(t[1]-y)/a],k=O([1,0],E);let F=O(E,[(-t[0]-x)/i,(-t[1]-y)/a]);return!f&&F>0?F-=A:f&&F<0&&(F+=A),{center:[o[0],o[1]],theta1:k,deltaTheta:F,rx:i,ry:a,phi:c}}})(),$=(()=>{const t=[0,0],n=[0,0],e=b();return function({center:o,theta1:r,deltaTheta:s,rx:i,ry:a,phi:c}){M(e,c),E(t,i*Math.cos(r),a*Math.sin(r)),P(t,t,e),v(t,t,o),E(n,i*Math.cos(r+s),a*Math.sin(r+s)),P(n,n,e),v(n,n,o);const u=Math.abs(s)>Math.PI;return["A",[t[0],t[1]],i,a,c,u,s>0,[n[0],n[1]]]}})(),D=(()=>{const t=[0,0],n=[0,0],e=[0,0],o=[0,0],r=[0,0],s=[0,0];return function(i,a){switch(i[0]){case"L":k(s,i[1],i[2],a);break;case"C":k(t,i[1],i[2],a),k(n,i[2],i[3],a),k(e,i[3],i[4],a),k(o,t,n,a),k(r,n,e,a),k(s,o,r,a);break;case"Q":k(t,i[1],i[2],a),k(n,i[2],i[3],a),k(s,t,n,a);break;case"A":{const t=q(i);if(!t){k(s,i[1],i[7],a);break}const{deltaTheta:n,phi:e,theta1:o,rx:r,ry:c,center:u}=t,f=o+a*n;E(s,r*Math.cos(f),c*Math.sin(f)),function(t,n,e,o){var r=n[0]-e[0],s=n[1]-e[1],i=Math.sin(o),a=Math.cos(o);t[0]=r*a-s*i+e[0],t[1]=r*i+s*a+e[1]}(s,s,[0,0],e),v(s,s,u);break}}return[s[0],s[1]]}})(),Z=(()=>{const t=w(),n=w();return function(e,o=Math.PI/2){const r=q(e);if(!r)return[["L",e[1],e[7]]];const{center:s,theta1:i,deltaTheta:a,rx:c,ry:u}=r,f=Math.ceil(Math.abs(a)/o);!function(t,n){t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=n[0],t[5]=n[1]}(t,s),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=Math.sin(e),f=Math.cos(e);t[0]=o*f+s*u,t[1]=r*f+i*u,t[2]=o*-u+s*f,t[3]=r*-u+i*f,t[4]=a,t[5]=c}(t,t,I(e[4])),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=e[0],f=e[1];t[0]=o*u,t[1]=r*u,t[2]=s*f,t[3]=i*f,t[4]=a,t[5]=c}(t,t,[c,u]);const g=[],h=a/f,l=4/3*Math.tan(h/4),d=Math.sin(h),p=Math.cos(h);for(let e=0;e1-o.param)&&(r[1]1-o.param)?[]:[r]}let r=[[{seg:t,startParam:0,endParam:1,boundingBox:G(t)},{seg:n,startParam:0,endParam:1,boundingBox:G(n)}]];const s=[];for(;r.length;){const t=[];for(const[n,e]of r){if(et(n.seg,e.seg,o.point))continue;const r=g(n.boundingBox)<=o.linear,i=g(e.boundingBox)<=o.linear;if(r&&i){const t=X(tt(n.seg),tt(e.seg),o.param);t&&s.push([Q(n.startParam,n.endParam,t[0]),Q(e.startParam,e.endParam,t[1])])}else{const o=r?[n]:Y(n),s=i?[e]:Y(e);for(const n of o)for(const e of s)nt(n,e)&&t.push([n,e])}}r=t}return e?s:s.filter((([t,n])=>t>o.param&&t<1-o.param||n>o.param&&n<1-o.param))}const rt=Object.hasOwn;function st(t){const n=new WeakMap;return(e,...o)=>{if(n.has(e))return n.get(e);{const r=t(e,...o);return n.set(e,r),r}}}function*it(t,n){let e=0;for(const o of t)yield n(o,e++)}const at=8,ct=8,ut={point:1e-6,linear:1e-4,param:1e-8};var ft,gt;function ht(){let t=0;return st((()=>t++))}function lt(t){return n=>({seg:n,parent:t})}function dt(t){return t.outgoingEdges.length}function pt({directionFlag:t,segments:n}){let e,o;const r=n[0];return t?(e=D(r,1),o=D(r,1-ut.param)):(e=D(r,0),o=D(r,ut.param)),Math.atan2(o[1]-e[1],o[0]-e[0])}function mt(t){const{outgoingEdges:n}=t.incidentVertices[1],e=n.findIndex((n=>n.twin===t));return n[(e+1)%n.length]}t.PathBooleanOperation=void 0,(ft=t.PathBooleanOperation||(t.PathBooleanOperation={}))[ft.Union=0]="Union",ft[ft.Difference=1]="Difference",ft[ft.Intersection=2]="Intersection",ft[ft.Exclusion=3]="Exclusion",ft[ft.Division=4]="Division",ft[ft.Fracture=5]="Fracture",t.FillRule=void 0,(gt=t.FillRule||(t.FillRule={}))[gt.NonZero=0]="NonZero",gt[gt.EvenOdd=1]="EvenOdd";const bt=st((t=>t.incidentEdges.flatMap((t=>{const n=[];for(const e of t.segments)for(let o=0;o<64;o++){const r=o/64,s=t.directionFlag?1-r:r;n.push(D(e,s))}return n}))));function Mt(t,n,e){return t>=e==n=e[0]);var o,r,s,i,a}function xt(t,n){if(t.length<=2)return 0;let e=t[t.length-1],o=0;for(const r of t)wt(e,r,n)&&(o+=r[1]>e[1]?-1:1),e=r;return o}function yt(t){const n=bt(t);for(let t=0;t=n[0]}function vt(t,n){const e=G(t);if(!Et(e,n))return 0;let o=[{boundingBox:e,seg:t}],r=0;for(;o.length>0;){const t=[];for(const{boundingBox:e,seg:s}of o)if(g(e)t>0,[t.PathBooleanOperation.Difference]:({flag:t})=>1===t,[t.PathBooleanOperation.Intersection]:({flag:t})=>3===t,[t.PathBooleanOperation.Exclusion]:({flag:t})=>1===t||2===t,[t.PathBooleanOperation.Division]:({flag:t})=>!(1&~t),[t.PathBooleanOperation.Fracture]:({flag:t})=>t>0};function Lt(t,n){return[2*t[0]-n[0],2*t[1]-n[1]]}t.pathBoolean=function(n,e,o,r,s){const i=[...it(n,lt(1)),...it(o,lt(2))];!function(t){for(let n=0;no[1]&&o.reverse();const[r,s]=o;if(Math.abs(r-s)({...t,boundingBox:G(t.seg)}))),e=n.reduce(((t,{boundingBox:n})=>u(t,n)),null);if(!e)return{edges:[],totalBoundingBox:null};const o=new l(e,at),r={};function s(t,n){rt(r,t)||(r[t]=[]),r[t].push(n)}for(let e=0;e1-ut.param)break;const r=(n-a)/(1-a);if(a=n,r1-ut.param)continue;const[c,u]=J(s,r);i.push({seg:c,boundingBox:G(c),parent:e.parent}),s=u}i.push({seg:s,boundingBox:G(s),parent:e.parent})}return{edges:i,totalBoundingBox:e}}(i);if(!c)return[];const f=function(t,n){const e=new l(n,ct),o=[];function r(t){const n=h(t,ut.point),r=e.find(n);if(r.size)return function(t){return t.values().next().value}(r);{const r={point:t,outgoingEdges:[]};return e.insert(n,r),o.push(r),r}}const s=ht(),i={};return{edges:t.flatMap((t=>{const n=r(T(t.seg)),e=r(N(t.seg));if(n===e)switch(t.seg[0]){case"L":return[];case"C":if(S(t.seg[1],t.seg[2],ut.point)&&S(t.seg[3],t.seg[4],ut.point))return[];break;case"Q":if(S(t.seg[1],t.seg[2],ut.point))return[];break;case"A":if(!1===t.seg[5])return[]}const o=`${s(n)}:${s(e)}`;if(rt(i,o)){const n=i[o].find((n=>et(n[0].seg,t.seg,ut.point)));if(n)return n[1].parent|=t.parent,n[2].parent|=t.parent,[]}const a=`${s(e)}:${s(n)}`;if(rt(i,a)){const n=W(t.seg),e=i[a].find((t=>et(t[0].seg,n,ut.point)));if(e)return e[0].parent===t.parent||(e[1].parent|=t.parent,e[2].parent|=t.parent),[]}const c={...t,incidentVertices:[n,e],directionFlag:!1,twin:null},u={...t,incidentVertices:[e,n],directionFlag:!0,twin:c};return c.twin=u,n.outgoingEdges.push(c),e.outgoingEdges.push(u),rt(i,o)?i[o].push([t,c,u]):i[o]=[[t,c,u]],[c,u]})),vertices:o}}(a,c),g=function({vertices:t}){const n=[],e=[],o=st((t=>{const n={outgoingEdges:[]};return e.push(n),n})),r=ht(),s={},i=new WeakSet;for(const e of t){if(2===dt(e))continue;const t=o(e);for(const a of e.outgoingEdges){const e=[];let c=a;for(;c.parent===a.parent&&c.directionFlag===a.directionFlag&&2===dt(c.incidentVertices[1]);){e.push(c.seg),i.add(c.incidentVertices[1]);const[t,n]=c.incidentVertices[1].outgoingEdges;c=t.twin===c?n:t}e.push(c.seg);const u=o(c.incidentVertices[1]),f=`${r(a)}-${r(c)}`,g=s[`${r(c.twin)}-${r(a.twin)}`]??null,h={segments:e,parent:a.parent,incidentVertices:[t,u],directionFlag:a.directionFlag,twin:g};g&&(g.twin=h),s[f]=h,t.outgoingEdges.push(h),n.push(h)}}const a=[];for(const n of t){if(2!==dt(n)||i.has(n))continue;let t=n.outgoingEdges[0];const e={segments:[],parent:t.parent,directionFlag:t.directionFlag};do{e.segments.push(t.seg),i.add(t.incidentVertices[0]);const[n,o]=t.incidentVertices[1].outgoingEdges;t=n.twin===t?o:n}while(t.incidentVertices[0]!==n);a.push(e)}return{edges:n,vertices:e,cycles:a}}(f);!function(t){function n(n){const e=new WeakSet,o=new WeakMap;function r(t,s,i){if(o.has(t))return o.get(t);o.set(t,i);let a=1/0;for(const e of t.outgoingEdges)e.parent&n&&e!==s&&(a=Math.min(a,r(e.incidentVertices[1],e.twin,i+1)));return a<=i&&e.add(t),a}for(const e of t.edges)e.parent&n&&r(e.incidentVertices[0],null,0);return e}const e=n(1),o=n(2);function r(t){return!(1&~t.parent)&&e.has(t.incidentVertices[0])&&e.has(t.incidentVertices[1])||!(2&~t.parent)&&o.has(t.incidentVertices[0])&&o.has(t.incidentVertices[1])}t.vertices=t.vertices.filter((function(t){return e.has(t)||o.has(t)}));for(const n of t.vertices)n.outgoingEdges=n.outgoingEdges.filter(r);t.edges=t.edges.filter(r)}(g),function({vertices:t}){const n=st(pt);for(const e of t)dt(e)>2&&e.outgoingEdges.sort(((t,e)=>n(t)-n(e)))}(g);const d=function(t){let n=[];function e(t,n){let o=!1;for(const r of t){const t=Bt(n,r.component);if(t){if(r.outgoingEdges.has(t)){const o=r.outgoingEdges.get(t);r.outgoingEdges.set(t,e(o,n))}else r.outgoingEdges.set(t,[{component:n,outgoingEdges:new Map}]);o=!0;break}}if(o)return t;{const e={component:n,outgoingEdges:new Map},o=[e];for(const r of t){const t=Bt(r.component,n);t?e.outgoingEdges.has(t)?e.outgoingEdges.get(t).push(r):e.outgoingEdges.set(t,[r]):o.push(r)}return o}}for(const o of t)n=e(n,o);return n}(function({edges:t,cycles:n}){const e=[],o=new WeakMap;for(const n of t){if(o.has(n))continue;const t={incidentEdges:[],flag:0};let r=n;do{const n=o.get(r.twin)??null,e={segments:r.segments,parent:r.parent,incidentVertex:t,directionFlag:r.directionFlag,twin:n};n&&(n.twin=e),o.set(r,e),t.incidentEdges.push(e),r=mt(r)}while(r.incidentVertices[0]!==n.incidentVertices[0]);e.push(t)}for(const t of n){const n={incidentEdges:[],flag:0},o={segments:t.segments,parent:t.parent,incidentVertex:n,directionFlag:t.directionFlag,twin:null},r={incidentEdges:[],flag:0},s={segments:[...t.segments].reverse(),parent:t.parent,incidentVertex:r,directionFlag:!t.directionFlag,twin:o};o.twin=s,n.incidentEdges.push(o),r.incidentEdges.push(s),e.push(n,r)}const r=[],s=new WeakSet,i=new WeakSet;for(const t of e){if(s.has(t))continue;const n=[],e=[],o=t=>{s.has(t)||n.push(t),s.add(t);for(const n of t.incidentEdges){if(i.has(n))continue;const{twin:t}=n;e.push(n,t),i.add(n),i.add(t),o(t.incidentVertex)}};o(t);const a=n.find((t=>yt(t).winding<0));r.push({vertices:n,edges:e,outerFace:a})}return r}(g));!function(t,n,e){function o(t,r,s){const i=new WeakSet;!function r(s,a,c){if(i.has(s))return;i.add(s);const u=kt(a,n),f=kt(c,e);s.flag=u|f<<1;for(const t of s.incidentEdges){const n=t.twin;let e=a;1&t.parent&&(e+=t.directionFlag?-1:1);let o=c;2&t.parent&&(o+=t.directionFlag?-1:1),r(n.incidentVertex,e,o)}if(t.outgoingEdges.has(s)){const n=t.outgoingEdges.get(s);for(const t of n)o(t,a,c)}}(t.component.outerFace,r,s)}for(const n of t)o(n,0,0)}(d,e,r);const m=Ft[s];switch(s){case t.PathBooleanOperation.Division:case t.PathBooleanOperation.Fracture:return function(t,n){const e=[];function o(t){for(const o of t.component.vertices){if(!n(o)||o===t.component.outerFace)continue;const r=[];for(const t of o.incidentEdges)t.directionFlag?r.push(...t.segments.map(W)):r.push(...t.segments);if(t.outgoingEdges.has(o))for(const n of t.outgoingEdges.get(o)){const{outerFace:t}=n.component;for(const n of t.incidentEdges)n.directionFlag?r.push(...n.segments.map(W)):r.push(...n.segments)}e.push(r)}for(const n of t.outgoingEdges.values())for(const t of n)o(t)}for(const n of t)o(n);return e}(d,m);default:{const t=new Set(function*(t,n){function*e(t){for(const e of t.component.vertices)n(e)&&(yield e);for(const n of t.outgoingEdges.values())for(const t of n)yield*e(t)}for(const n of t)yield*e(n)}(d,m));return[[...Pt(t)]]}}},t.pathFromCommands=function*(t){let n=null,e=null,o=null;function r(){throw new Error("Bad SVG path data sequence.")}for(const s of function*(t){let n=[0,0],e=n;for(const o of t)switch(o[0]){case"M":yield o,n=e=o[1];break;case"L":case"T":yield o,n=o[1];break;case"C":yield o,n=o[3];break;case"S":case"Q":yield o,n=o[2];break;case"A":yield o,n=o[6];break;case"Z":case"z":n=e,yield["Z"];break;case"H":n=[o[1],n[1]],yield["L",n];break;case"V":n=[n[0],o[1]],yield["L",n];break;case"m":n=e=[n[0]+o[1],n[1]+o[2]],yield["M",n];break;case"l":n=[n[0]+o[1],n[1]+o[2]],yield["L",n];break;case"h":n=[n[0]+o[1],n[1]],yield["L",n];break;case"v":n=[n[0],n[1]+o[1]],yield["L",n];break;case"c":yield["C",[n[0]+o[1],n[1]+o[2]],[n[0]+o[3],n[1]+o[4]],n=[n[0]+o[5],n[1]+o[6]]];break;case"s":yield["S",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"q":yield["Q",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"t":yield["T",n=[n[0]+o[1],n[1]+o[2]]];break;case"a":yield["A",o[1],o[2],o[3],o[4],o[5],n=[n[0]+o[6],n[1]+o[7]]]}}(t))switch(s[0]){case"M":e=n=s[1],o=null;break;case"L":e||r(),yield["L",e,s[1]],e=s[1],o=null;break;case"C":e||r(),yield["C",e,s[1],s[2],s[3]],e=s[3],o=s[2];break;case"S":e||r(),o||r(),yield["C",e,Lt(e,o),s[1],s[2]],e=s[2],o=s[1];break;case"Q":e||r(),yield["Q",e,s[1],s[2]],e=s[2],o=s[1];break;case"T":e||r(),o||r(),o=Lt(e,o),yield["Q",e,o,s[1]],e=s[1];break;case"A":e||r(),yield["A",e,s[1],s[2],s[3],s[4],s[5],s[6]],e=s[6],o=null;break;case"Z":case"z":e||r(),n||r(),yield["L",e,n],e=n,o=null}},t.pathToCommands=function*(t,n=1e-4){let e=null;for(const o of t)switch(e&&S(o[1],e,n)||(yield["M",o[1]]),o[0]){case"L":yield["L",e=o[2]];break;case"C":yield["C",o[2],o[3],e=o[4]];break;case"Q":yield["Q",o[2],e=o[3]];break;case"A":yield["A",o[2],o[3],o[4],o[5],o[6],e=o[7]]}}},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).PathBool={}); //# sourceMappingURL=path-bool.core.umd.js.map diff --git a/dist/path-bool.core.umd.js.map b/dist/path-bool.core.umd.js.map index f45ac8a..68d57f3 100644 --- a/dist/path-bool.core.umd.js.map +++ b/dist/path-bool.core.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"path-bool.core.umd.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/Path.ts","../src/primitives/PathCommand.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n // TODO: check other direction\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n"],"names":["INSIDE","LEFT","RIGHT","BOTTOM","TOP","outCode","x","y","boundingBox","code","left","right","top","bottom","lineSegmentAABBIntersect","seg","x0","y0","x1","y1","outcode0","outcode1","outcodeOut","boundingBoxesOverlap","a","b","mergeBoundingBoxes","Math","min","max","extendBoundingBox","point","boundingBoxMaxExtent","boundingBoxAroundPoint","padding","QuadTree","fromPairs","pairs","depth","innerNodeCapacity","length","Error","i","tree","key","value","insert","constructor","this","subtrees","ensureSubtrees","push","find","set","Set","add","findOnLineSegment","midX","midY","EPS","pathCubicSegmentSelfIntersection","A","B","C","D","ax","ay","bx","by","cx","cy","M","N","K","t1","sqrt","t2","ARRAY_TYPE","Float32Array","Array","create","out","glMatrix.ARRAY_TYPE","fromRotation","rad","s","sin","c","cos","hypot","arguments","mul","a0","a1","a2","a3","a4","a5","b0","b1","b2","b3","b4","b5","scale","lerp","t","transformMat2","m","transformMat2d","len","sub","TAU","PI","deg2rad","deg","vectorAngle","u","v","sign","abs","acos","vec2.len","vectorsEqual","eps","getStartPoint","getEndPoint","reversePathSegment","arcSegmentToCenter","xy1Prime","rotationMatrix","mat2.create","addend","cxy","_A","xy1","rx","ry","phi","fA","fS","xy2","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","rx2","ry2","x1Prime2","y1Prime2","lambda","lambdaSqrt","lambdaAbs","multiplier","cxPrime","cyPrime","mat2.transpose","vec2.add","vec1","theta1","deltaTheta","center","arcSegmentFromCenter","vec2.set","samplePathSegmentAt","p01","p12","p23","p012","p123","p","vec2.lerp","centerParametrization","theta","p0","p1","sinC","cosC","vec2.rotate","arcSegmentToCubics","fromUnit","mat2d.create","matrix","arc","maxDeltaTheta","count","ceil","mat2d.fromTranslation","mat2d.rotate","v0","v1","mat2d.scale","cubics","k","tan","sinTheta","cosTheta","start","control1","control2","end","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d","evalCubic1d","p2","p3","cubicBoundingInterval","sqrtD","t0","quadraticBoundingInterval","denominator","evalQuadratic1d","inInterval","mapped","pathSegmentBoundingBox","theta2","expandBoundingBox","splitLinearSegmentAt","splitCubicSegmentAt","splitSegmentAt","splitQuadraticSegmentAt","midDeltaTheta","splitArcSegmentAt","COLLINEAR_EPS","Number","MIN_VALUE","lineSegmentIntersection","x2","y2","x3","y3","x4","y4","c1","c2","denom","subdivideIntersectionSegment","intSeg","seg0","seg1","midParam","startParam","endParam","pathSegmentToLineSegment","intersectionSegmentsOverlap","boundingBox0","boundingBox1","seg2","lineSegmentsIntersect","segmentsEqual","pointEpsilon","type","pathSegmentIntersection","endpoints","st","param","params","nextPairs","isLinear0","linear","isLinear1","subdivided0","subdivided1","filter","hasOwn","Object","memoizeWeak","fn","cache","WeakMap","obj","args","has","get","val","map","iter","INTERSECTION_TREE_DEPTH","POINT_TREE_DEPTH","PathBooleanOperation","FillRule","createObjectCounter","segmentToEdge","parent","getOrder","vertex","outgoingEdges","getIncidenceAngle","directionFlag","segments","atan2","getNextEdge","edge","incidentVertices","index","findIndex","other","twin","exports","faceToPolygon","face","incidentEdges","flatMap","points","intervalCrossesPoint","lineSegmentIntersectsHorizontalRay","inMin","inMax","outMin","outMax","computePointWinding","polygon","testedPoint","prevPoint","winding","computeWinding","boundingBoxIntersectsHorizontalRay","pathSegmentHorizontalRayIntersectionCount","origSeg","totalBoundingBox","nextSegments","split","testInclusion","edges","vertices","outerFace","getFlag","fillRule","NonZero","EvenOdd","walkFaces","faces","isRemovedEdge","incidentVertex","edgeToNext","prevEdge","visitedEdges","WeakSet","startEdge","operationPredicates","Union","flag","Difference","Intersection","Exclusion","Division","Fracture","reflectControlPoint","controlPoint","aFillRule","bFillRule","op","unsplitEdges","intersection","reverse","tmpSeg","seg3","splitAtSelfIntersections","splitEdges","withBoundingBox","reduce","acc","edgeTree","splitsPerEdge","addSplit","candidates","j","candidate","includeEndpoints","newEdges","splits","sort","prevT","tt","splitAtIntersections","majorGraph","vertexTree","newVertices","getVertex","box","existingVertices","size","values","next","firstElementOfSet","getVertexId","vertexPairIdToEdges","startVertex","endVertex","vertexPairId","existingEdge","fwdEdge","bwdEdge","findVertices","minorGraph","toMinorVertex","_majorVertex","minorVertex","getEdgeId","idToEdge","visited","edge1","edge2","edgeId","newEdge","cycles","cycle","computeMinor","graph","walk","keptVertices","vertexToLevel","visit","incomingEdge","level","minLevel","Infinity","keptVerticesA","keptVerticesB","keepEdge","removeDanglingEdges","getAngle","sortOutgoingEdgesByAngle","nestingTrees","components","trees","component","found","children","Map","newTree","newTrees","computeNestingTree","minorToDualEdge","innerFace","innerHalfEdge","outerHalfEdge","visitedVertices","componentVertices","componentEdges","computeDual","visitTree","aRunningCount","bRunningCount","visitedFaces","visitFace","aFlag","bFlag","nextACount","nextBCount","subtree","flagFaces","predicate","paths","path","dumpFaces","selectedFaces","getSelectedFaces","commands","firstPoint","lastPoint","lastControlPoint","badSequence","cmd","toAbsoluteCommands"],"mappings":"6BAYA,MAAMA,EAAS,EACTC,EAAO,EACPC,EAAQ,EACRC,EAAS,EACTC,EAAM,EAEZ,SAASC,EAAQC,EAAWC,EAAWC,GACnC,IAAIC,EAAOT,EAcX,OAZIM,EAAIE,EAAYE,KAChBD,GAAQR,EACDK,EAAIE,EAAYG,QACvBF,GAAQP,GAGRK,EAAIC,EAAYI,IAChBH,GAAQN,EACDI,EAAIC,EAAYK,SACvBJ,GAAQL,GAGLK,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GACvB,MACJ,IAAK,IACIH,GAAWE,SACV,CAAC,IAAKF,EAAWG,EAAI,GAAIA,EAAI,IACnCH,EAAYG,EAAI,GAChBF,EAAmBE,EAAI,GACvB,MACJ,IAAK,IACIH,GAAWE,IACXD,GAAkBC,IACvBD,EAAmBlH,GACfiH,EACAC,QAEE,CAAC,IAAKD,EAAWC,EAAkBE,EAAI,IAC7CH,EAAYG,EAAI,GAChB,MACJ,IAAK,IACIH,GAAWE,SACV,CACF,IACAF,EACAG,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,IAERH,EAAYG,EAAI,GAChBF,EAAmB,KACnB,MACJ,IAAK,IACL,IAAK,IACID,GAAWE,IACXH,GAAYG,SACX,CAAC,IAAKF,EAAWD,GACvBC,EAAYD,EACZE,EAAmB,KAInC,mBAEM,UACF5K,EACAtK,EAAc,MAEd,IAAIiV,EAA2B,KAC/B,IAAK,MAAM9b,KAAOmR,EAKd,OAJK2K,GAAclV,EAAa5G,EAAI,GAAI8b,EAAWjV,UACzC,CAAC,IAAK7G,EAAI,KAGZA,EAAI,IACR,IAAK,SACK,CAAC,IAAM8b,EAAY9b,EAAI,IAC7B,MACJ,IAAK,SACK,CAAC,IAAKA,EAAI,GAAIA,EAAI,GAAK8b,EAAY9b,EAAI,IAC7C,MACJ,IAAK,SACK,CAAC,IAAKA,EAAI,GAAK8b,EAAY9b,EAAI,IACrC,MACJ,IAAK,SACK,CACF,IACAA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACH8b,EAAY9b,EAAI,IAKrC","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file +{"version":3,"file":"path-bool.core.umd.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/Path.ts","../src/primitives/PathCommand.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n // TODO: explain\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {\n const reversedSeg = reversePathSegment(edge.seg);\n const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(\n (other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),\n );\n if (existingEdge) {\n if (existingEdge[0].parent === edge.parent) {\n // discard \"there and back\" pairs\n return [];\n }\n\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n"],"names":["INSIDE","LEFT","RIGHT","BOTTOM","TOP","outCode","x","y","boundingBox","code","left","right","top","bottom","lineSegmentAABBIntersect","seg","x0","y0","x1","y1","outcode0","outcode1","outcodeOut","boundingBoxesOverlap","a","b","mergeBoundingBoxes","Math","min","max","extendBoundingBox","point","boundingBoxMaxExtent","boundingBoxAroundPoint","padding","QuadTree","fromPairs","pairs","depth","innerNodeCapacity","length","Error","i","tree","key","value","insert","constructor","this","subtrees","ensureSubtrees","push","find","set","Set","add","findOnLineSegment","midX","midY","EPS","pathCubicSegmentSelfIntersection","A","B","C","D","ax","ay","bx","by","cx","cy","M","N","K","t1","sqrt","t2","ARRAY_TYPE","Float32Array","Array","create","out","glMatrix.ARRAY_TYPE","fromRotation","rad","s","sin","c","cos","hypot","arguments","mul","a0","a1","a2","a3","a4","a5","b0","b1","b2","b3","b4","b5","scale","lerp","t","transformMat2","m","transformMat2d","len","sub","TAU","PI","deg2rad","deg","vectorAngle","u","v","sign","abs","acos","vec2.len","vectorsEqual","eps","getStartPoint","getEndPoint","reversePathSegment","arcSegmentToCenter","xy1Prime","rotationMatrix","mat2.create","addend","cxy","_A","xy1","rx","ry","phi","fA","fS","xy2","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","rx2","ry2","x1Prime2","y1Prime2","lambda","lambdaSqrt","lambdaAbs","multiplier","cxPrime","cyPrime","mat2.transpose","vec2.add","vec1","theta1","deltaTheta","center","arcSegmentFromCenter","vec2.set","samplePathSegmentAt","p01","p12","p23","p012","p123","p","vec2.lerp","centerParametrization","theta","p0","p1","sinC","cosC","vec2.rotate","arcSegmentToCubics","fromUnit","mat2d.create","matrix","arc","maxDeltaTheta","count","ceil","mat2d.fromTranslation","mat2d.rotate","v0","v1","mat2d.scale","cubics","k","tan","sinTheta","cosTheta","start","control1","control2","end","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d","evalCubic1d","p2","p3","cubicBoundingInterval","sqrtD","t0","quadraticBoundingInterval","denominator","evalQuadratic1d","inInterval","mapped","pathSegmentBoundingBox","theta2","expandBoundingBox","splitLinearSegmentAt","splitCubicSegmentAt","splitSegmentAt","splitQuadraticSegmentAt","midDeltaTheta","splitArcSegmentAt","COLLINEAR_EPS","Number","MIN_VALUE","lineSegmentIntersection","x2","y2","x3","y3","x4","y4","c1","c2","denom","subdivideIntersectionSegment","intSeg","seg0","seg1","midParam","startParam","endParam","pathSegmentToLineSegment","intersectionSegmentsOverlap","boundingBox0","boundingBox1","seg2","lineSegmentsIntersect","segmentsEqual","pointEpsilon","type","pathSegmentIntersection","endpoints","st","param","params","nextPairs","isLinear0","linear","isLinear1","subdivided0","subdivided1","filter","hasOwn","Object","memoizeWeak","fn","cache","WeakMap","obj","args","has","get","val","map","iter","INTERSECTION_TREE_DEPTH","POINT_TREE_DEPTH","PathBooleanOperation","FillRule","createObjectCounter","segmentToEdge","parent","getOrder","vertex","outgoingEdges","getIncidenceAngle","directionFlag","segments","atan2","getNextEdge","edge","incidentVertices","index","findIndex","other","twin","exports","faceToPolygon","face","incidentEdges","flatMap","points","intervalCrossesPoint","lineSegmentIntersectsHorizontalRay","inMin","inMax","outMin","outMax","computePointWinding","polygon","testedPoint","prevPoint","winding","computeWinding","boundingBoxIntersectsHorizontalRay","pathSegmentHorizontalRayIntersectionCount","origSeg","totalBoundingBox","nextSegments","split","testInclusion","edges","vertices","outerFace","getFlag","fillRule","NonZero","EvenOdd","walkFaces","faces","isRemovedEdge","incidentVertex","edgeToNext","prevEdge","visitedEdges","WeakSet","startEdge","operationPredicates","Union","flag","Difference","Intersection","Exclusion","Division","Fracture","reflectControlPoint","controlPoint","aFillRule","bFillRule","op","unsplitEdges","intersection","reverse","tmpSeg","seg3","splitAtSelfIntersections","splitEdges","withBoundingBox","reduce","acc","edgeTree","splitsPerEdge","addSplit","candidates","j","candidate","includeEndpoints","newEdges","splits","sort","prevT","tt","splitAtIntersections","majorGraph","vertexTree","newVertices","getVertex","box","existingVertices","size","values","next","firstElementOfSet","getVertexId","vertexPairIdToEdges","startVertex","endVertex","vertexPairId","existingEdge","vertexPairIdInv","reversedSeg","fwdEdge","bwdEdge","findVertices","minorGraph","toMinorVertex","_majorVertex","minorVertex","getEdgeId","idToEdge","visited","edge1","edge2","edgeId","newEdge","cycles","cycle","computeMinor","graph","walk","keptVertices","vertexToLevel","visit","incomingEdge","level","minLevel","Infinity","keptVerticesA","keptVerticesB","keepEdge","removeDanglingEdges","getAngle","sortOutgoingEdgesByAngle","nestingTrees","components","trees","component","found","children","Map","newTree","newTrees","computeNestingTree","minorToDualEdge","innerFace","innerHalfEdge","outerHalfEdge","visitedVertices","componentVertices","componentEdges","computeDual","visitTree","aRunningCount","bRunningCount","visitedFaces","visitFace","aFlag","bFlag","nextACount","nextBCount","subtree","flagFaces","predicate","paths","path","dumpFaces","selectedFaces","getSelectedFaces","commands","firstPoint","lastPoint","lastControlPoint","badSequence","cmd","toAbsoluteCommands"],"mappings":"6BAYA,MAAMA,EAAS,EACTC,EAAO,EACPC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,EAAa5G,EAAI,GAAIgc,EAAWnV,UACzC,CAAC,IAAK7G,EAAI,KAGZA,EAAI,IACR,IAAK,SACK,CAAC,IAAMgc,EAAYhc,EAAI,IAC7B,MACJ,IAAK,SACK,CAAC,IAAKA,EAAI,GAAIA,EAAI,GAAKgc,EAAYhc,EAAI,IAC7C,MACJ,IAAK,SACK,CAAC,IAAKA,EAAI,GAAKgc,EAAYhc,EAAI,IACrC,MACJ,IAAK,SACK,CACF,IACAA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACJA,EAAI,GACHgc,EAAYhc,EAAI,IAKrC","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file diff --git a/dist/path-bool.js b/dist/path-bool.js index 9f35656..c63b396 100644 --- a/dist/path-bool.js +++ b/dist/path-bool.js @@ -1590,6 +1590,7 @@ function findVertices(edges, boundingBox) { } break; case "A": + // TODO: explain if (edge.seg[5] === false) { return []; } @@ -1597,7 +1598,6 @@ function findVertices(edges, boundingBox) { } } const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`; - // TODO: check other direction if (hasOwn(vertexPairIdToEdges, vertexPairId)) { const existingEdge = vertexPairIdToEdges[vertexPairId].find((other) => segmentsEqual(other[0].seg, edge.seg, EPS.point)); if (existingEdge) { @@ -1606,6 +1606,20 @@ function findVertices(edges, boundingBox) { return []; } } + const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`; + if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) { + const reversedSeg = reversePathSegment(edge.seg); + const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find((other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point)); + if (existingEdge) { + if (existingEdge[0].parent === edge.parent) { + // discard "there and back" pairs + return []; + } + existingEdge[1].parent |= edge.parent; + existingEdge[2].parent |= edge.parent; + return []; + } + } const fwdEdge = { ...edge, incidentVertices: [startVertex, endVertex], diff --git a/dist/path-bool.js.map b/dist/path-bool.js.map index 12c4ce5..28e9a44 100644 --- a/dist/path-bool.js.map +++ b/dist/path-bool.js.map @@ -1 +1 @@ -{"version":3,"file":"path-bool.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/PathCommand.ts","../src/primitives/Path.ts","../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n // TODO: check other direction\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d.scale","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d"],"mappings":"AAUA;AAEA,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AAEnB,SAAS,OAAO,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IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;QAClC,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QAC/C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpD;IAED,OAAO;QACH,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1E,KAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file +{"version":3,"file":"path-bool.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/PathCommand.ts","../src/primitives/Path.ts","../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n // TODO: explain\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {\n const reversedSeg = reversePathSegment(edge.seg);\n const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(\n (other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),\n );\n if (existingEdge) {\n if (existingEdge[0].parent === edge.parent) {\n // discard \"there and back\" pairs\n return [];\n }\n\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d.scale","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d"],"mappings":"AAUA;AAEA,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AAEnB,SAAS,OAAO,CAAC,CAAS,EAAE,CAAS,EAAE,WAAiB,EAAA;IACpD,IAAI,IAAI,GAAG,MAAM,CAAC;AAElB,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE;QACtB,IAAI,IAAI,IAAI,CAAC;KAChB;AAAM,SAAA,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE;QAC9B,IAAI,IAAI,KAAK,CAAC;KACjB;AAED,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE;Q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E;AACV,oBAAA,QAAQ,EAAE;AACV,oBAAA,QAAQ,EAAE;AACV,oBAAA,OAAO,EAAE;AACT,oBAAA,OAAO,EAAE;AACT,oBAAA,QAAQ,EAAE;AACV,oBAAA,QAAQ,EAAE;iBACb,CAAC;gBACF,MAAM;AACV,YAAA,KAAK,GAAG;gBACJ,OAAO;SACd;KACJ;AACL,CAAC;AAEK,SAAU,gBAAgB,CAAC,CAAS,EAAA;IACtC,OAAO,CAAC,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;SAEe,cAAc,CAAC,IAAU,EAAE,MAAc,IAAI,EAAA;IACzD,SAAS,QAAQ,CAAC,KAAyC,EAAA;QACvD,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;QAClC,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QAC/C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpD;IAED,OAAO;QACH,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1E,KAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file diff --git a/dist/path-bool.umd.js b/dist/path-bool.umd.js index 15171b8..9a97ae9 100644 --- a/dist/path-bool.umd.js +++ b/dist/path-bool.umd.js @@ -1,2 +1,2 @@ -var t,n;t=this,n=function(t){const n=0,e=1,o=2,r=4,s=8;function i(t,i,a){let c=n;return ta.right&&(c|=o),ia.bottom&&(c|=s),c}function a(t,n){let[[a,c],[u,f]]=t,d=i(a,c,n),l=i(u,f,n);for(;;){if(!(d|l))return!0;if(d&l)return!1;{const{top:t,right:g,bottom:h,left:p}=n;let m,b;const M=l>d?l:d;M&s?(m=a+(u-a)*(h-c)/(f-c),b=h):M&r?(m=a+(u-a)*(t-c)/(f-c),b=t):M&o?(b=c+(f-c)*(g-a)/(u-a),m=g):M&e&&(b=c+(f-c)*(p-a)/(u-a),m=p),M==d?(a=m,c=b,d=i(a,c,n)):(u=m,f=b,l=i(u,f,n))}}}function c(t,n){return t.left<=n.right&&n.left<=t.right&&t.top<=n.bottom&&n.top<=t.bottom}function u(t,n){return t?{top:Math.min(t.top,n.top),right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom),left:Math.min(t.left,n.left)}:n}function f(t,n){return t?{top:Math.min(t.top,n[1]),right:Math.max(t.right,n[0]),bottom:Math.max(t.bottom,n[1]),left:Math.min(t.left,n[0])}:{top:n[1],right:n[0],bottom:n[1],left:n[0]}}function d(t){return Math.max(t.right-t.left,t.bottom-t.top)}function l(t,n){return{top:t[1]-n,right:t[0]+n,bottom:t[1]+n,left:t[0]-n}}class g{static fromPairs(t,n,e=8){if(0===t.length)throw new Error("QuadTree.fromPairs: at least one pair needed.");let o=t[0][0];for(let n=1;n0&&this.pairs.length>=this.innerNodeCapacity){this.ensureSubtrees();for(let e=0;e{const t=[0,0],n=b(),e=[0,0],o=[0,0];return function([r,s,i,a,c,u,f,d]){if(0===i||0===a)return null;M(n,-S(c)),V(t,s,d),v(t,t,.5),P(t,t,n);let l=i*i,g=a*a;const h=t[0]*t[0],p=t[1]*t[1];i=Math.abs(i),a=Math.abs(a);const m=h/l+p/g+1e-12;if(m>1){const t=Math.sqrt(m);i*=t,a*=t;const n=Math.abs(m);l*=n,g*=n}const b=u===f?-1:1,y=Math.sqrt((l*g-l*p-g*h)/(l*p+g*h)),x=b*y*(i*t[1]/a),w=b*y*(-a*t[0]/i);!function(t,n){if(t===n){var e=n[1];t[1]=n[2],t[2]=e}else t[0]=n[0],t[1]=n[2],t[2]=n[1],t[3]=n[3]}(n,n),E(e,s,d),v(e,e,.5),P(o,[x,w],n),E(o,o,e);const k=[(t[0]-x)/i,(t[1]-w)/a],B=Q([1,0],k);let F=Q(k,[(-t[0]-x)/i,(-t[1]-w)/a]);return!f&&F>0?F-=I:f&&F<0&&(F+=I),{center:[o[0],o[1]],theta1:B,deltaTheta:F,rx:i,ry:a,phi:c}}})(),W=(()=>{const t=[0,0],n=[0,0],e=b();return function({center:o,theta1:r,deltaTheta:s,rx:i,ry:a,phi:c}){M(e,c),k(t,i*Math.cos(r),a*Math.sin(r)),P(t,t,e),E(t,t,o),k(n,i*Math.cos(r+s),a*Math.sin(r+s)),P(n,n,e),E(n,n,o);const u=Math.abs(s)>Math.PI;return["A",[t[0],t[1]],i,a,c,u,s>0,[n[0],n[1]]]}})(),Z=(()=>{const t=[0,0],n=[0,0],e=[0,0],o=[0,0],r=[0,0],s=[0,0];return function(i,a){switch(i[0]){case"L":B(s,i[1],i[2],a);break;case"C":B(t,i[1],i[2],a),B(n,i[2],i[3],a),B(e,i[3],i[4],a),B(o,t,n,a),B(r,n,e,a),B(s,o,r,a);break;case"Q":B(t,i[1],i[2],a),B(n,i[2],i[3],a),B(s,t,n,a);break;case"A":{const t=D(i);if(!t){B(s,i[1],i[7],a);break}const{deltaTheta:n,phi:e,theta1:o,rx:r,ry:c,center:u}=t,f=o+a*n;k(s,r*Math.cos(f),c*Math.sin(f)),function(t,n,e,o){var r=n[0]-e[0],s=n[1]-e[1],i=Math.sin(o),a=Math.cos(o);t[0]=r*a-s*i+e[0],t[1]=r*i+s*a+e[1]}(s,s,[0,0],e),E(s,s,u);break}}return[s[0],s[1]]}})(),$=(()=>{const t=y(),n=y();return function(e,o=Math.PI/2){const r=D(e);if(!r)return[["L",e[1],e[7]]];const{center:s,theta1:i,deltaTheta:a,rx:c,ry:u}=r,f=Math.ceil(Math.abs(a)/o);!function(t,n){t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=n[0],t[5]=n[1]}(t,s),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=Math.sin(e),f=Math.cos(e);t[0]=o*f+s*u,t[1]=r*f+i*u,t[2]=o*-u+s*f,t[3]=r*-u+i*f,t[4]=a,t[5]=c}(t,t,S(e[4])),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=e[0],f=e[1];t[0]=o*u,t[1]=r*u,t[2]=s*f,t[3]=i*f,t[4]=a,t[5]=c}(t,t,[c,u]);const d=[],l=a/f,g=4/3*Math.tan(l/4),h=Math.sin(l),p=Math.cos(l);for(let e=0;e1-o.param)&&(r[1]1-o.param)?[]:[r]}let r=[[{seg:t,startParam:0,endParam:1,boundingBox:U(t)},{seg:n,startParam:0,endParam:1,boundingBox:U(n)}]];const s=[];for(;r.length;){const t=[];for(const[n,e]of r){if(et(n.seg,e.seg,o.point))continue;const r=d(n.boundingBox)<=o.linear,i=d(e.boundingBox)<=o.linear;if(r&&i){const t=X(tt(n.seg),tt(e.seg),o.param);t&&s.push([A(n.startParam,n.endParam,t[0]),A(e.startParam,e.endParam,t[1])])}else{const o=r?[n]:Y(n),s=i?[e]:Y(e);for(const n of o)for(const e of s)nt(n,e)&&t.push([n,e])}}r=t}return e?s:s.filter((([t,n])=>t>o.param&&t<1-o.param||n>o.param&&n<1-o.param))}const rt=Object.hasOwn;function st(t){const n=new WeakMap;return(e,...o)=>{if(n.has(e))return n.get(e);{const r=t(e,...o);return n.set(e,r),r}}}function*it(t,n){let e=0;for(const o of t)yield n(o,e++)}const at=8,ct=8,ut={point:1e-6,linear:1e-4,param:1e-8};var ft,dt;function lt(){let t=0;return st((()=>t++))}function gt(t){return n=>({seg:n,parent:t})}function ht(t){return t.outgoingEdges.length}function pt({directionFlag:t,segments:n}){let e,o;const r=n[0];return t?(e=Z(r,1),o=Z(r,1-ut.param)):(e=Z(r,0),o=Z(r,ut.param)),Math.atan2(o[1]-e[1],o[0]-e[0])}function mt(t){const{outgoingEdges:n}=t.incidentVertices[1],e=n.findIndex((n=>n.twin===t));return n[(e+1)%n.length]}t.PathBooleanOperation=void 0,(ft=t.PathBooleanOperation||(t.PathBooleanOperation={}))[ft.Union=0]="Union",ft[ft.Difference=1]="Difference",ft[ft.Intersection=2]="Intersection",ft[ft.Exclusion=3]="Exclusion",ft[ft.Division=4]="Division",ft[ft.Fracture=5]="Fracture",t.FillRule=void 0,(dt=t.FillRule||(t.FillRule={}))[dt.NonZero=0]="NonZero",dt[dt.EvenOdd=1]="EvenOdd";const bt=st((t=>t.incidentEdges.flatMap((t=>{const n=[];for(const e of t.segments)for(let o=0;o<64;o++){const r=o/64,s=t.directionFlag?1-r:r;n.push(Z(e,s))}return n}))));function Mt(t,n,e){return t>=e==n=e[0]);var o,r,s,i,a}function xt(t,n){if(t.length<=2)return 0;let e=t[t.length-1],o=0;for(const r of t)yt(e,r,n)&&(o+=r[1]>e[1]?-1:1),e=r;return o}function wt(t){const n=bt(t);for(let t=0;t=n[0]}function Et(t,n){const e=U(t);if(!kt(e,n))return 0;let o=[{boundingBox:e,seg:t}],r=0;for(;o.length>0;){const t=[];for(const{boundingBox:e,seg:s}of o)if(d(e)t>0,[t.PathBooleanOperation.Difference]:({flag:t})=>1===t,[t.PathBooleanOperation.Intersection]:({flag:t})=>3===t,[t.PathBooleanOperation.Exclusion]:({flag:t})=>1===t||2===t,[t.PathBooleanOperation.Division]:({flag:t})=>!(1&~t),[t.PathBooleanOperation.Fracture]:({flag:t})=>t>0};function Lt(t,n){return[2*t[0]-n[0],2*t[1]-n[1]]}function*Ct(t){let n=null,e=null,o=null;function r(){throw new Error("Bad SVG path data sequence.")}for(const s of function*(t){let n=[0,0],e=n;for(const o of t)switch(o[0]){case"M":yield o,n=e=o[1];break;case"L":case"T":yield o,n=o[1];break;case"C":yield o,n=o[3];break;case"S":case"Q":yield o,n=o[2];break;case"A":yield o,n=o[6];break;case"Z":case"z":n=e,yield["Z"];break;case"H":n=[o[1],n[1]],yield["L",n];break;case"V":n=[n[0],o[1]],yield["L",n];break;case"m":n=e=[n[0]+o[1],n[1]+o[2]],yield["M",n];break;case"l":n=[n[0]+o[1],n[1]+o[2]],yield["L",n];break;case"h":n=[n[0]+o[1],n[1]],yield["L",n];break;case"v":n=[n[0],n[1]+o[1]],yield["L",n];break;case"c":yield["C",[n[0]+o[1],n[1]+o[2]],[n[0]+o[3],n[1]+o[4]],n=[n[0]+o[5],n[1]+o[6]]];break;case"s":yield["S",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"q":yield["Q",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"t":yield["T",n=[n[0]+o[1],n[1]+o[2]]];break;case"a":yield["A",o[1],o[2],o[3],o[4],o[5],n=[n[0]+o[6],n[1]+o[7]]]}}(t))switch(s[0]){case"M":e=n=s[1],o=null;break;case"L":e||r(),yield["L",e,s[1]],e=s[1],o=null;break;case"C":e||r(),yield["C",e,s[1],s[2],s[3]],e=s[3],o=s[2];break;case"S":e||r(),o||r(),yield["C",e,Lt(e,o),s[1],s[2]],e=s[2],o=s[1];break;case"Q":e||r(),yield["Q",e,s[1],s[2]],e=s[2],o=s[1];break;case"T":e||r(),o||r(),o=Lt(e,o),yield["Q",e,o,s[1]],e=s[1];break;case"A":e||r(),yield["A",e,s[1],s[2],s[3],s[4],s[5],s[6]],e=s[6],o=null;break;case"Z":case"z":e||r(),n||r(),yield["L",e,n],e=n,o=null}}function*Vt(t,n=1e-4){let e=null;for(const o of t)switch(e&&T(o[1],e,n)||(yield["M",o[1]]),o[0]){case"L":yield["L",e=o[2]];break;case"C":yield["C",o[2],o[3],e=o[4]];break;case"Q":yield["Q",o[2],e=o[3]];break;case"A":yield["A",o[2],o[3],o[4],o[5],o[6],e=o[7]]}}const It=Symbol();function*At(t){const n=/\s*,?\s*(-?\d*(?:\d\.|\.\d|\d)\d*(?:[eE][+\-]?\d+)?)/y,e=/\s*([MLCSQTAZHVmlhvcsqtaz])/y,o=/\s*,?\s*([01])/y;let r=0,s="M";function i(){if(r>=t.length-1)return It;e.lastIndex=r;const n=e.exec(t);if(!n)switch(s){case"M":return"L";case"m":return"l";default:return s}return r=e.lastIndex,n[1]}function a(){n.lastIndex=r;const e=n.exec(t);if(!e)throw new Error(`Invalid path data. Expected a number at index ${r}.`);return r=n.lastIndex,Number(e[1])}function c(){o.lastIndex=r;const n=o.exec(t);if(!n)throw new Error(`Invalid path data. Expected a flag at index ${r}.`);return r=o.lastIndex,"1"===n[1]}for(;;)switch(i()){case"M":yield[s="M",[a(),a()]];break;case"L":yield[s="L",[a(),a()]];break;case"C":yield[s="C",[a(),a()],[a(),a()],[a(),a()]];break;case"S":yield[s="S",[a(),a()],[a(),a()]];break;case"Q":yield[s="Q",[a(),a()],[a(),a()]];break;case"T":yield[s="T",[a(),a()]];break;case"A":yield[s="A",a(),a(),a(),c(),c(),[a(),a()]];break;case"Z":case"z":yield[s="Z"];break;case"H":yield[s="H",a()];break;case"V":yield[s="V",a()];break;case"m":yield[s="m",a(),a()];break;case"l":yield[s="l",a(),a()];break;case"h":yield[s="h",a()];break;case"v":yield[s="v",a()];break;case"c":yield[s="c",a(),a(),a(),a(),a(),a()];break;case"s":yield[s="s",a(),a(),a(),a()];break;case"q":yield[s="q",a(),a(),a(),a()];break;case"t":yield[s="t",a(),a()];break;case"a":yield[s="a",a(),a(),a(),c(),c(),a(),a()];break;case It:return}}t.arcSegmentToCubics=$,t.commandsFromPathData=At,t.pathBoolean=function(n,e,o,r,s){const i=[...it(n,gt(1)),...it(o,gt(2))];!function(t){for(let n=0;no[1]&&o.reverse();const[r,s]=o;if(Math.abs(r-s)({...t,boundingBox:U(t.seg)}))),e=n.reduce(((t,{boundingBox:n})=>u(t,n)),null);if(!e)return{edges:[],totalBoundingBox:null};const o=new g(e,at),r={};function s(t,n){rt(r,t)||(r[t]=[]),r[t].push(n)}for(let e=0;e1-ut.param)break;const r=(n-a)/(1-a);if(a=n,r1-ut.param)continue;const[c,u]=J(s,r);i.push({seg:c,boundingBox:U(c),parent:e.parent}),s=u}i.push({seg:s,boundingBox:U(s),parent:e.parent})}return{edges:i,totalBoundingBox:e}}(i);if(!c)return[];const f=function(t,n){const e=new g(n,ct),o=[];function r(t){const n=l(t,ut.point),r=e.find(n);if(r.size)return function(t){return t.values().next().value}(r);{const r={point:t,outgoingEdges:[]};return e.insert(n,r),o.push(r),r}}const s=lt(),i={};return{edges:t.flatMap((t=>{const n=r(O(t.seg)),e=r(N(t.seg));if(n===e)switch(t.seg[0]){case"L":return[];case"C":if(T(t.seg[1],t.seg[2],ut.point)&&T(t.seg[3],t.seg[4],ut.point))return[];break;case"Q":if(T(t.seg[1],t.seg[2],ut.point))return[];break;case"A":if(!1===t.seg[5])return[]}const o=`${s(n)}:${s(e)}`;if(rt(i,o)){const n=i[o].find((n=>et(n[0].seg,t.seg,ut.point)));if(n)return n[1].parent|=t.parent,n[2].parent|=t.parent,[]}const a={...t,incidentVertices:[n,e],directionFlag:!1,twin:null},c={...t,incidentVertices:[e,n],directionFlag:!0,twin:a};return a.twin=c,n.outgoingEdges.push(a),e.outgoingEdges.push(c),rt(i,o)?i[o].push([t,a,c]):i[o]=[[t,a,c]],[a,c]})),vertices:o}}(a,c),d=function({vertices:t}){const n=[],e=[],o=st((t=>{const n={outgoingEdges:[]};return e.push(n),n})),r=lt(),s={},i=new WeakSet;for(const e of t){if(2===ht(e))continue;const t=o(e);for(const a of e.outgoingEdges){const e=[];let c=a;for(;c.parent===a.parent&&c.directionFlag===a.directionFlag&&2===ht(c.incidentVertices[1]);){e.push(c.seg),i.add(c.incidentVertices[1]);const[t,n]=c.incidentVertices[1].outgoingEdges;c=t.twin===c?n:t}e.push(c.seg);const u=o(c.incidentVertices[1]),f=`${r(a)}-${r(c)}`,d=s[`${r(c.twin)}-${r(a.twin)}`]??null,l={segments:e,parent:a.parent,incidentVertices:[t,u],directionFlag:a.directionFlag,twin:d};d&&(d.twin=l),s[f]=l,t.outgoingEdges.push(l),n.push(l)}}const a=[];for(const n of t){if(2!==ht(n)||i.has(n))continue;let t=n.outgoingEdges[0];const e={segments:[],parent:t.parent,directionFlag:t.directionFlag};do{e.segments.push(t.seg),i.add(t.incidentVertices[0]);const[n,o]=t.incidentVertices[1].outgoingEdges;t=n.twin===t?o:n}while(t.incidentVertices[0]!==n);a.push(e)}return{edges:n,vertices:e,cycles:a}}(f);!function(t){function n(n){const e=new WeakSet,o=new WeakMap;function r(t,s,i){if(o.has(t))return o.get(t);o.set(t,i);let a=1/0;for(const e of t.outgoingEdges)e.parent&n&&e!==s&&(a=Math.min(a,r(e.incidentVertices[1],e.twin,i+1)));return a<=i&&e.add(t),a}for(const e of t.edges)e.parent&n&&r(e.incidentVertices[0],null,0);return e}const e=n(1),o=n(2);function r(t){return!(1&~t.parent)&&e.has(t.incidentVertices[0])&&e.has(t.incidentVertices[1])||!(2&~t.parent)&&o.has(t.incidentVertices[0])&&o.has(t.incidentVertices[1])}t.vertices=t.vertices.filter((function(t){return e.has(t)||o.has(t)}));for(const n of t.vertices)n.outgoingEdges=n.outgoingEdges.filter(r);t.edges=t.edges.filter(r)}(d),function({vertices:t}){const n=st(pt);for(const e of t)ht(e)>2&&e.outgoingEdges.sort(((t,e)=>n(t)-n(e)))}(d);const h=function(t){let n=[];function e(t,n){let o=!1;for(const r of t){const t=vt(n,r.component);if(t){if(r.outgoingEdges.has(t)){const o=r.outgoingEdges.get(t);r.outgoingEdges.set(t,e(o,n))}else r.outgoingEdges.set(t,[{component:n,outgoingEdges:new Map}]);o=!0;break}}if(o)return t;{const e={component:n,outgoingEdges:new Map},o=[e];for(const r of t){const t=vt(r.component,n);t?e.outgoingEdges.has(t)?e.outgoingEdges.get(t).push(r):e.outgoingEdges.set(t,[r]):o.push(r)}return o}}for(const o of t)n=e(n,o);return n}(function({edges:t,cycles:n}){const e=[],o=new WeakMap;for(const n of t){if(o.has(n))continue;const t={incidentEdges:[],flag:0};let r=n;do{const n=o.get(r.twin)??null,e={segments:r.segments,parent:r.parent,incidentVertex:t,directionFlag:r.directionFlag,twin:n};n&&(n.twin=e),o.set(r,e),t.incidentEdges.push(e),r=mt(r)}while(r.incidentVertices[0]!==n.incidentVertices[0]);e.push(t)}for(const t of n){const n={incidentEdges:[],flag:0},o={segments:t.segments,parent:t.parent,incidentVertex:n,directionFlag:t.directionFlag,twin:null},r={incidentEdges:[],flag:0},s={segments:[...t.segments].reverse(),parent:t.parent,incidentVertex:r,directionFlag:!t.directionFlag,twin:o};o.twin=s,n.incidentEdges.push(o),r.incidentEdges.push(s),e.push(n,r)}const r=[],s=new WeakSet,i=new WeakSet;for(const t of e){if(s.has(t))continue;const n=[],e=[],o=t=>{s.has(t)||n.push(t),s.add(t);for(const n of t.incidentEdges){if(i.has(n))continue;const{twin:t}=n;e.push(n,t),i.add(n),i.add(t),o(t.incidentVertex)}};o(t);const a=n.find((t=>wt(t).winding<0));r.push({vertices:n,edges:e,outerFace:a})}return r}(d));!function(t,n,e){function o(t,r,s){const i=new WeakSet;!function r(s,a,c){if(i.has(s))return;i.add(s);const u=Bt(a,n),f=Bt(c,e);s.flag=u|f<<1;for(const t of s.incidentEdges){const n=t.twin;let e=a;1&t.parent&&(e+=t.directionFlag?-1:1);let o=c;2&t.parent&&(o+=t.directionFlag?-1:1),r(n.incidentVertex,e,o)}if(t.outgoingEdges.has(s)){const n=t.outgoingEdges.get(s);for(const t of n)o(t,a,c)}}(t.component.outerFace,r,s)}for(const n of t)o(n,0,0)}(h,e,r);const m=Ft[s];switch(s){case t.PathBooleanOperation.Division:case t.PathBooleanOperation.Fracture:return function(t,n){const e=[];function o(t){for(const o of t.component.vertices){if(!n(o)||o===t.component.outerFace)continue;const r=[];for(const t of o.incidentEdges)t.directionFlag?r.push(...t.segments.map(q)):r.push(...t.segments);if(t.outgoingEdges.has(o))for(const n of t.outgoingEdges.get(o)){const{outerFace:t}=n.component;for(const n of t.incidentEdges)n.directionFlag?r.push(...n.segments.map(q)):r.push(...n.segments)}e.push(r)}for(const n of t.outgoingEdges.values())for(const t of n)o(t)}for(const n of t)o(n);return e}(h,m);default:{const t=new Set(function*(t,n){function*e(t){for(const e of t.component.vertices)n(e)&&(yield e);for(const n of t.outgoingEdges.values())for(const t of n)yield*e(t)}for(const n of t)yield*e(n)}(h,m));return[[...Pt(t)]]}}},t.pathCubicSegmentSelfIntersection=p,t.pathFromCommands=Ct,t.pathFromPathData=function(t){return[...Ct(At(t))]},t.pathSegmentBoundingBox=U,t.pathSegmentIntersection=ot,t.pathToCommands=Vt,t.pathToPathData=function(t,n=1e-4){function e(t){return"string"==typeof t?t:function(t){return"number"==typeof t}(t)?t.toFixed(12):function(t){return"boolean"==typeof t}(t)?t?"1":"0":t.map((t=>t.toFixed(12))).join(",")}return[...it(Vt(t,n),(t=>t.map(e).join(" ")))].join(" ")},t.samplePathSegmentAt=Z},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).PathBool={}); +var t,n;t=this,n=function(t){const n=0,e=1,o=2,r=4,s=8;function i(t,i,a){let c=n;return ta.right&&(c|=o),ia.bottom&&(c|=s),c}function a(t,n){let[[a,c],[u,f]]=t,d=i(a,c,n),l=i(u,f,n);for(;;){if(!(d|l))return!0;if(d&l)return!1;{const{top:t,right:g,bottom:h,left:p}=n;let m,b;const M=l>d?l:d;M&s?(m=a+(u-a)*(h-c)/(f-c),b=h):M&r?(m=a+(u-a)*(t-c)/(f-c),b=t):M&o?(b=c+(f-c)*(g-a)/(u-a),m=g):M&e&&(b=c+(f-c)*(p-a)/(u-a),m=p),M==d?(a=m,c=b,d=i(a,c,n)):(u=m,f=b,l=i(u,f,n))}}}function c(t,n){return t.left<=n.right&&n.left<=t.right&&t.top<=n.bottom&&n.top<=t.bottom}function u(t,n){return t?{top:Math.min(t.top,n.top),right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom),left:Math.min(t.left,n.left)}:n}function f(t,n){return t?{top:Math.min(t.top,n[1]),right:Math.max(t.right,n[0]),bottom:Math.max(t.bottom,n[1]),left:Math.min(t.left,n[0])}:{top:n[1],right:n[0],bottom:n[1],left:n[0]}}function d(t){return Math.max(t.right-t.left,t.bottom-t.top)}function l(t,n){return{top:t[1]-n,right:t[0]+n,bottom:t[1]+n,left:t[0]-n}}class g{static fromPairs(t,n,e=8){if(0===t.length)throw new Error("QuadTree.fromPairs: at least one pair needed.");let o=t[0][0];for(let n=1;n0&&this.pairs.length>=this.innerNodeCapacity){this.ensureSubtrees();for(let e=0;e{const t=[0,0],n=b(),e=[0,0],o=[0,0];return function([r,s,i,a,c,u,f,d]){if(0===i||0===a)return null;M(n,-S(c)),V(t,s,d),v(t,t,.5),P(t,t,n);let l=i*i,g=a*a;const h=t[0]*t[0],p=t[1]*t[1];i=Math.abs(i),a=Math.abs(a);const m=h/l+p/g+1e-12;if(m>1){const t=Math.sqrt(m);i*=t,a*=t;const n=Math.abs(m);l*=n,g*=n}const b=u===f?-1:1,y=Math.sqrt((l*g-l*p-g*h)/(l*p+g*h)),x=b*y*(i*t[1]/a),w=b*y*(-a*t[0]/i);!function(t,n){if(t===n){var e=n[1];t[1]=n[2],t[2]=e}else t[0]=n[0],t[1]=n[2],t[2]=n[1],t[3]=n[3]}(n,n),E(e,s,d),v(e,e,.5),P(o,[x,w],n),E(o,o,e);const k=[(t[0]-x)/i,(t[1]-w)/a],B=Q([1,0],k);let F=Q(k,[(-t[0]-x)/i,(-t[1]-w)/a]);return!f&&F>0?F-=I:f&&F<0&&(F+=I),{center:[o[0],o[1]],theta1:B,deltaTheta:F,rx:i,ry:a,phi:c}}})(),W=(()=>{const t=[0,0],n=[0,0],e=b();return function({center:o,theta1:r,deltaTheta:s,rx:i,ry:a,phi:c}){M(e,c),k(t,i*Math.cos(r),a*Math.sin(r)),P(t,t,e),E(t,t,o),k(n,i*Math.cos(r+s),a*Math.sin(r+s)),P(n,n,e),E(n,n,o);const u=Math.abs(s)>Math.PI;return["A",[t[0],t[1]],i,a,c,u,s>0,[n[0],n[1]]]}})(),$=(()=>{const t=[0,0],n=[0,0],e=[0,0],o=[0,0],r=[0,0],s=[0,0];return function(i,a){switch(i[0]){case"L":B(s,i[1],i[2],a);break;case"C":B(t,i[1],i[2],a),B(n,i[2],i[3],a),B(e,i[3],i[4],a),B(o,t,n,a),B(r,n,e,a),B(s,o,r,a);break;case"Q":B(t,i[1],i[2],a),B(n,i[2],i[3],a),B(s,t,n,a);break;case"A":{const t=D(i);if(!t){B(s,i[1],i[7],a);break}const{deltaTheta:n,phi:e,theta1:o,rx:r,ry:c,center:u}=t,f=o+a*n;k(s,r*Math.cos(f),c*Math.sin(f)),function(t,n,e,o){var r=n[0]-e[0],s=n[1]-e[1],i=Math.sin(o),a=Math.cos(o);t[0]=r*a-s*i+e[0],t[1]=r*i+s*a+e[1]}(s,s,[0,0],e),E(s,s,u);break}}return[s[0],s[1]]}})(),Z=(()=>{const t=y(),n=y();return function(e,o=Math.PI/2){const r=D(e);if(!r)return[["L",e[1],e[7]]];const{center:s,theta1:i,deltaTheta:a,rx:c,ry:u}=r,f=Math.ceil(Math.abs(a)/o);!function(t,n){t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=n[0],t[5]=n[1]}(t,s),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=Math.sin(e),f=Math.cos(e);t[0]=o*f+s*u,t[1]=r*f+i*u,t[2]=o*-u+s*f,t[3]=r*-u+i*f,t[4]=a,t[5]=c}(t,t,S(e[4])),function(t,n,e){var o=n[0],r=n[1],s=n[2],i=n[3],a=n[4],c=n[5],u=e[0],f=e[1];t[0]=o*u,t[1]=r*u,t[2]=s*f,t[3]=i*f,t[4]=a,t[5]=c}(t,t,[c,u]);const d=[],l=a/f,g=4/3*Math.tan(l/4),h=Math.sin(l),p=Math.cos(l);for(let e=0;e1-o.param)&&(r[1]1-o.param)?[]:[r]}let r=[[{seg:t,startParam:0,endParam:1,boundingBox:U(t)},{seg:n,startParam:0,endParam:1,boundingBox:U(n)}]];const s=[];for(;r.length;){const t=[];for(const[n,e]of r){if(et(n.seg,e.seg,o.point))continue;const r=d(n.boundingBox)<=o.linear,i=d(e.boundingBox)<=o.linear;if(r&&i){const t=X(tt(n.seg),tt(e.seg),o.param);t&&s.push([A(n.startParam,n.endParam,t[0]),A(e.startParam,e.endParam,t[1])])}else{const o=r?[n]:Y(n),s=i?[e]:Y(e);for(const n of o)for(const e of s)nt(n,e)&&t.push([n,e])}}r=t}return e?s:s.filter((([t,n])=>t>o.param&&t<1-o.param||n>o.param&&n<1-o.param))}const rt=Object.hasOwn;function st(t){const n=new WeakMap;return(e,...o)=>{if(n.has(e))return n.get(e);{const r=t(e,...o);return n.set(e,r),r}}}function*it(t,n){let e=0;for(const o of t)yield n(o,e++)}const at=8,ct=8,ut={point:1e-6,linear:1e-4,param:1e-8};var ft,dt;function lt(){let t=0;return st((()=>t++))}function gt(t){return n=>({seg:n,parent:t})}function ht(t){return t.outgoingEdges.length}function pt({directionFlag:t,segments:n}){let e,o;const r=n[0];return t?(e=$(r,1),o=$(r,1-ut.param)):(e=$(r,0),o=$(r,ut.param)),Math.atan2(o[1]-e[1],o[0]-e[0])}function mt(t){const{outgoingEdges:n}=t.incidentVertices[1],e=n.findIndex((n=>n.twin===t));return n[(e+1)%n.length]}t.PathBooleanOperation=void 0,(ft=t.PathBooleanOperation||(t.PathBooleanOperation={}))[ft.Union=0]="Union",ft[ft.Difference=1]="Difference",ft[ft.Intersection=2]="Intersection",ft[ft.Exclusion=3]="Exclusion",ft[ft.Division=4]="Division",ft[ft.Fracture=5]="Fracture",t.FillRule=void 0,(dt=t.FillRule||(t.FillRule={}))[dt.NonZero=0]="NonZero",dt[dt.EvenOdd=1]="EvenOdd";const bt=st((t=>t.incidentEdges.flatMap((t=>{const n=[];for(const e of t.segments)for(let o=0;o<64;o++){const r=o/64,s=t.directionFlag?1-r:r;n.push($(e,s))}return n}))));function Mt(t,n,e){return t>=e==n=e[0]);var o,r,s,i,a}function xt(t,n){if(t.length<=2)return 0;let e=t[t.length-1],o=0;for(const r of t)yt(e,r,n)&&(o+=r[1]>e[1]?-1:1),e=r;return o}function wt(t){const n=bt(t);for(let t=0;t=n[0]}function Et(t,n){const e=U(t);if(!kt(e,n))return 0;let o=[{boundingBox:e,seg:t}],r=0;for(;o.length>0;){const t=[];for(const{boundingBox:e,seg:s}of o)if(d(e)t>0,[t.PathBooleanOperation.Difference]:({flag:t})=>1===t,[t.PathBooleanOperation.Intersection]:({flag:t})=>3===t,[t.PathBooleanOperation.Exclusion]:({flag:t})=>1===t||2===t,[t.PathBooleanOperation.Division]:({flag:t})=>!(1&~t),[t.PathBooleanOperation.Fracture]:({flag:t})=>t>0};function Lt(t,n){return[2*t[0]-n[0],2*t[1]-n[1]]}function*Ct(t){let n=null,e=null,o=null;function r(){throw new Error("Bad SVG path data sequence.")}for(const s of function*(t){let n=[0,0],e=n;for(const o of t)switch(o[0]){case"M":yield o,n=e=o[1];break;case"L":case"T":yield o,n=o[1];break;case"C":yield o,n=o[3];break;case"S":case"Q":yield o,n=o[2];break;case"A":yield o,n=o[6];break;case"Z":case"z":n=e,yield["Z"];break;case"H":n=[o[1],n[1]],yield["L",n];break;case"V":n=[n[0],o[1]],yield["L",n];break;case"m":n=e=[n[0]+o[1],n[1]+o[2]],yield["M",n];break;case"l":n=[n[0]+o[1],n[1]+o[2]],yield["L",n];break;case"h":n=[n[0]+o[1],n[1]],yield["L",n];break;case"v":n=[n[0],n[1]+o[1]],yield["L",n];break;case"c":yield["C",[n[0]+o[1],n[1]+o[2]],[n[0]+o[3],n[1]+o[4]],n=[n[0]+o[5],n[1]+o[6]]];break;case"s":yield["S",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"q":yield["Q",[n[0]+o[1],n[1]+o[2]],n=[n[0]+o[3],n[1]+o[4]]];break;case"t":yield["T",n=[n[0]+o[1],n[1]+o[2]]];break;case"a":yield["A",o[1],o[2],o[3],o[4],o[5],n=[n[0]+o[6],n[1]+o[7]]]}}(t))switch(s[0]){case"M":e=n=s[1],o=null;break;case"L":e||r(),yield["L",e,s[1]],e=s[1],o=null;break;case"C":e||r(),yield["C",e,s[1],s[2],s[3]],e=s[3],o=s[2];break;case"S":e||r(),o||r(),yield["C",e,Lt(e,o),s[1],s[2]],e=s[2],o=s[1];break;case"Q":e||r(),yield["Q",e,s[1],s[2]],e=s[2],o=s[1];break;case"T":e||r(),o||r(),o=Lt(e,o),yield["Q",e,o,s[1]],e=s[1];break;case"A":e||r(),yield["A",e,s[1],s[2],s[3],s[4],s[5],s[6]],e=s[6],o=null;break;case"Z":case"z":e||r(),n||r(),yield["L",e,n],e=n,o=null}}function*Vt(t,n=1e-4){let e=null;for(const o of t)switch(e&&T(o[1],e,n)||(yield["M",o[1]]),o[0]){case"L":yield["L",e=o[2]];break;case"C":yield["C",o[2],o[3],e=o[4]];break;case"Q":yield["Q",o[2],e=o[3]];break;case"A":yield["A",o[2],o[3],o[4],o[5],o[6],e=o[7]]}}const It=Symbol();function*At(t){const n=/\s*,?\s*(-?\d*(?:\d\.|\.\d|\d)\d*(?:[eE][+\-]?\d+)?)/y,e=/\s*([MLCSQTAZHVmlhvcsqtaz])/y,o=/\s*,?\s*([01])/y;let r=0,s="M";function i(){if(r>=t.length-1)return It;e.lastIndex=r;const n=e.exec(t);if(!n)switch(s){case"M":return"L";case"m":return"l";default:return s}return r=e.lastIndex,n[1]}function a(){n.lastIndex=r;const e=n.exec(t);if(!e)throw new Error(`Invalid path data. Expected a number at index ${r}.`);return r=n.lastIndex,Number(e[1])}function c(){o.lastIndex=r;const n=o.exec(t);if(!n)throw new Error(`Invalid path data. Expected a flag at index ${r}.`);return r=o.lastIndex,"1"===n[1]}for(;;)switch(i()){case"M":yield[s="M",[a(),a()]];break;case"L":yield[s="L",[a(),a()]];break;case"C":yield[s="C",[a(),a()],[a(),a()],[a(),a()]];break;case"S":yield[s="S",[a(),a()],[a(),a()]];break;case"Q":yield[s="Q",[a(),a()],[a(),a()]];break;case"T":yield[s="T",[a(),a()]];break;case"A":yield[s="A",a(),a(),a(),c(),c(),[a(),a()]];break;case"Z":case"z":yield[s="Z"];break;case"H":yield[s="H",a()];break;case"V":yield[s="V",a()];break;case"m":yield[s="m",a(),a()];break;case"l":yield[s="l",a(),a()];break;case"h":yield[s="h",a()];break;case"v":yield[s="v",a()];break;case"c":yield[s="c",a(),a(),a(),a(),a(),a()];break;case"s":yield[s="s",a(),a(),a(),a()];break;case"q":yield[s="q",a(),a(),a(),a()];break;case"t":yield[s="t",a(),a()];break;case"a":yield[s="a",a(),a(),a(),c(),c(),a(),a()];break;case It:return}}t.arcSegmentToCubics=Z,t.commandsFromPathData=At,t.pathBoolean=function(n,e,o,r,s){const i=[...it(n,gt(1)),...it(o,gt(2))];!function(t){for(let n=0;no[1]&&o.reverse();const[r,s]=o;if(Math.abs(r-s)({...t,boundingBox:U(t.seg)}))),e=n.reduce(((t,{boundingBox:n})=>u(t,n)),null);if(!e)return{edges:[],totalBoundingBox:null};const o=new g(e,at),r={};function s(t,n){rt(r,t)||(r[t]=[]),r[t].push(n)}for(let e=0;e1-ut.param)break;const r=(n-a)/(1-a);if(a=n,r1-ut.param)continue;const[c,u]=J(s,r);i.push({seg:c,boundingBox:U(c),parent:e.parent}),s=u}i.push({seg:s,boundingBox:U(s),parent:e.parent})}return{edges:i,totalBoundingBox:e}}(i);if(!c)return[];const f=function(t,n){const e=new g(n,ct),o=[];function r(t){const n=l(t,ut.point),r=e.find(n);if(r.size)return function(t){return t.values().next().value}(r);{const r={point:t,outgoingEdges:[]};return e.insert(n,r),o.push(r),r}}const s=lt(),i={};return{edges:t.flatMap((t=>{const n=r(O(t.seg)),e=r(N(t.seg));if(n===e)switch(t.seg[0]){case"L":return[];case"C":if(T(t.seg[1],t.seg[2],ut.point)&&T(t.seg[3],t.seg[4],ut.point))return[];break;case"Q":if(T(t.seg[1],t.seg[2],ut.point))return[];break;case"A":if(!1===t.seg[5])return[]}const o=`${s(n)}:${s(e)}`;if(rt(i,o)){const n=i[o].find((n=>et(n[0].seg,t.seg,ut.point)));if(n)return n[1].parent|=t.parent,n[2].parent|=t.parent,[]}const a=`${s(e)}:${s(n)}`;if(rt(i,a)){const n=q(t.seg),e=i[a].find((t=>et(t[0].seg,n,ut.point)));if(e)return e[0].parent===t.parent||(e[1].parent|=t.parent,e[2].parent|=t.parent),[]}const c={...t,incidentVertices:[n,e],directionFlag:!1,twin:null},u={...t,incidentVertices:[e,n],directionFlag:!0,twin:c};return c.twin=u,n.outgoingEdges.push(c),e.outgoingEdges.push(u),rt(i,o)?i[o].push([t,c,u]):i[o]=[[t,c,u]],[c,u]})),vertices:o}}(a,c),d=function({vertices:t}){const n=[],e=[],o=st((t=>{const n={outgoingEdges:[]};return e.push(n),n})),r=lt(),s={},i=new WeakSet;for(const e of t){if(2===ht(e))continue;const t=o(e);for(const a of e.outgoingEdges){const e=[];let c=a;for(;c.parent===a.parent&&c.directionFlag===a.directionFlag&&2===ht(c.incidentVertices[1]);){e.push(c.seg),i.add(c.incidentVertices[1]);const[t,n]=c.incidentVertices[1].outgoingEdges;c=t.twin===c?n:t}e.push(c.seg);const u=o(c.incidentVertices[1]),f=`${r(a)}-${r(c)}`,d=s[`${r(c.twin)}-${r(a.twin)}`]??null,l={segments:e,parent:a.parent,incidentVertices:[t,u],directionFlag:a.directionFlag,twin:d};d&&(d.twin=l),s[f]=l,t.outgoingEdges.push(l),n.push(l)}}const a=[];for(const n of t){if(2!==ht(n)||i.has(n))continue;let t=n.outgoingEdges[0];const e={segments:[],parent:t.parent,directionFlag:t.directionFlag};do{e.segments.push(t.seg),i.add(t.incidentVertices[0]);const[n,o]=t.incidentVertices[1].outgoingEdges;t=n.twin===t?o:n}while(t.incidentVertices[0]!==n);a.push(e)}return{edges:n,vertices:e,cycles:a}}(f);!function(t){function n(n){const e=new WeakSet,o=new WeakMap;function r(t,s,i){if(o.has(t))return o.get(t);o.set(t,i);let a=1/0;for(const e of t.outgoingEdges)e.parent&n&&e!==s&&(a=Math.min(a,r(e.incidentVertices[1],e.twin,i+1)));return a<=i&&e.add(t),a}for(const e of t.edges)e.parent&n&&r(e.incidentVertices[0],null,0);return e}const e=n(1),o=n(2);function r(t){return!(1&~t.parent)&&e.has(t.incidentVertices[0])&&e.has(t.incidentVertices[1])||!(2&~t.parent)&&o.has(t.incidentVertices[0])&&o.has(t.incidentVertices[1])}t.vertices=t.vertices.filter((function(t){return e.has(t)||o.has(t)}));for(const n of t.vertices)n.outgoingEdges=n.outgoingEdges.filter(r);t.edges=t.edges.filter(r)}(d),function({vertices:t}){const n=st(pt);for(const e of t)ht(e)>2&&e.outgoingEdges.sort(((t,e)=>n(t)-n(e)))}(d);const h=function(t){let n=[];function e(t,n){let o=!1;for(const r of t){const t=vt(n,r.component);if(t){if(r.outgoingEdges.has(t)){const o=r.outgoingEdges.get(t);r.outgoingEdges.set(t,e(o,n))}else r.outgoingEdges.set(t,[{component:n,outgoingEdges:new Map}]);o=!0;break}}if(o)return t;{const e={component:n,outgoingEdges:new Map},o=[e];for(const r of t){const t=vt(r.component,n);t?e.outgoingEdges.has(t)?e.outgoingEdges.get(t).push(r):e.outgoingEdges.set(t,[r]):o.push(r)}return o}}for(const o of t)n=e(n,o);return n}(function({edges:t,cycles:n}){const e=[],o=new WeakMap;for(const n of t){if(o.has(n))continue;const t={incidentEdges:[],flag:0};let r=n;do{const n=o.get(r.twin)??null,e={segments:r.segments,parent:r.parent,incidentVertex:t,directionFlag:r.directionFlag,twin:n};n&&(n.twin=e),o.set(r,e),t.incidentEdges.push(e),r=mt(r)}while(r.incidentVertices[0]!==n.incidentVertices[0]);e.push(t)}for(const t of n){const n={incidentEdges:[],flag:0},o={segments:t.segments,parent:t.parent,incidentVertex:n,directionFlag:t.directionFlag,twin:null},r={incidentEdges:[],flag:0},s={segments:[...t.segments].reverse(),parent:t.parent,incidentVertex:r,directionFlag:!t.directionFlag,twin:o};o.twin=s,n.incidentEdges.push(o),r.incidentEdges.push(s),e.push(n,r)}const r=[],s=new WeakSet,i=new WeakSet;for(const t of e){if(s.has(t))continue;const n=[],e=[],o=t=>{s.has(t)||n.push(t),s.add(t);for(const n of t.incidentEdges){if(i.has(n))continue;const{twin:t}=n;e.push(n,t),i.add(n),i.add(t),o(t.incidentVertex)}};o(t);const a=n.find((t=>wt(t).winding<0));r.push({vertices:n,edges:e,outerFace:a})}return r}(d));!function(t,n,e){function o(t,r,s){const i=new WeakSet;!function r(s,a,c){if(i.has(s))return;i.add(s);const u=Bt(a,n),f=Bt(c,e);s.flag=u|f<<1;for(const t of s.incidentEdges){const n=t.twin;let e=a;1&t.parent&&(e+=t.directionFlag?-1:1);let o=c;2&t.parent&&(o+=t.directionFlag?-1:1),r(n.incidentVertex,e,o)}if(t.outgoingEdges.has(s)){const n=t.outgoingEdges.get(s);for(const t of n)o(t,a,c)}}(t.component.outerFace,r,s)}for(const n of t)o(n,0,0)}(h,e,r);const m=Ft[s];switch(s){case t.PathBooleanOperation.Division:case t.PathBooleanOperation.Fracture:return function(t,n){const e=[];function o(t){for(const o of t.component.vertices){if(!n(o)||o===t.component.outerFace)continue;const r=[];for(const t of o.incidentEdges)t.directionFlag?r.push(...t.segments.map(q)):r.push(...t.segments);if(t.outgoingEdges.has(o))for(const n of t.outgoingEdges.get(o)){const{outerFace:t}=n.component;for(const n of t.incidentEdges)n.directionFlag?r.push(...n.segments.map(q)):r.push(...n.segments)}e.push(r)}for(const n of t.outgoingEdges.values())for(const t of n)o(t)}for(const n of t)o(n);return e}(h,m);default:{const t=new Set(function*(t,n){function*e(t){for(const e of t.component.vertices)n(e)&&(yield e);for(const n of t.outgoingEdges.values())for(const t of n)yield*e(t)}for(const n of t)yield*e(n)}(h,m));return[[...Pt(t)]]}}},t.pathCubicSegmentSelfIntersection=p,t.pathFromCommands=Ct,t.pathFromPathData=function(t){return[...Ct(At(t))]},t.pathSegmentBoundingBox=U,t.pathSegmentIntersection=ot,t.pathToCommands=Vt,t.pathToPathData=function(t,n=1e-4){function e(t){return"string"==typeof t?t:function(t){return"number"==typeof t}(t)?t.toFixed(12):function(t){return"boolean"==typeof t}(t)?t?"1":"0":t.map((t=>t.toFixed(12))).join(",")}return[...it(Vt(t,n),(t=>t.map(e).join(" ")))].join(" ")},t.samplePathSegmentAt=$},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).PathBool={}); //# sourceMappingURL=path-bool.umd.js.map diff --git a/dist/path-bool.umd.js.map b/dist/path-bool.umd.js.map index 55c8640..5387dd3 100644 --- a/dist/path-bool.umd.js.map +++ b/dist/path-bool.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"path-bool.umd.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/Path.ts","../src/primitives/PathCommand.ts","../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n // TODO: check other direction\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["INSIDE","LEFT","RIGHT","BOTTOM","TOP","outCode","x","y","boundingBox","code","left","right","top","bottom","lineSegmentAABBIntersect","seg","x0","y0","x1","y1","outcode0","outcode1","outcodeOut","boundingBoxesOverlap","a","b","mergeBoundingBoxes","Math","min","max","extendBoundingBox","point","boundingBoxMaxExtent","boundingBoxAroundPoint","padding","QuadTree","fromPairs","pairs","depth","innerNodeCapacity","length","Error","i","tree","key","value","insert","constructor","this","subtrees","ensureSubtrees","push","find","set","Set","add","findOnLineSegment","midX","midY","EPS","pathCubicSegmentSelfIntersection","A","B","C","D","ax","ay","bx","by","cx","cy","M","N","K","t1","sqrt","t2","ARRAY_TYPE","Float32Array","Array","create","out","glMatrix.ARRAY_TYPE","fromRotation","rad","s","sin","c","cos","hypot","arguments","mul","a0","a1","a2","a3","a4","a5","b0","b1","b2","b3","b4","b5","scale","lerp","t","transformMat2","m","transformMat2d","len","sub","TAU","PI","deg2rad","deg","vectorAngle","u","v","sign","abs","acos","vec2.len","vectorsEqual","eps","getStartPoint","getEndPoint","reversePathSegment","arcSegmentToCenter","xy1Prime","rotationMatrix","mat2.create","addend","cxy","_A","xy1","rx","ry","phi","fA","fS","xy2","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","rx2","ry2","x1Prime2","y1Prime2","lambda","lambdaSqrt","lambdaAbs","multiplier","cxPrime","cyPrime","mat2.transpose","vec2.add","vec1","theta1","deltaTheta","center","arcSegmentFromCenter","vec2.set","samplePathSegmentAt","p01","p12","p23","p012","p123","p","vec2.lerp","centerParametrization","theta","p0","p1","sinC","cosC","vec2.rotate","arcSegmentToCubics","fromUnit","mat2d.create","matrix","arc","maxDeltaTheta","count","ceil","mat2d.fromTranslation","mat2d.rotate","v0","v1","mat2d.scale","cubics","k","tan","sinTheta","cosTheta","start","control1","control2","end","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d","evalCubic1d","p2","p3","cubicBoundingInterval","sqrtD","t0","quadraticBoundingInterval","denominator","evalQuadratic1d","inInterval","mapped","pathSegmentBoundingBox","theta2","expandBoundingBox","splitLinearSegmentAt","splitCubicSegmentAt","splitSegmentAt","splitQuadraticSegmentAt","midDeltaTheta","splitArcSegmentAt","COLLINEAR_EPS","Number","MIN_VALUE","lineSegmentIntersection","x2","y2","x3","y3","x4","y4","c1","c2","denom","subdivideIntersectionSegment","intSeg","seg0","seg1","midParam","startParam","endParam","pathSegmentToLineSegment","intersectionSegmentsOverlap","boundingBox0","boundingBox1","seg2","lineSegmentsIntersect","segmentsEqual","pointEpsilon","type","pathSegmentIntersection","endpoints","st","param","params","nextPairs","isLinear0","linear","isLinear1","subdivided0","subdivided1","filter","hasOwn","Object","memoizeWeak","fn","cache","WeakMap","obj","args","has","get","val","map","iter","INTERSECTION_TREE_DEPTH","POINT_TREE_DEPTH","PathBooleanOperation","FillRule","createObjectCounter","segmentToEdge","parent","getOrder","vertex","outgoingEdges","getIncidenceAngle","directionFlag","segments","atan2","getNextEdge","edge","incidentVertices","index","findIndex","other","twin","exports","faceToPolygon","face","incidentEdges","flatMap","points","intervalCrossesPoint","lineSegmentIntersectsHorizontalRay","inMin","inMax","outMin","outMax","computePointWinding","polygon","testedPoint","prevPoint","winding","computeWinding","boundingBoxIntersectsHorizontalRay","pathSegmentHorizontalRayIntersectionCount","origSeg","totalBoundingBox","nextSegments","split","testInclusion","edges","vertices","outerFace","getFlag","fillRule","NonZero","EvenOdd","walkFaces","faces","isRemovedEdge","incidentVertex","edgeToNext","prevEdge","visitedEdges","WeakSet","startEdge","operationPredicates","Union","flag","Difference","Intersection","Exclusion","Division","Fracture","reflectControlPoint","controlPoint","pathFromCommands","commands","firstPoint","lastPoint","lastControlPoint","badSequence","cmd","toAbsoluteCommands","pathToCommands","eof","Symbol","commandsFromPathData","d","reFloat","reCmd","reBool","lastCmd","getCmd","lastIndex","match","exec","getFloat","getBool","aFillRule","bFillRule","op","unsplitEdges","intersection","reverse","tmpSeg","seg3","splitAtSelfIntersections","splitEdges","withBoundingBox","reduce","acc","edgeTree","splitsPerEdge","addSplit","candidates","j","candidate","includeEndpoints","newEdges","splits","sort","prevT","tt","splitAtIntersections","majorGraph","vertexTree","newVertices","getVertex","box","existingVertices","size","values","next","firstElementOfSet","getVertexId","vertexPairIdToEdges","startVertex","endVertex","vertexPairId","existingEdge","fwdEdge","bwdEdge","findVertices","minorGraph","toMinorVertex","_majorVertex","minorVertex","getEdgeId","idToEdge","visited","edge1","edge2","edgeId","newEdge","cycles","cycle","computeMinor","graph","walk","keptVertices","vertexToLevel","visit","incomingEdge","level","minLevel","Infinity","keptVerticesA","keptVerticesB","keepEdge","removeDanglingEdges","getAngle","sortOutgoingEdgesByAngle","nestingTrees","components","trees","component","found","children","Map","newTree","newTrees","computeNestingTree","minorToDualEdge","innerFace","innerHalfEdge","outerHalfEdge","visitedVertices","componentVertices","componentEdges","computeDual","visitTree","aRunningCount","bRunningCount","visitedFaces","visitFace","aFlag","bFlag","nextACount","nextBCount","subtree","flagFaces","predicate","paths","path","dumpFaces","selectedFaces","getSelectedFaces","mapParam","isNumber","toFixed","isBoolean","join"],"mappings":"6BAYA,MAAMA,EAAS,EACTC,EAAO,EACPC,EAAQ,EACRC,EAAS,EACTC,EAAM,EAEZ,SAASC,EAAQC,EAAWC,EAAWC,GACnC,IAAIC,EAAOT,EAcX,OAZIM,EAAIE,EAAYE,KAChBD,GAAQR,EACDK,EAAIE,EAAYG,QACvBF,GAAQP,GAGRK,EAAIC,EAAYI,IAChBH,GAAQN,EACDI,EAAIC,EAAYK,SACvBJ,GAAQL,GAGLK,CACX,CAEgB,SAAAK,EAAyBC,EAAkBP,GACvD,KAAMQ,EAAIC,IAAMC,EAAIC,IAAOJ,EAEvBK,EAAWf,EAAQW,EAAIC,EAAIT,GAC3Ba,EAAWhB,EAAQa,EAAIC,EAAIX,GAE/B,OAAa,CACT,KAAMY,EAAWC,GAEb,OAAO,EACJ,GAAID,EAAWC,EAGlB,OAAO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5P,KAAYN,EAAKoP,cAAcuH,SACtC,IAAK,MAAMoE,KAAWza,QACXmY,EAAMsC,EAGxB,CAED,IAAK,MAAM/a,KAAQoZ,QACRX,EAAMzY,EAErB,CA6MgBsb,CAAiBlC,EAAc6B,IAEnC,MAAO,CAAC,IAAIjJ,GAAUqJ,IACzB,EAET,gFG/gCM,SAA2BtH,GAC7B,MAAO,IAAIZ,GAAiBW,GAAqBC,IACrD,wGAE+BoH,EAAYlW,EAAc,MACrD,SAASsW,EAASlO,GACd,MLzLkB,iBKyLLA,EAAeA,EL9L9B,SAAmBmB,GACrB,MAAsB,iBAARA,CAClB,CK6LYgN,CAASnO,GAAeA,EAAMoO,QAAQ,ILvL5C,SAAoBjN,GACtB,MAAsB,kBAARA,CAClB,CKsLYkN,CAAUrO,GAAeA,EAAQ,IAAM,IACpCA,EAAMoB,KAAK7L,GAAMA,EAAE6Y,QAAQ,MAAKE,KAAK,IAC/C,CAED,MAAO,IACAlN,GAAIkF,GAAewH,EAAMlW,IAAOwO,GAAQA,EAAIhF,IAAI8M,GAAUI,KAAK,QACpEA,KAAK,IACX","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file +{"version":3,"file":"path-bool.umd.js","sources":["../src/intersections/line-segment-AABB.ts","../src/primitives/AABB.ts","../src/QuadTree.ts","../src/intersections/path-cubic-segment-self-intersection.ts","../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat2.js","../node_modules/gl-matrix/esm/mat2d.js","../node_modules/gl-matrix/esm/vec2.js","../src/util/math.ts","../src/primitives/Vector.ts","../src/primitives/PathSegment.ts","../src/intersections/line-segment.ts","../src/intersections/path-segment.ts","../src/util/generic.ts","../src/util/iterators.ts","../src/path-boolean.ts","../src/primitives/Path.ts","../src/primitives/PathCommand.ts","../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n // TODO: explain\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {\n const reversedSeg = reversePathSegment(edge.seg);\n const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(\n (other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),\n );\n if (existingEdge) {\n if (existingEdge[0].parent === edge.parent) {\n // discard \"there and back\" pairs\n return [];\n }\n\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["INSIDE","LEFT","RIGHT","BOTTOM","TOP","outCode","x","y","boundingBox","code","left","right","top","bottom","lineSegmentAABBIntersect","seg","x0","y0","x1","y1","outcode0","outcode1","outcodeOut","boundingBoxesOverlap","a","b","mergeBoundingBoxes","Math","min","max","extendBoundingBox","point","boundingBoxMaxExtent","boundingBoxAroundPoint","padding","QuadTree","fromPairs","pairs","depth","innerNodeCapacity","length","Error","i","tree","key","value","insert","constructor","this","subtrees","ensureSubtrees","push","find","set","Set","add","findOnLineSegment","midX","midY","EPS","pathCubicSegmentSelfIntersection","A","B","C","D","ax","ay","bx","by","cx","cy","M","N","K","t1","sqrt","t2","ARRAY_TYPE","Float32Array","Array","create","out","glMatrix.ARRAY_TYPE","fromRotation","rad","s","sin","c","cos","hypot","arguments","mul","a0","a1","a2","a3","a4","a5","b0","b1","b2","b3","b4","b5","scale","lerp","t","transformMat2","m","transformMat2d","len","sub","TAU","PI","deg2rad","deg","vectorAngle","u","v","sign","abs","acos","vec2.len","vectorsEqual","eps","getStartPoint","getEndPoint","reversePathSegment","arcSegmentToCenter","xy1Prime","rotationMatrix","mat2.create","addend","cxy","_A","xy1","rx","ry","phi","fA","fS","xy2","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","rx2","ry2","x1Prime2","y1Prime2","lambda","lambdaSqrt","lambdaAbs","multiplier","cxPrime","cyPrime","mat2.transpose","vec2.add","vec1","theta1","deltaTheta","center","arcSegmentFromCenter","vec2.set","samplePathSegmentAt","p01","p12","p23","p012","p123","p","vec2.lerp","centerParametrization","theta","p0","p1","sinC","cosC","vec2.rotate","arcSegmentToCubics","fromUnit","mat2d.create","matrix","arc","maxDeltaTheta","count","ceil","mat2d.fromTranslation","mat2d.rotate","v0","v1","mat2d.scale","cubics","k","tan","sinTheta","cosTheta","start","control1","control2","end","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d","evalCubic1d","p2","p3","cubicBoundingInterval","sqrtD","t0","quadraticBoundingInterval","denominator","evalQuadratic1d","inInterval","mapped","pathSegmentBoundingBox","theta2","expandBoundingBox","splitLinearSegmentAt","splitCubicSegmentAt","splitSegmentAt","splitQuadraticSegmentAt","midDeltaTheta","splitArcSegmentAt","COLLINEAR_EPS","Number","MIN_VALUE","lineSegmentIntersection","x2","y2","x3","y3","x4","y4","c1","c2","denom","subdivideIntersectionSegment","intSeg","seg0","seg1","midParam","startParam","endParam","pathSegmentToLineSegment","intersectionSegmentsOverlap","boundingBox0","boundingBox1","seg2","lineSegmentsIntersect","segmentsEqual","pointEpsilon","type","pathSegmentIntersection","endpoints","st","param","params","nextPairs","isLinear0","linear","isLinear1","subdivided0","subdivided1","filter","hasOwn","Object","memoizeWeak","fn","cache","WeakMap","obj","args","has","get","val","map","iter","INTERSECTION_TREE_DEPTH","POINT_TREE_DEPTH","PathBooleanOperation","FillRule","createObjectCounter","segmentToEdge","parent","getOrder","vertex","outgoingEdges","getIncidenceAngle","directionFlag","segments","atan2","getNextEdge","edge","incidentVertices","index","findIndex","other","twin","exports","faceToPolygon","face","incidentEdges","flatMap","points","intervalCrossesPoint","lineSegmentIntersectsHorizontalRay","inMin","inMax","outMin","outMax","computePointWinding","polygon","testedPoint","prevPoint","winding","computeWinding","boundingBoxIntersectsHorizontalRay","pathSegmentHorizontalRayIntersectionCount","origSeg","totalBoundingBox","nextSegments","split","testInclusion","edges","vertices","outerFace","getFlag","fillRule","NonZero","EvenOdd","walkFaces","faces","isRemovedEdge","incidentVertex","edgeToNext","prevEdge","visitedEdges","WeakSet","startEdge","operationPredicates","Union","flag","Difference","Intersection","Exclusion","Division","Fracture","reflectControlPoint","controlPoint","pathFromCommands","commands","firstPoint","lastPoint","lastControlPoint","badSequence","cmd","toAbsoluteCommands","pathToCommands","eof","Symbol","commandsFromPathData","d","reFloat","reCmd","reBool","lastCmd","getCmd","lastIndex","match","exec","getFloat","getBool","aFillRule","bFillRule","op","unsplitEdges","intersection","reverse","tmpSeg","seg3","splitAtSelfIntersections","splitEdges","withBoundingBox","reduce","acc","edgeTree","splitsPerEdge","addSplit","candidates","j","candidate","includeEndpoints","newEdges","splits","sort","prevT","tt","splitAtIntersections","majorGraph","vertexTree","newVertices","getVertex","box","existingVertices","size","values","next","firstElementOfSet","getVertexId","vertexPairIdToEdges","startVertex","endVertex","vertexPairId","existingEdge","vertexPairIdInv","reversedSeg","fwdEdge","bwdEdge","findVertices","minorGraph","toMinorVertex","_majorVertex","minorVertex","getEdgeId","idToEdge","visited","edge1","edge2","edgeId","newEdge","cycles","cycle","computeMinor","graph","walk","keptVertices","vertexToLevel","visit","incomingEdge","level","minLevel","Infinity","keptVerticesA","keptVerticesB","keepEdge","removeDanglingEdges","getAngle","sortOutgoingEdgesByAngle","nestingTrees","components","trees","component","found","children","Map","newTree","newTrees","computeNestingTree","minorToDualEdge","innerFace","innerHalfEdge","outerHalfEdge","visitedVertices","componentVertices","componentEdges","computeDual","visitTree","aRunningCount","bRunningCount","visitedFaces","visitFace","aFlag","bFlag","nextACount","nextBCount","subtree","flagFaces","predicate","paths","path","dumpFaces","selectedFaces","getSelectedFaces","mapParam","isNumber","toFixed","isBoolean","join"],"mappings":"6BAYA,MAAMA,EAAS,EACTC,EAAO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,GACrB,MAAsB,iBAARA,CAClB,CK6LYkN,CAASrO,GAAeA,EAAMsO,QAAQ,ILvL5C,SAAoBnN,GACtB,MAAsB,kBAARA,CAClB,CKsLYoN,CAAUvO,GAAeA,EAAQ,IAAM,IACpCA,EAAMoB,KAAK7L,GAAMA,EAAE+Y,QAAQ,MAAKE,KAAK,IAC/C,CAED,MAAO,IACApN,GAAIkF,GAAe0H,EAAMpW,IAAOwO,GAAQA,EAAIhF,IAAIgN,GAAUI,KAAK,QACpEA,KAAK,IACX","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file diff --git a/docs/js/path-bool.js b/docs/js/path-bool.js index 9f35656..c63b396 100644 --- a/docs/js/path-bool.js +++ b/docs/js/path-bool.js @@ -1590,6 +1590,7 @@ function findVertices(edges, boundingBox) { } break; case "A": + // TODO: explain if (edge.seg[5] === false) { return []; } @@ -1597,7 +1598,6 @@ function findVertices(edges, boundingBox) { } } const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`; - // TODO: check other direction if (hasOwn(vertexPairIdToEdges, vertexPairId)) { const existingEdge = vertexPairIdToEdges[vertexPairId].find((other) => segmentsEqual(other[0].seg, edge.seg, EPS.point)); if (existingEdge) { @@ -1606,6 +1606,20 @@ function findVertices(edges, boundingBox) { return []; } } + const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`; + if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) { + const reversedSeg = reversePathSegment(edge.seg); + const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find((other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point)); + if (existingEdge) { + if (existingEdge[0].parent === edge.parent) { + // discard "there and back" pairs + return []; + } + existingEdge[1].parent |= edge.parent; + existingEdge[2].parent |= edge.parent; + return []; + } + } const fwdEdge = { ...edge, incidentVertices: [startVertex, endVertex], diff --git a/docs/js/path-bool.js.map b/docs/js/path-bool.js.map index 58d3540..93e7d0b 100644 --- a/docs/js/path-bool.js.map +++ b/docs/js/path-bool.js.map @@ -1 +1 @@ -{"version":3,"file":"path-bool.js","sources":["../../src/intersections/line-segment-AABB.ts","../../src/primitives/AABB.ts","../../src/QuadTree.ts","../../src/intersections/path-cubic-segment-self-intersection.ts","../../node_modules/gl-matrix/esm/common.js","../../node_modules/gl-matrix/esm/mat2.js","../../node_modules/gl-matrix/esm/mat2d.js","../../node_modules/gl-matrix/esm/vec2.js","../../src/util/math.ts","../../src/primitives/Vector.ts","../../src/primitives/PathSegment.ts","../../src/intersections/line-segment.ts","../../src/intersections/path-segment.ts","../../src/util/generic.ts","../../src/util/iterators.ts","../../src/path-boolean.ts","../../src/primitives/PathCommand.ts","../../src/primitives/Path.ts","../../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n // TODO: check other direction\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d.scale","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d"],"mappings":"AAUA;AAEA,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AAEnB,SAAS,OAAO,CAAC,CAAS,E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CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;QAClC,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QAC/C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpD;IAED,OAAO;QACH,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1E,KAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file +{"version":3,"file":"path-bool.js","sources":["../../src/intersections/line-segment-AABB.ts","../../src/primitives/AABB.ts","../../src/QuadTree.ts","../../src/intersections/path-cubic-segment-self-intersection.ts","../../node_modules/gl-matrix/esm/common.js","../../node_modules/gl-matrix/esm/mat2.js","../../node_modules/gl-matrix/esm/mat2d.js","../../node_modules/gl-matrix/esm/vec2.js","../../src/util/math.ts","../../src/primitives/Vector.ts","../../src/primitives/PathSegment.ts","../../src/intersections/line-segment.ts","../../src/intersections/path-segment.ts","../../src/util/generic.ts","../../src/util/iterators.ts","../../src/path-boolean.ts","../../src/primitives/PathCommand.ts","../../src/primitives/Path.ts","../../src/path-data.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { AABB } from \"../primitives/AABB\";\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\n// https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm\n\nconst INSIDE = 0;\nconst LEFT = 1;\nconst RIGHT = 1 << 1;\nconst BOTTOM = 1 << 2;\nconst TOP = 1 << 3;\n\nfunction outCode(x: number, y: number, boundingBox: AABB) {\n let code = INSIDE;\n\n if (x < boundingBox.left) {\n code |= LEFT;\n } else if (x > boundingBox.right) {\n code |= RIGHT;\n }\n\n if (y < boundingBox.top) {\n code |= BOTTOM;\n } else if (y > boundingBox.bottom) {\n code |= TOP;\n }\n\n return code;\n}\n\nexport function lineSegmentAABBIntersect(seg: LineSegment, boundingBox: AABB) {\n let [[x0, y0], [x1, y1]] = seg;\n\n let outcode0 = outCode(x0, y0, boundingBox);\n let outcode1 = outCode(x1, y1, boundingBox);\n\n while (true) {\n if (!(outcode0 | outcode1)) {\n // bitwise OR is 0: both points inside window; trivially accept and exit loop\n return true;\n } else if (outcode0 & outcode1) {\n // bitwise AND is not 0: both points share an outside zone (LEFT, RIGHT, TOP,\n // or BOTTOM), so both must be outside window; exit loop (accept is false)\n return false;\n } else {\n const { top, right, bottom, left } = boundingBox;\n\n // failed both tests, so calculate the line segment to clip\n // from an outside point to an intersection with clip edge\n let x: number, y: number;\n\n // At least one endpoint is outside the clip rectangle; pick it.\n const outcodeOut = outcode1 > outcode0 ? outcode1 : outcode0;\n\n // Now find the intersection point;\n // use formulas:\n // slope = (y1 - y0) / (x1 - x0)\n // x = x0 + (1 / slope) * (ym - y0), where ym is ymin or ymax\n // y = y0 + slope * (xm - x0), where xm is xmin or xmax\n // No need to worry about divide-by-zero because, in each case, the\n // outcode bit being tested guarantees the denominator is non-zero\n\n if (outcodeOut & TOP) {\n // point is above the clip window\n x = x0 + ((x1 - x0) * (bottom - y0)) / (y1 - y0);\n y = bottom;\n } else if (outcodeOut & BOTTOM) {\n // point is below the clip window\n x = x0 + ((x1 - x0) * (top - y0)) / (y1 - y0);\n y = top;\n } else if (outcodeOut & RIGHT) {\n // point is to the right of clip window\n y = y0 + ((y1 - y0) * (right - x0)) / (x1 - x0);\n x = right;\n } else if (outcodeOut & LEFT) {\n // point is to the left of clip window\n y = y0 + ((y1 - y0) * (left - x0)) / (x1 - x0);\n x = left;\n }\n\n // Now we move outside point to intersection point to clip\n // and get ready for next pass.\n if (outcodeOut == outcode0) {\n x0 = x!;\n y0 = y!;\n outcode0 = outCode(x0, y0, boundingBox);\n } else {\n x1 = x!;\n y1 = y!;\n outcode1 = outCode(x1, y1, boundingBox);\n }\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AABB = {\n top: number;\n right: number;\n bottom: number;\n left: number;\n};\n\nexport function boundingBoxContainsPoint(boundingBox: AABB, point: Vector) {\n return (\n point[0] >= boundingBox.left &&\n point[0] <= boundingBox.right &&\n point[1] >= boundingBox.top &&\n point[1] <= boundingBox.bottom\n );\n}\n\nexport function boundingBoxesOverlap(a: AABB, b: AABB) {\n return (\n a.left <= b.right &&\n b.left <= a.right &&\n a.top <= b.bottom &&\n b.top <= a.bottom\n );\n}\n\nexport function mergeBoundingBoxes(a: AABB | null, b: AABB): AABB {\n if (!a) return b;\n\n return {\n top: Math.min(a.top, b.top),\n right: Math.max(a.right, b.right),\n bottom: Math.max(a.bottom, b.bottom),\n left: Math.min(a.left, b.left),\n };\n}\n\nexport function extendBoundingBox(boundingBox: AABB | null, point: Vector) {\n if (!boundingBox) {\n return {\n top: point[1],\n right: point[0],\n bottom: point[1],\n left: point[0],\n };\n }\n\n return {\n top: Math.min(boundingBox.top, point[1]),\n right: Math.max(boundingBox.right, point[0]),\n bottom: Math.max(boundingBox.bottom, point[1]),\n left: Math.min(boundingBox.left, point[0]),\n };\n}\n\nexport function boundingBoxMaxExtent(boundingBox: AABB) {\n return Math.max(\n boundingBox.right - boundingBox.left,\n boundingBox.bottom - boundingBox.top,\n );\n}\n\nexport function boundingBoxAroundPoint(point: Vector, padding: number): AABB {\n return {\n top: point[1] - padding,\n right: point[0] + padding,\n bottom: point[1] + padding,\n left: point[0] - padding,\n };\n}\n\nexport function expandBoundingBox(boundingBox: AABB, padding: number): AABB {\n return {\n top: boundingBox.top - padding,\n right: boundingBox.right + padding,\n bottom: boundingBox.bottom + padding,\n left: boundingBox.left - padding,\n };\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { lineSegmentAABBIntersect } from \"./intersections/line-segment-AABB\";\nimport {\n AABB,\n boundingBoxesOverlap,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Vector } from \"./primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nexport class QuadTree {\n static fromPairs(\n pairs: [AABB, T][],\n depth: number,\n innerNodeCapacity: number = 8,\n ): QuadTree {\n if (pairs.length === 0) {\n throw new Error(\"QuadTree.fromPairs: at least one pair needed.\");\n }\n\n let boundingBox = pairs[0][0];\n for (let i = 1; i < pairs.length; i++) {\n boundingBox = mergeBoundingBoxes(boundingBox, pairs[i][0]);\n }\n\n const tree = new QuadTree(boundingBox, depth, innerNodeCapacity);\n\n for (const [key, value] of pairs) {\n tree.insert(key, value);\n }\n\n return tree;\n }\n\n protected subtrees:\n | [QuadTree, QuadTree, QuadTree, QuadTree]\n | null = null;\n protected pairs: [AABB, T][] = [];\n\n constructor(\n readonly boundingBox: AABB,\n readonly depth: number,\n readonly innerNodeCapacity: number = 16,\n ) {}\n\n insert(boundingBox: AABB, value: T) {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return false;\n\n if (this.depth > 0 && this.pairs.length >= this.innerNodeCapacity) {\n this.ensureSubtrees();\n for (let i = 0; i < this.subtrees!.length; i++) {\n const tree = this.subtrees![i];\n tree.insert(boundingBox, value);\n }\n } else {\n this.pairs.push([boundingBox, value]);\n }\n\n return true;\n }\n\n find(boundingBox: AABB, set: Set = new Set()): Set {\n if (!boundingBoxesOverlap(boundingBox, this.boundingBox)) return set;\n\n for (let i = 0; i < this.pairs.length; i++) {\n const [key, value] = this.pairs[i];\n if (boundingBoxesOverlap(boundingBox, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (let i = 0; i < this.subtrees.length; i++) {\n const tree = this.subtrees[i];\n tree.find(boundingBox, set);\n }\n }\n\n return set;\n }\n\n findOnLineSegment(seg: LineSegment, set: Set = new Set()): Set {\n if (!lineSegmentAABBIntersect(seg, this.boundingBox)) return set;\n\n for (const [key, value] of this.pairs) {\n if (lineSegmentAABBIntersect(seg, key)) {\n set.add(value);\n }\n }\n\n if (this.subtrees) {\n for (const tree of this.subtrees) {\n tree.findOnLineSegment(seg, set);\n }\n }\n\n return set;\n }\n\n private ensureSubtrees() {\n if (this.subtrees) return;\n\n const { top, right, bottom, left } = this.boundingBox;\n const midX = (this.boundingBox.left + this.boundingBox.right) / 2;\n const midY = (this.boundingBox.top + this.boundingBox.bottom) / 2;\n\n this.subtrees = [\n new QuadTree(\n { top, right: midX, bottom: midY, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top, right, bottom: midY, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right: midX, bottom, left },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n new QuadTree(\n { top: midY, right, bottom, left: midX },\n this.depth - 1,\n this.innerNodeCapacity,\n ),\n ];\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCubicSegment } from \"../primitives/PathSegment\";\n\nconst EPS = 1e-12;\n\nexport function pathCubicSegmentSelfIntersection(\n seg: PathCubicSegment,\n): [number, number] | null {\n // https://math.stackexchange.com/questions/3931865/self-intersection-of-a-cubic-bezier-interpretation-of-the-solution\n\n const A = seg[1];\n const B = seg[2];\n const C = seg[3];\n const D = seg[4];\n\n const ax = -A[0] + 3 * B[0] - 3 * C[0] + D[0];\n const ay = -A[1] + 3 * B[1] - 3 * C[1] + D[1];\n const bx = 3 * A[0] - 6 * B[0] + 3 * C[0];\n const by = 3 * A[1] - 6 * B[1] + 3 * C[1];\n const cx = -3 * A[0] + 3 * B[0];\n const cy = -3 * A[1] + 3 * B[1];\n\n const M = ay * bx - ax * by;\n const N = ax * cy - ay * cx;\n\n const K =\n (-3 * ax * ax * cy * cy +\n 6 * ax * ay * cx * cy +\n 4 * ax * bx * by * cy -\n 4 * ax * by * by * cx -\n 3 * ay * ay * cx * cx -\n 4 * ay * bx * bx * cy +\n 4 * ay * bx * by * cx) /\n (ax * ax * by * by - 2 * ax * ay * bx * by + ay * ay * bx * bx);\n\n if (K < 0) return null;\n\n const t1 = (N / M + Math.sqrt(K)) / 2;\n const t2 = (N / M - Math.sqrt(K)) / 2;\n\n if (EPS <= t1 && t1 <= 1 - EPS && EPS <= t2 && t2 <= 1 - EPS) {\n return [t1, t2];\n }\n\n return null;\n}\n","/**\n * Common utilities\n * @module glMatrix\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\n * Convert Degree To Radian\n *\n * @param {Number} a Angle in Degrees\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\n * than or equal to 1.0, and a relative tolerance is used for larger values)\n *\n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}\nif (!Math.hypot) Math.hypot = function () {\n var y = 0,\n i = arguments.length;\n\n while (i--) {\n y += arguments[i] * arguments[i];\n }\n\n return Math.sqrt(y);\n};","import * as glMatrix from \"./common.js\";\n/**\n * 2x2 Matrix\n * @module mat2\n */\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\n\nexport function fromValues(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\n\nexport function set(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n}\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache\n // some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n\n return out;\n}\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3]; // Calculate the determinant\n\n var det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n return out;\n}\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the source matrix\n * @returns {mat2} out\n */\n\nexport function adjoint(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n return out;\n}\n/**\n * Calculates the determinant of a mat2\n *\n * @param {ReadonlyMat2} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[2] * a[1];\n}\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n}\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n}\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to rotate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2\n *\n * @param {ReadonlyMat2} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3]);\n}\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {ReadonlyMat2} L the lower triangular matrix\n * @param {ReadonlyMat2} D the diagonal matrix\n * @param {ReadonlyMat2} U the upper triangular matrix\n * @param {ReadonlyMat2} a the input matrix to factorize\n */\n\nexport function LDU(L, D, U, a) {\n L[2] = a[2] / a[0];\n U[0] = a[0];\n U[1] = a[1];\n U[3] = a[3] - L[2] * U[1];\n return [L, D, U];\n}\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @returns {mat2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2} a The first matrix.\n * @param {ReadonlyMat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {ReadonlyMat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {ReadonlyMat2} a the first operand\n * @param {ReadonlyMat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2x3 Matrix\n * @module mat2d\n * @description\n * A mat2d contains six elements defined as:\n *
\n * [a, b,\n *  c, d,\n *  tx, ty]\n * 
\n * This is a short form for the 3x3 matrix:\n *
\n * [a, b, 0,\n *  c, d, 0,\n *  tx, ty, 1]\n * 
\n * The last column is ignored so the array is shorter and operations are faster.\n */\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(6);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[4] = 0;\n out[5] = 0;\n }\n\n out[0] = 1;\n out[3] = 1;\n return out;\n}\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {ReadonlyMat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n}\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\n\nexport function fromValues(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\n\nexport function set(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n}\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {mat2d} out\n */\n\nexport function invert(out, a) {\n var aa = a[0],\n ab = a[1],\n ac = a[2],\n ad = a[3];\n var atx = a[4],\n aty = a[5];\n var det = aa * ad - ab * ac;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n}\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {ReadonlyMat2d} a the source matrix\n * @returns {Number} determinant of a\n */\n\nexport function determinant(a) {\n return a[0] * a[3] - a[1] * a[2];\n}\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function multiply(out, a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n}\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function rotate(out, a, rad) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\n\nexport function scale(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n}\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to translate\n * @param {ReadonlyVec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\n\nexport function translate(out, a, v) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var v0 = v[0],\n v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n}\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Scaling vector\n * @returns {mat2d} out\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {ReadonlyVec2} v Translation vector\n * @returns {mat2d} out\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n/**\n * Returns a string representation of a mat2d\n *\n * @param {ReadonlyMat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\n\nexport function str(a) {\n return \"mat2d(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \", \" + a[3] + \", \" + a[4] + \", \" + a[5] + \")\";\n}\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\n\nexport function frob(a) {\n return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);\n}\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n}\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @returns {mat2d} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n}\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {ReadonlyMat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n}\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {ReadonlyMat2d} a the first operand\n * @param {ReadonlyMat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n return out;\n}\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n}\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {ReadonlyMat2d} a The first matrix.\n * @param {ReadonlyMat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));\n}\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\n * 2 Dimensional Vector\n * @module vec2\n */\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {ReadonlyVec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the source vector\n * @returns {vec2} out\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to ceil\n * @returns {vec2} out\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to floor\n * @returns {vec2} out\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec2} out\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to round\n * @returns {vec2} out\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} distance between a and b\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\n * Calculates the length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate length of\n * @returns {Number} length of a\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.hypot(x, y);\n}\n/**\n * Calculates the squared length of a vec2\n *\n * @param {ReadonlyVec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to negate\n * @returns {vec2} out\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to invert\n * @returns {vec2} out\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a vector to normalize\n * @returns {vec2} out\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {Number} dot product of a and b\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @returns {vec3} out\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the first operand\n * @param {ReadonlyVec2} b the second operand\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\n * @returns {vec2} out\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat2d} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat3} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {ReadonlyVec2} a the vector to transform\n * @param {ReadonlyMat4} m matrix to transform with\n * @returns {vec2} out\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\n * Rotate a 2D vector\n * @param {vec2} out The receiving vec2\n * @param {ReadonlyVec2} a The vec2 point to rotate\n * @param {ReadonlyVec2} b The origin of the rotation\n * @param {Number} rad The angle of rotation in radians\n * @returns {vec2} out\n */\n\nexport function rotate(out, a, b, rad) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(rad),\n cosC = Math.cos(rad); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\n * Get the angle between two 2D vectors\n * @param {ReadonlyVec2} a The first operand\n * @param {ReadonlyVec2} b The second operand\n * @returns {Number} The angle in radians\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1],\n // mag is the product of the magnitudes of a and b\n mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),\n // mag &&.. short circuits if mag == 0\n cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1\n\n return Math.acos(Math.min(Math.max(cosine, -1), 1));\n}\n/**\n * Set the components of a vec2 to zero\n *\n * @param {vec2} out the receiving vector\n * @returns {vec2} out\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\n * Returns a string representation of a vector\n *\n * @param {ReadonlyVec2} a vector to represent as a string\n * @returns {String} string representation of the vector\n */\n\nexport function str(a) {\n return \"vec2(\" + a[0] + \", \" + a[1] + \")\";\n}\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {ReadonlyVec2} a The first vector.\n * @param {ReadonlyVec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\n * Alias for {@link vec2.length}\n * @function\n */\n\nexport var len = length;\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\n\nexport var sub = subtract;\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\n\nexport var mul = multiply;\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\n\nexport var div = divide;\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\n\nexport var dist = distance;\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\n\nexport var sqrDist = squaredDistance;\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\n\nexport var sqrLen = squaredLength;\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { vec2 } from \"gl-matrix\";\n\nexport const TAU = 2 * Math.PI;\n\nexport function linMap(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;\n}\n\nexport function lerp(a: number, b: number, t: number) {\n return a + (b - a) * t;\n}\n\nexport function rad2deg(rad: number) {\n return (rad / Math.PI) * 180;\n}\n\nexport function deg2rad(deg: number) {\n return (deg / 180) * Math.PI;\n}\n\nexport function vectorAngle(u: [number, number], v: [number, number]) {\n const EPS = 1e-12;\n\n const sign = Math.sign(u[0] * v[1] - u[1] * v[0]);\n\n if (\n sign === 0 &&\n Math.abs(u[0] + v[0]) < EPS &&\n Math.abs(u[1] + v[1]) < EPS\n ) {\n // TODO: u can be scaled\n return Math.PI;\n }\n\n return sign * Math.acos(vec2.dot(u, v) / vec2.len(u) / vec2.len(v));\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport type Vector = [number, number];\n\nexport function createVector(): Vector {\n return [0, 0];\n}\n\nexport function vectorsEqual(a: Vector, b: Vector, eps: number = 0) {\n return Math.abs(a[0] - b[0]) <= eps && Math.abs(a[1] - b[1]) <= eps;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { mat2, mat2d, vec2 } from \"gl-matrix\";\n\nimport { deg2rad, lerp, TAU, vectorAngle } from \"../util/math\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n expandBoundingBox,\n extendBoundingBox,\n mergeBoundingBoxes,\n} from \"./AABB\";\nimport { createVector, Vector } from \"./Vector\";\n\nexport type PathLineSegment = [\"L\", Vector, Vector];\n\nexport type PathCubicSegment = [\"C\", Vector, Vector, Vector, Vector];\n\nexport type PathQuadraticSegment = [\"Q\", Vector, Vector, Vector];\n\nexport type PathArcSegment = [\n \"A\",\n Vector,\n number, // rx\n number, // ry\n number, // rotation\n boolean, // large-arc-flag\n boolean, // sweep-flag\n Vector,\n];\n\nexport type PathSegment =\n | PathLineSegment\n | PathCubicSegment\n | PathQuadraticSegment\n | PathArcSegment;\n\ntype PathArcSegmentCenterParametrization = {\n center: Vector;\n theta1: number;\n deltaTheta: number;\n rx: number;\n ry: number;\n phi: number;\n};\n\nexport function getStartPoint(seg: PathSegment): Vector {\n return seg[1];\n}\n\nexport function getEndPoint(seg: PathSegment): Vector {\n switch (seg[0]) {\n case \"L\":\n return seg[2];\n case \"C\":\n return seg[4];\n case \"Q\":\n return seg[3];\n case \"A\":\n return seg[7];\n }\n}\n\nexport function reversePathSegment(seg: PathSegment): PathSegment {\n switch (seg[0]) {\n case \"L\":\n return [\"L\", seg[2], seg[1]];\n case \"C\":\n return [\"C\", seg[4], seg[3], seg[2], seg[1]];\n case \"Q\":\n return [\"Q\", seg[3], seg[2], seg[1]];\n case \"A\":\n return [\n \"A\",\n seg[7],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n !seg[6],\n seg[1],\n ];\n }\n}\n\nexport const arcSegmentToCenter = (() => {\n const xy1Prime = createVector();\n const rotationMatrix = mat2.create();\n const addend = createVector();\n const cxy = createVector();\n\n return function arcSegmentToCenter([\n _A,\n xy1,\n rx,\n ry,\n phi,\n fA,\n fS,\n xy2,\n ]: PathArcSegment): PathArcSegmentCenterParametrization | null {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n if (rx === 0 || ry === 0) {\n return null;\n }\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionEndpointToCenter\n\n mat2.fromRotation(rotationMatrix, -deg2rad(phi));\n\n vec2.sub(xy1Prime, xy1, xy2);\n vec2.scale(xy1Prime, xy1Prime, 0.5);\n vec2.transformMat2(xy1Prime, xy1Prime, rotationMatrix);\n\n let rx2 = rx * rx;\n let ry2 = ry * ry;\n const x1Prime2 = xy1Prime[0] * xy1Prime[0];\n const y1Prime2 = xy1Prime[1] * xy1Prime[1];\n\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n rx = Math.abs(rx);\n ry = Math.abs(ry);\n const lambda = x1Prime2 / rx2 + y1Prime2 / ry2 + 1e-12; // small epsilon needed because of float precision\n if (lambda > 1) {\n const lambdaSqrt = Math.sqrt(lambda);\n rx *= lambdaSqrt;\n ry *= lambdaSqrt;\n const lambdaAbs = Math.abs(lambda);\n rx2 *= lambdaAbs;\n ry2 *= lambdaAbs;\n }\n\n const sign = fA === fS ? -1 : 1;\n const multiplier = Math.sqrt(\n (rx2 * ry2 - rx2 * y1Prime2 - ry2 * x1Prime2) /\n (rx2 * y1Prime2 + ry2 * x1Prime2),\n );\n const cxPrime = sign * multiplier * ((rx * xy1Prime[1]) / ry);\n const cyPrime = sign * multiplier * ((-ry * xy1Prime[0]) / rx);\n\n mat2.transpose(rotationMatrix, rotationMatrix);\n vec2.add(addend, xy1, xy2);\n vec2.scale(addend, addend, 0.5);\n vec2.transformMat2(cxy, [cxPrime, cyPrime], rotationMatrix);\n vec2.add(cxy, cxy, addend);\n\n const vec1: Vector = [\n (xy1Prime[0] - cxPrime) / rx,\n (xy1Prime[1] - cyPrime) / ry,\n ];\n const theta1 = vectorAngle([1, 0], vec1);\n let deltaTheta = vectorAngle(vec1, [\n (-xy1Prime[0] - cxPrime) / rx,\n (-xy1Prime[1] - cyPrime) / ry,\n ]);\n\n if (!fS && deltaTheta > 0) {\n deltaTheta -= TAU;\n } else if (fS && deltaTheta < 0) {\n deltaTheta += TAU;\n }\n\n return {\n center: [cxy[0], cxy[1]],\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n };\n };\n})();\n\nexport const arcSegmentFromCenter = (() => {\n const xy1 = createVector();\n const xy2 = createVector();\n const rotationMatrix = mat2.create();\n\n return function arcSegmentFromCenter({\n center,\n theta1,\n deltaTheta,\n rx,\n ry,\n phi,\n }: PathArcSegmentCenterParametrization): PathArcSegment {\n // https://svgwg.org/svg2-draft/implnote.html#ArcConversionCenterToEndpoint\n mat2.fromRotation(rotationMatrix, phi); // TODO: sign (also in sampleAt)\n\n vec2.set(xy1, rx * Math.cos(theta1), ry * Math.sin(theta1));\n vec2.transformMat2(xy1, xy1, rotationMatrix);\n vec2.add(xy1, xy1, center);\n\n vec2.set(\n xy2,\n rx * Math.cos(theta1 + deltaTheta),\n ry * Math.sin(theta1 + deltaTheta),\n );\n vec2.transformMat2(xy2, xy2, rotationMatrix);\n vec2.add(xy2, xy2, center);\n\n const fA = Math.abs(deltaTheta) > Math.PI;\n\n const fS = deltaTheta > 0;\n\n return [\"A\", [xy1[0], xy1[1]], rx, ry, phi, fA, fS, [xy2[0], xy2[1]]];\n };\n})();\n\nexport const samplePathSegmentAt = (() => {\n const p01 = createVector();\n const p12 = createVector();\n const p23 = createVector();\n const p012 = createVector();\n const p123 = createVector();\n const p = createVector();\n\n return function samplePathSegmentAt(seg: PathSegment, t: number): Vector {\n switch (seg[0]) {\n case \"L\":\n vec2.lerp(p, seg[1], seg[2], t);\n break;\n case \"C\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p23, seg[3], seg[4], t);\n vec2.lerp(p012, p01, p12, t);\n vec2.lerp(p123, p12, p23, t);\n vec2.lerp(p, p012, p123, t);\n break;\n case \"Q\":\n vec2.lerp(p01, seg[1], seg[2], t);\n vec2.lerp(p12, seg[2], seg[3], t);\n vec2.lerp(p, p01, p12, t);\n break;\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n vec2.lerp(p, seg[1], seg[7], t);\n break;\n }\n const { deltaTheta, phi, theta1, rx, ry, center } =\n centerParametrization;\n const theta = theta1 + t * deltaTheta;\n vec2.set(p, rx * Math.cos(theta), ry * Math.sin(theta));\n vec2.rotate(p, p, [0, 0], phi); // TODO: sign (also in fromCenter)\n vec2.add(p, p, center);\n break;\n }\n }\n\n return [p[0], p[1]];\n };\n})();\n\nexport const arcSegmentToCubics = (() => {\n const fromUnit = mat2d.create();\n const matrix = mat2d.create();\n\n return function arcSegmentToCubics(\n arc: PathArcSegment,\n maxDeltaTheta: number = Math.PI / 2,\n ): PathCubicSegment[] | [PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(arc);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n // \"If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop.\"\n return [[\"L\", arc[1], arc[7]]];\n }\n\n const { center, theta1, deltaTheta, rx, ry } = centerParametrization;\n\n const count = Math.ceil(Math.abs(deltaTheta) / maxDeltaTheta);\n\n mat2d.fromTranslation(fromUnit, center);\n mat2d.rotate(fromUnit, fromUnit, deg2rad(arc[4]));\n mat2d.scale(fromUnit, fromUnit, [rx, ry]);\n\n // https://pomax.github.io/bezierinfo/#circles_cubic\n const cubics: PathCubicSegment[] = [];\n const theta = deltaTheta / count;\n const k = (4 / 3) * Math.tan(theta / 4);\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n for (let i = 0; i < count; i++) {\n const start: Vector = [1, 0];\n const control1: Vector = [1, k];\n const control2: Vector = [\n cosTheta + k * sinTheta,\n sinTheta - k * cosTheta,\n ];\n const end: Vector = [cosTheta, sinTheta];\n\n mat2d.fromRotation(matrix, theta1 + i * theta);\n mat2d.mul(matrix, fromUnit, matrix);\n vec2.transformMat2d(start, start, matrix);\n vec2.transformMat2d(control1, control1, matrix);\n vec2.transformMat2d(control2, control2, matrix);\n vec2.transformMat2d(end, end, matrix);\n\n cubics.push([\"C\", start, control1, control2, end]);\n }\n\n return cubics;\n };\n})();\n\nfunction evalCubic1d(\n p0: number,\n p1: number,\n p2: number,\n p3: number,\n t: number,\n) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n const p23 = lerp(p2, p3, t);\n const p012 = lerp(p01, p12, t);\n const p123 = lerp(p12, p23, t);\n return lerp(p012, p123, t);\n}\n\nfunction cubicBoundingInterval(p0: number, p1: number, p2: number, p3: number) {\n let min = Math.min(p0, p3);\n let max = Math.max(p0, p3);\n\n const a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3);\n const b = 6 * (p0 - 2 * p1 + p2);\n const c = 3 * (p1 - p0);\n const D = b * b - 4 * a * c;\n\n if (D < 0 || a === 0) {\n // TODO: if a=0, solve linear\n return [min, max];\n }\n\n const sqrtD = Math.sqrt(D);\n\n const t0 = (-b - sqrtD) / (2 * a);\n if (0 < t0 && t0 < 1) {\n const x0 = evalCubic1d(p0, p1, p2, p3, t0);\n min = Math.min(min, x0);\n max = Math.max(max, x0);\n }\n\n const t1 = (-b + sqrtD) / (2 * a);\n if (0 < t1 && t1 < 1) {\n const x1 = evalCubic1d(p0, p1, p2, p3, t1);\n min = Math.min(min, x1);\n max = Math.max(max, x1);\n }\n\n return [min, max];\n}\n\nfunction evalQuadratic1d(p0: number, p1: number, p2: number, t: number) {\n const p01 = lerp(p0, p1, t);\n const p12 = lerp(p1, p2, t);\n return lerp(p01, p12, t);\n}\n\nfunction quadraticBoundingInterval(p0: number, p1: number, p2: number) {\n let min = Math.min(p0, p2);\n let max = Math.max(p0, p2);\n\n const denominator = p0 - 2 * p1 + p2;\n\n if (denominator === 0) {\n return [min, max];\n }\n\n const t = (p0 - p1) / denominator;\n if (0 <= t && t <= 1) {\n const x = evalQuadratic1d(p0, p1, p2, t);\n min = Math.min(min, x);\n max = Math.max(max, x);\n }\n\n return [min, max];\n}\n\nfunction inInterval(x: number, x0: number, x1: number) {\n const mapped = (x - x0) / (x1 - x0);\n return 0 <= mapped && mapped <= 1;\n}\n\nexport function pathSegmentBoundingBox(seg: PathSegment): AABB {\n switch (seg[0]) {\n case \"L\":\n return {\n top: Math.min(seg[1][1], seg[2][1]),\n right: Math.max(seg[1][0], seg[2][0]),\n bottom: Math.max(seg[1][1], seg[2][1]),\n left: Math.min(seg[1][0], seg[2][0]),\n };\n case \"C\": {\n const [left, right] = cubicBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n seg[4][0],\n );\n const [top, bottom] = cubicBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n seg[4][1],\n );\n return { top, right, bottom, left };\n }\n case \"Q\": {\n const [left, right] = quadraticBoundingInterval(\n seg[1][0],\n seg[2][0],\n seg[3][0],\n );\n const [top, bottom] = quadraticBoundingInterval(\n seg[1][1],\n seg[2][1],\n seg[3][1],\n );\n return { top, right, bottom, left };\n }\n case \"A\": {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n return extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n }\n\n const { theta1, deltaTheta, phi, center, rx, ry } =\n centerParametrization;\n\n if (phi === 0 || rx === ry) {\n const theta2 = theta1 + deltaTheta;\n let boundingBox = extendBoundingBox(\n boundingBoxAroundPoint(seg[1], 0),\n seg[7],\n );\n // FIXME: the following gives false positives, resulting in larger boxes\n if (\n inInterval(-Math.PI, theta1, theta2) ||\n inInterval(Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] - rx,\n center[1],\n ]);\n }\n if (\n inInterval(-Math.PI / 2, theta1, theta2) ||\n inInterval((3 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] - ry,\n ]);\n }\n if (\n inInterval(0, theta1, theta2) ||\n inInterval(2 * Math.PI, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0] + rx,\n center[1],\n ]);\n }\n if (\n inInterval(Math.PI / 2, theta1, theta2) ||\n inInterval((5 * Math.PI) / 2, theta1, theta2)\n ) {\n boundingBox = extendBoundingBox(boundingBox, [\n center[0],\n center[1] + ry,\n ]);\n }\n return expandBoundingBox(boundingBox, 1e-11); // TODO: get rid of expansion\n }\n\n // TODO: don't convert to cubics\n const cubics = arcSegmentToCubics(seg, Math.PI / 16);\n let boundingBox: AABB | null = null;\n for (const seg of cubics) {\n boundingBox = mergeBoundingBoxes(\n boundingBox,\n pathSegmentBoundingBox(seg),\n );\n }\n if (!boundingBox) {\n return boundingBoxAroundPoint(seg[1], 0); // TODO: what to do here?\n }\n return boundingBox;\n }\n }\n}\n\nfunction splitLinearSegmentAt(\n seg: PathLineSegment,\n t: number,\n): [PathLineSegment, PathLineSegment] {\n const a = seg[1];\n const b = seg[2];\n\n const p = vec2.lerp(createVector(), a, b, t) as Vector;\n\n return [\n [\"L\", a, p],\n [\"L\", p, b],\n ];\n}\n\nexport function splitCubicSegmentAt(\n seg: PathCubicSegment,\n t: number,\n): [PathCubicSegment, PathCubicSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n const p3 = seg[4];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p23 = vec2.lerp(createVector(), p2, p3, t) as Vector;\n const p012 = vec2.lerp(createVector(), p01, p12, t) as Vector;\n const p123 = vec2.lerp(createVector(), p12, p23, t) as Vector;\n const p = vec2.lerp(createVector(), p012, p123, t) as Vector;\n\n return [\n [\"C\", p0, p01, p012, p],\n [\"C\", p, p123, p23, p3],\n ];\n}\n\nfunction splitQuadraticSegmentAt(\n seg: PathQuadraticSegment,\n t: number,\n): [PathQuadraticSegment, PathQuadraticSegment] {\n // https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm\n const p0 = seg[1];\n const p1 = seg[2];\n const p2 = seg[3];\n\n const p01 = vec2.lerp(createVector(), p0, p1, t) as Vector;\n const p12 = vec2.lerp(createVector(), p1, p2, t) as Vector;\n const p = vec2.lerp(createVector(), p01, p12, t) as Vector;\n\n return [\n [\"Q\", p0, p01, p],\n [\"Q\", p, p12, p2],\n ];\n}\n\nfunction splitArcSegmentAt(\n seg: PathArcSegment,\n t: number,\n): [PathArcSegment, PathArcSegment] | [PathLineSegment, PathLineSegment] {\n const centerParametrization = arcSegmentToCenter(seg);\n\n if (!centerParametrization) {\n // https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii\n return splitLinearSegmentAt([\"L\", seg[1], seg[7]], t);\n }\n\n const midDeltaTheta = centerParametrization.deltaTheta * t;\n return [\n arcSegmentFromCenter({\n ...centerParametrization,\n deltaTheta: midDeltaTheta,\n }),\n arcSegmentFromCenter({\n ...centerParametrization,\n theta1: centerParametrization.theta1 + midDeltaTheta,\n deltaTheta: centerParametrization.deltaTheta - midDeltaTheta,\n }),\n ];\n}\n\nexport function splitSegmentAt(\n seg: PathSegment,\n t: number,\n): [PathSegment, PathSegment] {\n switch (seg[0]) {\n case \"L\":\n return splitLinearSegmentAt(seg, t);\n case \"C\":\n return splitCubicSegmentAt(seg, t);\n case \"Q\":\n return splitQuadraticSegmentAt(seg, t);\n case \"A\":\n return splitArcSegmentAt(seg, t);\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"../primitives/Vector\";\n\ntype LineSegment = [Vector, Vector];\n\nconst COLLINEAR_EPS = Number.MIN_VALUE * 64;\n\nexport function lineSegmentIntersection(\n [[x1, y1], [x2, y2]]: LineSegment,\n [[x3, y3], [x4, y4]]: LineSegment,\n eps: number,\n): [number, number] | null {\n // https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments\n\n const a1 = x2 - x1;\n const b1 = x3 - x4;\n const c1 = x3 - x1;\n const a2 = y2 - y1;\n const b2 = y3 - y4;\n const c2 = y3 - y1;\n\n const denom = a1 * b2 - a2 * b1;\n\n if (Math.abs(denom) < COLLINEAR_EPS) return null;\n\n const s = (c1 * b2 - c2 * b1) / denom;\n const t = (a1 * c2 - a2 * c1) / denom;\n\n if (-eps <= s && s <= 1 + eps && -eps <= t && t <= 1 + eps) {\n return [s, t];\n }\n\n return null;\n}\n\nexport function lineSegmentsIntersect(\n seg1: LineSegment,\n seg2: LineSegment,\n eps: number,\n) {\n return !!lineSegmentIntersection(seg1, seg2, eps);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"../Epsilons\";\nimport {\n AABB,\n boundingBoxesOverlap,\n boundingBoxMaxExtent,\n} from \"../primitives/AABB\";\nimport {\n PathSegment,\n pathSegmentBoundingBox,\n splitSegmentAt,\n} from \"../primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"../primitives/Vector\";\nimport { lerp } from \"../util/math\";\nimport { lineSegmentIntersection, lineSegmentsIntersect } from \"./line-segment\";\nimport { lineSegmentAABBIntersect } from \"./line-segment-AABB\";\n\ntype IntersectionSegment = {\n seg: PathSegment;\n startParam: number;\n endParam: number;\n boundingBox: AABB;\n};\n\nfunction subdivideIntersectionSegment(\n intSeg: IntersectionSegment,\n): IntersectionSegment[] {\n const [seg0, seg1] = splitSegmentAt(intSeg.seg, 0.5);\n const midParam = (intSeg.startParam + intSeg.endParam) / 2;\n return [\n {\n seg: seg0,\n startParam: intSeg.startParam,\n endParam: midParam,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: midParam,\n endParam: intSeg.endParam,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ];\n}\n\nfunction pathSegmentToLineSegment(seg: PathSegment): [Vector, Vector] {\n switch (seg[0]) {\n case \"L\":\n return [seg[1], seg[2]];\n case \"C\":\n return [seg[1], seg[4]];\n case \"Q\":\n return [seg[1], seg[3]];\n case \"A\":\n return [seg[1], seg[7]];\n }\n}\n\nfunction intersectionSegmentsOverlap(\n { seg: seg0, boundingBox: boundingBox0 }: IntersectionSegment,\n { seg: seg1, boundingBox: boundingBox1 }: IntersectionSegment,\n) {\n if (seg0[0] === \"L\") {\n if (seg1[0] === \"L\") {\n return lineSegmentsIntersect(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n 1e-6, // TODO: configurable\n );\n } else {\n return lineSegmentAABBIntersect([seg0[1], seg0[2]], boundingBox1);\n }\n } else {\n if (seg1[0] === \"L\") {\n return lineSegmentAABBIntersect([seg1[1], seg1[2]], boundingBox0);\n } else {\n return boundingBoxesOverlap(boundingBox0, boundingBox1);\n }\n }\n}\n\nexport function segmentsEqual(\n seg0: PathSegment,\n seg1: PathSegment,\n pointEpsilon: number,\n): boolean {\n const type = seg0[0];\n\n if (seg1[0] !== type) return false;\n\n switch (type) {\n case \"L\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon)\n );\n case \"C\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[4], seg1[4] as Vector, pointEpsilon)\n );\n case \"Q\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n vectorsEqual(seg0[2], seg1[2] as Vector, pointEpsilon) &&\n vectorsEqual(seg0[3], seg1[3] as Vector, pointEpsilon)\n );\n case \"A\":\n return (\n vectorsEqual(seg0[1], seg1[1], pointEpsilon) &&\n Math.abs(seg0[2] - (seg1[2] as number)) < pointEpsilon &&\n Math.abs(seg0[3] - (seg1[3] as number)) < pointEpsilon &&\n Math.abs(seg0[4] - (seg1[4] as number)) < pointEpsilon && // TODO: Phi can be anything if rx = ry. Also, handle rotations by Pi/2.\n seg0[5] === seg1[5] &&\n seg0[6] === seg1[6] &&\n vectorsEqual(seg0[7], seg1[7] as Vector, pointEpsilon)\n );\n }\n}\n\nexport function pathSegmentIntersection(\n seg0: PathSegment,\n seg1: PathSegment,\n endpoints: boolean,\n eps: Epsilons,\n): [number, number][] {\n if (seg0[0] === \"L\" && seg1[0] === \"L\") {\n const st = lineSegmentIntersection(\n [seg0[1], seg0[2]],\n [seg1[1], seg1[2]],\n eps.param,\n );\n if (st) {\n if (\n !endpoints &&\n (st[0] < eps.param || st[0] > 1 - eps.param) &&\n (st[1] < eps.param || st[1] > 1 - eps.param)\n ) {\n return [];\n }\n return [st];\n }\n }\n\n // https://math.stackexchange.com/questions/20321/how-can-i-tell-when-two-cubic-b%C3%A9zier-curves-intersect\n\n let pairs: [IntersectionSegment, IntersectionSegment][] = [\n [\n {\n seg: seg0,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg0),\n },\n {\n seg: seg1,\n startParam: 0,\n endParam: 1,\n boundingBox: pathSegmentBoundingBox(seg1),\n },\n ],\n ];\n\n const params: [number, number][] = [];\n\n while (pairs.length) {\n const nextPairs: [IntersectionSegment, IntersectionSegment][] = [];\n\n for (const [seg0, seg1] of pairs) {\n if (segmentsEqual(seg0.seg, seg1.seg, eps.point)) {\n // TODO: move this outside of this loop?\n continue; // TODO: what to do?\n }\n\n const isLinear0 =\n boundingBoxMaxExtent(seg0.boundingBox) <= eps.linear;\n const isLinear1 =\n boundingBoxMaxExtent(seg1.boundingBox) <= eps.linear;\n\n if (isLinear0 && isLinear1) {\n const lineSegment0 = pathSegmentToLineSegment(seg0.seg);\n const lineSegment1 = pathSegmentToLineSegment(seg1.seg);\n const st = lineSegmentIntersection(\n lineSegment0,\n lineSegment1,\n eps.param,\n );\n if (st) {\n params.push([\n lerp(seg0.startParam, seg0.endParam, st[0]),\n lerp(seg1.startParam, seg1.endParam, st[1]),\n ]);\n }\n } else {\n const subdivided0 = isLinear0\n ? [seg0]\n : subdivideIntersectionSegment(seg0);\n const subdivided1 = isLinear1\n ? [seg1]\n : subdivideIntersectionSegment(seg1);\n\n for (const seg0 of subdivided0) {\n for (const seg1 of subdivided1) {\n if (intersectionSegmentsOverlap(seg0, seg1)) {\n nextPairs.push([seg0, seg1]);\n }\n }\n }\n }\n }\n\n pairs = nextPairs;\n }\n\n if (!endpoints) {\n return params.filter(\n ([s, t]) =>\n (s > eps.param && s < 1 - eps.param) ||\n (t > eps.param && t < 1 - eps.param),\n );\n }\n\n return params;\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function isNumber(val: unknown): val is number {\n return typeof val === \"number\";\n}\n\nexport function isString(val: unknown): val is string {\n return typeof val === \"string\";\n}\n\nexport function isBoolean(val: unknown): val is boolean {\n return typeof val === \"boolean\";\n}\n\nexport const hasOwn = Object.hasOwn;\n\nexport function memoizeWeak(\n fn: (obj: Obj, ...args: Args[]) => Ret,\n) {\n const cache = new WeakMap();\n return (obj: Obj, ...args: Args[]) => {\n if (cache.has(obj)) {\n return cache.get(obj)!;\n } else {\n const val = fn(obj, ...args);\n cache.set(obj, val);\n return val;\n }\n };\n}\n\nexport function countIf(arr: T[], pred: (value: T) => boolean): number {\n return arr.reduce((acc: number, item: T) => acc + (pred(item) ? 1 : 0), 0);\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\n\nexport function* map(\n iter: Iterable,\n fn: (val: T1, index: number) => T2,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield fn(val, i++);\n }\n}\n\nexport function* flatMap(\n iter: Iterable,\n fn: (val: T1, index: number) => Iterable,\n): Iterable {\n let i = 0;\n for (const val of iter) {\n yield* fn(val, i++);\n }\n}\n\nexport function* filter(\n iter: Iterable,\n fn: (val: T) => boolean,\n): Iterable {\n for (const val of iter) {\n if (fn(val)) {\n yield val;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Epsilons } from \"./Epsilons\";\nimport { QuadTree } from \"./QuadTree\";\nimport {\n assertCondition,\n assertDefined,\n assertEqual,\n assertUnreachable,\n} from \"./assert\";\nimport { pathCubicSegmentSelfIntersection } from \"./intersections/path-cubic-segment-self-intersection\";\nimport {\n pathSegmentIntersection,\n segmentsEqual,\n} from \"./intersections/path-segment\";\nimport {\n AABB,\n boundingBoxAroundPoint,\n boundingBoxMaxExtent,\n mergeBoundingBoxes,\n} from \"./primitives/AABB\";\nimport { Path } from \"./primitives/Path\";\nimport {\n getEndPoint,\n getStartPoint,\n PathSegment,\n pathSegmentBoundingBox,\n reversePathSegment,\n samplePathSegmentAt,\n splitCubicSegmentAt,\n splitSegmentAt,\n} from \"./primitives/PathSegment\";\nimport { Vector, vectorsEqual } from \"./primitives/Vector\";\nimport { countIf, hasOwn, memoizeWeak } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\nimport { linMap } from \"./util/math\";\n\nconst INTERSECTION_TREE_DEPTH = 8;\nconst POINT_TREE_DEPTH = 8;\n\nconst EPS: Epsilons = {\n point: 1e-6,\n linear: 1e-4,\n param: 1e-8,\n};\n\nexport enum PathBooleanOperation {\n Union,\n Difference,\n Intersection,\n Exclusion,\n Division,\n Fracture,\n}\n\nexport enum FillRule {\n NonZero,\n EvenOdd,\n}\n\ntype MajorGraphEdgeStage1 = {\n seg: PathSegment;\n parent: number;\n};\n\ntype MajorGraphEdgeStage2 = MajorGraphEdgeStage1 & {\n boundingBox: AABB;\n};\n\ntype MajorGraphEdge = MajorGraphEdgeStage2 & {\n incidentVertices: [MajorGraphVertex, MajorGraphVertex];\n directionFlag: boolean;\n twin: MajorGraphEdge | null;\n};\n\ntype MajorGraphVertex = {\n point: Vector;\n outgoingEdges: MajorGraphEdge[];\n};\n\ntype MajorGraph = {\n edges: MajorGraphEdge[];\n vertices: MajorGraphVertex[];\n};\n\ntype MinorGraphEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertices: [MinorGraphVertex, MinorGraphVertex];\n directionFlag: boolean;\n twin: MinorGraphEdge | null;\n};\n\ntype MinorGraphVertex = {\n outgoingEdges: MinorGraphEdge[];\n};\n\ntype MinorGraphCycle = {\n segments: PathSegment[];\n parent: number;\n directionFlag: boolean;\n};\n\ntype MinorGraph = {\n edges: MinorGraphEdge[];\n vertices: MinorGraphVertex[];\n cycles: MinorGraphCycle[];\n};\n\ntype DualGraphHalfEdge = {\n segments: PathSegment[];\n parent: number;\n incidentVertex: DualGraphVertex;\n directionFlag: boolean;\n twin: DualGraphHalfEdge | null;\n};\n\ntype DualGraphVertex = {\n incidentEdges: DualGraphHalfEdge[];\n flag: number;\n};\n\ntype DualGraphComponent = {\n edges: DualGraphHalfEdge[];\n vertices: DualGraphVertex[];\n outerFace: DualGraphVertex | null;\n};\n\ntype NestingTree = {\n component: DualGraphComponent;\n outgoingEdges: Map;\n};\n\nfunction firstElementOfSet(set: Set): T {\n return set.values().next().value;\n}\n\nfunction createObjectCounter(): (obj: Object) => number {\n let i = 0;\n return memoizeWeak(() => i++);\n}\n\nfunction segmentToEdge(\n parent: 1 | 2,\n): (seg: PathSegment) => MajorGraphEdgeStage1 {\n return (seg) => ({ seg, parent });\n}\n\nfunction splitAtSelfIntersections(edges: MajorGraphEdgeStage1[]) {\n for (let i = 0; i < edges.length; i++) {\n const edge = edges[i];\n if (edge.seg[0] !== \"C\") continue;\n const intersection = pathCubicSegmentSelfIntersection(edge.seg);\n if (!intersection) continue;\n if (intersection[0] > intersection[1]) {\n intersection.reverse();\n }\n const [t1, t2] = intersection;\n if (Math.abs(t1 - t2) < EPS.param) {\n const [seg1, seg2] = splitCubicSegmentAt(edge.seg, t1);\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push({\n seg: seg2,\n parent: edge.parent,\n });\n } else {\n const [seg1, tmpSeg] = splitCubicSegmentAt(edge.seg, t1);\n const [seg2, seg3] = splitCubicSegmentAt(\n tmpSeg,\n (t2 - t1) / (1 - t1),\n );\n edges[i] = {\n seg: seg1,\n parent: edge.parent,\n };\n edges.push(\n {\n seg: seg2,\n parent: edge.parent,\n },\n {\n seg: seg3,\n parent: edge.parent,\n },\n );\n }\n }\n}\n\nfunction splitAtIntersections(edges: MajorGraphEdgeStage1[]) {\n const withBoundingBox: MajorGraphEdgeStage2[] = edges.map((edge) => ({\n ...edge,\n boundingBox: pathSegmentBoundingBox(edge.seg),\n }));\n\n const totalBoundingBox = withBoundingBox.reduce(\n (acc, { boundingBox }) => mergeBoundingBoxes(acc, boundingBox),\n null as AABB | null,\n );\n\n if (!totalBoundingBox) {\n return { edges: [], totalBoundingBox: null };\n }\n\n const edgeTree = new QuadTree(\n totalBoundingBox,\n INTERSECTION_TREE_DEPTH,\n );\n\n const splitsPerEdge: Record = {};\n\n function addSplit(i: number, t: number) {\n if (!hasOwn(splitsPerEdge, i)) splitsPerEdge[i] = [];\n splitsPerEdge[i].push(t);\n }\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n const candidates = edgeTree.find(edge.boundingBox);\n for (const j of candidates) {\n const candidate = edges[j];\n const includeEndpoints =\n edge.parent !== candidate.parent ||\n !(\n // TODO: this is not correct\n (\n vectorsEqual(\n getEndPoint(candidate.seg),\n getStartPoint(edge.seg),\n EPS.point,\n ) ||\n vectorsEqual(\n getStartPoint(candidate.seg),\n getEndPoint(edge.seg),\n EPS.point,\n )\n )\n );\n const intersection = pathSegmentIntersection(\n edge.seg,\n candidate.seg,\n includeEndpoints,\n EPS,\n );\n for (const [t0, t1] of intersection) {\n addSplit(i, t0);\n addSplit(j, t1);\n }\n }\n\n /*\n Insert the edge to the tree here, after checking intersections.\n That way, each pair is only tested once.\n */\n edgeTree.insert(edge.boundingBox, i);\n }\n\n const newEdges: MajorGraphEdgeStage2[] = [];\n\n for (let i = 0; i < withBoundingBox.length; i++) {\n const edge = withBoundingBox[i];\n if (!hasOwn(splitsPerEdge, i)) {\n newEdges.push(edge);\n continue;\n }\n const splits = splitsPerEdge[i];\n splits.sort();\n let tmpSeg = edge.seg;\n let prevT = 0;\n for (let j = 0; j < splits.length; j++) {\n const t = splits[j];\n\n if (t > 1 - EPS.param) break; // skip splits near end\n\n const tt = (t - prevT) / (1 - prevT);\n prevT = t;\n\n if (tt < EPS.param) continue; // skip splits near start\n if (tt > 1 - EPS.param) continue; // skip splits near end\n\n const [seg1, seg2] = splitSegmentAt(tmpSeg, tt);\n newEdges.push({\n seg: seg1,\n boundingBox: pathSegmentBoundingBox(seg1),\n parent: edge.parent,\n });\n tmpSeg = seg2;\n }\n newEdges.push({\n seg: tmpSeg,\n boundingBox: pathSegmentBoundingBox(tmpSeg),\n parent: edge.parent,\n });\n }\n\n return { edges: newEdges, totalBoundingBox };\n}\n\nfunction findVertices(\n edges: MajorGraphEdgeStage2[],\n boundingBox: AABB,\n): MajorGraph {\n const vertexTree = new QuadTree(\n boundingBox,\n POINT_TREE_DEPTH,\n );\n\n const newVertices: MajorGraphVertex[] = [];\n\n function getVertex(point: Vector): MajorGraphVertex {\n const box = boundingBoxAroundPoint(point, EPS.point);\n const existingVertices = vertexTree.find(box);\n if (existingVertices.size) {\n return firstElementOfSet(existingVertices);\n } else {\n const vertex: MajorGraphVertex = {\n point,\n outgoingEdges: [],\n };\n vertexTree.insert(box, vertex);\n newVertices.push(vertex);\n return vertex;\n }\n }\n\n const getVertexId = createObjectCounter();\n const vertexPairIdToEdges: Record<\n string,\n [MajorGraphEdgeStage2, MajorGraphEdge, MajorGraphEdge][]\n > = {};\n\n const newEdges = edges.flatMap((edge) => {\n const startVertex = getVertex(getStartPoint(edge.seg));\n const endVertex = getVertex(getEndPoint(edge.seg));\n\n // discard zero-length segments\n if (startVertex === endVertex) {\n switch (edge.seg[0]) {\n case \"L\":\n return [];\n case \"C\":\n if (\n vectorsEqual(edge.seg[1], edge.seg[2], EPS.point) &&\n vectorsEqual(edge.seg[3], edge.seg[4], EPS.point)\n ) {\n return [];\n }\n break;\n case \"Q\":\n if (vectorsEqual(edge.seg[1], edge.seg[2], EPS.point)) {\n return [];\n }\n break;\n case \"A\":\n // TODO: explain\n if (edge.seg[5] === false) {\n return [];\n }\n break;\n }\n }\n\n const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n const existingEdge = vertexPairIdToEdges[vertexPairId].find(\n (other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),\n );\n if (existingEdge) {\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;\n if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {\n const reversedSeg = reversePathSegment(edge.seg);\n const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(\n (other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),\n );\n if (existingEdge) {\n if (existingEdge[0].parent === edge.parent) {\n // discard \"there and back\" pairs\n return [];\n }\n\n existingEdge[1].parent |= edge.parent;\n existingEdge[2].parent |= edge.parent;\n return [];\n }\n }\n\n const fwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [startVertex, endVertex],\n directionFlag: false,\n twin: null,\n };\n\n const bwdEdge: MajorGraphEdge = {\n ...edge,\n incidentVertices: [endVertex, startVertex],\n directionFlag: true,\n twin: fwdEdge,\n };\n\n fwdEdge.twin = bwdEdge;\n\n startVertex.outgoingEdges.push(fwdEdge);\n endVertex.outgoingEdges.push(bwdEdge);\n\n if (hasOwn(vertexPairIdToEdges, vertexPairId)) {\n vertexPairIdToEdges[vertexPairId].push([edge, fwdEdge, bwdEdge]);\n } else {\n vertexPairIdToEdges[vertexPairId] = [[edge, fwdEdge, bwdEdge]];\n }\n\n return [fwdEdge, bwdEdge];\n });\n\n return {\n edges: newEdges,\n vertices: newVertices,\n };\n}\n\nfunction getOrder(vertex: MajorGraphVertex | MinorGraphVertex) {\n return vertex.outgoingEdges.length;\n}\n\nfunction computeMinor({ vertices }: MajorGraph): MinorGraph {\n const newEdges: MinorGraphEdge[] = [];\n const newVertices: MinorGraphVertex[] = [];\n\n const toMinorVertex = memoizeWeak((_majorVertex: MajorGraphVertex) => {\n const minorVertex: MinorGraphVertex = { outgoingEdges: [] };\n newVertices.push(minorVertex);\n return minorVertex;\n }) as (majorVertex: MajorGraphVertex) => MinorGraphVertex;\n\n const getEdgeId = createObjectCounter();\n const idToEdge: Record = {};\n const visited = new WeakSet();\n\n // first handle components that are not cycles\n for (const vertex of vertices) {\n if (getOrder(vertex) === 2) continue;\n\n const startVertex = toMinorVertex(vertex);\n\n for (const startEdge of vertex.outgoingEdges) {\n const segments: PathSegment[] = [];\n let edge = startEdge;\n while (\n edge.parent === startEdge.parent &&\n edge.directionFlag === startEdge.directionFlag &&\n getOrder(edge.incidentVertices[1]) === 2\n ) {\n segments.push(edge.seg);\n visited.add(edge.incidentVertices[1]);\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1; // choose the one we didn't use to come here\n }\n segments.push(edge.seg);\n const endVertex = toMinorVertex(edge.incidentVertices[1]);\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n assertDefined(startEdge.twin, \"Edge doesn't have a twin.\");\n const edgeId = `${getEdgeId(startEdge)}-${getEdgeId(edge)}`;\n const twinId = `${getEdgeId(edge.twin)}-${getEdgeId(startEdge.twin)}`;\n const twin = idToEdge[twinId] ?? null;\n const newEdge: MinorGraphEdge = {\n segments,\n parent: startEdge.parent,\n incidentVertices: [startVertex, endVertex],\n directionFlag: startEdge.directionFlag,\n twin: twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n idToEdge[edgeId] = newEdge;\n startVertex.outgoingEdges.push(newEdge);\n newEdges.push(newEdge);\n }\n }\n\n // handle cyclic components\n const cycles: MinorGraphCycle[] = [];\n for (const vertex of vertices) {\n if (getOrder(vertex) !== 2 || visited.has(vertex)) continue;\n let edge = vertex.outgoingEdges[0];\n const cycle: MinorGraphCycle = {\n segments: [],\n parent: edge.parent,\n directionFlag: edge.directionFlag,\n };\n do {\n cycle.segments.push(edge.seg);\n visited.add(edge.incidentVertices[0]);\n assertEqual(\n getOrder(edge.incidentVertices[1]),\n 2,\n \"Found an unvisited vertex of order != 2.\",\n );\n const [edge1, edge2] = edge.incidentVertices[1].outgoingEdges;\n assertCondition(\n edge1.twin === edge || edge2.twin === edge,\n \"Wrong twin structure.\",\n );\n edge = edge1.twin === edge ? edge2 : edge1;\n } while (edge.incidentVertices[0] !== vertex);\n cycles.push(cycle);\n }\n\n return {\n edges: newEdges,\n vertices: newVertices,\n cycles,\n };\n}\n\nfunction removeDanglingEdges(graph: MinorGraph) {\n function walk(parent: 1 | 2) {\n const keptVertices = new WeakSet();\n const vertexToLevel = new WeakMap();\n\n function visit(\n vertex: MinorGraphVertex,\n incomingEdge: MinorGraphEdge | null,\n level: number,\n ): number {\n if (vertexToLevel.has(vertex)) {\n return vertexToLevel.get(vertex)!;\n }\n vertexToLevel.set(vertex, level);\n\n let minLevel = Infinity;\n for (const edge of vertex.outgoingEdges) {\n if (edge.parent & parent && edge !== incomingEdge) {\n minLevel = Math.min(\n minLevel,\n visit(edge.incidentVertices[1], edge.twin, level + 1),\n );\n }\n }\n\n if (minLevel <= level) {\n keptVertices.add(vertex);\n }\n\n return minLevel;\n }\n\n for (const edge of graph.edges) {\n if (edge.parent & parent) {\n visit(edge.incidentVertices[0], null, 0);\n }\n }\n\n return keptVertices;\n }\n\n const keptVerticesA = walk(1);\n const keptVerticesB = walk(2);\n\n function keepVertex(vertex: MinorGraphVertex): boolean {\n return keptVerticesA.has(vertex) || keptVerticesB.has(vertex);\n }\n\n function keepEdge(edge: MinorGraphEdge): boolean {\n return (\n ((edge.parent & 1) === 1 &&\n keptVerticesA.has(edge.incidentVertices[0]) &&\n keptVerticesA.has(edge.incidentVertices[1])) ||\n ((edge.parent & 2) === 2 &&\n keptVerticesB.has(edge.incidentVertices[0]) &&\n keptVerticesB.has(edge.incidentVertices[1]))\n );\n }\n\n graph.vertices = graph.vertices.filter(keepVertex);\n\n for (const vertex of graph.vertices) {\n vertex.outgoingEdges = vertex.outgoingEdges.filter(keepEdge);\n }\n\n graph.edges = graph.edges.filter(keepEdge);\n}\n\nfunction getIncidenceAngle({ directionFlag, segments }: MinorGraphEdge) {\n let p0: Vector;\n let p1: Vector;\n\n const seg = segments[0]; // TODO: explain in comment why this is always the incident one in both fwd and bwd\n\n if (!directionFlag) {\n p0 = samplePathSegmentAt(seg, 0);\n p1 = samplePathSegmentAt(seg, EPS.param);\n } else {\n p0 = samplePathSegmentAt(seg, 1);\n p1 = samplePathSegmentAt(seg, 1 - EPS.param);\n }\n\n return Math.atan2(p1[1] - p0[1], p1[0] - p0[0]);\n}\n\nfunction sortOutgoingEdgesByAngle({ vertices }: MinorGraph) {\n // TODO: this will hardly be a bottleneck, but profile whether memoization\n // actually helps and maybe use a simpler function that's monotonic\n // in angle.\n\n const getAngle = memoizeWeak(getIncidenceAngle);\n\n for (const vertex of vertices) {\n if (getOrder(vertex) > 2) {\n vertex.outgoingEdges.sort((a, b) => getAngle(a) - getAngle(b));\n }\n }\n}\n\nfunction getNextEdge(edge: MinorGraphEdge) {\n const { outgoingEdges } = edge.incidentVertices[1];\n const index = outgoingEdges.findIndex((other) => other.twin === edge);\n return outgoingEdges[(index + 1) % outgoingEdges.length];\n}\n\nconst faceToPolygon = memoizeWeak((face: DualGraphVertex) =>\n face.incidentEdges.flatMap((edge): Vector[] => {\n const CNT = 64;\n\n const points: Vector[] = [];\n\n for (const seg of edge.segments) {\n for (let i = 0; i < CNT; i++) {\n const t0 = i / CNT;\n const t = edge.directionFlag ? 1 - t0 : t0;\n points.push(samplePathSegmentAt(seg, t));\n }\n }\n\n return points;\n }),\n);\n\nfunction intervalCrossesPoint(a: number, b: number, p: number) {\n /*\n This deserves its own routine because of the following trick.\n We use different inequalities here to make sure we only count one of\n two intervals that meet precisely at p.\n */\n const dy1 = a >= p;\n const dy2 = b < p;\n return dy1 === dy2;\n}\n\nfunction lineSegmentIntersectsHorizontalRay(\n a: Vector,\n b: Vector,\n point: Vector,\n): boolean {\n if (!intervalCrossesPoint(a[1], b[1], point[1])) return false;\n const x = linMap(point[1], a[1], b[1], a[0], b[0]);\n return x >= point[0];\n}\n\nfunction computePointWinding(polygon: Vector[], testedPoint: Vector) {\n if (polygon.length <= 2) return 0;\n let prevPoint = polygon[polygon.length - 1];\n let winding = 0;\n for (const point of polygon) {\n if (lineSegmentIntersectsHorizontalRay(prevPoint, point, testedPoint)) {\n winding += point[1] > prevPoint[1] ? -1 : 1;\n }\n prevPoint = point;\n }\n return winding;\n}\n\nfunction computeWinding(face: DualGraphVertex) {\n const polygon = faceToPolygon(face);\n\n for (let i = 0; i < polygon.length; i++) {\n const a = polygon[i];\n const b = polygon[(i + 1) % polygon.length];\n const c = polygon[(i + 2) % polygon.length];\n const testedPoint: Vector = [\n (a[0] + b[0] + c[0]) / 3,\n (a[1] + b[1] + c[1]) / 3,\n ];\n const winding = computePointWinding(polygon, testedPoint);\n if (winding !== 0) {\n return {\n winding,\n point: testedPoint,\n };\n }\n }\n\n assertUnreachable(\"No ear in polygon found.\");\n}\n\nfunction computeDual({ edges, cycles }: MinorGraph): DualGraphComponent[] {\n const newVertices: DualGraphVertex[] = [];\n\n const minorToDualEdge = new WeakMap();\n for (const startEdge of edges) {\n if (minorToDualEdge.has(startEdge)) continue;\n const face: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n let edge = startEdge;\n do {\n assertDefined(edge.twin, \"Edge doesn't have a twin\");\n const twin = minorToDualEdge.get(edge.twin) ?? null;\n const newEdge = {\n segments: edge.segments,\n parent: edge.parent,\n incidentVertex: face,\n directionFlag: edge.directionFlag,\n twin,\n };\n if (twin) {\n twin.twin = newEdge;\n }\n minorToDualEdge.set(edge, newEdge);\n face.incidentEdges.push(newEdge);\n edge = getNextEdge(edge);\n } while (edge.incidentVertices[0] !== startEdge.incidentVertices[0]);\n newVertices.push(face);\n }\n\n for (const cycle of cycles) {\n const innerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const innerHalfEdge: DualGraphHalfEdge = {\n segments: cycle.segments,\n parent: cycle.parent,\n incidentVertex: innerFace,\n directionFlag: cycle.directionFlag,\n twin: null,\n };\n\n const outerFace: DualGraphVertex = {\n incidentEdges: [],\n flag: 0,\n };\n\n const outerHalfEdge: DualGraphHalfEdge = {\n segments: [...cycle.segments].reverse(),\n parent: cycle.parent,\n incidentVertex: outerFace,\n directionFlag: !cycle.directionFlag,\n twin: innerHalfEdge,\n };\n\n innerHalfEdge.twin = outerHalfEdge;\n innerFace.incidentEdges.push(innerHalfEdge);\n outerFace.incidentEdges.push(outerHalfEdge);\n\n newVertices.push(innerFace, outerFace);\n }\n\n const components: DualGraphComponent[] = [];\n\n const visitedVertices = new WeakSet();\n const visitedEdges = new WeakSet();\n for (const vertex of newVertices) {\n if (visitedVertices.has(vertex)) continue;\n const componentVertices: DualGraphVertex[] = [];\n const componentEdges: DualGraphHalfEdge[] = [];\n const visit = (vertex: DualGraphVertex) => {\n if (!visitedVertices.has(vertex)) {\n componentVertices.push(vertex);\n }\n visitedVertices.add(vertex);\n for (const edge of vertex.incidentEdges) {\n if (visitedEdges.has(edge)) {\n continue;\n }\n const { twin } = edge;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n componentEdges.push(edge, twin);\n visitedEdges.add(edge);\n visitedEdges.add(twin);\n visit(twin.incidentVertex);\n }\n };\n visit(vertex);\n const outerFace = componentVertices.find(\n (face) => computeWinding(face).winding < 0,\n );\n assertDefined(outerFace, \"No outer face of a component found.\");\n assertEqual(\n countIf(\n componentVertices,\n (face) => computeWinding(face).winding < 0,\n ),\n 1,\n \"Multiple outer faces found.\",\n );\n components.push({\n vertices: componentVertices,\n edges: componentEdges,\n outerFace,\n });\n }\n\n return components;\n}\n\nfunction boundingBoxIntersectsHorizontalRay(\n boundingBox: AABB,\n point: Vector,\n): boolean {\n return (\n intervalCrossesPoint(boundingBox.top, boundingBox.bottom, point[1]) &&\n boundingBox.right >= point[0]\n );\n}\n\nfunction pathSegmentHorizontalRayIntersectionCount(\n origSeg: PathSegment,\n point: Vector,\n): number {\n type IntersectionSegment = { boundingBox: AABB; seg: PathSegment };\n const totalBoundingBox = pathSegmentBoundingBox(origSeg);\n if (!boundingBoxIntersectsHorizontalRay(totalBoundingBox, point)) return 0;\n let segments: IntersectionSegment[] = [\n { boundingBox: totalBoundingBox, seg: origSeg },\n ];\n let count = 0;\n while (segments.length > 0) {\n const nextSegments: IntersectionSegment[] = [];\n for (const { boundingBox, seg } of segments) {\n if (boundingBoxMaxExtent(boundingBox) < EPS.linear) {\n if (\n lineSegmentIntersectsHorizontalRay(\n getStartPoint(seg),\n getEndPoint(seg),\n point,\n )\n ) {\n count++;\n }\n } else {\n const split = splitSegmentAt(seg, 0.5);\n const boundingBox0 = pathSegmentBoundingBox(split[0]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox0, point)) {\n nextSegments.push({\n boundingBox: boundingBox0,\n seg: split[0],\n });\n }\n const boundingBox1 = pathSegmentBoundingBox(split[1]);\n if (boundingBoxIntersectsHorizontalRay(boundingBox1, point)) {\n nextSegments.push({\n boundingBox: boundingBox1,\n seg: split[1],\n });\n }\n }\n }\n segments = nextSegments;\n }\n return count;\n}\n\nfunction testInclusion(a: DualGraphComponent, b: DualGraphComponent) {\n // TODO: Intersection counting will fail if a curve touches the horizontal line but doesn't go through.\n const testedPoint = getStartPoint(a.edges[0].segments[0]);\n for (const face of b.vertices) {\n if (face === b.outerFace) continue;\n let count = 0;\n for (const edge of face.incidentEdges) {\n for (const seg of edge.segments) {\n count += pathSegmentHorizontalRayIntersectionCount(\n seg,\n testedPoint,\n );\n }\n }\n\n if (count % 2 === 1) return face;\n }\n return null;\n}\n\nfunction computeNestingTree(components: DualGraphComponent[]): NestingTree[] {\n let nestingTrees: NestingTree[] = [];\n\n function insert(trees: NestingTree[], component: DualGraphComponent) {\n let found = false;\n for (const tree of trees) {\n const face = testInclusion(component, tree.component);\n if (face) {\n if (tree.outgoingEdges.has(face)) {\n const children = tree.outgoingEdges.get(face)!;\n tree.outgoingEdges.set(face, insert(children, component));\n } else {\n tree.outgoingEdges.set(face, [\n { component, outgoingEdges: new Map() },\n ]);\n }\n found = true;\n break;\n }\n }\n if (found) {\n return trees;\n } else {\n const newTree: NestingTree = {\n component,\n outgoingEdges: new Map(),\n };\n const newTrees: NestingTree[] = [newTree];\n for (const tree of trees) {\n const face = testInclusion(tree.component, component);\n if (face) {\n if (newTree.outgoingEdges.has(face)) {\n newTree.outgoingEdges.get(face)!.push(tree);\n } else {\n newTree.outgoingEdges.set(face, [tree]);\n }\n } else {\n newTrees.push(tree);\n }\n }\n return newTrees;\n }\n }\n\n for (const component of components) {\n nestingTrees = insert(nestingTrees, component);\n }\n\n return nestingTrees;\n}\n\nfunction getFlag(count: number, fillRule: FillRule) {\n switch (fillRule) {\n case FillRule.NonZero:\n return count === 0 ? 0 : 1;\n case FillRule.EvenOdd:\n return count % 2 === 0 ? 0 : 1;\n }\n}\n\nfunction flagFaces(\n nestingTrees: NestingTree[],\n aFillRule: FillRule,\n bFillRule: FillRule,\n) {\n function visitTree(\n tree: NestingTree,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n const visitedFaces = new WeakSet();\n\n function visitFace(\n face: DualGraphVertex,\n aRunningCount: number,\n bRunningCount: number,\n ) {\n if (visitedFaces.has(face)) return;\n visitedFaces.add(face);\n const aFlag = getFlag(aRunningCount, aFillRule);\n const bFlag = getFlag(bRunningCount, bFillRule);\n face.flag = aFlag | (bFlag << 1);\n for (const edge of face.incidentEdges) {\n const twin = edge.twin;\n assertDefined(twin, \"Edge doesn't have a twin.\");\n let nextACount = aRunningCount;\n if (edge.parent & 1) {\n nextACount += edge.directionFlag ? -1 : 1;\n }\n let nextBCount = bRunningCount;\n if (edge.parent & 2) {\n nextBCount += edge.directionFlag ? -1 : 1;\n }\n visitFace(twin.incidentVertex, nextACount, nextBCount);\n }\n if (tree.outgoingEdges.has(face)) {\n const subtrees = tree.outgoingEdges.get(face)!;\n for (const subtree of subtrees) {\n visitTree(subtree, aRunningCount, bRunningCount);\n }\n }\n }\n\n assertDefined(\n tree.component.outerFace,\n \"Component doesn't have an outer face.\",\n );\n\n visitFace(tree.component.outerFace, aRunningCount, bRunningCount);\n }\n\n for (const tree of nestingTrees) {\n visitTree(tree, 0, 0);\n }\n}\n\nfunction* getSelectedFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Iterable {\n function* visit(tree: NestingTree): Iterable {\n for (const face of tree.component.vertices) {\n if (predicate(face)) {\n yield face;\n }\n }\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n yield* visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n yield* visit(tree);\n }\n}\n\nfunction* walkFaces(faces: Set) {\n function isRemovedEdge(edge: DualGraphHalfEdge) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n return (\n faces.has(edge.incidentVertex) ===\n faces.has(edge.twin.incidentVertex)\n );\n }\n\n const edgeToNext = new WeakMap();\n for (const face of faces) {\n let prevEdge = face.incidentEdges[face.incidentEdges.length - 1];\n for (const edge of face.incidentEdges) {\n edgeToNext.set(prevEdge, edge);\n prevEdge = edge;\n }\n }\n\n const visitedEdges = new WeakSet();\n for (const face of faces) {\n for (const startEdge of face.incidentEdges) {\n if (isRemovedEdge(startEdge) || visitedEdges.has(startEdge)) {\n continue;\n }\n let edge = startEdge;\n do {\n if (edge.directionFlag) {\n yield* map(edge.segments, reversePathSegment);\n } else {\n yield* edge.segments;\n }\n visitedEdges.add(edge);\n edge = edgeToNext.get(edge)!;\n while (isRemovedEdge(edge)) {\n assertDefined(edge.twin, \"Edge doesn't have a twin.\");\n edge = edgeToNext.get(edge.twin)!;\n }\n } while (edge !== startEdge);\n }\n }\n}\n\nfunction dumpFaces(\n nestingTrees: NestingTree[],\n predicate: (face: DualGraphVertex) => boolean,\n): Path[] {\n const paths: Path[] = [];\n\n function visit(tree: NestingTree) {\n for (const face of tree.component.vertices) {\n if (!predicate(face) || face === tree.component.outerFace) {\n continue;\n }\n\n const path: Path = [];\n\n for (const edge of face.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n\n // poke holes in the face\n if (tree.outgoingEdges.has(face)) {\n for (const subtree of tree.outgoingEdges.get(face)!) {\n const { outerFace } = subtree.component;\n\n assertDefined(outerFace, \"Component has no outer face.\");\n\n for (const edge of outerFace.incidentEdges) {\n if (edge.directionFlag) {\n path.push(...edge.segments.map(reversePathSegment));\n } else {\n path.push(...edge.segments);\n }\n }\n }\n }\n\n paths.push(path);\n }\n\n for (const subtrees of tree.outgoingEdges.values()) {\n for (const subtree of subtrees) {\n visit(subtree);\n }\n }\n }\n\n for (const tree of nestingTrees) {\n visit(tree);\n }\n\n return paths;\n}\n\nfunction majorGraphToDot({ vertices, edges }: MajorGraph) {\n const toNumber = createObjectCounter();\n return `digraph {\n${vertices.map((v) => ` ${toNumber(v)} [pos=\"${v.point.map((v) => v / 10).join(\",\")}!\"]`).join(\"\\n\")}\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction minorGraphToDot(edges: MinorGraphEdge[]) {\n const toNumber = createObjectCounter();\n return `digraph {\n${edges.map((edge) => \" \" + edge.incidentVertices.map(toNumber).join(\" -> \")).join(\"\\n\")}\n}\n`;\n}\n\nfunction dualGraphToDot(components: DualGraphComponent[]) {\n const toNumber = createObjectCounter();\n return `strict graph {\n${components.map(({ edges }) => edges.map((edge) => ` ${toNumber(edge.incidentVertex)} -- ${toNumber(edge.twin!.incidentVertex)}`).join(\"\\n\")).join(\"\\n\")}\n}\n`;\n}\n\nfunction nestingTreesToDot(trees: NestingTree[]) {\n const toNumber = createObjectCounter();\n let out = \"digraph {\\n\";\n\n function visit(tree: NestingTree) {\n for (const edges of tree.outgoingEdges.values()) {\n for (const subtree of edges) {\n out += ` ${toNumber(tree.component)} -> ${toNumber(subtree.component)}\\n`;\n visit(subtree);\n }\n }\n }\n\n trees.forEach(visit);\n\n return out + \"}\\n\";\n}\n\nconst operationPredicates: Record<\n PathBooleanOperation,\n (face: DualGraphVertex) => boolean\n> = {\n [PathBooleanOperation.Union]: ({ flag }) => flag > 0,\n [PathBooleanOperation.Difference]: ({ flag }) => flag === 1,\n [PathBooleanOperation.Intersection]: ({ flag }) => flag === 3,\n [PathBooleanOperation.Exclusion]: ({ flag }) => flag === 1 || flag === 2,\n [PathBooleanOperation.Division]: ({ flag }) => (flag & 1) === 1,\n [PathBooleanOperation.Fracture]: ({ flag }) => flag > 0,\n};\n\nexport function pathBoolean(\n a: Path,\n aFillRule: FillRule,\n b: Path,\n bFillRule: FillRule,\n op: PathBooleanOperation,\n): Path[] {\n const unsplitEdges = [\n ...map(a, segmentToEdge(1)),\n ...map(b, segmentToEdge(2)),\n ];\n\n splitAtSelfIntersections(unsplitEdges);\n\n const { edges: splitEdges, totalBoundingBox } =\n splitAtIntersections(unsplitEdges);\n\n if (!totalBoundingBox) {\n // input geometry is empty\n return [];\n }\n\n const majorGraph = findVertices(splitEdges, totalBoundingBox);\n // console.log(majorGraphToDot(majorGraph));\n\n const minorGraph = computeMinor(majorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n // console.dir(minorGraph.cycles, { depth: 4 });\n\n removeDanglingEdges(minorGraph);\n // console.log(minorGraphToDot(minorGraph.edges));\n\n sortOutgoingEdgesByAngle(minorGraph);\n\n const dualGraphComponents = computeDual(minorGraph);\n // console.log(dualGraphToDot(dualGraphComponents));\n\n const nestingTrees = computeNestingTree(dualGraphComponents);\n // console.log(nestingTrees.length, nestingTreesToDot(nestingTrees));\n\n flagFaces(nestingTrees, aFillRule, bFillRule);\n\n const predicate = operationPredicates[op];\n\n switch (op) {\n case PathBooleanOperation.Division:\n case PathBooleanOperation.Fracture:\n return dumpFaces(nestingTrees, predicate);\n default: {\n const selectedFaces = new Set(\n getSelectedFaces(nestingTrees, predicate),\n );\n return [[...walkFaces(selectedFaces)]];\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Vector } from \"./Vector\";\n\nexport type AbsolutePathCommand =\n | [\"M\", Vector]\n | [\"L\", Vector]\n | [\"C\", Vector, Vector, Vector]\n | [\"S\", Vector, Vector]\n | [\"Q\", Vector, Vector]\n | [\"T\", Vector]\n | [\"A\", number, number, number, boolean, boolean, Vector]\n | [\"Z\"]\n | [\"z\"];\n\ntype RelativePathCommand =\n | [\"H\", number]\n | [\"V\", number]\n | [\"m\", number, number]\n | [\"l\", number, number]\n | [\"h\", number]\n | [\"v\", number]\n | [\"c\", number, number, number, number, number, number]\n | [\"s\", number, number, number, number]\n | [\"q\", number, number, number, number]\n | [\"t\", number, number]\n | [\"a\", number, number, number, boolean, boolean, number, number];\n\nexport type PathCommand = AbsolutePathCommand | RelativePathCommand;\n\nexport function* toAbsoluteCommands(\n commands: Iterable,\n): Iterable {\n let lastPoint: Vector = [0, 0];\n let firstPoint = lastPoint;\n\n for (const cmd of commands) {\n switch (cmd[0]) {\n case \"M\":\n yield cmd;\n lastPoint = firstPoint = cmd[1];\n break;\n case \"L\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"C\":\n yield cmd;\n lastPoint = cmd[3];\n break;\n case \"S\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"Q\":\n yield cmd;\n lastPoint = cmd[2];\n break;\n case \"T\":\n yield cmd;\n lastPoint = cmd[1];\n break;\n case \"A\":\n yield cmd;\n lastPoint = cmd[6];\n break;\n case \"Z\":\n case \"z\":\n lastPoint = firstPoint;\n yield [\"Z\"];\n break;\n case \"H\":\n lastPoint = [cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"V\":\n lastPoint = [lastPoint[0], cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"m\":\n lastPoint = firstPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ];\n yield [\"M\", lastPoint];\n break;\n case \"l\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]];\n yield [\"L\", lastPoint];\n break;\n case \"h\":\n lastPoint = [lastPoint[0] + cmd[1], lastPoint[1]];\n yield [\"L\", lastPoint];\n break;\n case \"v\":\n lastPoint = [lastPoint[0], lastPoint[1] + cmd[1]];\n yield [\"L\", lastPoint];\n break;\n case \"c\":\n yield [\n \"C\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n [lastPoint[0] + cmd[3], lastPoint[1] + cmd[4]],\n (lastPoint = [\n lastPoint[0] + cmd[5],\n lastPoint[1] + cmd[6],\n ]),\n ];\n break;\n case \"s\":\n yield [\n \"S\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"q\":\n yield [\n \"Q\",\n [lastPoint[0] + cmd[1], lastPoint[1] + cmd[2]],\n (lastPoint = [\n lastPoint[0] + cmd[3],\n lastPoint[1] + cmd[4],\n ]),\n ];\n break;\n case \"t\":\n yield [\n \"T\",\n (lastPoint = [\n lastPoint[0] + cmd[1],\n lastPoint[1] + cmd[2],\n ]),\n ];\n break;\n case \"a\":\n yield [\n \"A\",\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n (lastPoint = [\n lastPoint[0] + cmd[6],\n lastPoint[1] + cmd[7],\n ]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { PathCommand, toAbsoluteCommands } from \"./PathCommand\";\nimport { PathSegment } from \"./PathSegment\";\nimport { Vector, vectorsEqual } from \"./Vector\";\n\nexport type Path = PathSegment[];\n\nfunction reflectControlPoint(point: Vector, controlPoint: Vector): Vector {\n return [2 * point[0] - controlPoint[0], 2 * point[1] - controlPoint[1]];\n}\n\nexport function* pathFromCommands(\n commands: Iterable,\n): Iterable {\n let firstPoint: Vector | null = null;\n let lastPoint: Vector | null = null;\n let lastControlPoint: Vector | null = null;\n\n function badSequence(): never {\n throw new Error(\"Bad SVG path data sequence.\");\n }\n\n for (const cmd of toAbsoluteCommands(commands)) {\n switch (cmd[0]) {\n case \"M\":\n lastPoint = firstPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"L\":\n if (!lastPoint) badSequence();\n yield [\"L\", lastPoint, cmd[1]];\n lastPoint = cmd[1];\n lastControlPoint = null;\n break;\n case \"C\":\n if (!lastPoint) badSequence();\n yield [\"C\", lastPoint, cmd[1], cmd[2], cmd[3]];\n lastPoint = cmd[3];\n lastControlPoint = cmd[2];\n break;\n case \"S\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n yield [\n \"C\",\n lastPoint,\n reflectControlPoint(lastPoint, lastControlPoint),\n cmd[1],\n cmd[2],\n ];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"Q\":\n if (!lastPoint) badSequence();\n yield [\"Q\", lastPoint, cmd[1], cmd[2]];\n lastPoint = cmd[2];\n lastControlPoint = cmd[1];\n break;\n case \"T\":\n if (!lastPoint) badSequence();\n if (!lastControlPoint) badSequence(); // TODO: really?\n lastControlPoint = reflectControlPoint(\n lastPoint,\n lastControlPoint,\n );\n yield [\"Q\", lastPoint, lastControlPoint, cmd[1]];\n lastPoint = cmd[1];\n break;\n case \"A\":\n if (!lastPoint) badSequence();\n yield [\n \"A\",\n lastPoint,\n cmd[1],\n cmd[2],\n cmd[3],\n cmd[4],\n cmd[5],\n cmd[6],\n ];\n lastPoint = cmd[6];\n lastControlPoint = null;\n break;\n case \"Z\":\n case \"z\":\n if (!lastPoint) badSequence();\n if (!firstPoint) badSequence(); // TODO: really?\n yield [\"L\", lastPoint, firstPoint];\n lastPoint = firstPoint;\n lastControlPoint = null;\n break;\n }\n }\n}\n\nexport function* pathToCommands(\n segments: Iterable,\n eps: number = 1e-4,\n): Iterable {\n let lastPoint: Vector | null = null;\n for (const seg of segments) {\n if (!lastPoint || !vectorsEqual(seg[1], lastPoint, eps)) {\n yield [\"M\", seg[1]];\n }\n\n switch (seg[0]) {\n case \"L\":\n yield [\"L\", (lastPoint = seg[2])];\n break;\n case \"C\":\n yield [\"C\", seg[2], seg[3], (lastPoint = seg[4])];\n break;\n case \"Q\":\n yield [\"Q\", seg[2], (lastPoint = seg[3])];\n break;\n case \"A\":\n yield [\n \"A\",\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n (lastPoint = seg[7]),\n ];\n break;\n }\n }\n}\n","/*\n * SPDX-FileCopyrightText: 2024 Adam Platkevič \n *\n * SPDX-License-Identifier: MIT\n */\nimport { Path, pathFromCommands, pathToCommands } from \"./primitives/Path\";\nimport { PathCommand } from \"./primitives/PathCommand\";\nimport { Vector } from \"./primitives/Vector\";\nimport { isBoolean, isNumber, isString } from \"./util/generic\";\nimport { map } from \"./util/iterators\";\n\nconst eof = Symbol();\n\nexport function* commandsFromPathData(d: string): Iterable {\n const reFloat = /\\s*,?\\s*(-?\\d*(?:\\d\\.|\\.\\d|\\d)\\d*(?:[eE][+\\-]?\\d+)?)/y;\n const reCmd = /\\s*([MLCSQTAZHVmlhvcsqtaz])/y;\n const reBool = /\\s*,?\\s*([01])/y;\n\n let i = 0;\n\n let lastCmd = \"M\";\n\n function getCmd() {\n if (i >= d.length - 1) return eof;\n\n reCmd.lastIndex = i;\n const match = reCmd.exec(d);\n\n // https://razrfalcon.github.io/notes-on-svg-parsing/path-data.html#implicit-sequential-moveto-commands\n if (!match) {\n switch (lastCmd) {\n case \"M\":\n return \"L\";\n case \"m\":\n return \"l\";\n default:\n return lastCmd;\n }\n }\n\n i = reCmd.lastIndex;\n return match[1];\n }\n\n function getFloat() {\n reFloat.lastIndex = i;\n const match = reFloat.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a number at index ${i}.`,\n );\n }\n\n i = reFloat.lastIndex;\n return Number(match[1]);\n }\n\n function getBool() {\n reBool.lastIndex = i;\n const match = reBool.exec(d);\n\n if (!match) {\n throw new Error(\n `Invalid path data. Expected a flag at index ${i}.`,\n );\n }\n\n i = reBool.lastIndex;\n return match[1] === \"1\";\n }\n\n while (true) {\n const cmd = getCmd();\n\n switch (cmd) {\n case \"M\":\n yield [(lastCmd = \"M\"), [getFloat(), getFloat()]];\n break;\n case \"L\":\n yield [(lastCmd = \"L\"), [getFloat(), getFloat()]];\n break;\n case \"C\":\n yield [\n (lastCmd = \"C\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"S\":\n yield [\n (lastCmd = \"S\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"Q\":\n yield [\n (lastCmd = \"Q\"),\n [getFloat(), getFloat()],\n [getFloat(), getFloat()],\n ];\n break;\n case \"T\":\n yield [(lastCmd = \"T\"), [getFloat(), getFloat()]];\n break;\n case \"A\":\n yield [\n (lastCmd = \"A\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n [getFloat(), getFloat()],\n ];\n break;\n case \"Z\":\n case \"z\":\n yield [(lastCmd = \"Z\")];\n break;\n case \"H\":\n yield [(lastCmd = \"H\"), getFloat()];\n break;\n case \"V\":\n yield [(lastCmd = \"V\"), getFloat()];\n break;\n case \"m\":\n yield [(lastCmd = \"m\"), getFloat(), getFloat()];\n break;\n case \"l\":\n yield [(lastCmd = \"l\"), getFloat(), getFloat()];\n break;\n case \"h\":\n yield [(lastCmd = \"h\"), getFloat()];\n break;\n case \"v\":\n yield [(lastCmd = \"v\"), getFloat()];\n break;\n case \"c\":\n yield [\n (lastCmd = \"c\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"s\":\n yield [\n (lastCmd = \"s\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"q\":\n yield [\n (lastCmd = \"q\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getFloat(),\n ];\n break;\n case \"t\":\n yield [(lastCmd = \"t\"), getFloat(), getFloat()];\n break;\n case \"a\":\n yield [\n (lastCmd = \"a\"),\n getFloat(),\n getFloat(),\n getFloat(),\n getBool(),\n getBool(),\n getFloat(),\n getFloat(),\n ];\n break;\n case eof:\n return;\n }\n }\n}\n\nexport function pathFromPathData(d: string): Path {\n return [...pathFromCommands(commandsFromPathData(d))];\n}\n\nexport function pathToPathData(path: Path, eps: number = 1e-4): string {\n function mapParam(param: string | number | boolean | Vector) {\n if (isString(param)) return param;\n if (isNumber(param)) return param.toFixed(12);\n if (isBoolean(param)) return param ? \"1\" : \"0\";\n return param.map((c) => c.toFixed(12)).join(\",\");\n }\n\n return [\n ...map(pathToCommands(path, eps), (cmd) => cmd.map(mapParam).join(\" \")),\n ].join(\" \");\n}\n"],"names":["EPS","create","glMatrix.ARRAY_TYPE","fromRotation","rotate","scale","lerp","vec2.dot","vec2.len","mat2.create","mat2.fromRotation","vec2.sub","vec2.scale","vec2.transformMat2","mat2.transpose","vec2.add","vec2.set","vec2.lerp","vec2.rotate","mat2d.create","mat2d.fromTranslation","mat2d.rotate","mat2d.scale","mat2d.fromRotation","mat2d.mul","vec2.transformMat2d"],"mappings":"AAUA;AAEA,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AAEnB,SAAS,OAAO,CAAC,CAAS,EAAE,CAAS,EAAE,WAAiB,EAAA;IACpD,IAAI,IAAI,GAAG,MAAM,CAAC;AAElB,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE;QACtB,IAAI,IAAI,IAAI,CAAC;KAChB;AAAM,SAAA,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE;QAC9B,IAAI,IAAI,KAAK,CAAC;KACjB;AAED,IAAA,IAAI,CAAC,GAAG,WAAW,CAAC,GAA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AAQ,EAAE;AACV,oBAAA,QAAQ,EAAE;AACV,oBAAA,QAAQ,EAAE;AACV,oBAAA,OAAO,EAAE;AACT,oBAAA,OAAO,EAAE;AACT,oBAAA,QAAQ,EAAE;AACV,oBAAA,QAAQ,EAAE;iBACb,CAAC;gBACF,MAAM;AACV,YAAA,KAAK,GAAG;gBACJ,OAAO;SACd;KACJ;AACL,CAAC;AAEK,SAAU,gBAAgB,CAAC,CAAS,EAAA;IACtC,OAAO,CAAC,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;SAEe,cAAc,CAAC,IAAU,EAAE,MAAc,IAAI,EAAA;IACzD,SAAS,QAAQ,CAAC,KAAyC,EAAA;QACvD,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;QAClC,IAAI,QAAQ,CAAC,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QAC/C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpD;IAED,OAAO;QACH,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1E,KAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB;;;;","x_google_ignoreList":[4,5,6,7]} \ No newline at end of file diff --git a/package.json b/package.json index 30a7c26..d1ef60f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "path-bool", - "version": "0.0.2", + "version": "0.0.3", "license": "MIT", "author": { "name": "Adam Platkevič",