pantograph2d 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{exportJSON-26bb92ef.js → Diagram-1c56996e.js} +544 -515
- package/dist/Diagram-1c56996e.js.map +1 -0
- package/dist/Diagram-4fa55d2b.cjs +4 -0
- package/dist/Diagram-4fa55d2b.cjs.map +1 -0
- package/dist/draw-44dd36a9.js +256 -0
- package/dist/draw-44dd36a9.js.map +1 -0
- package/dist/draw-8c69c65f.cjs +2 -0
- package/dist/draw-8c69c65f.cjs.map +1 -0
- package/dist/drawShape.d.ts +153 -0
- package/dist/models.d.ts +7 -1
- package/dist/pantograph/drawShape.cjs +2 -0
- package/dist/pantograph/drawShape.cjs.map +1 -0
- package/dist/pantograph/drawShape.d.ts +1 -0
- package/dist/pantograph/drawShape.js +24 -0
- package/dist/pantograph/drawShape.js.map +1 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +7 -6
- package/dist/pantograph.cjs +5 -5
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +13 -2
- package/dist/pantograph.js +292 -449
- package/dist/pantograph.js.map +1 -1
- package/package.json +6 -2
- package/dist/exportJSON-26bb92ef.js.map +0 -1
- package/dist/exportJSON-3b325312.cjs +0 -4
- package/dist/exportJSON-3b325312.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exportJSON-3b325312.cjs","sources":["../src/models/BoundingBox.ts","../src/utils/removeDuplicatePoints.ts","../src/vectorOperations.ts","../src/models/TransformationMatrix.ts","../src/models/utils/Transformable.ts","../src/models/segments/Segment.ts","../src/models/segments/Line.ts","../src/utils/range.ts","../src/utils/zip.ts","../src/utils/unitAngle.ts","../src/utils/angularDistance.ts","../src/algorithms/intersections/lineLineIntersection.ts","../src/models/segments/Arc.ts","../src/utils/projectPointOnLine.ts","../src/algorithms/intersections/lineArcIntersection.ts","../src/algorithms/intersections/arcArcIntersection.ts","../src/algorithms/intersections/index.ts","../src/utils/allCombinations.ts","../src/models/Figure.ts","../src/algorithms/organiseLoops.ts","../src/utils/allPairs.ts","../src/models/Stroke.ts","../src/algorithms/simplify.ts","../src/models/Strand.ts","../src/algorithms/intersections/rayIntersections.ts","../src/models/Loop.ts","../../../node_modules/.pnpm/flatqueue@2.0.3/node_modules/flatqueue/index.js","../../../node_modules/.pnpm/flatbush@4.1.0/node_modules/flatbush/index.js","../src/algorithms/stitchSegments.ts","../src/algorithms/boolean/loopBooleans.ts","../src/algorithms/boolean/figureBooleans.ts","../src/models/Diagram.ts","../src/export/json/jsonSegment.ts","../src/export/json/jsonLoop.ts","../src/export/json/jsonFigure.ts","../src/export/json/jsonDiagram.ts","../src/export/json/exportJSON.ts"],"sourcesContent":["import { Vector } from \"../definitions\";\n\nfunction overlap1D(\n min1: number,\n max1: number,\n min2: number,\n max2: number\n): boolean {\n return min1 <= max2 && max1 >= min2;\n}\n\nexport class BoundingBox {\n readonly xMin: number;\n readonly yMin: number;\n\n readonly xMax: number;\n readonly yMax: number;\n\n constructor(\n xMin = Infinity,\n yMin = Infinity,\n xMax = -Infinity,\n yMax = -Infinity\n ) {\n this.xMin = xMin;\n this.yMin = yMin;\n this.xMax = xMax;\n this.yMax = yMax;\n }\n\n get width(): number {\n return this.xMax - this.xMin;\n }\n\n get height(): number {\n return this.yMax - this.yMin;\n }\n\n contains(point: Vector): boolean {\n const [x, y] = point;\n return (\n overlap1D(this.xMin, this.xMax, x, x) &&\n overlap1D(this.yMin, this.yMax, y, y)\n );\n }\n\n overlaps(other: BoundingBox): boolean {\n return (\n overlap1D(this.xMin, this.xMax, other.xMin, other.xMax) &&\n overlap1D(this.yMin, this.yMax, other.yMin, other.yMax)\n );\n }\n\n addPoint(point: Vector): BoundingBox {\n const [x, y] = point;\n return new BoundingBox(\n Math.min(this.xMin, x),\n Math.min(this.yMin, y),\n\n Math.max(this.xMax, x),\n Math.max(this.yMax, y)\n );\n }\n\n merge(other: BoundingBox): BoundingBox {\n return new BoundingBox(\n Math.min(this.xMin, other.xMin),\n Math.min(this.yMin, other.yMin),\n Math.max(this.xMax, other.xMax),\n Math.max(this.yMax, other.yMax)\n );\n }\n}\n","import type { Vector } from \"../definitions\";\n\nconst asFixed = (p: number, precision = 1e-9): string => {\n let num = p;\n if (Math.abs(p) < precision) num = 0;\n return num.toFixed(-Math.log10(precision));\n};\nexport default function removeDuplicatePoints(\n points: Vector[],\n precision = 1e-9\n): Vector[] {\n return Array.from(\n new Map(\n points.map(([p0, p1]) => [\n `[${asFixed(p0, precision)},${asFixed(p1, precision)}]`,\n [p0, p1] as Vector,\n ])\n ).values()\n );\n}\n","import type { Vector } from \"./definitions\";\n\nexport const DEG2RAD = Math.PI / 180;\n\nexport const reprVector = (vector: Vector): string => {\n return `[${vector[0]}, ${vector[1]}]`;\n};\n\nexport const sameVector = (\n [x0, y0]: Vector,\n [x1, y1]: Vector,\n precision = 1e-9\n): boolean => {\n return Math.abs(x0 - x1) <= precision && Math.abs(y0 - y1) <= precision;\n};\n\nexport const add = ([x0, y0]: Vector, [x1, y1]: Vector): Vector => {\n return [x0 + x1, y0 + y1];\n};\n\nexport const subtract = ([x0, y0]: Vector, [x1, y1]: Vector): Vector => {\n return [x0 - x1, y0 - y1];\n};\n\nexport const squareLength = ([x, y]: Vector): number => {\n return x * x + y * y;\n};\n\nexport const length = ([x, y]: Vector): number => {\n return Math.sqrt(squareLength([x, y]));\n};\n\nexport const scalarMultiply = ([x0, y0]: Vector, scalar: number): Vector => {\n return [x0 * scalar, y0 * scalar];\n};\n\nexport const squareDistance = (\n [x0, y0]: Vector,\n [x1, y1]: Vector = [0, 0]\n): number => {\n return (x0 - x1) ** 2 + (y0 - y1) ** 2;\n};\n\nexport const distance = (p0: Vector, p1: Vector = [0, 0]): number => {\n return Math.sqrt(squareDistance(p0, p1));\n};\n\nexport function crossProduct([x0, y0]: Vector, [x1, y1]: Vector): number {\n return x0 * y1 - y0 * x1;\n}\n\nexport function dotProduct([x0, y0]: Vector, [x1, y1]: Vector): number {\n return x0 * x1 + y0 * y1;\n}\n\nexport const angle = ([x0, y0]: Vector, [x1, y1]: Vector = [0, 0]): number => {\n return Math.atan2(y1 * x0 - y0 * x1, x0 * x1 + y0 * y1);\n};\n\nexport function normalize([x0, y0]: Vector): Vector {\n const l = distance([x0, y0]);\n return [x0 / l, y0 / l];\n}\n\nexport function polarToCartesian(r: number, theta: number): Vector {\n const x = Math.cos(theta) * r;\n const y = Math.sin(theta) * r;\n return [x, y];\n}\n\nexport function polarAngle([x, y]: Vector): number {\n return Math.atan2(y, x);\n}\n\nexport function cartesianToPolar(v: Vector): [number, number] {\n const r = distance(v);\n const theta = polarAngle(v);\n\n return [r, theta];\n}\n\nexport function parallel(v1: Vector, v2: Vector, precision = 1e-9): boolean {\n const V1xV2 = crossProduct(v1, v2);\n\n const xLength = squareLength(v1);\n const yLength = squareLength(v2);\n\n return V1xV2 * V1xV2 < xLength * yLength * precision * precision;\n}\n\nexport function perpendicular(v: Vector): Vector {\n return [-v[1], v[0]];\n}\n\nexport function perpendicularClockwise(v: Vector): Vector {\n return [v[1], -v[0]];\n}\n","import { Vector } from \"../definitions\";\n\ntype Matrix = [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number\n];\n\nconst matMult = (m1: Matrix, m2: Matrix): Matrix => {\n const [a, b, c, d, e, f, g, h, i] = m1;\n const [j, k, l, m, n, o, p, q, r] = m2;\n return [\n a * j + b * m + c * p,\n a * k + b * n + c * q,\n a * l + b * o + c * r,\n d * j + e * m + f * p,\n d * k + e * n + f * q,\n d * l + e * o + f * r,\n g * j + h * m + i * p,\n g * k + h * n + i * q,\n g * l + h * o + i * r,\n ];\n};\n\nexport class TransformationMatrix {\n private _matrix: Matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];\n\n translate(x: number, y: number): TransformationMatrix {\n this._matrix = matMult(this._matrix, [1, 0, x, 0, 1, y, 0, 0, 1]);\n return this;\n }\n\n rotate(angle: number, center?: Vector): TransformationMatrix {\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n\n const rotationMatrix: Matrix = [cos, -sin, 0, sin, cos, 0, 0, 0, 1];\n\n if (center) this.translate(center[0], center[1]);\n this._matrix = matMult(this._matrix, rotationMatrix);\n if (center) this.translate(-center[0], -center[1]);\n\n return this;\n }\n\n mirrorX(): TransformationMatrix {\n this._matrix = matMult(this._matrix, [1, 0, 0, 0, -1, 0, 0, 0, 1]);\n return this;\n }\n\n mirrorY(): TransformationMatrix {\n this._matrix = matMult(this._matrix, [-1, 0, 0, 0, 1, 0, 0, 0, 1]);\n return this;\n }\n\n mirrorLine(normal: Vector, point?: Vector): TransformationMatrix {\n const [a, b] = normal;\n\n const angle = Math.atan2(b, a);\n\n if (point) this.translate(point[0], point[1]);\n this.rotate(angle);\n this.mirrorX();\n this.rotate(-angle);\n if (point) this.translate(-point[0], -point[1]);\n return this;\n }\n\n mirrorCenter(center?: Vector): TransformationMatrix {\n if (center) this.translate(center[0], center[1]);\n this._matrix = matMult(this._matrix, [-1, 0, 0, 0, -1, 0, 0, 0, 1]);\n if (center) this.translate(-center[0], -center[1]);\n return this;\n }\n\n scale(scalar: number, center?: Vector): TransformationMatrix {\n if (center) this.translate(center[0], center[1]);\n this._matrix = matMult(this._matrix, [scalar, 0, 0, 0, scalar, 0, 0, 0, 1]);\n if (center) this.translate(-center[0], -center[1]);\n\n return this;\n }\n\n transform(point: Vector): Vector {\n const [x, y] = point;\n const [a, b, c, d, e, f] = this._matrix;\n return [a * x + b * y + c, d * x + e * y + f];\n }\n\n keepsOrientation(): boolean {\n const [a, , , , e] = this._matrix;\n return a * e > 0;\n }\n}\n","import { Vector } from \"../../definitions\";\nimport { DEG2RAD } from \"../../vectorOperations\";\nimport { TransformationMatrix } from \"../TransformationMatrix\";\n\nexport abstract class Transformable<T> {\n abstract transform(matrix: TransformationMatrix): T;\n translateX(x: number): T {\n const transform = new TransformationMatrix().translate(x, 0);\n return this.transform(transform);\n }\n\n translateY(y: number): T {\n const transform = new TransformationMatrix().translate(0, y);\n return this.transform(transform);\n }\n\n translate(x: number, y: number): T {\n const transform = new TransformationMatrix().translate(x, y);\n return this.transform(transform);\n }\n\n translateTo([x, y]: Vector): T {\n const transform = new TransformationMatrix().translate(x, y);\n return this.transform(transform);\n }\n\n rotate(angle: number, center?: Vector): T {\n const transform = new TransformationMatrix().rotate(\n angle * DEG2RAD,\n center\n );\n return this.transform(transform);\n }\n\n scale(factor: number, center?: Vector): T {\n const transform = new TransformationMatrix().scale(factor, center);\n return this.transform(transform);\n }\n\n mirrorCenter(center?: Vector): T {\n const transform = new TransformationMatrix().mirrorCenter(center);\n return this.transform(transform);\n }\n\n mirror(axis?: \"x\" | \"y\"): T;\n mirror(direction: Vector, center?: Vector): T;\n mirror(axisOrDirection: \"x\" | \"y\" | Vector = \"x\", center?: Vector): T {\n const transform = new TransformationMatrix();\n if (axisOrDirection === \"x\") {\n transform.mirrorX();\n } else if (axisOrDirection === \"y\") {\n transform.mirrorY();\n } else {\n transform.mirrorLine(axisOrDirection, center);\n }\n return this.transform(transform);\n }\n}\n","import type { Vector } from \"../../definitions\";\nimport { BoundingBox } from \"../BoundingBox\";\nimport type { TransformationMatrix } from \"../TransformationMatrix\";\nimport { reprVector } from \"../../vectorOperations\";\nimport { Transformable } from \"../utils/Transformable\";\n\nexport type Segment = AbstractSegment<any>;\n\nexport abstract class AbstractSegment<\n T extends AbstractSegment<T>\n> extends Transformable<T> {\n constructor(public firstPoint: Vector, public lastPoint: Vector) {\n super();\n this.firstPoint = firstPoint;\n this.lastPoint = lastPoint;\n }\n\n readonly precision: number = 1e-9;\n\n abstract segmentType: string;\n\n get repr() {\n return `${this.segmentType} ${reprVector(this.firstPoint)} - ${reprVector(\n this.lastPoint\n )}`;\n }\n\n abstract get midPoint(): Vector;\n\n abstract get boundingBox(): BoundingBox;\n\n abstract clone(): T;\n\n abstract reverse(): T;\n\n abstract isSame(other: AbstractSegment<any>): boolean;\n\n abstract distanceFrom(element: Vector): number;\n\n abstract isOnSegment(point: Vector): boolean;\n\n abstract tangentAt(point: Vector): Vector;\n\n abstract get tangentAtFirstPoint(): Vector;\n abstract get tangentAtLastPoint(): Vector;\n\n abstract splitAt(points: Vector[] | number[]): T[];\n\n abstract transform(matrix: TransformationMatrix): T;\n\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.repr;\n }\n\n abstract paramPoint(t: number): Vector;\n}\n","import { BoundingBox } from \"../BoundingBox\";\nimport { Vector } from \"../../definitions\";\nimport { TransformationMatrix } from \"../TransformationMatrix\";\nimport removeDuplicatePoints from \"../../utils/removeDuplicatePoints\";\nimport {\n add,\n distance,\n dotProduct,\n normalize,\n parallel,\n perpendicular,\n reprVector,\n sameVector,\n scalarMultiply,\n squareDistance,\n subtract,\n} from \"../../vectorOperations\";\nimport { Segment, AbstractSegment } from \"./Segment\";\n\nexport class Line extends AbstractSegment<Line> {\n segmentType = \"LINE\";\n isValidParameter(t: number): boolean {\n const linearPrecision = this.length * this.precision;\n return t >= -linearPrecision && 1 - t >= -linearPrecision;\n }\n\n paramPoint(t: number): Vector {\n return add(this.firstPoint, scalarMultiply(this.V, t));\n }\n\n get length(): number {\n return distance(this.firstPoint, this.lastPoint);\n }\n\n get squareLength(): number {\n return squareDistance(this.firstPoint, this.lastPoint);\n }\n\n private _V: Vector | null = null;\n get V(): Vector {\n if (this._V === null) {\n this._V = subtract(this.lastPoint, this.firstPoint);\n }\n return this._V;\n }\n\n get midPoint(): Vector {\n return add(this.firstPoint, scalarMultiply(this.V, 0.5));\n }\n\n isSame(other: Segment): boolean {\n if (!(other instanceof Line)) return false;\n return (\n (sameVector(this.firstPoint, other.firstPoint) &&\n sameVector(this.lastPoint, other.lastPoint)) ||\n (sameVector(this.lastPoint, other.firstPoint) &&\n sameVector(this.firstPoint, other.lastPoint))\n );\n }\n\n clone(): Line {\n return new Line(this.firstPoint, this.lastPoint);\n }\n\n reverse(): Line {\n return new Line(this.lastPoint, this.firstPoint);\n }\n\n private _boundingBox: BoundingBox | null = null;\n get boundingBox(): BoundingBox {\n if (this._boundingBox === null) {\n this._boundingBox = new BoundingBox(\n Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,\n Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,\n Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,\n Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision\n );\n }\n return this._boundingBox;\n }\n\n distanceFrom(point: Vector): number {\n const delta = subtract(point, this.firstPoint);\n const u = dotProduct(delta, this.V) / this.squareLength;\n\n if (u < 0) {\n return distance(point, this.firstPoint);\n }\n\n if (u > 1) {\n return distance(point, this.lastPoint);\n }\n\n const intersection = this.paramPoint(u);\n return distance(point, intersection);\n }\n isOnSegment(point: Vector): boolean {\n if (sameVector(point, this.firstPoint, this.precision)) return true;\n const pointVec = subtract(point, this.firstPoint);\n\n if (!parallel(this.V, pointVec)) return false;\n\n const u = dotProduct(pointVec, this.V) / this.squareLength;\n return this.isValidParameter(u);\n }\n\n tangentAt(point: Vector): Vector {\n if (!this.isOnSegment(point)) throw new Error(\"Point is not on segment\");\n return normalize(this.V);\n }\n\n get normalVector() {\n return perpendicular(normalize(this.V));\n }\n\n get tangentAtFirstPoint(): Vector {\n return normalize(this.V);\n }\n\n get tangentAtLastPoint(): Vector {\n return normalize(this.V);\n }\n\n splitAt(points: Vector | Vector[]): Line[] {\n let splitPoints: Vector[];\n if (Array.isArray(points) && points.length === 0) {\n return [this];\n }\n if (!Array.isArray(points[0])) {\n splitPoints = [points as Vector];\n } else {\n splitPoints = points as Vector[];\n }\n\n // Check that all points are on the segment\n splitPoints.forEach((point) => {\n if (!this.isOnSegment(point))\n throw new Error(\n `Point ${reprVector(point)} is not on segment ${this.repr}`\n );\n });\n\n const allPoints = [this.firstPoint, ...splitPoints, this.lastPoint];\n const uniquePoints = removeDuplicatePoints(allPoints);\n\n // Sort the points to make sure they go from the first point to the last\n const xChange = this.lastPoint[0] - this.firstPoint[0];\n let defaultDir = Math.sign(xChange);\n let comparisonAxis = 0;\n\n if (Math.abs(xChange) < this.precision) {\n defaultDir = Math.sign(this.lastPoint[1] - this.firstPoint[1]);\n comparisonAxis = 1;\n }\n\n uniquePoints.sort(\n (a, b) => defaultDir * (a[comparisonAxis] - b[comparisonAxis])\n );\n\n return uniquePoints.flatMap((point, index) => {\n if (index === uniquePoints.length - 1) return [];\n return new Line(point, uniquePoints[index + 1]);\n });\n }\n\n transform(matrix: TransformationMatrix): Line {\n return new Line(\n matrix.transform(this.firstPoint),\n matrix.transform(this.lastPoint)\n );\n }\n}\n","export default function range(len: number): number[] {\n return Array.from(Array(len).keys());\n}\n","import range from \"./range\";\n\nexport default function zip<T extends unknown[][]>(\n arrays: T\n): { [K in keyof T]: T[K] extends (infer V)[] ? V : never }[] {\n const minLength = Math.min(...arrays.map((arr) => arr.length));\n // @ts-expect-error This is too much for ts\n return range(minLength).map((i) => arrays.map((arr) => arr[i]));\n}\n","// makes sure the angle is in one unit circle\nexport function unitAngle(angle: number) {\n if (angle < 0) {\n return angle + 2 * Math.PI;\n }\n if (angle >= 2 * Math.PI) {\n return angle % (2 * Math.PI);\n }\n return angle;\n}\n","export function angularDistance(\n angle1: number,\n angle2: number,\n clockwise: boolean\n) {\n let relDistance = angle2 - angle1;\n\n if (clockwise) {\n relDistance = -relDistance;\n }\n\n if (relDistance < 0) {\n relDistance += 2 * Math.PI;\n }\n return relDistance;\n}\n","import { crossProduct, squareLength, subtract } from \"../../vectorOperations\";\nimport { Line } from \"../../models/segments/Line\";\nimport { Vector } from \"../../definitions\";\nimport removeDuplicatePoints from \"../../utils/removeDuplicatePoints\";\n\nexport const lineLineParams = (\n line1: { V: Vector; firstPoint: Vector; precision: number },\n line2: { V: Vector; firstPoint: Vector; precision: number },\n precision?: number\n):\n | \"parallel\"\n | {\n intersectionParam1: number;\n intersectionParam2: number;\n } => {\n const V1xV2 = crossProduct(line1.V, line2.V);\n\n const xLength = squareLength(line1.V);\n const yLength = squareLength(line2.V);\n\n const squarePrecision = precision\n ? precision * precision\n : line1.precision * line2.precision;\n\n if (V1xV2 * V1xV2 < xLength * yLength * squarePrecision) {\n return \"parallel\";\n }\n\n const diffPoint = subtract(line2.firstPoint, line1.firstPoint);\n\n const intersectionParam1 = crossProduct(diffPoint, line2.V) / V1xV2;\n const intersectionParam2 = crossProduct(diffPoint, line1.V) / V1xV2;\n\n return {\n intersectionParam1,\n intersectionParam2,\n };\n};\n/**\n * Returns the intersection point between two segment of lines\n *\n * Note that collinear segments are not considered to intersect at all.\n * Additionally, if the segments intersect at a start or end point of one of the\n * segments, the intersection point is considered to be an intersection.\n *\n * @param line1\n * @param line2\n * @returns {Vector} the intersection point or null if the segments do not\n * intersect\n *\n **/\n\nexport function lineLineIntersection(\n line1: Line,\n line2: Line,\n includeOverlaps = false,\n precision?: number\n): null | Vector | Line {\n const intersectionParams = lineLineParams(line1, line2, precision);\n if (intersectionParams === \"parallel\") {\n if (!includeOverlaps) return null;\n if (line1.isSame(line2)) return line1;\n\n const points = removeDuplicatePoints(\n [\n line2.isOnSegment(line1.firstPoint) ? line1.firstPoint : null,\n line2.isOnSegment(line1.lastPoint) ? line1.lastPoint : null,\n line1.isOnSegment(line2.firstPoint) ? line2.firstPoint : null,\n line1.isOnSegment(line2.lastPoint) ? line2.lastPoint : null,\n ].filter((p) => p !== null) as Vector[]\n ).sort((a, b) => a[0] - b[0]);\n\n if (points.length === 0) return null;\n // We consider the case when the lines are collinear and touch only on\n // the last point. We consider that they do not overlap there\n // We might want to revisit this choice\n else if (points.length === 1) return null;\n else if (points.length === 2) return new Line(points[0], points[1]);\n else {\n console.error(points);\n throw new Error(\n \"Unexpected number of points while intersecting parallel lines\"\n );\n }\n }\n\n const { intersectionParam1, intersectionParam2 } = intersectionParams;\n if (!line1.isValidParameter(intersectionParam1)) return null;\n if (!line2.isValidParameter(intersectionParam2)) return null;\n\n return line1.paramPoint(intersectionParam1);\n}\n","import { BoundingBox } from \"../BoundingBox\";\nimport { Vector } from \"../../definitions\";\nimport { TransformationMatrix } from \"../TransformationMatrix\";\nimport {\n add,\n cartesianToPolar,\n crossProduct,\n distance,\n normalize,\n perpendicular,\n perpendicularClockwise,\n polarToCartesian,\n reprVector,\n sameVector,\n scalarMultiply,\n squareDistance,\n subtract,\n} from \"../../vectorOperations\";\nimport { Segment, AbstractSegment } from \"./Segment\";\nimport zip from \"../../utils/zip\";\nimport { unitAngle } from \"../../utils/unitAngle\";\nimport { angularDistance } from \"../../utils/angularDistance\";\nimport { Line } from \"./Line\";\nimport { lineLineParams } from \"../../algorithms/intersections/lineLineIntersection\";\n\nconst polarCoordsFromCenter = (point: Vector, center: Vector) => {\n const vector = subtract(point, center);\n return cartesianToPolar(vector);\n};\n\nexport class Arc extends AbstractSegment<Arc> {\n segmentType = \"ARC\";\n\n readonly center: Vector;\n readonly clockwise: boolean;\n\n constructor(\n firstPoint: Vector,\n lastPoint: Vector,\n center: Vector,\n clockwise = false,\n { ignoreChecks = false } = {}\n ) {\n super(firstPoint, lastPoint);\n this.center = center;\n this.clockwise = clockwise;\n\n if (!ignoreChecks) {\n if (sameVector(firstPoint, lastPoint)) {\n throw new Error(\"Invalid arc, cannot be a full circle\");\n }\n if (\n Math.abs(this.radius - distance(this.lastPoint, this.center)) >\n this.precision\n )\n throw new Error(\n \"Invalid arc, radius does not match between start and end\"\n );\n }\n }\n\n isValidParameter(t: number): boolean {\n return 1 - t >= -this.precision && t >= -this.precision;\n }\n\n angleToParam(angle: number): number {\n return (\n angularDistance(this.firstAngle, unitAngle(angle), this.clockwise) /\n this.angularLength\n );\n }\n\n private _angularLength: number | null = null;\n get angularLength() {\n if (!this._angularLength) {\n this._angularLength = angularDistance(\n this.firstAngle,\n this.lastAngle,\n this.clockwise\n );\n }\n return this._angularLength;\n }\n\n paramPoint(t: number): Vector {\n return add(\n this.center,\n polarToCartesian(\n this.radius,\n this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1)\n )\n );\n }\n\n pointToParam(point: Vector): number {\n const [r, theta] = polarCoordsFromCenter(point, this.center);\n if (Math.abs(r - this.radius) > this.precision)\n throw new Error(\n `Point ${reprVector(point)} is not on segment ${this.repr}`\n );\n\n const param = this.angleToParam(theta);\n if (!this.isValidParameter(param))\n throw new Error(\n `Point ${reprVector(point)} is not on segment ${this.repr}`\n );\n\n return param;\n }\n\n private _radius: number | null = null;\n get radius(): number {\n if (this._radius === null) {\n this._radius = distance(this.firstPoint, this.center);\n }\n return this._radius;\n }\n\n private _firstAngle: number | null = null;\n get firstAngle(): number {\n if (this._firstAngle === null) {\n const [x, y] = subtract(this.firstPoint, this.center);\n this._firstAngle = unitAngle(Math.atan2(y, x));\n }\n return this._firstAngle;\n }\n\n private _lastAngle: number | null = null;\n get lastAngle(): number {\n if (this._lastAngle === null) {\n const [x, y] = subtract(this.lastPoint, this.center);\n this._lastAngle = unitAngle(Math.atan2(y, x));\n }\n return this._lastAngle;\n }\n\n get length(): number {\n return this.radius * this.angularLength;\n }\n\n get squareLength(): number {\n return this.length * this.length;\n }\n\n get midPoint(): Vector {\n return this.paramPoint(0.5);\n }\n\n isSame(other: Segment): boolean {\n if (!(other instanceof Arc)) return false;\n if (!sameVector(this.center, other.center)) return false;\n\n return (\n (sameVector(this.firstPoint, other.firstPoint) &&\n sameVector(this.lastPoint, other.lastPoint) &&\n this.clockwise === other.clockwise) ||\n (sameVector(this.lastPoint, other.firstPoint) &&\n sameVector(this.firstPoint, other.lastPoint) &&\n this.clockwise === !other.clockwise)\n );\n }\n\n clone(): Arc {\n return new Arc(\n this.firstPoint,\n this.lastPoint,\n this.center,\n this.clockwise\n );\n }\n\n reverse(): Arc {\n return new Arc(\n this.lastPoint,\n this.firstPoint,\n this.center,\n !this.clockwise\n );\n }\n\n private _boundingBox: BoundingBox | null = null;\n get boundingBox(): BoundingBox {\n if (this._boundingBox === null) {\n const extendedR = this.radius + this.precision;\n const validAngle = (angle: number) =>\n this.isValidParameter(this.angleToParam(angle));\n this._boundingBox = new BoundingBox(\n validAngle(Math.PI)\n ? this.center[0] - extendedR\n : Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,\n validAngle(Math.PI * 1.5)\n ? this.center[1] - extendedR\n : Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,\n validAngle(0)\n ? this.center[0] + extendedR\n : Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,\n validAngle(Math.PI / 2)\n ? this.center[1] + extendedR\n : Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision\n );\n }\n return this._boundingBox;\n }\n\n distanceFrom(point: Vector): number {\n const [r, theta] = polarCoordsFromCenter(point, this.center);\n if (this.isValidParameter(this.angleToParam(theta))) {\n return Math.abs(r - this.radius);\n }\n return Math.sqrt(\n Math.min(\n squareDistance(point, this.firstPoint),\n squareDistance(point, this.lastPoint)\n )\n );\n }\n\n isOnSegment(point: Vector): boolean {\n if (sameVector(point, this.firstPoint) || sameVector(point, this.lastPoint))\n return true;\n const [r, theta] = polarCoordsFromCenter(point, this.center);\n if (Math.abs(r - this.radius) > this.precision) return false;\n\n const param = this.angleToParam(theta);\n return this.isValidParameter(param);\n }\n\n tangentAt(point: Vector): Vector {\n const [r, theta] = polarCoordsFromCenter(point, this.center);\n if (Math.abs(r - this.radius) > this.precision)\n throw new Error(\"Point is not on the arc\");\n\n const param = this.angleToParam(theta);\n if (!this.isValidParameter(param))\n throw new Error(\"Point is not on the arc\");\n\n const tangent = polarToCartesian(1, theta);\n const fcn = this.clockwise ? perpendicularClockwise : perpendicular;\n return fcn(normalize(tangent));\n }\n\n get tangentAtFirstPoint(): Vector {\n const tangent = polarToCartesian(1, this.firstAngle);\n const fcn = this.clockwise ? perpendicularClockwise : perpendicular;\n return fcn(normalize(tangent));\n }\n\n get tangentAtLastPoint(): Vector {\n const tangent = polarToCartesian(1, this.lastAngle);\n const fcn = this.clockwise ? perpendicularClockwise : perpendicular;\n return fcn(normalize(tangent));\n }\n\n splitAt(points: Vector | Vector[]): Arc[] {\n let splitPoints: Vector[];\n if (Array.isArray(points) && points.length === 0) {\n return [this];\n }\n if (!Array.isArray(points[0])) {\n splitPoints = [points as Vector];\n } else {\n splitPoints = points as Vector[];\n }\n\n // Point to param also checks that all points are on the segment\n const splitParams = splitPoints.map((point) => this.pointToParam(point));\n\n const allParams = [0, 1, ...splitParams];\n\n // We use a map here, because we want to keep the entered split points\n // exactly (no change from the transformation from and to params).\n const paramsMap = new Map<number, Vector>(\n zip([allParams, [this.firstPoint, this.lastPoint, ...splitPoints]]) as [\n number,\n Vector\n ][]\n );\n allParams.sort((a, b) => a - b);\n\n let skipped: null | number = null;\n return allParams.flatMap((param, index) => {\n if (index === allParams.length - 1) return [];\n const nextParam = allParams[index + 1];\n\n if (nextParam - param < this.precision) {\n if (skipped === null) skipped = param;\n return [];\n }\n\n const startParam = skipped === null ? param : skipped;\n const arc = new Arc(\n paramsMap.get(startParam) || this.paramPoint(startParam),\n paramsMap.get(nextParam) || this.paramPoint(nextParam),\n this.center,\n this.clockwise\n );\n skipped = null;\n return arc;\n });\n }\n\n transform(matrix: TransformationMatrix): Arc {\n return new Arc(\n matrix.transform(this.firstPoint),\n matrix.transform(this.lastPoint),\n matrix.transform(this.center),\n matrix.keepsOrientation() ? this.clockwise : !this.clockwise\n );\n }\n}\n\nexport function threePointsArc(\n firstPoint: Vector,\n midPoint: Vector,\n lastPoint: Vector\n) {\n const chord1 = new Line(midPoint, firstPoint);\n const chord2 = new Line(midPoint, lastPoint);\n\n const dir1 = perpendicular(chord1.tangentAtFirstPoint);\n const dir2 = perpendicular(chord2.tangentAtLastPoint);\n\n const result = lineLineParams(\n { firstPoint: chord1.midPoint, V: dir1, precision: 1e-9 },\n { firstPoint: chord2.midPoint, V: dir2, precision: 1e-9 }\n );\n\n if (result === \"parallel\")\n throw new Error(\"Cannot create an arc from three colinear points\");\n\n const clockwise =\n crossProduct(\n subtract(firstPoint, midPoint),\n subtract(lastPoint, midPoint)\n ) > 0;\n\n return new Arc(\n firstPoint,\n lastPoint,\n add(chord1.midPoint, scalarMultiply(dir1, result.intersectionParam1)),\n clockwise,\n { ignoreChecks: true }\n );\n}\n\nexport function tangentArc(\n firstPoint: Vector,\n lastPoint: Vector,\n tangentAtFirstPoint: Vector\n) {\n const chord = new Line(lastPoint, firstPoint);\n const dir = perpendicular(chord.tangentAtFirstPoint);\n\n const result = lineLineParams(\n { firstPoint: chord.midPoint, V: dir, precision: 1e-9 },\n {\n firstPoint: firstPoint,\n V: perpendicular(tangentAtFirstPoint),\n precision: 1e-9,\n }\n );\n\n if (result === \"parallel\")\n throw new Error(\"Cannot create an arc from three colinear points\");\n\n const center = add(\n chord.midPoint,\n scalarMultiply(dir, result.intersectionParam1)\n );\n\n const clockwise =\n crossProduct(\n subtract(center, firstPoint),\n subtract(center, add(firstPoint, tangentAtFirstPoint))\n ) < 0;\n\n return new Arc(firstPoint, lastPoint, center, clockwise, {\n ignoreChecks: true,\n });\n}\n","import type { Vector } from \"../definitions\";\nimport type { Line } from \"../models/segments/Line\";\n\nimport { dotProduct, subtract } from \"../vectorOperations\";\n\nexport function projectPointOnLine(line: Line, point: Vector): Vector {\n const delta = subtract(point, line.firstPoint);\n const u = dotProduct(delta, line.V) / line.squareLength;\n return line.paramPoint(u);\n}\n","import { add, scalarMultiply, distance } from \"../../vectorOperations\";\nimport { Line } from \"../../models/segments/Line\";\nimport { Vector } from \"../../definitions\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport { projectPointOnLine } from \"../../utils/projectPointOnLine\";\n\nexport function lineArcIntersection(\n line: Line,\n arc: Arc,\n precision?: number\n): Vector[] {\n const epsilon = precision ? precision : line.precision;\n\n const centerOnLine = projectPointOnLine(line, arc.center);\n const centerDistance = distance(centerOnLine, arc.center);\n\n // the line does not touch the circle\n if (centerDistance > arc.radius + epsilon) return [];\n\n // The line is tangent to the arc\n if (Math.abs(centerDistance - arc.radius) < epsilon) {\n const intersectionPoint = centerOnLine;\n if (\n line.isOnSegment(intersectionPoint) &&\n arc.isOnSegment(intersectionPoint)\n ) {\n return [intersectionPoint];\n }\n return [];\n }\n\n // The line crosses the arc\n const intersections = [];\n\n // delta corresponds to the length between the project center on the line and\n // the crossing points\n const delta = Math.sqrt(\n arc.radius * arc.radius - centerDistance * centerDistance\n );\n\n // We might be able to optimise the check on segment, but it is not clear\n // that it is worth it\n const lineDir = line.tangentAtFirstPoint;\n const p1 = add(centerOnLine, scalarMultiply(lineDir, delta));\n if (line.isOnSegment(p1) && arc.isOnSegment(p1)) {\n intersections.push(p1);\n }\n\n const p2 = add(centerOnLine, scalarMultiply(lineDir, -delta));\n if (line.isOnSegment(p2) && arc.isOnSegment(p2)) {\n intersections.push(p2);\n }\n\n return intersections;\n}\n","import { Vector } from \"../../definitions\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport removeDuplicatePoints from \"../../utils/removeDuplicatePoints\";\nimport {\n add,\n distance,\n normalize,\n perpendicular,\n sameVector,\n scalarMultiply,\n subtract,\n} from \"../../vectorOperations\";\n\nconst complementArc = (arc: Arc): Arc => {\n const { firstPoint, lastPoint, center, clockwise } = arc;\n return new Arc(lastPoint, firstPoint, center, clockwise, {\n ignoreChecks: true,\n });\n};\n\nconst handleOverlaps = (arc1: Arc, arc2: Arc): Arc[] => {\n // handle the case with common points at start or end first\n if (arc1.isSame(arc2)) {\n return [arc1];\n }\n // two arcs with common points at start and end (but not the same arc)\n\n const points = removeDuplicatePoints(\n [\n arc2.isOnSegment(arc1.firstPoint) ? arc1.firstPoint : null,\n arc2.isOnSegment(arc1.lastPoint) ? arc1.lastPoint : null,\n arc1.isOnSegment(arc2.firstPoint) ? arc2.firstPoint : null,\n arc1.isOnSegment(arc2.lastPoint) ? arc2.lastPoint : null,\n ].filter((p) => p !== null) as Vector[]\n // We sort by the param value of the first arc. This means that the points\n // will be sorted with the same orientation than arc1\n ).sort((a, b) => arc1.pointToParam(a) - arc1.pointToParam(b));\n\n if (points.length === 0) return [];\n // We consider the case when the arcs touch only on\n // the last point. We consider that they do not overlap there\n //\n // We might want to revisit this choice\n else if (points.length === 1) return [];\n else if (points.length === 2) {\n // Similar to the case with length 1, we ignore the double overlapping point\n if (arc1.isSame(complementArc(arc2))) return [];\n return [new Arc(points[0], points[1], arc1.center, arc1.clockwise)];\n } else if (points.length === 3) {\n // Similar to the case with length 1, we ignore the single overlapping point\n const startIndex =\n sameVector(points[0], arc2.lastPoint) ||\n sameVector(points[0], arc2.firstPoint)\n ? 1\n : 0;\n return [\n new Arc(\n points[0 + startIndex],\n points[1 + startIndex],\n arc1.center,\n arc1.clockwise\n ),\n ];\n } else if (points.length === 4) {\n return [\n new Arc(points[0], points[1], arc1.center, arc1.clockwise),\n new Arc(points[2], points[3], arc1.center, arc1.clockwise),\n ];\n }\n throw new Error(\"Bug in the arc arc overlap algorithm\");\n};\n\nexport function arcArcIntersection(\n arc1: Arc,\n arc2: Arc,\n includeOverlaps = false,\n precision?: number\n): Vector[] | Arc[] {\n const epsilon = precision ? precision : arc1.precision;\n const centersDistance = distance(arc1.center, arc2.center);\n\n const radiusSum = arc1.radius + arc2.radius;\n\n // The circles do not touch\n if (centersDistance > radiusSum + epsilon) {\n return [];\n }\n\n const radiusDifference = Math.abs(arc1.radius - arc2.radius);\n\n // The arcs are concentric\n if (centersDistance < radiusDifference - epsilon) {\n return [];\n }\n\n // With a common center we can have overlaps\n if (centersDistance < epsilon) {\n if (radiusDifference > epsilon) {\n return [];\n } else {\n if (!includeOverlaps) {\n return [];\n }\n return handleOverlaps(arc1, arc2);\n }\n }\n\n const centersVector = normalize(subtract(arc2.center, arc1.center));\n // The circles are tangent to each other\n const isOutsideTangent = centersDistance > radiusSum - epsilon;\n if (\n // circles are outside each other\n isOutsideTangent ||\n // circles are inside each other\n Math.abs(centersDistance - radiusDifference) < epsilon\n ) {\n const orientation = isOutsideTangent || arc1.radius > arc2.radius ? 1 : -1;\n const intersectionPoint = add(\n arc1.center,\n scalarMultiply(centersVector, orientation * arc1.radius)\n );\n\n if (\n arc1.isOnSegment(intersectionPoint) &&\n arc2.isOnSegment(intersectionPoint)\n ) {\n return [intersectionPoint];\n } else {\n return [];\n }\n }\n\n // The circles cross each other\n const radiusToChord =\n (arc1.radius * arc1.radius) / (2 * centersDistance) -\n (arc2.radius * arc2.radius) / (2 * centersDistance) +\n centersDistance / 2;\n\n const midPoint = add(\n arc1.center,\n scalarMultiply(centersVector, radiusToChord)\n );\n\n const halfChord = Math.sqrt(\n arc1.radius * arc1.radius - radiusToChord * radiusToChord\n );\n\n const chordVector = perpendicular(centersVector);\n\n const p1 = add(midPoint, scalarMultiply(chordVector, halfChord));\n const p2 = add(midPoint, scalarMultiply(chordVector, -halfChord));\n\n const intersections = [];\n if (arc1.isOnSegment(p1) && arc2.isOnSegment(p1)) {\n intersections.push(p1);\n }\n if (arc1.isOnSegment(p2) && arc2.isOnSegment(p2)) {\n intersections.push(p2);\n }\n\n return intersections;\n}\n","import { Line } from \"../../models/segments/Line\";\n\nimport type { Vector } from \"../../definitions\";\nimport { Segment } from \"../../models/segments/Segment\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport { lineArcIntersection } from \"./lineArcIntersection\";\nimport { lineLineIntersection } from \"./lineLineIntersection\";\nimport { arcArcIntersection } from \"./arcArcIntersection\";\n\nexport function findIntersections(\n segment1: Segment,\n segment2: Segment,\n precision?: number\n): Vector[] {\n if (segment1 instanceof Line && segment2 instanceof Line) {\n const intersection = lineLineIntersection(\n segment1,\n segment2,\n false,\n precision\n );\n if (intersection === null) return [];\n return [intersection as Vector];\n }\n if (segment1 instanceof Line && segment2 instanceof Arc) {\n return lineArcIntersection(segment1, segment2, precision);\n }\n if (segment1 instanceof Arc && segment2 instanceof Line) {\n return lineArcIntersection(segment2, segment1, precision);\n }\n if (segment1 instanceof Arc && segment2 instanceof Arc) {\n return arcArcIntersection(segment1, segment2, false, precision) as Vector[];\n }\n\n throw new Error(\"Not implemented\");\n}\n\nexport function findIntersectionsAndOverlaps(\n segment1: Segment,\n segment2: Segment,\n precision?: number\n): { intersections: Vector[]; overlaps: Segment[]; count: number } {\n // If we have two lines, checks are fast enough to not use bounding boxes\n if (segment1 instanceof Line && segment2 instanceof Line) {\n const intersection = lineLineIntersection(\n segment1,\n segment2,\n true,\n precision\n );\n if (intersection === null)\n return { intersections: [], overlaps: [], count: 0 };\n if (intersection instanceof Line)\n return { intersections: [], overlaps: [intersection], count: 1 };\n return { intersections: [intersection], overlaps: [], count: 1 };\n }\n\n if (!segment1.boundingBox.overlaps(segment2.boundingBox)) {\n return { intersections: [], overlaps: [], count: 0 };\n }\n\n if (segment1 instanceof Line && segment2 instanceof Arc) {\n const intersections = lineArcIntersection(segment1, segment2, precision);\n return { intersections, overlaps: [], count: intersections.length };\n }\n\n if (segment1 instanceof Arc && segment2 instanceof Line) {\n const intersections = lineArcIntersection(segment2, segment1, precision);\n return { intersections, overlaps: [], count: intersections.length };\n }\n\n if (segment1 instanceof Arc && segment2 instanceof Arc) {\n const intersections = arcArcIntersection(\n segment1,\n segment2,\n true,\n precision\n );\n if (!intersections.length)\n return { intersections: [], overlaps: [], count: 0 };\n if (intersections[0] instanceof Arc)\n return {\n intersections: [],\n overlaps: intersections as Arc[],\n count: intersections.length,\n };\n return {\n intersections: intersections as Vector[],\n overlaps: [],\n count: intersections.length,\n };\n }\n\n throw new Error(\"Not implemented\");\n}\n","export function allCombinations(count: number): [number, number][] {\n const result: [number, number][] = [];\n\n for (let i = 0; i < count; i++) {\n for (let j = 0; j <= i; j++) {\n result.push([i, j]);\n }\n }\n\n return result;\n}\n\nexport function* combineDifferentValues<T>(array: T[]): Generator<[T, T]> {\n for (const [i, j] of allCombinations(array.length)) {\n if (i === j) continue;\n yield [array[i], array[j]];\n }\n}\n","import { Vector } from \"../definitions\";\nimport { TransformationMatrix } from \"./TransformationMatrix\";\nimport type { BoundingBox } from \"./BoundingBox\";\nimport { Loop } from \"./Loop\";\nimport { combineDifferentValues } from \"../utils/allCombinations\";\nimport { Transformable } from \"./utils/Transformable\";\nimport { exportJSON } from \"../main\";\n\nexport class Figure extends Transformable<Figure> {\n readonly contour: Loop;\n readonly holes: Loop[];\n\n constructor(\n contour: Loop,\n holes: Loop[] = [],\n { ignoreChecks = false } = {}\n ) {\n super();\n if (!ignoreChecks) checkIsValidFigure(contour, holes);\n this.contour = contour;\n this.holes = holes;\n }\n\n get boundingBox(): BoundingBox {\n return this.contour.boundingBox;\n }\n\n get isFull(): boolean {\n return this.holes.length === 0;\n }\n\n get allLoops(): Loop[] {\n return [this.contour, ...this.holes];\n }\n\n clone(): Figure {\n return new Figure(\n this.contour.clone(),\n this.holes.map((hole) => hole.clone())\n );\n }\n\n transform(matrix: TransformationMatrix): Figure {\n return new Figure(\n this.contour.transform(matrix),\n this.holes.map((hole) => hole.transform(matrix))\n );\n }\n\n contains(point: Vector): boolean {\n return (\n this.contour.contains(point) &&\n !this.holes.some((hole) => hole.contains(point))\n );\n }\n\n intersects(other: Figure): boolean {\n return this.allLoops.some((loop) =>\n other.allLoops.some((otherLoop) => loop.intersects(otherLoop))\n );\n }\n}\n\nexport function checkIsValidFigure(contour?: Loop, holes: Loop[] = []): void {\n if (!contour) throw new Error(\"Figure must have a contour\");\n for (const [loop1, loop2] of combineDifferentValues([contour, ...holes])) {\n if (loop1.intersects(loop2)) {\n throw new Error(\"Loops in a figure must not intersect\");\n }\n }\n\n if (\n holes.some(\n (hole) =>\n !contour.contains(hole.firstPoint) && !contour.onStroke(hole.firstPoint)\n )\n ) {\n throw new Error(\"Holes must be inside the contour\");\n }\n\n for (const [hole1, hole2] of combineDifferentValues(holes)) {\n if (hole1.contains(hole2.firstPoint)) {\n console.error(exportJSON(hole1), exportJSON(hole2));\n throw new Error(\"Holes must not be inside other holes\");\n }\n }\n}\n","import { Figure } from \"../models/Figure\";\nimport { Loop } from \"../models/Loop\";\n\nconst groupByBoundingBoxOverlap = (loops: Loop[]): Loop[][] => {\n const overlaps = loops.map((loop, i) => {\n return loops\n .slice(i + 1)\n .map((v, j): [number, Loop] => [j + i + 1, v])\n .filter(([, other]) => loop.boundingBox.overlaps(other.boundingBox))\n .map(([index]) => index);\n });\n const groups: Loop[][] = [];\n const groupsInOverlaps = Array(overlaps.length);\n\n overlaps.forEach((indices, i) => {\n let myGroup = groupsInOverlaps[i];\n if (!myGroup) {\n myGroup = [];\n groups.push(myGroup);\n }\n\n myGroup.push(loops[i]);\n\n if (indices.length) {\n indices.forEach((index) => {\n groupsInOverlaps[index] = myGroup;\n });\n }\n });\n\n return groups;\n};\n\ninterface ContainedLoop {\n loop: Loop;\n isIn: Loop[];\n}\n\nconst addContainmentInfo = (groupedLoops: Loop[]): ContainedLoop[] => {\n return groupedLoops.map((loop, index) => {\n const firstCurve = loop.segments[0];\n const point = firstCurve.midPoint;\n\n const isIn = groupedLoops.filter((potentialOuterLoop, j) => {\n if (index === j) return false;\n return potentialOuterLoop.contains(point);\n });\n\n return {\n loop,\n isIn,\n };\n });\n};\n\nconst splitMultipleOuterLoops = (\n outerLoops: ContainedLoop[],\n allLoops: ContainedLoop[]\n): ContainedLoop[][] => {\n return outerLoops.flatMap(({ loop: outerLoop }) => {\n return cleanEdgeCases(\n allLoops.filter(\n ({ loop, isIn }) => loop === outerLoop || isIn.indexOf(outerLoop) !== -1\n )\n );\n });\n};\n\nconst handleNestedLoops = (\n nestedLoops: ContainedLoop[],\n allLoops: ContainedLoop[]\n): ContainedLoop[][] => {\n const firstLevelOuterLoops = allLoops.filter(({ isIn }) => isIn.length <= 1);\n\n const innerLevelsLoops = cleanEdgeCases(\n addContainmentInfo(nestedLoops.map(({ loop }) => loop))\n );\n return [firstLevelOuterLoops, ...innerLevelsLoops];\n};\n\nconst cleanEdgeCases = (groupedLoops: ContainedLoop[]): ContainedLoop[][] => {\n if (!groupedLoops.length) return [];\n\n const outerLoops = groupedLoops.filter(({ isIn }) => !isIn.length);\n const nestedLoops = groupedLoops.filter(({ isIn }) => isIn.length > 1);\n\n if (outerLoops.length === 1 && nestedLoops.length === 0) {\n return [groupedLoops];\n } else if (outerLoops.length > 1) {\n return splitMultipleOuterLoops(outerLoops, groupedLoops);\n } else {\n return handleNestedLoops(nestedLoops, groupedLoops);\n }\n};\n\n/**\n * Groups an array of loops such that loops that correspond to holes\n * in other loops are set in a Figure\n *\n * This algorithm assumes non intersecting loops.\n */\nexport function organiseLoops(loops: Loop[]): Figure[] {\n const basicGrouping =\n groupByBoundingBoxOverlap(loops).map(addContainmentInfo);\n return basicGrouping.flatMap(cleanEdgeCases).map((compounds) => {\n if (compounds.length === 1) return new Figure(compounds[0].loop);\n\n compounds.sort((a, b) => a.isIn.length - b.isIn.length);\n const [contour, ...holes] = compounds.map(({ loop }) => loop);\n return new Figure(contour, holes);\n });\n}\n","export function allPairs<S, T>(list1: T[], list2: S[]): [T, S][] {\n const result: [T, S][] = [];\n\n for (const l1 of list1) {\n for (const l2 of list2) {\n result.push([l1, l2]);\n }\n }\n\n return result;\n}\n","import { BoundingBox } from \"./BoundingBox\";\nimport { Vector } from \"../definitions\";\nimport { findIntersectionsAndOverlaps } from \"../algorithms/intersections\";\nimport { Segment } from \"./segments/Segment\";\nimport { TransformationMatrix } from \"./TransformationMatrix\";\nimport { allCombinations } from \"../utils/allCombinations\";\nimport zip from \"../utils/zip\";\nimport { sameVector } from \"../vectorOperations\";\nimport { Transformable } from \"./utils/Transformable\";\n\nexport type Stroke = AbstractStroke<any>;\n\nexport abstract class AbstractStroke<\n T extends AbstractStroke<T>\n> extends Transformable<T> {\n readonly segments: Segment[];\n\n abstract strokeType: string;\n\n get repr(): string {\n return this.segments.map((segment) => segment.repr).join(\"\\n\") + \"\\n\";\n }\n constructor(segments: Segment[], { ignoreChecks = false } = {}) {\n super();\n if (!ignoreChecks) checkValidStroke(segments);\n this.segments = segments;\n }\n\n get firstPoint(): Vector {\n return this.segments[0].firstPoint;\n }\n\n get lastPoint(): Vector {\n return this.segments[this.segments.length - 1].lastPoint;\n }\n\n get segmentsCount(): number {\n return this.segments.length;\n }\n\n onStroke(point: Vector): boolean {\n return this.segments.some((segment) => segment.isOnSegment(point));\n }\n\n intersects(other: Stroke): boolean {\n if (!this.boundingBox.overlaps(other.boundingBox)) return false;\n return this.segments.some((segment) =>\n other.segments.some(\n (otherSegment) =>\n findIntersectionsAndOverlaps(segment, otherSegment).count > 0\n )\n );\n }\n\n private _boundingBox: BoundingBox | null = null;\n get boundingBox(): BoundingBox {\n if (this._boundingBox === null) {\n let bbox = this.segments[0].boundingBox;\n\n this.segments.slice(1).forEach((segment) => {\n bbox = bbox.merge(segment.boundingBox);\n });\n this._boundingBox = bbox;\n }\n return this._boundingBox;\n }\n\n abstract reverse(): T;\n\n abstract clone(): T;\n\n abstract transform(matrix: TransformationMatrix): T;\n\n abstract simplify(): T;\n\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.repr;\n }\n}\n\nexport function checkSelfIntersections(\n segments: Segment[],\n type = \"Stroke\"\n): void {\n allCombinations(segments.length).forEach(\n ([segmentIndex, otherSegmentIndex]) => {\n if (segmentIndex === otherSegmentIndex) return;\n const segment = segments[segmentIndex];\n const otherSegment = segments[otherSegmentIndex];\n\n const intersections = findIntersectionsAndOverlaps(segment, otherSegment);\n if (intersections.count === 0) return;\n if (intersections.count === 1 && !intersections.overlaps.length) {\n const distance = segmentIndex - otherSegmentIndex;\n\n const intersection = intersections.intersections[0];\n\n if (distance === 1) {\n if (sameVector(segment.firstPoint, intersection)) return;\n }\n if (distance === -1) {\n if (sameVector(segment.lastPoint, intersection)) return;\n }\n if (distance === segments.length - 1) {\n if (\n sameVector(segment.lastPoint, intersection) &&\n sameVector(otherSegment.firstPoint, intersection)\n )\n return;\n }\n if (-distance === segments.length - 1) {\n if (\n sameVector(segment.firstPoint, intersection) &&\n sameVector(otherSegment.lastPoint, intersection)\n )\n return;\n }\n }\n throw new Error(\n `${type} segments must not intersect, but segments ${segment.repr} and ${otherSegment.repr} do`\n );\n }\n );\n}\n\nexport function checkValidStroke(segments: Segment[], type = \"Stroke\"): void {\n if (segments.length === 0)\n throw new Error(`${type} must have at least one segment`);\n\n zip([segments.slice(0, -1), segments.slice(1)]).forEach(\n ([segment, nextSegment]) => {\n if (!sameVector(segment.lastPoint, nextSegment.firstPoint))\n throw new Error(\n `${type} segments must be connected, but ${segment.repr} and ${nextSegment.repr} are not`\n );\n }\n );\n\n checkSelfIntersections(segments, type);\n}\n","import type { Stroke } from \"../models/Stroke\";\nimport { Line } from \"../models/segments/Line\";\nimport { Segment } from \"../models/segments/Segment\";\nimport { parallel, sameVector } from \"../vectorOperations\";\nimport { Arc } from \"../models/segments/Arc\";\n\nfunction canExtendSegment(segment1: Segment, segment2: Segment): boolean {\n if (segment1 instanceof Line && segment2 instanceof Line) {\n if (parallel(segment1.V, segment2.V)) {\n return true;\n }\n }\n\n if (segment1 instanceof Arc && segment2 instanceof Arc) {\n if (\n sameVector(segment1.center, segment2.center) &&\n segment1.radius - segment2.radius < segment1.precision\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction extendSegment(segment1: Segment, segment2: Segment): Segment {\n if (segment1 instanceof Line && segment2 instanceof Line) {\n return new Line(segment1.firstPoint, segment2.lastPoint);\n }\n if (segment1 instanceof Arc && segment2 instanceof Arc) {\n // clockwise is the same for both segments, we would otherwise have some\n // self-intersections in the stroke\n return new Arc(\n segment1.firstPoint,\n segment2.lastPoint,\n segment1.center,\n segment1.clockwise\n );\n }\n\n throw new Error(\"Not implemented\");\n}\n\nexport function simplifySegments(stroke: Stroke): Segment[] | null {\n let foundSimplification = false;\n const simplifiedSegments: Segment[] = [];\n\n for (const segment of stroke.segments) {\n if (simplifiedSegments.length === 0) {\n simplifiedSegments.push(segment);\n continue;\n }\n\n const lastSegment = simplifiedSegments[simplifiedSegments.length - 1];\n if (canExtendSegment(lastSegment, segment)) {\n foundSimplification = true;\n simplifiedSegments.pop();\n simplifiedSegments.push(extendSegment(lastSegment, segment));\n } else {\n simplifiedSegments.push(segment);\n }\n }\n\n if (sameVector(stroke.firstPoint, stroke.lastPoint)) {\n if (\n canExtendSegment(\n simplifiedSegments[0],\n simplifiedSegments[simplifiedSegments.length - 1]\n )\n ) {\n foundSimplification = true;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSegment = simplifiedSegments.pop()!;\n simplifiedSegments[0] = extendSegment(lastSegment, simplifiedSegments[0]);\n }\n }\n\n if (!foundSimplification) return null;\n return simplifiedSegments;\n}\n","import { AbstractStroke } from \"./Stroke\";\n\nimport { TransformationMatrix } from \"./TransformationMatrix\";\nimport { sameVector } from \"../vectorOperations\";\nimport { simplifySegments } from \"../algorithms/simplify\";\n\nexport class Strand extends AbstractStroke<Strand> {\n strokeType = \"STRAND\";\n reverse(): Strand {\n const reversedSegments = this.segments.map((segment) => segment.reverse());\n reversedSegments.reverse();\n return new Strand(reversedSegments, { ignoreChecks: true });\n }\n\n clone(): Strand {\n return new Strand(\n this.segments.map((segment) => segment.clone()),\n { ignoreChecks: true }\n );\n }\n\n extend(strand: Strand): Strand {\n if (!sameVector(this.lastPoint, strand.firstPoint)) {\n console.error(this.repr, strand.repr);\n throw new Error(\"Cannot extend strand: connection point is not the same\");\n }\n return new Strand([...this.segments, ...strand.segments]);\n }\n\n simplify(): Strand {\n const newSegments = simplifySegments(this);\n if (!newSegments) return this;\n return new Strand(newSegments, { ignoreChecks: true });\n }\n\n transform(matrix: TransformationMatrix): Strand {\n return new Strand(\n this.segments.map((segment) => segment.transform(matrix)),\n { ignoreChecks: true }\n );\n }\n}\n","import { Line } from \"../../models/segments/Line\";\nimport { lineLineParams } from \"./lineLineIntersection\";\nimport type { Vector } from \"../../definitions\";\nimport { Segment } from \"../../models/segments/Segment\";\nimport { sameVector, squareDistance } from \"../../vectorOperations\";\nimport { Arc } from \"../../models/segments/Arc\";\n\nconst rayLineIntersectionsCount = (point: Vector, line: Line) => {\n const intersectionParams = lineLineParams(line, {\n V: [1, 0],\n firstPoint: point,\n precision: line.precision,\n });\n if (intersectionParams === \"parallel\") {\n // When the ray is parallel with the line, we can ignore its extremities.\n // They will be handled by the segments getting into and out of this one.\n return 0;\n }\n\n const { intersectionParam1, intersectionParam2 } = intersectionParams;\n\n if (!line.isValidParameter(intersectionParam1)) return 0;\n // With the ray we only check one side of the parameter\n if (intersectionParam2 <= -line.precision) return 0;\n\n // We need to check if the ray intersects the line segment at the extremities\n // In that case we considers that it crosses the segment if its midpoint is\n // above the line.\n\n if (\n Math.abs(intersectionParam1) < line.precision ||\n Math.abs(intersectionParam1 - 1) < line.precision\n ) {\n const [, y] = line.midPoint;\n return point[1] - y < 0 ? 1 : 0;\n }\n\n return 1;\n};\n\nconst rayArcIntersectionsCount = (point: Vector, arc: Arc) => {\n const epsilon = arc.precision;\n\n const verticalDistance = Math.abs(point[1] - arc.center[1]);\n\n // the line is above or below the circle\n if (verticalDistance > arc.radius + epsilon) return 0;\n\n const squareDist = squareDistance(point, arc.center);\n const squareR = arc.radius * arc.radius;\n const squareEpsilon = epsilon * epsilon;\n\n // On the border\n if (Math.abs(squareDist - squareR) < squareEpsilon && arc.isOnSegment(point))\n return 0;\n\n const pointOutsideCircle = squareDist - squareR > squareEpsilon;\n\n // the point is at the right of the circle\n if (pointOutsideCircle && arc.center[0] < point[0]) return 0;\n\n // delta corresponds to the length between the project center on the line and\n // the crossing points\n const delta = Math.sqrt(\n arc.radius * arc.radius - verticalDistance * verticalDistance\n );\n\n let intersectionsCount = 0;\n\n const updateIntersectionsCount = (intersectionPoint: Vector) => {\n if (!arc.isOnSegment(intersectionPoint)) return;\n\n // We extend the convention of the line ray interaction. We look at the\n // tangent at the point of intersection. If it is pointing to the top we\n // consider that the ray is crossing the arc.\n if (sameVector(intersectionPoint, arc.firstPoint)) {\n intersectionsCount += arc.tangentAtFirstPoint[1] > 0 ? 1 : 0;\n } else if (sameVector(intersectionPoint, arc.lastPoint)) {\n intersectionsCount += arc.tangentAtLastPoint[1] > 0 ? 0 : 1;\n } else {\n intersectionsCount += 1;\n }\n };\n\n // We might be able to optimise the check on segment, but it is not clear\n // that it is worth it\n updateIntersectionsCount([arc.center[0] + delta, point[1]]);\n\n if (pointOutsideCircle) {\n updateIntersectionsCount([arc.center[0] - delta, point[1]]);\n }\n\n return intersectionsCount;\n};\n\nexport function rayIntersectionsCount(point: Vector, segment: Segment): number {\n if (segment instanceof Line) {\n return rayLineIntersectionsCount(point, segment);\n }\n\n if (segment instanceof Arc) {\n return rayArcIntersectionsCount(point, segment);\n }\n\n throw new Error(\"Not implemented\");\n}\n","import type { Vector } from \"../definitions\";\nimport { rayIntersectionsCount } from \"../algorithms/intersections/rayIntersections\";\nimport { AbstractStroke, checkValidStroke } from \"./Stroke\";\nimport type { TransformationMatrix } from \"./TransformationMatrix\";\nimport { simplifySegments } from \"../algorithms/simplify\";\nimport { Segment } from \"./segments/Segment\";\nimport { sameVector } from \"../vectorOperations\";\nimport { Line } from \"./segments/Line\";\n\nexport class Loop extends AbstractStroke<Loop> {\n strokeType = \"LOOP\";\n\n constructor(segments: Segment[], { ignoreChecks = false } = {}) {\n super(segments, { ignoreChecks: true });\n if (!ignoreChecks) checkValidLoop(segments);\n }\n\n private _clockwise: boolean | null = null;\n get clockwise(): boolean {\n if (this._clockwise === null) {\n const vertices = this.segments.flatMap((c) => {\n if (!(c instanceof Line)) {\n // We just go with a simple approximation here, we should use some extrema\n // points instead, but this is quick (and good enough for now)\n return [c.firstPoint, c.paramPoint(0.5)];\n }\n return [c.firstPoint];\n });\n\n const approximateArea = vertices\n .map((v1, i) => {\n const v2 = vertices[(i + 1) % vertices.length];\n return (v2[0] - v1[0]) * (v2[1] + v1[1]);\n })\n .reduce((a, b) => a + b, 0);\n\n this._clockwise = approximateArea > 0;\n }\n return this._clockwise;\n }\n\n clone(): Loop {\n return new Loop(\n this.segments.map((segment) => segment.clone()),\n { ignoreChecks: true }\n );\n }\n\n reverse(): Loop {\n const reversedSegments = this.segments.map((segment) => segment.reverse());\n reversedSegments.reverse();\n return new Loop(reversedSegments, { ignoreChecks: true });\n }\n\n transform(matrix: TransformationMatrix): Loop {\n return new Loop(\n this.segments.map((segment) => segment.transform(matrix)),\n { ignoreChecks: true }\n );\n }\n\n contains(point: Vector): boolean {\n if (this.onStroke(point)) return false;\n if (!this.boundingBox.contains(point)) return false;\n\n const intersections = this.segments.reduce((acc, segment) => {\n return acc + rayIntersectionsCount(point, segment);\n }, 0);\n\n return intersections % 2 === 1;\n }\n\n simplify(): Loop {\n const newSegments = simplifySegments(this);\n if (!newSegments) return this;\n return new Loop(newSegments, { ignoreChecks: true });\n }\n}\n\nexport function checkValidLoop(segments: Segment[]): void {\n checkValidStroke(segments, \"Loop\");\n if (\n !sameVector(segments[0].firstPoint, segments[segments.length - 1].lastPoint)\n )\n throw new Error(\"Loop segment must be closed\");\n}\n","\nexport default class FlatQueue {\n\n constructor() {\n this.ids = [];\n this.values = [];\n this.length = 0;\n }\n\n clear() {\n this.length = 0;\n }\n\n push(id, value) {\n let pos = this.length++;\n\n while (pos > 0) {\n const parent = (pos - 1) >> 1;\n const parentValue = this.values[parent];\n if (value >= parentValue) break;\n this.ids[pos] = this.ids[parent];\n this.values[pos] = parentValue;\n pos = parent;\n }\n\n this.ids[pos] = id;\n this.values[pos] = value;\n }\n\n pop() {\n if (this.length === 0) return undefined;\n\n const top = this.ids[0];\n this.length--;\n\n if (this.length > 0) {\n const id = this.ids[0] = this.ids[this.length];\n const value = this.values[0] = this.values[this.length];\n const halfLength = this.length >> 1;\n let pos = 0;\n\n while (pos < halfLength) {\n let left = (pos << 1) + 1;\n const right = left + 1;\n let bestIndex = this.ids[left];\n let bestValue = this.values[left];\n const rightValue = this.values[right];\n\n if (right < this.length && rightValue < bestValue) {\n left = right;\n bestIndex = this.ids[right];\n bestValue = rightValue;\n }\n if (bestValue >= value) break;\n\n this.ids[pos] = bestIndex;\n this.values[pos] = bestValue;\n pos = left;\n }\n\n this.ids[pos] = id;\n this.values[pos] = value;\n }\n\n return top;\n }\n\n peek() {\n if (this.length === 0) return undefined;\n return this.ids[0];\n }\n\n peekValue() {\n if (this.length === 0) return undefined;\n return this.values[0];\n }\n\n shrink() {\n this.ids.length = this.values.length = this.length;\n }\n}\n","import FlatQueue from 'flatqueue';\n\nconst ARRAY_TYPES = [\n Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,\n Int32Array, Uint32Array, Float32Array, Float64Array\n];\n\nconst VERSION = 3; // serialized format version\n\nexport default class Flatbush {\n\n static from(data) {\n if (!data || data.byteLength === undefined || data.buffer) {\n throw new Error('Data must be an instance of ArrayBuffer or SharedArrayBuffer.');\n }\n const [magic, versionAndType] = new Uint8Array(data, 0, 2);\n if (magic !== 0xfb) {\n throw new Error('Data does not appear to be in a Flatbush format.');\n }\n if (versionAndType >> 4 !== VERSION) {\n throw new Error(`Got v${versionAndType >> 4} data when expected v${VERSION}.`);\n }\n const [nodeSize] = new Uint16Array(data, 2, 1);\n const [numItems] = new Uint32Array(data, 4, 1);\n\n return new Flatbush(numItems, nodeSize, ARRAY_TYPES[versionAndType & 0x0f], undefined, data);\n }\n\n constructor(numItems, nodeSize = 16, ArrayType = Float64Array, ArrayBufferType = ArrayBuffer, data) {\n if (numItems === undefined) throw new Error('Missing required argument: numItems.');\n if (isNaN(numItems) || numItems <= 0) throw new Error(`Unexpected numItems value: ${numItems}.`);\n\n this.numItems = +numItems;\n this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);\n\n // calculate the total number of nodes in the R-tree to allocate space for\n // and the index of each tree level (used in search later)\n let n = numItems;\n let numNodes = n;\n this._levelBounds = [n * 4];\n do {\n n = Math.ceil(n / this.nodeSize);\n numNodes += n;\n this._levelBounds.push(numNodes * 4);\n } while (n !== 1);\n\n this.ArrayType = ArrayType || Float64Array;\n this.IndexArrayType = numNodes < 16384 ? Uint16Array : Uint32Array;\n\n const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);\n const nodesByteSize = numNodes * 4 * this.ArrayType.BYTES_PER_ELEMENT;\n\n if (arrayTypeIndex < 0) {\n throw new Error(`Unexpected typed array class: ${ArrayType}.`);\n }\n\n if (data && data.byteLength !== undefined && !data.buffer) {\n this.data = data;\n this._boxes = new this.ArrayType(this.data, 8, numNodes * 4);\n this._indices = new this.IndexArrayType(this.data, 8 + nodesByteSize, numNodes);\n\n this._pos = numNodes * 4;\n this.minX = this._boxes[this._pos - 4];\n this.minY = this._boxes[this._pos - 3];\n this.maxX = this._boxes[this._pos - 2];\n this.maxY = this._boxes[this._pos - 1];\n\n } else {\n this.data = new ArrayBufferType(8 + nodesByteSize + numNodes * this.IndexArrayType.BYTES_PER_ELEMENT);\n this._boxes = new this.ArrayType(this.data, 8, numNodes * 4);\n this._indices = new this.IndexArrayType(this.data, 8 + nodesByteSize, numNodes);\n this._pos = 0;\n this.minX = Infinity;\n this.minY = Infinity;\n this.maxX = -Infinity;\n this.maxY = -Infinity;\n\n new Uint8Array(this.data, 0, 2).set([0xfb, (VERSION << 4) + arrayTypeIndex]);\n new Uint16Array(this.data, 2, 1)[0] = nodeSize;\n new Uint32Array(this.data, 4, 1)[0] = numItems;\n }\n\n // a priority queue for k-nearest-neighbors queries\n this._queue = new FlatQueue();\n }\n\n add(minX, minY, maxX, maxY) {\n const index = this._pos >> 2;\n const boxes = this._boxes;\n this._indices[index] = index;\n boxes[this._pos++] = minX;\n boxes[this._pos++] = minY;\n boxes[this._pos++] = maxX;\n boxes[this._pos++] = maxY;\n\n if (minX < this.minX) this.minX = minX;\n if (minY < this.minY) this.minY = minY;\n if (maxX > this.maxX) this.maxX = maxX;\n if (maxY > this.maxY) this.maxY = maxY;\n\n return index;\n }\n\n finish() {\n if (this._pos >> 2 !== this.numItems) {\n throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);\n }\n const boxes = this._boxes;\n\n if (this.numItems <= this.nodeSize) {\n // only one node, skip sorting and just fill the root box\n boxes[this._pos++] = this.minX;\n boxes[this._pos++] = this.minY;\n boxes[this._pos++] = this.maxX;\n boxes[this._pos++] = this.maxY;\n return;\n }\n\n const width = (this.maxX - this.minX) || 1;\n const height = (this.maxY - this.minY) || 1;\n const hilbertValues = new Uint32Array(this.numItems);\n const hilbertMax = (1 << 16) - 1;\n\n // map item centers into Hilbert coordinate space and calculate Hilbert values\n for (let i = 0, pos = 0; i < this.numItems; i++) {\n const minX = boxes[pos++];\n const minY = boxes[pos++];\n const maxX = boxes[pos++];\n const maxY = boxes[pos++];\n const x = Math.floor(hilbertMax * ((minX + maxX) / 2 - this.minX) / width);\n const y = Math.floor(hilbertMax * ((minY + maxY) / 2 - this.minY) / height);\n hilbertValues[i] = hilbert(x, y);\n }\n\n // sort items by their Hilbert value (for packing later)\n sort(hilbertValues, boxes, this._indices, 0, this.numItems - 1, this.nodeSize);\n\n // generate nodes at each tree level, bottom-up\n for (let i = 0, pos = 0; i < this._levelBounds.length - 1; i++) {\n const end = this._levelBounds[i];\n\n // generate a parent node for each block of consecutive <nodeSize> nodes\n while (pos < end) {\n const nodeIndex = pos;\n\n // calculate bbox for the new node\n let nodeMinX = boxes[pos++];\n let nodeMinY = boxes[pos++];\n let nodeMaxX = boxes[pos++];\n let nodeMaxY = boxes[pos++];\n for (let j = 1; j < this.nodeSize && pos < end; j++) {\n nodeMinX = Math.min(nodeMinX, boxes[pos++]);\n nodeMinY = Math.min(nodeMinY, boxes[pos++]);\n nodeMaxX = Math.max(nodeMaxX, boxes[pos++]);\n nodeMaxY = Math.max(nodeMaxY, boxes[pos++]);\n }\n\n // add the new node to the tree data\n this._indices[this._pos >> 2] = nodeIndex;\n boxes[this._pos++] = nodeMinX;\n boxes[this._pos++] = nodeMinY;\n boxes[this._pos++] = nodeMaxX;\n boxes[this._pos++] = nodeMaxY;\n }\n }\n }\n\n search(minX, minY, maxX, maxY, filterFn) {\n if (this._pos !== this._boxes.length) {\n throw new Error('Data not yet indexed - call index.finish().');\n }\n\n let nodeIndex = this._boxes.length - 4;\n const queue = [];\n const results = [];\n\n while (nodeIndex !== undefined) {\n // find the end index of the node\n const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));\n\n // search through child nodes\n for (let pos = nodeIndex; pos < end; pos += 4) {\n // check if node bbox intersects with query bbox\n if (maxX < this._boxes[pos]) continue; // maxX < nodeMinX\n if (maxY < this._boxes[pos + 1]) continue; // maxY < nodeMinY\n if (minX > this._boxes[pos + 2]) continue; // minX > nodeMaxX\n if (minY > this._boxes[pos + 3]) continue; // minY > nodeMaxY\n\n const index = this._indices[pos >> 2] | 0;\n\n if (nodeIndex >= this.numItems * 4) {\n queue.push(index); // node; add it to the search queue\n\n } else if (filterFn === undefined || filterFn(index)) {\n results.push(index); // leaf item\n }\n }\n\n nodeIndex = queue.pop();\n }\n\n return results;\n }\n\n neighbors(x, y, maxResults = Infinity, maxDistance = Infinity, filterFn) {\n if (this._pos !== this._boxes.length) {\n throw new Error('Data not yet indexed - call index.finish().');\n }\n\n let nodeIndex = this._boxes.length - 4;\n const q = this._queue;\n const results = [];\n const maxDistSquared = maxDistance * maxDistance;\n\n while (nodeIndex !== undefined) {\n // find the end index of the node\n const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));\n\n // add child nodes to the queue\n for (let pos = nodeIndex; pos < end; pos += 4) {\n const index = this._indices[pos >> 2] | 0;\n\n const dx = axisDist(x, this._boxes[pos], this._boxes[pos + 2]);\n const dy = axisDist(y, this._boxes[pos + 1], this._boxes[pos + 3]);\n const dist = dx * dx + dy * dy;\n\n if (nodeIndex >= this.numItems * 4) {\n q.push(index << 1, dist); // node (use even id)\n\n } else if (filterFn === undefined || filterFn(index)) {\n q.push((index << 1) + 1, dist); // leaf item (use odd id)\n }\n }\n\n // pop items from the queue\n while (q.length && (q.peek() & 1)) {\n const dist = q.peekValue();\n if (dist > maxDistSquared) {\n q.clear();\n return results;\n }\n results.push(q.pop() >> 1);\n\n if (results.length === maxResults) {\n q.clear();\n return results;\n }\n }\n\n nodeIndex = q.pop() >> 1;\n }\n\n q.clear();\n return results;\n }\n}\n\nfunction axisDist(k, min, max) {\n return k < min ? min - k : k <= max ? 0 : k - max;\n}\n\n// binary search for the first value in the array bigger than the given\nfunction upperBound(value, arr) {\n let i = 0;\n let j = arr.length - 1;\n while (i < j) {\n const m = (i + j) >> 1;\n if (arr[m] > value) {\n j = m;\n } else {\n i = m + 1;\n }\n }\n return arr[i];\n}\n\n// custom quicksort that partially sorts bbox data alongside the hilbert values\nfunction sort(values, boxes, indices, left, right, nodeSize) {\n if (Math.floor(left / nodeSize) >= Math.floor(right / nodeSize)) return;\n\n const pivot = values[(left + right) >> 1];\n let i = left - 1;\n let j = right + 1;\n\n while (true) {\n do i++; while (values[i] < pivot);\n do j--; while (values[j] > pivot);\n if (i >= j) break;\n swap(values, boxes, indices, i, j);\n }\n\n sort(values, boxes, indices, left, j, nodeSize);\n sort(values, boxes, indices, j + 1, right, nodeSize);\n}\n\n// swap two values and two corresponding boxes\nfunction swap(values, boxes, indices, i, j) {\n const temp = values[i];\n values[i] = values[j];\n values[j] = temp;\n\n const k = 4 * i;\n const m = 4 * j;\n\n const a = boxes[k];\n const b = boxes[k + 1];\n const c = boxes[k + 2];\n const d = boxes[k + 3];\n boxes[k] = boxes[m];\n boxes[k + 1] = boxes[m + 1];\n boxes[k + 2] = boxes[m + 2];\n boxes[k + 3] = boxes[m + 3];\n boxes[m] = a;\n boxes[m + 1] = b;\n boxes[m + 2] = c;\n boxes[m + 3] = d;\n\n const e = indices[i];\n indices[i] = indices[j];\n indices[j] = e;\n}\n\n// Fast Hilbert curve algorithm by http://threadlocalmutex.com/\n// Ported from C++ https://github.com/rawrunprotected/hilbert_curves (public domain)\nfunction hilbert(x, y) {\n let a = x ^ y;\n let b = 0xFFFF ^ a;\n let c = 0xFFFF ^ (x | y);\n let d = x & (y ^ 0xFFFF);\n\n let A = a | (b >> 1);\n let B = (a >> 1) ^ a;\n let C = ((c >> 1) ^ (b & (d >> 1))) ^ c;\n let D = ((a & (c >> 1)) ^ (d >> 1)) ^ d;\n\n a = A; b = B; c = C; d = D;\n A = ((a & (a >> 2)) ^ (b & (b >> 2)));\n B = ((a & (b >> 2)) ^ (b & ((a ^ b) >> 2)));\n C ^= ((a & (c >> 2)) ^ (b & (d >> 2)));\n D ^= ((b & (c >> 2)) ^ ((a ^ b) & (d >> 2)));\n\n a = A; b = B; c = C; d = D;\n A = ((a & (a >> 4)) ^ (b & (b >> 4)));\n B = ((a & (b >> 4)) ^ (b & ((a ^ b) >> 4)));\n C ^= ((a & (c >> 4)) ^ (b & (d >> 4)));\n D ^= ((b & (c >> 4)) ^ ((a ^ b) & (d >> 4)));\n\n a = A; b = B; c = C; d = D;\n C ^= ((a & (c >> 8)) ^ (b & (d >> 8)));\n D ^= ((b & (c >> 8)) ^ ((a ^ b) & (d >> 8)));\n\n a = C ^ (C >> 1);\n b = D ^ (D >> 1);\n\n let i0 = x ^ y;\n let i1 = b | (0xFFFF ^ (i0 | a));\n\n i0 = (i0 | (i0 << 8)) & 0x00FF00FF;\n i0 = (i0 | (i0 << 4)) & 0x0F0F0F0F;\n i0 = (i0 | (i0 << 2)) & 0x33333333;\n i0 = (i0 | (i0 << 1)) & 0x55555555;\n\n i1 = (i1 | (i1 << 8)) & 0x00FF00FF;\n i1 = (i1 | (i1 << 4)) & 0x0F0F0F0F;\n i1 = (i1 | (i1 << 2)) & 0x33333333;\n i1 = (i1 | (i1 << 1)) & 0x55555555;\n\n return ((i1 << 1) | i0) >>> 0;\n}\n","import Flatbush from \"flatbush\";\nimport { Segment } from \"../models/segments/Segment\";\n\nexport function stitchSegments(\n segments: Segment[],\n precision = 1e-7\n): Segment[][] {\n // We create a spacial index of the startpoints\n const startPoints = new Flatbush(segments.length);\n segments.forEach((c) => {\n const [x, y] = c.firstPoint;\n startPoints.add(x - precision, y - precision, x + precision, y + precision);\n });\n startPoints.finish();\n\n const stitchedSegments: Segment[][] = [];\n const visited = new Set<number>();\n\n segments.forEach((segment, index) => {\n if (visited.has(index)) return;\n\n const connectedSegments: Segment[] = [segment];\n let currentIndex = index;\n\n visited.add(index);\n\n // Once we have started a connected segment segment, we look for the next\n\n let maxLoops = segments.length;\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (maxLoops-- < 0) {\n throw new Error(\"Infinite loop detected\");\n }\n\n const lastPoint =\n connectedSegments[connectedSegments.length - 1].lastPoint;\n\n const [x, y] = lastPoint;\n const neighbors = startPoints.search(\n x - precision,\n y - precision,\n x + precision,\n y + precision\n );\n\n const indexDistance = (otherIndex: number) =>\n Math.abs((currentIndex - otherIndex) % segments.length);\n const potentialNextSegments = neighbors\n .filter((neighborIndex) => !visited.has(neighborIndex))\n .map((neighborIndex): [Segment, number, number] => [\n segments[neighborIndex],\n neighborIndex,\n indexDistance(neighborIndex),\n ])\n .sort(([, , a], [, , b]) => indexDistance(a) - indexDistance(b));\n\n if (potentialNextSegments.length === 0) {\n // No more segments to connect we should have wrapped\n stitchedSegments.push(connectedSegments);\n break;\n }\n\n const [nextSegment, nextSegmentIndex] = potentialNextSegments[0];\n\n connectedSegments.push(nextSegment);\n visited.add(nextSegmentIndex);\n currentIndex = nextSegmentIndex;\n }\n });\n\n return stitchedSegments;\n}\n","import { Vector } from \"../../definitions\";\nimport zip from \"../../utils/zip\";\n\nimport { Segment } from \"../../models/segments/Segment\";\nimport { Strand } from \"../../models/Strand\";\nimport { reprVector, sameVector } from \"../../vectorOperations\";\nimport { Loop } from \"../../models/Loop\";\nimport { findIntersectionsAndOverlaps } from \"../intersections\";\nimport removeDuplicatePoints from \"../../utils/removeDuplicatePoints\";\nimport { stitchSegments } from \"../stitchSegments\";\n\nconst rotateToStartAt = (segments: Segment[], point: Vector) => {\n const startIndex = segments.findIndex((segment: Segment) => {\n return sameVector(point, segment.firstPoint);\n });\n\n const start = segments.slice(0, startIndex);\n const end = segments.slice(startIndex);\n\n return end.concat(start);\n};\n\nconst rotateToStartAtSegment = (segments: Segment[], segment: Segment) => {\n let usedSegments = segments;\n\n const onSegment = (seg: Segment) => {\n return (\n sameVector(seg.firstPoint, segment.firstPoint) &&\n sameVector(seg.lastPoint, segment.lastPoint)\n );\n };\n\n let startIndex = segments.findIndex(onSegment);\n\n // it is also possible that the segment is oriented the other way. We still\n // need to align a start point\n if (startIndex === -1) {\n const reversedSegments = segments.map((s) => s.reverse());\n reversedSegments.reverse();\n startIndex = reversedSegments.findIndex(onSegment);\n if (startIndex === -1) {\n console.error(\n reversedSegments.map((c) => c.repr),\n segment.repr\n );\n throw new Error(\"Failed to rotate to segment start\");\n }\n usedSegments = reversedSegments;\n }\n\n const start = usedSegments.slice(0, startIndex);\n const end = usedSegments.slice(startIndex);\n\n return end.concat(start);\n};\n\nfunction* strandsBetweenIntersections(\n segments: Segment[],\n allIntersections: Vector[],\n allCommonSegments: Segment[]\n): Generator<Strand> {\n const endsAtIntersection = (segment: Segment) => {\n return allIntersections.some((intersection) => {\n return sameVector(intersection, segment.lastPoint);\n });\n };\n\n const isCommonSegment = (commonSegment: Segment) => {\n return allCommonSegments.some((segment) => {\n return commonSegment.isSame(segment);\n });\n };\n\n let currentCurves: Segment[] = [];\n for (const segment of segments) {\n // We ignore the checks at strand creation as these strands are part of\n // a loop and can be trusted to be valid\n if (endsAtIntersection(segment)) {\n currentCurves.push(segment);\n yield new Strand(currentCurves, { ignoreChecks: true });\n currentCurves = [];\n } else if (isCommonSegment(segment)) {\n if (currentCurves.length) {\n yield new Strand(currentCurves, { ignoreChecks: true });\n currentCurves = [];\n }\n yield new Strand([segment], { ignoreChecks: true });\n } else {\n currentCurves.push(segment);\n }\n }\n if (currentCurves.length) {\n yield new Strand(currentCurves, { ignoreChecks: true });\n }\n}\n\ntype IntersectionStrand = [Strand, Strand | \"same\"];\n\nfunction removeNonCrossingPoint(\n allIntersections: Vector[],\n segmentedCurve: Segment[],\n loopToCheck: Loop\n) {\n return allIntersections.filter((intersection: Vector) => {\n const segmentsOfIntersection = segmentedCurve.filter((s) => {\n return (\n sameVector(s.firstPoint, intersection) ||\n sameVector(s.lastPoint, intersection)\n );\n });\n if (segmentsOfIntersection.length % 2) {\n throw new Error(\"Bug in the intersection algo on non crossing point\");\n }\n\n const isInside = segmentsOfIntersection.map((segment: Segment): boolean => {\n return loopToCheck.contains(segment.midPoint);\n });\n\n // Either they are all inside or outside\n const segmentsOnTheSameSide =\n isInside.every((i) => i) || !isInside.some((i) => i);\n\n return !segmentsOnTheSameSide;\n });\n}\n\n/* When two shape intersect we cut them into segments between the intersection\n * points.\n *\n * This function returns the list of segments that have the same start and end\n * at the same intersection points or null if there is no intersection.\n */\nfunction loopIntersectionStrands(\n first: Loop,\n second: Loop,\n precision?: number\n): IntersectionStrand[] | null {\n // For each segment of each blueprint we figure out where the intersection\n // points are.\n let allIntersections: Vector[] = [];\n const allCommonSegments: Segment[] = [];\n\n const firstCurvePoints: Vector[][] = new Array(first.segments.length)\n .fill(0)\n .map(() => []);\n const secondCurvePoints: Vector[][] = new Array(second.segments.length)\n .fill(0)\n .map(() => []);\n\n first.segments.forEach((thisSegments, firstIndex) => {\n second.segments.forEach((otherSegments, secondIndex) => {\n const { intersections, overlaps } = findIntersectionsAndOverlaps(\n thisSegments,\n otherSegments,\n precision\n );\n\n allIntersections.push(...intersections);\n firstCurvePoints[firstIndex].push(...intersections);\n secondCurvePoints[secondIndex].push(...intersections);\n\n allCommonSegments.push(...overlaps);\n const commonSegmentsPoints = overlaps.flatMap((s) => [\n s.firstPoint,\n s.lastPoint,\n ]);\n allIntersections.push(...commonSegmentsPoints);\n firstCurvePoints[firstIndex].push(...commonSegmentsPoints);\n secondCurvePoints[secondIndex].push(...commonSegmentsPoints);\n });\n });\n\n allIntersections = removeDuplicatePoints(allIntersections, precision);\n\n // If there is only one intersection point we consider that the loops\n // are not intersecting\n if (!allIntersections.length || allIntersections.length === 1) return null;\n\n // We further split the segments at the intersections\n const cutCurve = ([segment, intersections]: [\n Segment,\n Vector[]\n ]): Segment[] => {\n if (!intersections.length) return [segment];\n return segment.splitAt(intersections);\n };\n let firstCurveSegments = zip([first.segments, firstCurvePoints] as [\n Segment[],\n Vector[][]\n ]).flatMap(cutCurve);\n\n let secondCurveSegments = zip([second.segments, secondCurvePoints] as [\n Segment[],\n Vector[][]\n ]).flatMap(cutCurve);\n\n // We need to remove intersection points that are not crossing into each\n // other (i.e. the two blueprints are only touching in one point and not\n // intersecting there.)\n allIntersections = removeNonCrossingPoint(\n allIntersections,\n firstCurveSegments,\n second\n );\n\n if (!allIntersections.length && !allCommonSegments.length) return null;\n\n // We align the beginning of the segments\n if (!allCommonSegments.length) {\n const startAt = allIntersections[0];\n firstCurveSegments = rotateToStartAt(firstCurveSegments, startAt);\n secondCurveSegments = rotateToStartAt(secondCurveSegments, startAt);\n } else {\n // When there are common segments we always start on one\n const startSegment = allCommonSegments[0];\n firstCurveSegments = rotateToStartAtSegment(\n firstCurveSegments,\n startSegment\n );\n secondCurveSegments = rotateToStartAtSegment(\n secondCurveSegments,\n startSegment\n );\n }\n\n // We group segments between intersections in strands\n let strandsFromFirst = Array.from(\n strandsBetweenIntersections(\n firstCurveSegments,\n allIntersections,\n allCommonSegments\n )\n );\n\n let strandsFromSecond = Array.from(\n strandsBetweenIntersections(\n secondCurveSegments,\n allIntersections,\n allCommonSegments\n )\n );\n\n if (\n !sameVector(\n strandsFromSecond[0].lastPoint,\n strandsFromFirst[0].lastPoint\n ) ||\n (allCommonSegments.length > 0 && strandsFromSecond[0].segmentsCount !== 1)\n ) {\n strandsFromSecond = strandsFromSecond.map((s) => s.reverse()).reverse();\n if (\n !sameVector(strandsFromSecond[0].lastPoint, strandsFromFirst[0].lastPoint)\n ) {\n strandsFromFirst = strandsFromFirst.map((s) => s.reverse()).reverse();\n }\n }\n\n return zip([strandsFromFirst, strandsFromSecond]).map(([first, second]) => {\n if (\n first.segmentsCount === 1 &&\n allCommonSegments.some((commonSegment) => {\n return first.segments[0].isSame(commonSegment);\n })\n ) {\n return [first, \"same\"];\n }\n return [first, second];\n });\n}\n\nfunction mergeStrandsAsLoop(strands: Strand[]) {\n let outStrand = strands[0];\n\n for (const strand of strands.slice(1)) {\n outStrand = outStrand.extend(strand);\n }\n\n if (!sameVector(outStrand.firstPoint, outStrand.lastPoint)) {\n console.error(\n reprVector(outStrand.firstPoint),\n reprVector(outStrand.lastPoint)\n );\n throw new Error(\"Bug in the intersection algo on non closing strand\");\n }\n\n return new Loop(outStrand.segments);\n}\n\nfunction mergeDiscontinuities(\n inputStrands: Strand[],\n discontinuities: number[]\n) {\n const strands = zip([\n discontinuities.slice(0, -1),\n discontinuities.slice(1),\n ]).map(([start, end]) => {\n return mergeStrandsAsLoop(inputStrands.slice(start, end));\n });\n\n let lastStrand = inputStrands.slice(\n discontinuities[discontinuities.length - 1]\n );\n if (discontinuities[0] !== 0) {\n lastStrand = lastStrand.concat(inputStrands.slice(0, discontinuities[0]));\n }\n strands.push(mergeStrandsAsLoop(lastStrand));\n\n return strands;\n}\n\nfunction groupLoops(inputStrands: Strand[]): Loop[] {\n if (!inputStrands.length) return [];\n\n const startPoints = inputStrands.map((c) => c.firstPoint);\n let endPoints = inputStrands.map((c) => c.lastPoint);\n endPoints = endPoints.slice(-1).concat(endPoints.slice(0, -1));\n\n const discontinuities = zip([startPoints, endPoints]).flatMap(\n ([startPoint, endPoint], index) => {\n if (!sameVector(startPoint, endPoint)) {\n return index;\n }\n return [];\n }\n );\n\n try {\n return mergeDiscontinuities(inputStrands, discontinuities);\n } catch (e) {\n // Sometimes the shapes are weird enough that our assumptions about the\n // strands do not work\n return stitchSegments(inputStrands.flatMap((s) => s.segments))\n .filter((c) => c.length > 1)\n .filter((c) => sameVector(c[0].firstPoint, c.at(-1)!.lastPoint))\n .map((c) => new Loop(c));\n }\n}\n\nconst extendStrandList = (strandList: Strand[], strand: Strand) => {\n if (strandList.length === 0) return [strand];\n const lastStrand = strandList.at(-1)!;\n if (sameVector(lastStrand.lastPoint, strand.firstPoint)) {\n return strandList.slice(0, -1).concat([lastStrand.extend(strand)]);\n } else if (sameVector(lastStrand.lastPoint, strand.lastPoint)) {\n return strandList\n .slice(0, -1)\n .concat([lastStrand.extend(strand.reverse())]);\n } else {\n return strandList.concat([strand]);\n }\n};\n\nconst prependStrandList = (strandList: Strand[], strand: Strand) => {\n if (strandList.length === 0) return [strand];\n if (sameVector(strandList[0].firstPoint, strand.lastPoint)) {\n return [strand.extend(strandList[0])].concat(strandList.slice(1));\n } else {\n return [strand].concat(strandList);\n }\n};\n\nexport function loopBooleanOperation(\n first: Loop,\n second: Loop,\n {\n firstInside,\n secondInside,\n }: {\n firstInside: \"keep\" | \"remove\";\n secondInside: \"keep\" | \"remove\";\n }\n):\n | Loop[]\n | { identical: true }\n | {\n firstCurveInSecond: boolean;\n secondCurveInFirst: boolean;\n identical: false;\n } {\n const strands = loopIntersectionStrands(first, second);\n\n // The case where we have no intersections\n if (!strands) {\n const firstStrandPoint = first.segments[0].midPoint;\n const firstCurveInSecond = second.contains(firstStrandPoint);\n\n const secondStrandPoint = second.segments[0].midPoint;\n const secondCurveInFirst = first.contains(secondStrandPoint);\n\n return {\n identical: false,\n firstCurveInSecond,\n secondCurveInFirst,\n };\n }\n\n if (strands.every(([, secondStrand]) => secondStrand === \"same\")) {\n return { identical: true };\n }\n\n let lastWasSame: null | Strand = null;\n let strandsIn: number | null = null;\n\n const s = strands.flatMap(([firstStrand, secondStrand]) => {\n let mergedStrands: Strand[] = [];\n let strandsOut = 0;\n\n // When two strands are on top of each other we base our decision on the\n // fact that every point should have one strand entering, and one going\n // out.\n if (secondStrand === \"same\") {\n if (strandsIn === 1) {\n strandsIn = 1;\n return firstStrand;\n }\n\n if (strandsIn === 2 || strandsIn === 0) {\n strandsIn = null;\n return [];\n }\n\n if (strandsIn === null) {\n if (!lastWasSame) lastWasSame = firstStrand;\n else lastWasSame = lastWasSame.extend(firstStrand);\n return [];\n }\n\n console.error(\"weird situation\");\n return [];\n }\n\n // Every strand is kept or removed according to the fact that it is within\n // or not of the other closed loop\n\n const firstSegmentPoint = firstStrand.segments[0].midPoint;\n const firstSegmentInSecondShape = second.contains(firstSegmentPoint);\n\n if (\n (firstInside === \"keep\" && firstSegmentInSecondShape) ||\n (firstInside === \"remove\" && !firstSegmentInSecondShape)\n ) {\n strandsOut += 1;\n mergedStrands = extendStrandList(mergedStrands, firstStrand);\n }\n\n const secondSegmentPoint = secondStrand.segments[0].midPoint;\n const secondSegmentInFirstShape = first.contains(secondSegmentPoint);\n\n if (\n (secondInside === \"keep\" && secondSegmentInFirstShape) ||\n (secondInside === \"remove\" && !secondSegmentInFirstShape)\n ) {\n const strandToAdd = secondStrand;\n\n strandsOut += 1;\n\n if (strandsOut === 2 && mergedStrands.length) {\n mergedStrands = extendStrandList(mergedStrands, strandToAdd);\n lastWasSame = null;\n } else {\n mergedStrands = [strandToAdd];\n }\n }\n\n // This is the case where the information about the strands entering the\n // previous node where not known and no strand was selected\n if (strandsIn === null && strandsOut === 1 && lastWasSame) {\n mergedStrands = prependStrandList(mergedStrands, lastWasSame);\n }\n\n if (strandsOut === 1) {\n strandsIn = strandsOut;\n lastWasSame = null;\n }\n if (!mergedStrands.length) {\n lastWasSame = null;\n return [];\n }\n return mergedStrands;\n });\n\n // We now have a bunch of strands, we need to group them into loops\n return groupLoops(s);\n}\n\nexport const fuseLoops = (first: Loop, second: Loop): Loop[] => {\n const result = loopBooleanOperation(first, second, {\n firstInside: \"remove\",\n secondInside: \"remove\",\n });\n\n if (Array.isArray(result)) return result;\n\n if (result.identical) {\n return [first];\n }\n\n if (result.firstCurveInSecond) {\n return [second];\n }\n\n if (result.secondCurveInFirst) {\n return [first];\n }\n\n return [first, second];\n};\n\nexport const cutLoops = (first: Loop, second: Loop): Loop[] => {\n const result = loopBooleanOperation(first, second, {\n firstInside: \"remove\",\n secondInside: \"keep\",\n });\n\n if (Array.isArray(result)) return result;\n\n if (result.identical) {\n return [];\n }\n\n if (result.firstCurveInSecond) {\n return [];\n }\n\n if (result.secondCurveInFirst) {\n return [first, second];\n }\n\n return [first];\n};\n\nexport const intersectLoops = (first: Loop, second: Loop): Loop[] => {\n const result = loopBooleanOperation(first, second, {\n firstInside: \"keep\",\n secondInside: \"keep\",\n });\n\n if (Array.isArray(result)) return result;\n\n if (result.identical) {\n return [first];\n }\n\n if (result.firstCurveInSecond) {\n return [first];\n }\n\n if (result.secondCurveInFirst) {\n return [second];\n }\n\n return [];\n};\n","import { Figure } from \"../../models/Figure\";\nimport { organiseLoops } from \"../organiseLoops\";\nimport { allPairs } from \"../../utils/allPairs\";\nimport { cutLoops, fuseLoops, intersectLoops } from \"./loopBooleans\";\n\nexport function fuseIntersectingFigures(figures: Figure[]) {\n const fused = new Map();\n\n const output: { current: Figure[] }[] = [];\n\n figures.forEach((inputFigure, i) => {\n let savedFigures: {\n current: Figure[];\n fusedWith: Set<number>;\n };\n\n if (fused.has(i)) {\n savedFigures = fused.get(i);\n } else {\n savedFigures = { current: [inputFigure], fusedWith: new Set([i]) };\n output.push(savedFigures);\n }\n\n figures.slice(i + 1).forEach((inputOtherFigure, j) => {\n const figure = savedFigures.current;\n\n const currentIndex = i + j + 1;\n\n if (savedFigures.fusedWith.has(currentIndex)) return;\n\n let otherFigure = [inputOtherFigure];\n let otherIsFused = false;\n\n if (fused.has(currentIndex)) {\n otherFigure = fused.get(currentIndex).current;\n otherIsFused = true;\n }\n\n const doListIntersect = figure.some((f) =>\n otherFigure.some((s) => f.intersects(s))\n );\n if (!doListIntersect) return;\n\n let newFused: Figure[];\n if (figure.length > 1 || otherFigure.length > 1) {\n newFused = fuseFiguresLists(figure, otherFigure);\n } else {\n newFused = fuseFigures(figure[0], otherFigure[0]);\n }\n\n savedFigures.fusedWith.add(currentIndex);\n savedFigures.current = newFused;\n if (!otherIsFused) fused.set(currentIndex, savedFigures);\n });\n });\n\n return output.flatMap(({ current }) => current);\n}\n\nexport function fuseFigures(first: Figure, second: Figure) {\n const outerFused = fuseLoops(first.contour, second.contour);\n\n const inner1Fused = second.holes.flatMap((c) => cutLoops(c, first.contour));\n const inner2Fused = first.holes.flatMap((c) => cutLoops(c, second.contour));\n\n const innerIntersections = allPairs(first.holes, second.holes).flatMap(\n ([first, second]) => intersectLoops(first, second)\n );\n\n return organiseLoops([\n ...outerFused,\n ...inner1Fused,\n ...inner2Fused,\n ...innerIntersections,\n ]);\n}\n\nexport function cutFigures(first: Figure, second: Figure): Figure[] {\n if (first.isFull && second.isFull) {\n return organiseLoops(cutLoops(first.contour, second.contour));\n }\n\n if (first.isFull) {\n const cutContour = cutLoops(first.contour, second.contour);\n const cutHoles = second.holes.flatMap((c) =>\n intersectLoops(c, first.contour)\n );\n // We might be able to assume that the contour and the holes are already\n // distinct figures.\n return organiseLoops([...cutContour, ...cutHoles]);\n } else if (second.isFull) {\n if (!first.contour.intersects(second.contour)) {\n if (!first.contour.contains(second.contour.firstPoint)) {\n // nothing to do here, the second figure is outside the first\n return [first];\n } else {\n const fusedCuts = fuseFiguresLists(\n first.holes.map((h) => new Figure(h)),\n [second]\n );\n\n return organiseLoops([\n first.contour,\n ...fusedCuts.flatMap((f) => f.allLoops),\n ]);\n }\n }\n }\n\n // We turn the last case in one where the second is full\n let newFigures = cutFigures(new Figure(first.contour), second);\n first.holes.forEach((cut) => {\n newFigures = newFigures.flatMap((c) => cutFigures(c, new Figure(cut)));\n });\n\n return newFigures;\n}\n\nexport function intersectFigures(first: Figure, second: Figure): Figure[] {\n const outerIntersection = intersectLoops(first.contour, second.contour);\n if (!outerIntersection.length) return [];\n\n let out = organiseLoops(outerIntersection);\n out = cutFiguresLists(\n out,\n first.holes.map((h) => new Figure(h))\n );\n\n // Here we need to do the cut in two steps, because the holes might intersect\n return cutFiguresLists(\n out,\n second.holes.map((h) => new Figure(h))\n );\n}\n\nexport function fuseFiguresLists(first: Figure[], second: Figure[]): Figure[] {\n if (!first.length) return second;\n if (!second.length) return first;\n\n if (\n (first.length === 1 && second.length > 1) ||\n (second.length === 1 && first.length > 1)\n ) {\n return fuseIntersectingFigures([...first, ...second]);\n }\n\n if (first.length > 1 && second.length > 1) {\n let out = fuseFiguresLists([first[0]], second);\n\n first.slice(1).forEach((fig) => {\n out = fuseFiguresLists([fig], out);\n });\n return out;\n }\n\n if (first.length === 1 && second.length === 1) {\n return fuseFigures(first[0], second[0]);\n }\n\n return [];\n}\n\nexport function cutFiguresLists(first: Figure[], second: Figure[]): Figure[] {\n if (!first.length) return [];\n if (!second.length) return first;\n\n // The easy case\n if (first.length === 1 && second.length === 1) {\n return cutFigures(first[0], second[0]);\n }\n\n if (first.length > 1) {\n // All the figures here are independant, so we can cut them independently\n return first.flatMap((fig) => cutFiguresLists([fig], second));\n }\n\n // We are now in the case where there is only one figure in the first list\n // and multiple figures in the second list\n //\n // We turn it in the case with (potentially) multiple figures in the first list\n // and one figure in the second list\n\n let out = cutFigures(first[0], second[0]);\n second.slice(1).forEach((fig) => {\n out = cutFiguresLists(out, [fig]);\n });\n return out;\n}\n\nexport function intersectFiguresLists(\n first: Figure[],\n second: Figure[]\n): Figure[] {\n if (!first.length || !second.length) {\n return [];\n }\n\n if (first.length === 1 && second.length === 1) {\n return intersectFigures(first[0], second[0]);\n }\n\n if (first.length > 1) {\n return first.flatMap((fig) => intersectFiguresLists([fig], second));\n }\n\n return second.flatMap((fig) => intersectFiguresLists(first, [fig]));\n}\n","import type { Vector } from \"../definitions\";\nimport { BoundingBox } from \"./BoundingBox\";\nimport type { Figure } from \"./Figure\";\nimport type { TransformationMatrix } from \"./TransformationMatrix\";\n\nimport {\n cutFiguresLists,\n fuseFiguresLists,\n intersectFiguresLists,\n} from \"../algorithms/boolean/figureBooleans\";\nimport { combineDifferentValues } from \"../utils/allCombinations\";\nimport { Transformable } from \"./utils/Transformable\";\n\nexport class Diagram extends Transformable<Diagram> {\n figures: Figure[];\n\n constructor(figures: Figure[] = [], { ignoreChecks = false } = {}) {\n super();\n if (!ignoreChecks) checkIsValidDiagram(figures);\n this.figures = figures;\n }\n\n private _boundingBox: BoundingBox | null = null;\n\n get isEmpty(): boolean {\n return this.figures.length === 0;\n }\n\n get boundingBox(): BoundingBox {\n if (this.isEmpty) return new BoundingBox();\n if (this._boundingBox === null) {\n let boundingBox = this.figures[0].boundingBox;\n for (const figure of this.figures.slice(1)) {\n boundingBox = boundingBox.merge(figure.boundingBox);\n }\n this._boundingBox = boundingBox;\n }\n return this._boundingBox;\n }\n\n clone(): Diagram {\n return new Diagram(this.figures.map((figure) => figure.clone()));\n }\n\n transform(matrix: TransformationMatrix): Diagram {\n return new Diagram(this.figures.map((figure) => figure.transform(matrix)));\n }\n\n contains(point: Vector): boolean {\n return this.figures.some((figure) => figure.contains(point));\n }\n\n intersects(other: Diagram): boolean {\n return this.figures.some((figure) =>\n other.figures.some((otherFigure) => figure.intersects(otherFigure))\n );\n }\n\n fuse(other: Diagram): Diagram {\n return new Diagram(fuseFiguresLists(this.figures, other.figures));\n }\n\n cut(other: Diagram): Diagram {\n return new Diagram(cutFiguresLists(this.figures, other.figures));\n }\n\n intersect(other: Diagram): Diagram {\n return new Diagram(intersectFiguresLists(this.figures, other.figures));\n }\n}\n\nexport function checkIsValidDiagram(figures: Figure[]): void {\n for (const [figure, otherFigure] of combineDifferentValues(figures)) {\n if (figure.intersects(otherFigure)) {\n throw new Error(\"Diagram figures must not intersect\");\n }\n }\n}\n","import { Arc } from \"../../models/segments/Arc\";\nimport { Line } from \"../../models/segments/Line\";\nimport { Segment } from \"../../models/segments/Segment\";\n\nexport function jsonSegment(segment: Segment) {\n if (segment instanceof Line) {\n return {\n type: segment.segmentType,\n firstPoint: segment.firstPoint,\n lastPoint: segment.lastPoint,\n };\n }\n if (segment instanceof Arc) {\n return {\n type: segment.segmentType,\n firstPoint: segment.firstPoint,\n lastPoint: segment.lastPoint,\n center: segment.center,\n clockwise: segment.clockwise,\n };\n }\n\n throw new Error(\"Unknown segment type\");\n}\n","import type { Loop } from \"../../models/Loop\";\nimport { jsonSegment } from \"./jsonSegment\";\n\nexport function jsonLoop(loop: Loop) {\n return {\n type: \"LOOP\",\n segments: loop.segments.map(jsonSegment),\n };\n}\n","import type { Figure } from \"../../models/Figure\";\nimport { jsonLoop } from \"./jsonLoop\";\n\nexport function jsonFigure(figure: Figure) {\n return {\n type: \"FIGURE\",\n contour: jsonLoop(figure.contour),\n holes: figure.holes.map(jsonLoop),\n };\n}\n","import { Diagram } from \"../../models/Diagram\";\nimport { jsonFigure } from \"./jsonFigure\";\n\nexport function jsonDiagram(diagram: Diagram) {\n return {\n type: \"DIAGRAM\",\n figures: diagram.figures.map(jsonFigure),\n };\n}\n","import { Diagram } from \"../../models/Diagram\";\nimport { Figure } from \"../../models/Figure\";\nimport { Loop } from \"../../models/Loop\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport { Line } from \"../../models/segments/Line\";\nimport { jsonDiagram } from \"./jsonDiagram\";\nimport { jsonFigure } from \"./jsonFigure\";\nimport { jsonLoop } from \"./jsonLoop\";\nimport { jsonSegment } from \"./jsonSegment\";\n\ntype Shape = Loop | Figure | Diagram | Arc | Line;\n\nexport function exportJSON(shape: Shape) {\n if (shape instanceof Diagram) {\n return jsonDiagram(shape);\n } else if (shape instanceof Figure) {\n return jsonFigure(shape);\n } else if (shape instanceof Loop) {\n return jsonLoop(shape);\n } else if (shape instanceof Arc || shape instanceof Line) {\n return jsonSegment(shape);\n } else {\n throw new Error(\"Unknown shape type\");\n }\n}\n"],"names":["overlap1D","min1","max1","min2","max2","BoundingBox","xMin","yMin","xMax","yMax","point","x","y","other","asFixed","p","precision","num","removeDuplicatePoints","points","p0","p1","DEG2RAD","reprVector","vector","sameVector","x0","y0","x1","y1","add","subtract","squareLength","scalarMultiply","scalar","squareDistance","distance","crossProduct","dotProduct","normalize","l","polarToCartesian","r","theta","polarAngle","cartesianToPolar","v","parallel","v1","v2","V1xV2","xLength","yLength","perpendicular","perpendicularClockwise","matMult","m1","m2","a","b","c","d","e","f","g","h","i","j","k","m","n","o","q","TransformationMatrix","angle","center","cos","sin","rotationMatrix","normal","Transformable","transform","factor","axisOrDirection","AbstractSegment","firstPoint","lastPoint","Line","linearPrecision","delta","u","intersection","pointVec","splitPoints","allPoints","uniquePoints","xChange","defaultDir","comparisonAxis","index","matrix","range","len","zip","arrays","minLength","arr","unitAngle","angularDistance","angle1","angle2","clockwise","relDistance","lineLineParams","line1","line2","squarePrecision","diffPoint","intersectionParam1","intersectionParam2","lineLineIntersection","includeOverlaps","intersectionParams","polarCoordsFromCenter","Arc","ignoreChecks","param","extendedR","validAngle","tangent","allParams","paramsMap","skipped","nextParam","startParam","arc","threePointsArc","midPoint","chord1","chord2","dir1","dir2","result","tangentArc","tangentAtFirstPoint","chord","dir","projectPointOnLine","line","lineArcIntersection","epsilon","centerOnLine","centerDistance","intersectionPoint","intersections","lineDir","p2","complementArc","handleOverlaps","arc1","arc2","startIndex","arcArcIntersection","centersDistance","radiusSum","radiusDifference","centersVector","isOutsideTangent","orientation","radiusToChord","halfChord","chordVector","findIntersections","segment1","segment2","findIntersectionsAndOverlaps","allCombinations","count","combineDifferentValues","array","Figure","contour","holes","checkIsValidFigure","hole","loop","otherLoop","loop1","loop2","hole1","hole2","exportJSON","groupByBoundingBoxOverlap","loops","overlaps","groups","groupsInOverlaps","indices","myGroup","addContainmentInfo","groupedLoops","isIn","potentialOuterLoop","splitMultipleOuterLoops","outerLoops","allLoops","outerLoop","cleanEdgeCases","handleNestedLoops","nestedLoops","firstLevelOuterLoops","innerLevelsLoops","organiseLoops","compounds","allPairs","list1","list2","l1","l2","AbstractStroke","segments","checkValidStroke","segment","otherSegment","bbox","checkSelfIntersections","type","segmentIndex","otherSegmentIndex","nextSegment","canExtendSegment","extendSegment","simplifySegments","stroke","foundSimplification","simplifiedSegments","lastSegment","Strand","reversedSegments","strand","newSegments","rayLineIntersectionsCount","rayArcIntersectionsCount","verticalDistance","squareDist","squareR","squareEpsilon","pointOutsideCircle","intersectionsCount","updateIntersectionsCount","rayIntersectionsCount","Loop","checkValidLoop","vertices","approximateArea","acc","FlatQueue","id","value","pos","parent","parentValue","top","halfLength","left","right","bestIndex","bestValue","rightValue","ARRAY_TYPES","VERSION","Flatbush","data","magic","versionAndType","nodeSize","numItems","ArrayType","ArrayBufferType","numNodes","arrayTypeIndex","nodesByteSize","minX","minY","maxX","maxY","boxes","width","height","hilbertValues","hilbertMax","hilbert","sort","end","nodeIndex","nodeMinX","nodeMinY","nodeMaxX","nodeMaxY","filterFn","queue","results","upperBound","maxResults","maxDistance","maxDistSquared","dx","axisDist","dy","dist","min","max","values","pivot","swap","temp","A","B","C","D","i0","i1","stitchSegments","startPoints","stitchedSegments","visited","connectedSegments","currentIndex","maxLoops","neighbors","indexDistance","otherIndex","potentialNextSegments","neighborIndex","nextSegmentIndex","rotateToStartAt","start","rotateToStartAtSegment","usedSegments","onSegment","seg","s","strandsBetweenIntersections","allIntersections","allCommonSegments","endsAtIntersection","isCommonSegment","commonSegment","currentCurves","removeNonCrossingPoint","segmentedCurve","loopToCheck","segmentsOfIntersection","isInside","loopIntersectionStrands","first","second","firstCurvePoints","secondCurvePoints","thisSegments","firstIndex","otherSegments","secondIndex","commonSegmentsPoints","cutCurve","firstCurveSegments","secondCurveSegments","startSegment","startAt","strandsFromFirst","strandsFromSecond","mergeStrandsAsLoop","strands","outStrand","mergeDiscontinuities","inputStrands","discontinuities","lastStrand","groupLoops","endPoints","startPoint","endPoint","extendStrandList","strandList","prependStrandList","loopBooleanOperation","firstInside","secondInside","firstStrandPoint","firstCurveInSecond","secondStrandPoint","secondCurveInFirst","secondStrand","lastWasSame","strandsIn","firstStrand","mergedStrands","strandsOut","firstSegmentPoint","firstSegmentInSecondShape","secondSegmentPoint","secondSegmentInFirstShape","strandToAdd","fuseLoops","cutLoops","intersectLoops","fuseIntersectingFigures","figures","fused","output","inputFigure","savedFigures","inputOtherFigure","figure","otherFigure","otherIsFused","newFused","fuseFiguresLists","fuseFigures","current","outerFused","inner1Fused","inner2Fused","innerIntersections","cutFigures","cutContour","cutHoles","fusedCuts","newFigures","cut","intersectFigures","outerIntersection","out","cutFiguresLists","fig","intersectFiguresLists","Diagram","checkIsValidDiagram","boundingBox","jsonSegment","jsonLoop","jsonFigure","jsonDiagram","diagram","shape"],"mappings":"aAEA,SAASA,EACPC,EACAC,EACAC,EACAC,EACS,CACF,OAAAH,GAAQG,GAAQF,GAAQ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