@tldraw/editor 3.14.0-canary.c69104f4d831 → 3.14.0-canary.d649afc753b1
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-cjs/index.d.ts +51 -46
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +2 -4
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager.js +5 -1
- package/dist-cjs/lib/editor/managers/FontManager.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +39 -33
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +13 -8
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +41 -21
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +11 -11
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +13 -16
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +4 -4
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Edge2d.js +14 -17
- package/dist-cjs/lib/primitives/geometry/Edge2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +10 -10
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Point2d.js +6 -6
- package/dist-cjs/lib/primitives/geometry/Point2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js +3 -0
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +8 -5
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js +22 -11
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +22 -22
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/utils/areShapesContentEqual.js +1 -1
- package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +51 -46
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +2 -4
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager.mjs +5 -1
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +39 -33
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +13 -8
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +41 -21
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +13 -16
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +4 -4
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs +14 -17
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Point2d.mjs +6 -6
- package/dist-esm/lib/primitives/geometry/Point2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs +3 -0
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +8 -5
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs +22 -11
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +22 -22
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/utils/areShapesContentEqual.mjs +1 -1
- package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/lib/editor/Editor.ts +3 -4
- package/src/lib/editor/managers/FontManager.ts +5 -1
- package/src/lib/primitives/Box.test.ts +588 -7
- package/src/lib/primitives/Box.ts +41 -33
- package/src/lib/primitives/Vec.test.ts +2 -2
- package/src/lib/primitives/Vec.ts +13 -8
- package/src/lib/primitives/geometry/Arc2d.ts +42 -23
- package/src/lib/primitives/geometry/Circle2d.ts +12 -12
- package/src/lib/primitives/geometry/CubicBezier2d.test.ts +5 -0
- package/src/lib/primitives/geometry/CubicBezier2d.ts +13 -17
- package/src/lib/primitives/geometry/CubicSpline2d.ts +5 -5
- package/src/lib/primitives/geometry/Edge2d.ts +14 -18
- package/src/lib/primitives/geometry/Ellipse2d.ts +12 -13
- package/src/lib/primitives/geometry/Point2d.ts +6 -6
- package/src/lib/primitives/geometry/Polygon2d.ts +4 -0
- package/src/lib/primitives/geometry/Polyline2d.ts +10 -7
- package/src/lib/primitives/geometry/Rectangle2d.ts +24 -11
- package/src/lib/primitives/geometry/Stadium2d.ts +22 -23
- package/src/lib/utils/areShapesContentEqual.ts +2 -1
- package/src/version.ts +3 -3
|
@@ -5,30 +5,38 @@ import { Geometry2d } from "./Geometry2d.mjs";
|
|
|
5
5
|
import { getVerticesCountForLength } from "./geometry-constants.mjs";
|
|
6
6
|
class Arc2d extends Geometry2d {
|
|
7
7
|
_center;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
_radius;
|
|
9
|
+
_start;
|
|
10
|
+
_end;
|
|
11
|
+
_largeArcFlag;
|
|
12
|
+
_sweepFlag;
|
|
13
|
+
_measure;
|
|
14
|
+
_angleStart;
|
|
15
|
+
_angleEnd;
|
|
16
16
|
constructor(config) {
|
|
17
17
|
super({ ...config, isFilled: false, isClosed: false });
|
|
18
18
|
const { center, sweepFlag, largeArcFlag, start, end } = config;
|
|
19
19
|
if (start.equals(end)) throw Error(`Arc must have different start and end points.`);
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
20
|
+
this._angleStart = Vec.Angle(center, start);
|
|
21
|
+
this._angleEnd = Vec.Angle(center, end);
|
|
22
|
+
this._radius = Vec.Dist(center, start);
|
|
23
|
+
this._measure = getArcMeasure(this._angleStart, this._angleEnd, sweepFlag, largeArcFlag);
|
|
24
|
+
this._start = start;
|
|
25
|
+
this._end = end;
|
|
26
|
+
this._sweepFlag = sweepFlag;
|
|
27
|
+
this._largeArcFlag = largeArcFlag;
|
|
28
28
|
this._center = center;
|
|
29
29
|
}
|
|
30
30
|
nearestPoint(point) {
|
|
31
|
-
const {
|
|
31
|
+
const {
|
|
32
|
+
_center,
|
|
33
|
+
_measure: measure,
|
|
34
|
+
_radius: radius,
|
|
35
|
+
_angleEnd: angleEnd,
|
|
36
|
+
_angleStart: angleStart,
|
|
37
|
+
_start: A,
|
|
38
|
+
_end: B
|
|
39
|
+
} = this;
|
|
32
40
|
const t = getPointInArcT(measure, angleStart, angleEnd, _center.angle(point));
|
|
33
41
|
if (t <= 0) return A;
|
|
34
42
|
if (t >= 1) return B;
|
|
@@ -47,7 +55,13 @@ class Arc2d extends Geometry2d {
|
|
|
47
55
|
return nearest;
|
|
48
56
|
}
|
|
49
57
|
hitTestLineSegment(A, B) {
|
|
50
|
-
const {
|
|
58
|
+
const {
|
|
59
|
+
_center,
|
|
60
|
+
_radius: radius,
|
|
61
|
+
_measure: measure,
|
|
62
|
+
_angleStart: angleStart,
|
|
63
|
+
_angleEnd: angleEnd
|
|
64
|
+
} = this;
|
|
51
65
|
const intersection = intersectLineSegmentCircle(A, B, _center, radius);
|
|
52
66
|
if (intersection === null) return false;
|
|
53
67
|
return intersection.some((p) => {
|
|
@@ -56,7 +70,7 @@ class Arc2d extends Geometry2d {
|
|
|
56
70
|
});
|
|
57
71
|
}
|
|
58
72
|
getVertices() {
|
|
59
|
-
const { _center, measure, length, radius, angleStart } = this;
|
|
73
|
+
const { _center, _measure: measure, length, _radius: radius, _angleStart: angleStart } = this;
|
|
60
74
|
const vertices = [];
|
|
61
75
|
for (let i = 0, n = getVerticesCountForLength(Math.abs(length)); i < n + 1; i++) {
|
|
62
76
|
const t = i / n * measure;
|
|
@@ -66,11 +80,17 @@ class Arc2d extends Geometry2d {
|
|
|
66
80
|
return vertices;
|
|
67
81
|
}
|
|
68
82
|
getSvgPathData(first = true) {
|
|
69
|
-
const {
|
|
83
|
+
const {
|
|
84
|
+
_start: start,
|
|
85
|
+
_end: end,
|
|
86
|
+
_radius: radius,
|
|
87
|
+
_largeArcFlag: largeArcFlag,
|
|
88
|
+
_sweepFlag: sweepFlag
|
|
89
|
+
} = this;
|
|
70
90
|
return `${first ? `M${start.toFixed()}` : ``} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.toFixed()}`;
|
|
71
91
|
}
|
|
72
92
|
getLength() {
|
|
73
|
-
return Math.abs(this.
|
|
93
|
+
return Math.abs(this._measure * this._radius);
|
|
74
94
|
}
|
|
75
95
|
}
|
|
76
96
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Arc2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { intersectLineSegmentCircle } from '../intersect'\nimport { getArcMeasure, getPointInArcT, getPointOnCircle } from '../utils'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Arc2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,eAAe,gBAAgB,wBAAwB;AAChE,SAAS,kBAAqC;AAC9C,SAAS,iCAAiC;AAGnC,MAAM,cAAc,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { intersectLineSegmentCircle } from '../intersect'\nimport { getArcMeasure, getPointInArcT, getPointOnCircle } from '../utils'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Arc2d extends Geometry2d {\n\tprivate _center: Vec\n\tprivate _radius: number\n\tprivate _start: Vec\n\tprivate _end: Vec\n\tprivate _largeArcFlag: number\n\tprivate _sweepFlag: number\n\tprivate _measure: number\n\tprivate _angleStart: number\n\tprivate _angleEnd: number\n\n\tconstructor(\n\t\tconfig: Omit<Geometry2dOptions, 'isFilled' | 'isClosed'> & {\n\t\t\tcenter: Vec\n\t\t\tstart: Vec\n\t\t\tend: Vec\n\t\t\tsweepFlag: number\n\t\t\tlargeArcFlag: number\n\t\t}\n\t) {\n\t\tsuper({ ...config, isFilled: false, isClosed: false })\n\t\tconst { center, sweepFlag, largeArcFlag, start, end } = config\n\t\tif (start.equals(end)) throw Error(`Arc must have different start and end points.`)\n\n\t\t// ensure that the start and end are clockwise\n\t\tthis._angleStart = Vec.Angle(center, start)\n\t\tthis._angleEnd = Vec.Angle(center, end)\n\t\tthis._radius = Vec.Dist(center, start)\n\t\tthis._measure = getArcMeasure(this._angleStart, this._angleEnd, sweepFlag, largeArcFlag)\n\n\t\tthis._start = start\n\t\tthis._end = end\n\n\t\tthis._sweepFlag = sweepFlag\n\t\tthis._largeArcFlag = largeArcFlag\n\t\tthis._center = center\n\t}\n\n\tnearestPoint(point: VecLike): Vec {\n\t\tconst {\n\t\t\t_center,\n\t\t\t_measure: measure,\n\t\t\t_radius: radius,\n\t\t\t_angleEnd: angleEnd,\n\t\t\t_angleStart: angleStart,\n\t\t\t_start: A,\n\t\t\t_end: B,\n\t\t} = this\n\t\tconst t = getPointInArcT(measure, angleStart, angleEnd, _center.angle(point))\n\t\tif (t <= 0) return A\n\t\tif (t >= 1) return B\n\n\t\t// Get the point (P) on the arc, then pick the nearest of A, B, and P\n\t\tconst P = Vec.Sub(point, _center).uni().mul(radius).add(_center)\n\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number\n\t\tfor (const p of [A, B, P]) {\n\t\t\td = Vec.Dist2(point, p)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike): boolean {\n\t\tconst {\n\t\t\t_center,\n\t\t\t_radius: radius,\n\t\t\t_measure: measure,\n\t\t\t_angleStart: angleStart,\n\t\t\t_angleEnd: angleEnd,\n\t\t} = this\n\t\tconst intersection = intersectLineSegmentCircle(A, B, _center, radius)\n\t\tif (intersection === null) return false\n\n\t\treturn intersection.some((p) => {\n\t\t\tconst result = getPointInArcT(measure, angleStart, angleEnd, _center.angle(p))\n\t\t\treturn result >= 0 && result <= 1\n\t\t})\n\t}\n\n\tgetVertices(): Vec[] {\n\t\tconst { _center, _measure: measure, length, _radius: radius, _angleStart: angleStart } = this\n\t\tconst vertices: Vec[] = []\n\t\tfor (let i = 0, n = getVerticesCountForLength(Math.abs(length)); i < n + 1; i++) {\n\t\t\tconst t = (i / n) * measure\n\t\t\tconst angle = angleStart + t\n\t\t\tvertices.push(getPointOnCircle(_center, radius, angle))\n\t\t}\n\t\treturn vertices\n\t}\n\n\tgetSvgPathData(first = true) {\n\t\tconst {\n\t\t\t_start: start,\n\t\t\t_end: end,\n\t\t\t_radius: radius,\n\t\t\t_largeArcFlag: largeArcFlag,\n\t\t\t_sweepFlag: sweepFlag,\n\t\t} = this\n\t\treturn `${first ? `M${start.toFixed()}` : ``} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.toFixed()}`\n\t}\n\n\toverride getLength() {\n\t\treturn Math.abs(this._measure * this._radius)\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,eAAe,gBAAgB,wBAAwB;AAChE,SAAS,kBAAqC;AAC9C,SAAS,iCAAiC;AAGnC,MAAM,cAAc,WAAW;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACC,QAOC;AACD,UAAM,EAAE,GAAG,QAAQ,UAAU,OAAO,UAAU,MAAM,CAAC;AACrD,UAAM,EAAE,QAAQ,WAAW,cAAc,OAAO,IAAI,IAAI;AACxD,QAAI,MAAM,OAAO,GAAG,EAAG,OAAM,MAAM,+CAA+C;AAGlF,SAAK,cAAc,IAAI,MAAM,QAAQ,KAAK;AAC1C,SAAK,YAAY,IAAI,MAAM,QAAQ,GAAG;AACtC,SAAK,UAAU,IAAI,KAAK,QAAQ,KAAK;AACrC,SAAK,WAAW,cAAc,KAAK,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AAQ,SAAS,QAAQ,aAAa,WAAW,IAAI;AACzF,UAAM,WAAkB,CAAC;AACzB,aAAS,IAAI,GAAG,IAAI,0BAA0B,KAAK,IAAI,MAAM,CAAC,GAAG,IAAI,IAAI,GAAG,KAAK;AAChF,YAAM,IAAK,IAAI,IAAK;AACpB,YAAM,QAAQ,aAAa;AAC3B,eAAS,KAAK,iBAAiB,SAAS,QAAQ,KAAK,CAAC;AAAA,IACvD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,eAAe,QAAQ,MAAM;AAC5B,UAAM;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,SAAS;AAAA,MACT,eAAe;AAAA,MACf,YAAY;AAAA,IACb,IAAI;AACJ,WAAO,GAAG,QAAQ,IAAI,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,MAAM,IAAI,MAAM,MAAM,YAAY,IAAI,SAAS,IAAI,IAAI,QAAQ,CAAC;AAAA,EAClH;AAAA,EAES,YAAY;AACpB,WAAO,KAAK,IAAI,KAAK,WAAW,KAAK,OAAO;AAAA,EAC7C;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,20 +9,20 @@ class Circle2d extends Geometry2d {
|
|
|
9
9
|
super({ isClosed: true, ...config });
|
|
10
10
|
this.config = config;
|
|
11
11
|
const { x = 0, y = 0, radius } = config;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this._x = x;
|
|
13
|
+
this._y = y;
|
|
14
14
|
this._center = new Vec(radius + x, radius + y);
|
|
15
|
-
this.
|
|
15
|
+
this._radius = radius;
|
|
16
16
|
}
|
|
17
17
|
_center;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
_radius;
|
|
19
|
+
_x;
|
|
20
|
+
_y;
|
|
21
21
|
getBounds() {
|
|
22
|
-
return new Box(this.
|
|
22
|
+
return new Box(this._x, this._y, this._radius * 2, this._radius * 2);
|
|
23
23
|
}
|
|
24
24
|
getVertices() {
|
|
25
|
-
const { _center, radius } = this;
|
|
25
|
+
const { _center, _radius: radius } = this;
|
|
26
26
|
const perimeter = PI2 * radius;
|
|
27
27
|
const vertices = [];
|
|
28
28
|
for (let i = 0, n = getVerticesCountForLength(perimeter); i < n; i++) {
|
|
@@ -32,16 +32,16 @@ class Circle2d extends Geometry2d {
|
|
|
32
32
|
return vertices;
|
|
33
33
|
}
|
|
34
34
|
nearestPoint(point) {
|
|
35
|
-
const { _center, radius } = this;
|
|
35
|
+
const { _center, _radius: radius } = this;
|
|
36
36
|
if (_center.equals(point)) return Vec.AddXY(_center, radius, 0);
|
|
37
37
|
return Vec.Sub(point, _center).uni().mul(radius).add(_center);
|
|
38
38
|
}
|
|
39
39
|
hitTestLineSegment(A, B, distance = 0) {
|
|
40
|
-
const { _center, radius } = this;
|
|
40
|
+
const { _center, _radius: radius } = this;
|
|
41
41
|
return intersectLineSegmentCircle(A, B, _center, radius + distance) !== null;
|
|
42
42
|
}
|
|
43
43
|
getSvgPathData() {
|
|
44
|
-
const { _center, radius } = this;
|
|
44
|
+
const { _center, _radius: radius } = this;
|
|
45
45
|
return `M${_center.x + radius},${_center.y} a${radius},${radius} 0 1,0 ${radius * 2},0a${radius},${radius} 0 1,0 -${radius * 2},0`;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Circle2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { intersectLineSegmentCircle } from '../intersect'\nimport { PI2, getPointOnCircle } from '../utils'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Circle2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,KAAK,wBAAwB;AACtC,SAAS,kBAAqC;AAC9C,SAAS,iCAAiC;AAGnC,MAAM,iBAAiB,WAAW;AAAA,EAMxC,YACQ,QAMN;AACD,UAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAAC;AAP5B;AAQP,UAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,IAAI;AACjC,SAAK,
|
|
4
|
+
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { intersectLineSegmentCircle } from '../intersect'\nimport { PI2, getPointOnCircle } from '../utils'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Circle2d extends Geometry2d {\n\tprivate _center: Vec\n\tprivate _radius: number\n\tprivate _x: number\n\tprivate _y: number\n\n\tconstructor(\n\t\tpublic config: Omit<Geometry2dOptions, 'isClosed'> & {\n\t\t\tx?: number\n\t\t\ty?: number\n\t\t\tradius: number\n\t\t\tisFilled: boolean\n\t\t}\n\t) {\n\t\tsuper({ isClosed: true, ...config })\n\t\tconst { x = 0, y = 0, radius } = config\n\t\tthis._x = x\n\t\tthis._y = y\n\t\tthis._center = new Vec(radius + x, radius + y)\n\t\tthis._radius = radius\n\t}\n\n\tgetBounds() {\n\t\treturn new Box(this._x, this._y, this._radius * 2, this._radius * 2)\n\t}\n\n\tgetVertices(): Vec[] {\n\t\tconst { _center, _radius: radius } = this\n\t\tconst perimeter = PI2 * radius\n\t\tconst vertices: Vec[] = []\n\t\tfor (let i = 0, n = getVerticesCountForLength(perimeter); i < n; i++) {\n\t\t\tconst angle = (i / n) * PI2\n\t\t\tvertices.push(getPointOnCircle(_center, radius, angle))\n\t\t}\n\t\treturn vertices\n\t}\n\n\tnearestPoint(point: VecLike): Vec {\n\t\tconst { _center, _radius: radius } = this\n\t\tif (_center.equals(point)) return Vec.AddXY(_center, radius, 0)\n\t\treturn Vec.Sub(point, _center).uni().mul(radius).add(_center)\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, distance = 0): boolean {\n\t\tconst { _center, _radius: radius } = this\n\t\treturn intersectLineSegmentCircle(A, B, _center, radius + distance) !== null\n\t}\n\n\tgetSvgPathData(): string {\n\t\tconst { _center, _radius: radius } = this\n\t\treturn `M${_center.x + radius},${_center.y} a${radius},${radius} 0 1,0 ${radius * 2},0a${radius},${radius} 0 1,0 -${radius * 2},0`\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,KAAK,wBAAwB;AACtC,SAAS,kBAAqC;AAC9C,SAAS,iCAAiC;AAGnC,MAAM,iBAAiB,WAAW;AAAA,EAMxC,YACQ,QAMN;AACD,UAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAAC;AAP5B;AAQP,UAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,IAAI;AACjC,SAAK,KAAK;AACV,SAAK,KAAK;AACV,SAAK,UAAU,IAAI,IAAI,SAAS,GAAG,SAAS,CAAC;AAC7C,SAAK,UAAU;AAAA,EAChB;AAAA,EAnBQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAkBR,YAAY;AACX,WAAO,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,UAAU,GAAG,KAAK,UAAU,CAAC;AAAA,EACpE;AAAA,EAEA,cAAqB;AACpB,UAAM,EAAE,SAAS,SAAS,OAAO,IAAI;AACrC,UAAM,YAAY,MAAM;AACxB,UAAM,WAAkB,CAAC;AACzB,aAAS,IAAI,GAAG,IAAI,0BAA0B,SAAS,GAAG,IAAI,GAAG,KAAK;AACrE,YAAM,QAAS,IAAI,IAAK;AACxB,eAAS,KAAK,iBAAiB,SAAS,QAAQ,KAAK,CAAC;AAAA,IACvD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,aAAa,OAAqB;AACjC,UAAM,EAAE,SAAS,SAAS,OAAO,IAAI;AACrC,QAAI,QAAQ,OAAO,KAAK,EAAG,QAAO,IAAI,MAAM,SAAS,QAAQ,CAAC;AAC9D,WAAO,IAAI,IAAI,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,IAAI,OAAO;AAAA,EAC7D;AAAA,EAEA,mBAAmB,GAAY,GAAY,WAAW,GAAY;AACjE,UAAM,EAAE,SAAS,SAAS,OAAO,IAAI;AACrC,WAAO,2BAA2B,GAAG,GAAG,SAAS,SAAS,QAAQ,MAAM;AAAA,EACzE;AAAA,EAEA,iBAAyB;AACxB,UAAM,EAAE,SAAS,SAAS,OAAO,IAAI;AACrC,WAAO,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,CAAC,KAAK,MAAM,IAAI,MAAM,UAAU,SAAS,CAAC,MAAM,MAAM,IAAI,MAAM,WAAW,SAAS,CAAC;AAAA,EAC/H;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Vec } from "../Vec.mjs";
|
|
2
2
|
import { Polyline2d } from "./Polyline2d.mjs";
|
|
3
3
|
class CubicBezier2d extends Polyline2d {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
_a;
|
|
5
|
+
_b;
|
|
6
|
+
_c;
|
|
7
|
+
_d;
|
|
8
8
|
constructor(config) {
|
|
9
9
|
const { start: a, cp1: b, cp2: c, end: d } = config;
|
|
10
10
|
super({ ...config, points: [a, d] });
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
11
|
+
this._a = a;
|
|
12
|
+
this._b = b;
|
|
13
|
+
this._c = c;
|
|
14
|
+
this._d = d;
|
|
15
15
|
}
|
|
16
16
|
getVertices() {
|
|
17
17
|
const vertices = [];
|
|
18
|
-
const { a, b, c, d } = this;
|
|
18
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
19
19
|
for (let i = 0, n = 10; i <= n; i++) {
|
|
20
20
|
const t = i / n;
|
|
21
21
|
vertices.push(
|
|
@@ -27,9 +27,6 @@ class CubicBezier2d extends Polyline2d {
|
|
|
27
27
|
}
|
|
28
28
|
return vertices;
|
|
29
29
|
}
|
|
30
|
-
midPoint() {
|
|
31
|
-
return CubicBezier2d.GetAtT(this, 0.5);
|
|
32
|
-
}
|
|
33
30
|
nearestPoint(A) {
|
|
34
31
|
let nearest;
|
|
35
32
|
let dist = Infinity;
|
|
@@ -47,18 +44,18 @@ class CubicBezier2d extends Polyline2d {
|
|
|
47
44
|
return nearest;
|
|
48
45
|
}
|
|
49
46
|
getSvgPathData(first = true) {
|
|
50
|
-
const { a, b, c, d } = this;
|
|
47
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
51
48
|
return `${first ? `M ${a.toFixed()} ` : ``} C${b.toFixed()} ${c.toFixed()} ${d.toFixed()}`;
|
|
52
49
|
}
|
|
53
50
|
static GetAtT(segment, t) {
|
|
54
|
-
const { a, b, c, d } = segment;
|
|
51
|
+
const { _a: a, _b: b, _c: c, _d: d } = segment;
|
|
55
52
|
return new Vec(
|
|
56
53
|
(1 - t) * (1 - t) * (1 - t) * a.x + 3 * ((1 - t) * (1 - t)) * t * b.x + 3 * (1 - t) * (t * t) * c.x + t * t * t * d.x,
|
|
57
54
|
(1 - t) * (1 - t) * (1 - t) * a.y + 3 * ((1 - t) * (1 - t)) * t * b.y + 3 * (1 - t) * (t * t) * c.y + t * t * t * d.y
|
|
58
55
|
);
|
|
59
56
|
}
|
|
60
|
-
getLength(
|
|
61
|
-
let n1, p1 = this.
|
|
57
|
+
getLength(_filters, precision = 32) {
|
|
58
|
+
let n1, p1 = this._a, length = 0;
|
|
62
59
|
for (let i = 1; i <= precision; i++) {
|
|
63
60
|
n1 = CubicBezier2d.GetAtT(this, i / precision);
|
|
64
61
|
length += Vec.Dist(p1, n1);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/CubicBezier2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2dFilters, Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class CubicBezier2d extends Polyline2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAE7B,SAAS,kBAAkB;AAGpB,MAAM,sBAAsB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2dFilters, Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class CubicBezier2d extends Polyline2d {\n\tprivate _a: Vec\n\tprivate _b: Vec\n\tprivate _c: Vec\n\tprivate _d: Vec\n\n\tconstructor(\n\t\tconfig: Omit<Geometry2dOptions, 'isFilled' | 'isClosed'> & {\n\t\t\tstart: Vec\n\t\t\tcp1: Vec\n\t\t\tcp2: Vec\n\t\t\tend: Vec\n\t\t}\n\t) {\n\t\tconst { start: a, cp1: b, cp2: c, end: d } = config\n\t\tsuper({ ...config, points: [a, d] })\n\n\t\tthis._a = a\n\t\tthis._b = b\n\t\tthis._c = c\n\t\tthis._d = d\n\t}\n\n\toverride getVertices() {\n\t\tconst vertices = [] as Vec[]\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\t// we'll always use ten vertices for each bezier curve\n\t\tfor (let i = 0, n = 10; i <= n; i++) {\n\t\t\tconst t = i / n\n\t\t\tvertices.push(\n\t\t\t\tnew Vec(\n\t\t\t\t\t(1 - t) * (1 - t) * (1 - t) * a.x +\n\t\t\t\t\t\t3 * ((1 - t) * (1 - t)) * t * b.x +\n\t\t\t\t\t\t3 * (1 - t) * (t * t) * c.x +\n\t\t\t\t\t\tt * t * t * d.x,\n\t\t\t\t\t(1 - t) * (1 - t) * (1 - t) * a.y +\n\t\t\t\t\t\t3 * ((1 - t) * (1 - t)) * t * b.y +\n\t\t\t\t\t\t3 * (1 - t) * (t * t) * c.y +\n\t\t\t\t\t\tt * t * t * d.y\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\treturn vertices\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number\n\t\tlet p: Vec\n\t\tfor (const edge of this.segments) {\n\t\t\tp = edge.nearestPoint(A)\n\t\t\td = Vec.Dist2(p, A)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\tgetSvgPathData(first = true) {\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\treturn `${first ? `M ${a.toFixed()} ` : ``} C${b.toFixed()} ${c.toFixed()} ${d.toFixed()}`\n\t}\n\n\tstatic GetAtT(segment: CubicBezier2d, t: number) {\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = segment\n\t\treturn new Vec(\n\t\t\t(1 - t) * (1 - t) * (1 - t) * a.x +\n\t\t\t\t3 * ((1 - t) * (1 - t)) * t * b.x +\n\t\t\t\t3 * (1 - t) * (t * t) * c.x +\n\t\t\t\tt * t * t * d.x,\n\t\t\t(1 - t) * (1 - t) * (1 - t) * a.y +\n\t\t\t\t3 * ((1 - t) * (1 - t)) * t * b.y +\n\t\t\t\t3 * (1 - t) * (t * t) * c.y +\n\t\t\t\tt * t * t * d.y\n\t\t)\n\t}\n\n\toverride getLength(_filters?: Geometry2dFilters, precision = 32) {\n\t\tlet n1: Vec,\n\t\t\tp1 = this._a,\n\t\t\tlength = 0\n\t\tfor (let i = 1; i <= precision; i++) {\n\t\t\tn1 = CubicBezier2d.GetAtT(this, i / precision)\n\t\t\tlength += Vec.Dist(p1, n1)\n\t\t\tp1 = n1\n\t\t}\n\t\treturn length\n\t}\n}\n"],
|
|
5
|
+
"mappings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.mjs";
|
|
4
4
|
class CubicSpline2d extends Geometry2d {
|
|
5
|
-
|
|
5
|
+
_points;
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super({ ...config, isClosed: false, isFilled: false });
|
|
8
8
|
const { points } = config;
|
|
9
|
-
this.
|
|
9
|
+
this._points = points;
|
|
10
10
|
}
|
|
11
11
|
_segments;
|
|
12
12
|
// eslint-disable-next-line no-restricted-syntax
|
|
13
13
|
get segments() {
|
|
14
14
|
if (!this._segments) {
|
|
15
15
|
this._segments = [];
|
|
16
|
-
const { points } = this;
|
|
16
|
+
const { _points: points } = this;
|
|
17
17
|
const len = points.length;
|
|
18
18
|
const last = len - 2;
|
|
19
19
|
const k = 1.25;
|
|
@@ -35,7 +35,7 @@ class CubicSpline2d extends Geometry2d {
|
|
|
35
35
|
const vertices = this.segments.reduce((acc, segment) => {
|
|
36
36
|
return acc.concat(segment.vertices);
|
|
37
37
|
}, []);
|
|
38
|
-
vertices.push(this.
|
|
38
|
+
vertices.push(this._points[this._points.length - 1]);
|
|
39
39
|
return vertices;
|
|
40
40
|
}
|
|
41
41
|
nearestPoint(A) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/CubicSpline2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { CubicBezier2d } from './CubicBezier2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class CubicSpline2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,kBAAqC;AAGvC,MAAM,sBAAsB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { CubicBezier2d } from './CubicBezier2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class CubicSpline2d extends Geometry2d {\n\tprivate _points: Vec[]\n\n\tconstructor(config: Omit<Geometry2dOptions, 'isClosed' | 'isFilled'> & { points: Vec[] }) {\n\t\tsuper({ ...config, isClosed: false, isFilled: false })\n\t\tconst { points } = config\n\n\t\tthis._points = points\n\t}\n\n\tprivate _segments?: CubicBezier2d[]\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget segments() {\n\t\tif (!this._segments) {\n\t\t\tthis._segments = []\n\t\t\tconst { _points: points } = this\n\n\t\t\tconst len = points.length\n\t\t\tconst last = len - 2\n\t\t\tconst k = 1.25\n\n\t\t\tfor (let i = 0; i < len - 1; i++) {\n\t\t\t\tconst p0 = i === 0 ? points[0] : points[i - 1]\n\t\t\t\tconst p1 = points[i]\n\t\t\t\tconst p2 = points[i + 1]\n\t\t\t\tconst p3 = i === last ? p2 : points[i + 2]\n\t\t\t\tconst start = p1,\n\t\t\t\t\tcp1 =\n\t\t\t\t\t\ti === 0 ? p0 : new Vec(p1.x + ((p2.x - p0.x) / 6) * k, p1.y + ((p2.y - p0.y) / 6) * k),\n\t\t\t\t\tcp2 =\n\t\t\t\t\t\ti === last\n\t\t\t\t\t\t\t? p2\n\t\t\t\t\t\t\t: new Vec(p2.x - ((p3.x - p1.x) / 6) * k, p2.y - ((p3.y - p1.y) / 6) * k),\n\t\t\t\t\tend = p2\n\n\t\t\t\tthis._segments.push(new CubicBezier2d({ start, cp1, cp2, end }))\n\t\t\t}\n\t\t}\n\n\t\treturn this._segments\n\t}\n\n\toverride getLength() {\n\t\treturn this.segments.reduce((acc, segment) => acc + segment.length, 0)\n\t}\n\n\tgetVertices() {\n\t\tconst vertices = this.segments.reduce((acc, segment) => {\n\t\t\treturn acc.concat(segment.vertices)\n\t\t}, [] as Vec[])\n\t\tvertices.push(this._points[this._points.length - 1])\n\t\treturn vertices\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number\n\t\tlet p: Vec\n\t\tfor (const segment of this.segments) {\n\t\t\tp = segment.nearestPoint(A)\n\t\t\td = Vec.Dist2(p, A)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike): boolean {\n\t\treturn this.segments.some((segment) => segment.hitTestLineSegment(A, B))\n\t}\n\n\tgetSvgPathData() {\n\t\tlet d = this.segments.reduce((d, segment, i) => {\n\t\t\treturn d + segment.getSvgPathData(i === 0)\n\t\t}, '')\n\n\t\tif (this.isClosed) {\n\t\t\td += 'Z'\n\t\t}\n\n\t\treturn d\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,kBAAqC;AAGvC,MAAM,sBAAsB,WAAW;AAAA,EACrC;AAAA,EAER,YAAY,QAA8E;AACzF,UAAM,EAAE,GAAG,QAAQ,UAAU,OAAO,UAAU,MAAM,CAAC;AACrD,UAAM,EAAE,OAAO,IAAI;AAEnB,SAAK,UAAU;AAAA,EAChB;AAAA,EAEQ;AAAA;AAAA,EAGR,IAAI,WAAW;AACd,QAAI,CAAC,KAAK,WAAW;AACpB,WAAK,YAAY,CAAC;AAClB,YAAM,EAAE,SAAS,OAAO,IAAI;AAE5B,YAAM,MAAM,OAAO;AACnB,YAAM,OAAO,MAAM;AACnB,YAAM,IAAI;AAEV,eAAS,IAAI,GAAG,IAAI,MAAM,GAAG,KAAK;AACjC,cAAM,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;AAC7C,cAAM,KAAK,OAAO,CAAC;AACnB,cAAM,KAAK,OAAO,IAAI,CAAC;AACvB,cAAM,KAAK,MAAM,OAAO,KAAK,OAAO,IAAI,CAAC;AACzC,cAAM,QAAQ,IACb,MACC,MAAM,IAAI,KAAK,IAAI,IAAI,GAAG,KAAM,GAAG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,MAAM,CAAC;AAAA,IAC1C,GAAG,EAAE;AAEL,QAAI,KAAK,UAAU;AAClB,WAAK;AAAA,IACN;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": ["d"]
|
|
7
7
|
}
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { Vec } from "../Vec.mjs";
|
|
2
2
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
3
3
|
class Edge2d extends Geometry2d {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
_start;
|
|
5
|
+
_end;
|
|
6
|
+
_d;
|
|
7
|
+
_u;
|
|
8
|
+
_ul;
|
|
9
9
|
constructor(config) {
|
|
10
10
|
super({ ...config, isClosed: false, isFilled: false });
|
|
11
11
|
const { start, end } = config;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
12
|
+
this._start = start;
|
|
13
|
+
this._end = end;
|
|
14
|
+
this._d = start.clone().sub(end);
|
|
15
|
+
this._u = this._d.clone().uni();
|
|
16
|
+
this._ul = this._u.len();
|
|
17
17
|
}
|
|
18
18
|
getLength() {
|
|
19
|
-
return this.
|
|
20
|
-
}
|
|
21
|
-
midPoint() {
|
|
22
|
-
return this.start.lrp(this.end, 0.5);
|
|
19
|
+
return this._d.len();
|
|
23
20
|
}
|
|
24
21
|
getVertices() {
|
|
25
|
-
return [this.
|
|
22
|
+
return [this._start, this._end];
|
|
26
23
|
}
|
|
27
24
|
nearestPoint(point) {
|
|
28
|
-
const { start, end, d, u,
|
|
25
|
+
const { _start: start, _end: end, _d: d, _u: u, _ul: l } = this;
|
|
29
26
|
if (d.len() === 0) return start;
|
|
30
27
|
if (l === 0) return start;
|
|
31
28
|
const k = Vec.Sub(point, start).dpr(u) / l;
|
|
@@ -38,7 +35,7 @@ class Edge2d extends Geometry2d {
|
|
|
38
35
|
return new Vec(cx, cy);
|
|
39
36
|
}
|
|
40
37
|
getSvgPathData(first = true) {
|
|
41
|
-
const { start, end } = this;
|
|
38
|
+
const { _start: start, _end: end } = this;
|
|
42
39
|
return `${first ? `M${start.toFixed()}` : ``} L${end.toFixed()}`;
|
|
43
40
|
}
|
|
44
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Edge2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d } from './Geometry2d'\n\n/** @public */\nexport class Edge2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAkB;AAGpB,MAAM,eAAe,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d } from './Geometry2d'\n\n/** @public */\nexport class Edge2d extends Geometry2d {\n\tprivate _start: Vec\n\tprivate _end: Vec\n\tprivate _d: Vec\n\tprivate _u: Vec\n\tprivate _ul: number\n\n\tconstructor(config: { start: Vec; end: Vec }) {\n\t\tsuper({ ...config, isClosed: false, isFilled: false })\n\t\tconst { start, end } = config\n\n\t\tthis._start = start\n\t\tthis._end = end\n\n\t\tthis._d = start.clone().sub(end) // the delta from start to end\n\t\tthis._u = this._d.clone().uni() // the unit vector of the edge\n\t\tthis._ul = this._u.len() // the length of the unit vector\n\t}\n\n\toverride getLength() {\n\t\treturn this._d.len()\n\t}\n\n\toverride getVertices(): Vec[] {\n\t\treturn [this._start, this._end]\n\t}\n\n\toverride nearestPoint(point: VecLike): Vec {\n\t\tconst { _start: start, _end: end, _d: d, _u: u, _ul: l } = this\n\t\tif (d.len() === 0) return start // start and end are the same\n\t\tif (l === 0) return start // no length in the unit vector\n\t\tconst k = Vec.Sub(point, start).dpr(u) / l\n\t\tconst cx = start.x + u.x * k\n\t\tif (cx < Math.min(start.x, end.x)) return start.x < end.x ? start : end\n\t\tif (cx > Math.max(start.x, end.x)) return start.x > end.x ? start : end\n\t\tconst cy = start.y + u.y * k\n\t\tif (cy < Math.min(start.y, end.y)) return start.y < end.y ? start : end\n\t\tif (cy > Math.max(start.y, end.y)) return start.y > end.y ? start : end\n\t\treturn new Vec(cx, cy)\n\t}\n\n\tgetSvgPathData(first = true) {\n\t\tconst { _start: start, _end: end } = this\n\t\treturn `${first ? `M${start.toFixed()}` : ``} L${end.toFixed()}`\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAkB;AAGpB,MAAM,eAAe,WAAW;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAkC;AAC7C,UAAM,EAAE,GAAG,QAAQ,UAAU,OAAO,UAAU,MAAM,CAAC;AACrD,UAAM,EAAE,OAAO,IAAI,IAAI;AAEvB,SAAK,SAAS;AACd,SAAK,OAAO;AAEZ,SAAK,KAAK,MAAM,MAAM,EAAE,IAAI,GAAG;AAC/B,SAAK,KAAK,KAAK,GAAG,MAAM,EAAE,IAAI;AAC9B,SAAK,MAAM,KAAK,GAAG,IAAI;AAAA,EACxB;AAAA,EAES,YAAY;AACpB,WAAO,KAAK,GAAG,IAAI;AAAA,EACpB;AAAA,EAES,cAAqB;AAC7B,WAAO,CAAC,KAAK,QAAQ,KAAK,IAAI;AAAA,EAC/B;AAAA,EAES,aAAa,OAAqB;AAC1C,UAAM,EAAE,QAAQ,OAAO,MAAM,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK,EAAE,IAAI;AAC3D,QAAI,EAAE,IAAI,MAAM,EAAG,QAAO;AAC1B,QAAI,MAAM,EAAG,QAAO;AACpB,UAAM,IAAI,IAAI,IAAI,OAAO,KAAK,EAAE,IAAI,CAAC,IAAI;AACzC,UAAM,KAAK,MAAM,IAAI,EAAE,IAAI;AAC3B,QAAI,KAAK,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,EAAG,QAAO,MAAM,IAAI,IAAI,IAAI,QAAQ;AACpE,QAAI,KAAK,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,EAAG,QAAO,MAAM,IAAI,IAAI,IAAI,QAAQ;AACpE,UAAM,KAAK,MAAM,IAAI,EAAE,IAAI;AAC3B,QAAI,KAAK,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,EAAG,QAAO,MAAM,IAAI,IAAI,IAAI,QAAQ;AACpE,QAAI,KAAK,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,EAAG,QAAO,MAAM,IAAI,IAAI,IAAI,QAAQ;AACpE,WAAO,IAAI,IAAI,IAAI,EAAE;AAAA,EACtB;AAAA,EAEA,eAAe,QAAQ,MAAM;AAC5B,UAAM,EAAE,QAAQ,OAAO,MAAM,IAAI,IAAI;AACrC,WAAO,GAAG,QAAQ,IAAI,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box } from "../Box.mjs";
|
|
2
2
|
import { Vec } from "../Vec.mjs";
|
|
3
|
-
import { PI, PI2, perimeterOfEllipse } from "../utils.mjs";
|
|
3
|
+
import { PI, PI2, clamp, perimeterOfEllipse } from "../utils.mjs";
|
|
4
4
|
import { Edge2d } from "./Edge2d.mjs";
|
|
5
5
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
6
6
|
import { getVerticesCountForLength } from "./geometry-constants.mjs";
|
|
@@ -9,11 +9,11 @@ class Ellipse2d extends Geometry2d {
|
|
|
9
9
|
super({ ...config, isClosed: true });
|
|
10
10
|
this.config = config;
|
|
11
11
|
const { width, height } = config;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this._w = width;
|
|
13
|
+
this._h = height;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
_w;
|
|
16
|
+
_h;
|
|
17
17
|
_edges;
|
|
18
18
|
// eslint-disable-next-line no-restricted-syntax
|
|
19
19
|
get edges() {
|
|
@@ -29,8 +29,8 @@ class Ellipse2d extends Geometry2d {
|
|
|
29
29
|
return this._edges;
|
|
30
30
|
}
|
|
31
31
|
getVertices() {
|
|
32
|
-
const w = Math.max(1, this.
|
|
33
|
-
const h = Math.max(1, this.
|
|
32
|
+
const w = Math.max(1, this._w);
|
|
33
|
+
const h = Math.max(1, this._h);
|
|
34
34
|
const cx = w / 2;
|
|
35
35
|
const cy = h / 2;
|
|
36
36
|
const q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2);
|
|
@@ -45,7 +45,7 @@ class Ellipse2d extends Geometry2d {
|
|
|
45
45
|
let tc = 1;
|
|
46
46
|
const vertices = Array(len);
|
|
47
47
|
for (let i = 0; i < len; i++) {
|
|
48
|
-
vertices[i] = new Vec(cx + cx * cos, cy + cy * sin);
|
|
48
|
+
vertices[i] = new Vec(clamp(cx + cx * cos, 0, w), clamp(cy + cy * sin, 0, h));
|
|
49
49
|
ts = b * cos + a * sin;
|
|
50
50
|
tc = a * cos - b * sin;
|
|
51
51
|
sin = ts;
|
|
@@ -73,10 +73,10 @@ class Ellipse2d extends Geometry2d {
|
|
|
73
73
|
return this.edges.some((edge) => edge.hitTestLineSegment(A, B));
|
|
74
74
|
}
|
|
75
75
|
getBounds() {
|
|
76
|
-
return new Box(0, 0, this.
|
|
76
|
+
return new Box(0, 0, this._w, this._h);
|
|
77
77
|
}
|
|
78
78
|
getLength() {
|
|
79
|
-
const { w, h } = this;
|
|
79
|
+
const { _w: w, _h: h } = this;
|
|
80
80
|
const cx = w / 2;
|
|
81
81
|
const cy = h / 2;
|
|
82
82
|
const rx = Math.max(0, cx);
|
|
@@ -84,7 +84,7 @@ class Ellipse2d extends Geometry2d {
|
|
|
84
84
|
return perimeterOfEllipse(rx, ry);
|
|
85
85
|
}
|
|
86
86
|
getSvgPathData(first = false) {
|
|
87
|
-
const { w, h } = this;
|
|
87
|
+
const { _w: w, _h: h } = this;
|
|
88
88
|
const cx = w / 2;
|
|
89
89
|
const cy = h / 2;
|
|
90
90
|
const rx = Math.max(0, cx);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Ellipse2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI, PI2, perimeterOfEllipse } from '../utils'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Ellipse2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,IAAI,KAAK,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI, PI2, clamp, perimeterOfEllipse } from '../utils'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Ellipse2d extends Geometry2d {\n\tprivate _w: number\n\tprivate _h: number\n\tprivate _edges?: Edge2d[]\n\n\tconstructor(\n\t\tpublic config: Omit<Geometry2dOptions, 'isClosed'> & {\n\t\t\twidth: number\n\t\t\theight: number\n\t\t}\n\t) {\n\t\tsuper({ ...config, isClosed: true })\n\t\tconst { width, height } = config\n\t\tthis._w = width\n\t\tthis._h = height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget edges() {\n\t\tif (!this._edges) {\n\t\t\tconst { vertices } = this\n\t\t\tthis._edges = []\n\t\t\tfor (let i = 0, n = vertices.length; i < n; i++) {\n\t\t\t\tconst start = vertices[i]\n\t\t\t\tconst end = vertices[(i + 1) % n]\n\t\t\t\tthis._edges.push(new Edge2d({ start, end }))\n\t\t\t}\n\t\t}\n\n\t\treturn this._edges\n\t}\n\n\tgetVertices() {\n\t\t// Perimeter of the ellipse\n\t\tconst w = Math.max(1, this._w)\n\t\tconst h = Math.max(1, this._h)\n\t\tconst cx = w / 2\n\t\tconst cy = h / 2\n\t\tconst q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2)\n\t\tconst p = PI * (cx + cy) * (1 + (3 * q) / (10 + Math.sqrt(4 - 3 * q)))\n\t\t// Number of points\n\t\tconst len = getVerticesCountForLength(p)\n\t\t// Size of step\n\t\tconst step = PI2 / len\n\n\t\tconst a = Math.cos(step)\n\t\tconst b = Math.sin(step)\n\n\t\tlet sin = 0\n\t\tlet cos = 1\n\t\tlet ts = 0\n\t\tlet tc = 1\n\n\t\tconst vertices = Array(len)\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tvertices[i] = new Vec(clamp(cx + cx * cos, 0, w), clamp(cy + cy * sin, 0, h))\n\t\t\tts = b * cos + a * sin\n\t\t\ttc = a * cos - b * sin\n\t\t\tsin = ts\n\t\t\tcos = tc\n\t\t}\n\n\t\treturn vertices\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number\n\t\tlet p: Vec\n\t\tfor (const edge of this.edges) {\n\t\t\tp = edge.nearestPoint(A)\n\t\t\td = Vec.Dist2(p, A)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike): boolean {\n\t\treturn this.edges.some((edge) => edge.hitTestLineSegment(A, B))\n\t}\n\n\tgetBounds() {\n\t\treturn new Box(0, 0, this._w, this._h)\n\t}\n\n\tgetLength(): number {\n\t\tconst { _w: w, _h: h } = this\n\t\tconst cx = w / 2\n\t\tconst cy = h / 2\n\t\tconst rx = Math.max(0, cx)\n\t\tconst ry = Math.max(0, cy)\n\t\treturn perimeterOfEllipse(rx, ry)\n\t}\n\n\tgetSvgPathData(first = false) {\n\t\tconst { _w: w, _h: h } = this\n\t\tconst cx = w / 2\n\t\tconst cy = h / 2\n\t\tconst rx = Math.max(0, cx)\n\t\tconst ry = Math.max(0, cy)\n\t\treturn `${first ? `M${cx - rx},${cy}` : ``} a${rx},${ry},0,1,1,${rx * 2},0a${rx},${ry},0,1,1,-${rx * 2},0`\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,IAAI,KAAK,OAAO,0BAA0B;AACnD,SAAS,cAAc;AACvB,SAAS,kBAAqC;AAC9C,SAAS,iCAAiC;AAGnC,MAAM,kBAAkB,WAAW;AAAA,EAKzC,YACQ,QAIN;AACD,UAAM,EAAE,GAAG,QAAQ,UAAU,KAAK,CAAC;AAL5B;AAMP,UAAM,EAAE,OAAO,OAAO,IAAI;AAC1B,SAAK,KAAK;AACV,SAAK,KAAK;AAAA,EACX;AAAA,EAdQ;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAeR,IAAI,QAAQ;AACX,QAAI,CAAC,KAAK,QAAQ;AACjB,YAAM,EAAE,SAAS,IAAI;AACrB,WAAK,SAAS,CAAC;AACf,eAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,IAAI,GAAG,KAAK;AAChD,cAAM,QAAQ,SAAS,CAAC;AACxB,cAAM,MAAM,UAAU,IAAI,KAAK,CAAC;AAChC,aAAK,OAAO,KAAK,IAAI,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;AAAA,MAC5C;AAAA,IACD;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,cAAc;AAEb,UAAM,IAAI,KAAK,IAAI,GAAG,KAAK,EAAE;AAC7B,UAAM,IAAI,KAAK,IAAI,GAAG,KAAK,EAAE;AAC7B,UAAM,KAAK,IAAI;AACf,UAAM,KAAK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AoB;AACnB,UAAM,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI;AACzB,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,WAAO,mBAAmB,IAAI,EAAE;AAAA,EACjC;AAAA,EAEA,eAAe,QAAQ,OAAO;AAC7B,UAAM,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI;AACzB,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,WAAO,GAAG,QAAQ,IAAI,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,CAAC;AAAA,EACvG;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { Vec } from "../Vec.mjs";
|
|
2
2
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
3
3
|
class Point2d extends Geometry2d {
|
|
4
|
-
|
|
4
|
+
_point;
|
|
5
5
|
constructor(config) {
|
|
6
6
|
super({ ...config, isClosed: true, isFilled: true });
|
|
7
7
|
const { point } = config;
|
|
8
|
-
this.
|
|
8
|
+
this._point = point;
|
|
9
9
|
}
|
|
10
10
|
getVertices() {
|
|
11
|
-
return [this.
|
|
11
|
+
return [this._point];
|
|
12
12
|
}
|
|
13
13
|
nearestPoint() {
|
|
14
|
-
return this.
|
|
14
|
+
return this._point;
|
|
15
15
|
}
|
|
16
16
|
hitTestLineSegment(A, B, margin) {
|
|
17
|
-
return Vec.DistanceToLineSegment(A, B, this.
|
|
17
|
+
return Vec.DistanceToLineSegment(A, B, this._point) < margin;
|
|
18
18
|
}
|
|
19
19
|
getSvgPathData() {
|
|
20
|
-
const { point } = this;
|
|
20
|
+
const { _point: point } = this;
|
|
21
21
|
return `M${point.toFixed()}`;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Point2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Point2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAqC;AAGvC,MAAM,gBAAgB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Point2d extends Geometry2d {\n\tprivate _point: Vec\n\n\tconstructor(\n\t\tconfig: Omit<Geometry2dOptions, 'isClosed' | 'isFilled'> & { margin: number; point: Vec }\n\t) {\n\t\tsuper({ ...config, isClosed: true, isFilled: true })\n\t\tconst { point } = config\n\n\t\tthis._point = point\n\t}\n\n\tgetVertices() {\n\t\treturn [this._point]\n\t}\n\n\tnearestPoint(): Vec {\n\t\treturn this._point\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, margin: number): boolean {\n\t\treturn Vec.DistanceToLineSegment(A, B, this._point) < margin\n\t}\n\n\tgetSvgPathData() {\n\t\tconst { _point: point } = this\n\t\treturn `M${point.toFixed()}`\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAqC;AAGvC,MAAM,gBAAgB,WAAW;AAAA,EAC/B;AAAA,EAER,YACC,QACC;AACD,UAAM,EAAE,GAAG,QAAQ,UAAU,MAAM,UAAU,KAAK,CAAC;AACnD,UAAM,EAAE,MAAM,IAAI;AAElB,SAAK,SAAS;AAAA,EACf;AAAA,EAEA,cAAc;AACb,WAAO,CAAC,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,eAAoB;AACnB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,mBAAmB,GAAY,GAAY,QAAyB;AACnE,WAAO,IAAI,sBAAsB,GAAG,GAAG,KAAK,MAAM,IAAI;AAAA,EACvD;AAAA,EAEA,iBAAiB;AAChB,UAAM,EAAE,QAAQ,MAAM,IAAI;AAC1B,WAAO,IAAI,MAAM,QAAQ,CAAC;AAAA,EAC3B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Polygon2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class Polygon2d extends Polyline2d {\n\tconstructor(config: Omit<Geometry2dOptions, 'isClosed'> & { points: Vec[] }) {\n\t\tsuper({ ...config })\n\t\tthis.isClosed = true\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,kBAAkB;AAGpB,MAAM,kBAAkB,WAAW;AAAA,EACzC,YAAY,QAAiE;AAC5E,UAAM,EAAE,GAAG,OAAO,CAAC;AACnB,SAAK,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class Polygon2d extends Polyline2d {\n\tconstructor(config: Omit<Geometry2dOptions, 'isClosed'> & { points: Vec[] }) {\n\t\tsuper({ ...config })\n\t\tthis.isClosed = true\n\n\t\tif (config.points.length < 3) {\n\t\t\tthrow new Error('Polygon2d: points must be an array of at least 3 points')\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,kBAAkB;AAGpB,MAAM,kBAAkB,WAAW;AAAA,EACzC,YAAY,QAAiE;AAC5E,UAAM,EAAE,GAAG,OAAO,CAAC;AACnB,SAAK,WAAW;AAEhB,QAAI,OAAO,OAAO,SAAS,GAAG;AAC7B,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC1E;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|