@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
|
@@ -28,30 +28,38 @@ var import_Geometry2d = require("./Geometry2d");
|
|
|
28
28
|
var import_geometry_constants = require("./geometry-constants");
|
|
29
29
|
class Arc2d extends import_Geometry2d.Geometry2d {
|
|
30
30
|
_center;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
_radius;
|
|
32
|
+
_start;
|
|
33
|
+
_end;
|
|
34
|
+
_largeArcFlag;
|
|
35
|
+
_sweepFlag;
|
|
36
|
+
_measure;
|
|
37
|
+
_angleStart;
|
|
38
|
+
_angleEnd;
|
|
39
39
|
constructor(config) {
|
|
40
40
|
super({ ...config, isFilled: false, isClosed: false });
|
|
41
41
|
const { center, sweepFlag, largeArcFlag, start, end } = config;
|
|
42
42
|
if (start.equals(end)) throw Error(`Arc must have different start and end points.`);
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
43
|
+
this._angleStart = import_Vec.Vec.Angle(center, start);
|
|
44
|
+
this._angleEnd = import_Vec.Vec.Angle(center, end);
|
|
45
|
+
this._radius = import_Vec.Vec.Dist(center, start);
|
|
46
|
+
this._measure = (0, import_utils.getArcMeasure)(this._angleStart, this._angleEnd, sweepFlag, largeArcFlag);
|
|
47
|
+
this._start = start;
|
|
48
|
+
this._end = end;
|
|
49
|
+
this._sweepFlag = sweepFlag;
|
|
50
|
+
this._largeArcFlag = largeArcFlag;
|
|
51
51
|
this._center = center;
|
|
52
52
|
}
|
|
53
53
|
nearestPoint(point) {
|
|
54
|
-
const {
|
|
54
|
+
const {
|
|
55
|
+
_center,
|
|
56
|
+
_measure: measure,
|
|
57
|
+
_radius: radius,
|
|
58
|
+
_angleEnd: angleEnd,
|
|
59
|
+
_angleStart: angleStart,
|
|
60
|
+
_start: A,
|
|
61
|
+
_end: B
|
|
62
|
+
} = this;
|
|
55
63
|
const t = (0, import_utils.getPointInArcT)(measure, angleStart, angleEnd, _center.angle(point));
|
|
56
64
|
if (t <= 0) return A;
|
|
57
65
|
if (t >= 1) return B;
|
|
@@ -70,7 +78,13 @@ class Arc2d extends import_Geometry2d.Geometry2d {
|
|
|
70
78
|
return nearest;
|
|
71
79
|
}
|
|
72
80
|
hitTestLineSegment(A, B) {
|
|
73
|
-
const {
|
|
81
|
+
const {
|
|
82
|
+
_center,
|
|
83
|
+
_radius: radius,
|
|
84
|
+
_measure: measure,
|
|
85
|
+
_angleStart: angleStart,
|
|
86
|
+
_angleEnd: angleEnd
|
|
87
|
+
} = this;
|
|
74
88
|
const intersection = (0, import_intersect.intersectLineSegmentCircle)(A, B, _center, radius);
|
|
75
89
|
if (intersection === null) return false;
|
|
76
90
|
return intersection.some((p) => {
|
|
@@ -79,7 +93,7 @@ class Arc2d extends import_Geometry2d.Geometry2d {
|
|
|
79
93
|
});
|
|
80
94
|
}
|
|
81
95
|
getVertices() {
|
|
82
|
-
const { _center, measure, length, radius, angleStart } = this;
|
|
96
|
+
const { _center, _measure: measure, length, _radius: radius, _angleStart: angleStart } = this;
|
|
83
97
|
const vertices = [];
|
|
84
98
|
for (let i = 0, n = (0, import_geometry_constants.getVerticesCountForLength)(Math.abs(length)); i < n + 1; i++) {
|
|
85
99
|
const t = i / n * measure;
|
|
@@ -89,11 +103,17 @@ class Arc2d extends import_Geometry2d.Geometry2d {
|
|
|
89
103
|
return vertices;
|
|
90
104
|
}
|
|
91
105
|
getSvgPathData(first = true) {
|
|
92
|
-
const {
|
|
106
|
+
const {
|
|
107
|
+
_start: start,
|
|
108
|
+
_end: end,
|
|
109
|
+
_radius: radius,
|
|
110
|
+
_largeArcFlag: largeArcFlag,
|
|
111
|
+
_sweepFlag: sweepFlag
|
|
112
|
+
} = this;
|
|
93
113
|
return `${first ? `M${start.toFixed()}` : ``} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.toFixed()}`;
|
|
94
114
|
}
|
|
95
115
|
getLength() {
|
|
96
|
-
return Math.abs(this.
|
|
116
|
+
return Math.abs(this._measure * this._radius);
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
//# sourceMappingURL=Arc2d.js.map
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,uBAA2C;AAC3C,mBAAgE;AAChE,wBAA8C;AAC9C,gCAA0C;AAGnC,MAAM,cAAc,6BAAW;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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,uBAA2C;AAC3C,mBAAgE;AAChE,wBAA8C;AAC9C,gCAA0C;AAGnC,MAAM,cAAc,6BAAW;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,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UAAU,QAAQ,MAAM,CAAC,CAAC;AAC7E,aAAO,UAAU,KAAK,UAAU;AAAA,IACjC,CAAC;AAAA,EACF;AAAA,EAEA,cAAqB;AACpB,UAAM,EAAE,SAAS,UAAU,SAAS,QAAQ,SAAS,QAAQ,aAAa,WAAW,IAAI;AACzF,UAAM,WAAkB,CAAC;AACzB,aAAS,IAAI,GAAG,QAAI,qDAA0B,KAAK,IAAI,MAAM,CAAC,GAAG,IAAI,IAAI,GAAG,KAAK;AAChF,YAAM,IAAK,IAAI,IAAK;AACpB,YAAM,QAAQ,aAAa;AAC3B,eAAS,SAAK,+BAAiB,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
|
}
|
|
@@ -32,20 +32,20 @@ class Circle2d extends import_Geometry2d.Geometry2d {
|
|
|
32
32
|
super({ isClosed: true, ...config });
|
|
33
33
|
this.config = config;
|
|
34
34
|
const { x = 0, y = 0, radius } = config;
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
35
|
+
this._x = x;
|
|
36
|
+
this._y = y;
|
|
37
37
|
this._center = new import_Vec.Vec(radius + x, radius + y);
|
|
38
|
-
this.
|
|
38
|
+
this._radius = radius;
|
|
39
39
|
}
|
|
40
40
|
_center;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
_radius;
|
|
42
|
+
_x;
|
|
43
|
+
_y;
|
|
44
44
|
getBounds() {
|
|
45
|
-
return new import_Box.Box(this.
|
|
45
|
+
return new import_Box.Box(this._x, this._y, this._radius * 2, this._radius * 2);
|
|
46
46
|
}
|
|
47
47
|
getVertices() {
|
|
48
|
-
const { _center, radius } = this;
|
|
48
|
+
const { _center, _radius: radius } = this;
|
|
49
49
|
const perimeter = import_utils.PI2 * radius;
|
|
50
50
|
const vertices = [];
|
|
51
51
|
for (let i = 0, n = (0, import_geometry_constants.getVerticesCountForLength)(perimeter); i < n; i++) {
|
|
@@ -55,16 +55,16 @@ class Circle2d extends import_Geometry2d.Geometry2d {
|
|
|
55
55
|
return vertices;
|
|
56
56
|
}
|
|
57
57
|
nearestPoint(point) {
|
|
58
|
-
const { _center, radius } = this;
|
|
58
|
+
const { _center, _radius: radius } = this;
|
|
59
59
|
if (_center.equals(point)) return import_Vec.Vec.AddXY(_center, radius, 0);
|
|
60
60
|
return import_Vec.Vec.Sub(point, _center).uni().mul(radius).add(_center);
|
|
61
61
|
}
|
|
62
62
|
hitTestLineSegment(A, B, distance = 0) {
|
|
63
|
-
const { _center, radius } = this;
|
|
63
|
+
const { _center, _radius: radius } = this;
|
|
64
64
|
return (0, import_intersect.intersectLineSegmentCircle)(A, B, _center, radius + distance) !== null;
|
|
65
65
|
}
|
|
66
66
|
getSvgPathData() {
|
|
67
|
-
const { _center, radius } = this;
|
|
67
|
+
const { _center, _radius: radius } = this;
|
|
68
68
|
return `M${_center.x + radius},${_center.y} a${radius},${radius} 0 1,0 ${radius * 2},0a${radius},${radius} 0 1,0 -${radius * 2},0`;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoB;AACpB,iBAA6B;AAC7B,uBAA2C;AAC3C,mBAAsC;AACtC,wBAA8C;AAC9C,gCAA0C;AAGnC,MAAM,iBAAiB,6BAAW;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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoB;AACpB,iBAA6B;AAC7B,uBAA2C;AAC3C,mBAAsC;AACtC,wBAA8C;AAC9C,gCAA0C;AAGnC,MAAM,iBAAiB,6BAAW;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,eAAI,SAAS,GAAG,SAAS,CAAC;AAC7C,SAAK,UAAU;AAAA,EAChB;AAAA,EAnBQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAkBR,YAAY;AACX,WAAO,IAAI,eAAI,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,mBAAM;AACxB,UAAM,WAAkB,CAAC;AACzB,aAAS,IAAI,GAAG,QAAI,qDAA0B,SAAS,GAAG,IAAI,GAAG,KAAK;AACrE,YAAM,QAAS,IAAI,IAAK;AACxB,eAAS,SAAK,+BAAiB,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,eAAI,MAAM,SAAS,QAAQ,CAAC;AAC9D,WAAO,eAAI,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,eAAO,6CAA2B,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
|
}
|
|
@@ -24,21 +24,21 @@ module.exports = __toCommonJS(CubicBezier2d_exports);
|
|
|
24
24
|
var import_Vec = require("../Vec");
|
|
25
25
|
var import_Polyline2d = require("./Polyline2d");
|
|
26
26
|
class CubicBezier2d extends import_Polyline2d.Polyline2d {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
_a;
|
|
28
|
+
_b;
|
|
29
|
+
_c;
|
|
30
|
+
_d;
|
|
31
31
|
constructor(config) {
|
|
32
32
|
const { start: a, cp1: b, cp2: c, end: d } = config;
|
|
33
33
|
super({ ...config, points: [a, d] });
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
34
|
+
this._a = a;
|
|
35
|
+
this._b = b;
|
|
36
|
+
this._c = c;
|
|
37
|
+
this._d = d;
|
|
38
38
|
}
|
|
39
39
|
getVertices() {
|
|
40
40
|
const vertices = [];
|
|
41
|
-
const { a, b, c, d } = this;
|
|
41
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
42
42
|
for (let i = 0, n = 10; i <= n; i++) {
|
|
43
43
|
const t = i / n;
|
|
44
44
|
vertices.push(
|
|
@@ -50,9 +50,6 @@ class CubicBezier2d extends import_Polyline2d.Polyline2d {
|
|
|
50
50
|
}
|
|
51
51
|
return vertices;
|
|
52
52
|
}
|
|
53
|
-
midPoint() {
|
|
54
|
-
return CubicBezier2d.GetAtT(this, 0.5);
|
|
55
|
-
}
|
|
56
53
|
nearestPoint(A) {
|
|
57
54
|
let nearest;
|
|
58
55
|
let dist = Infinity;
|
|
@@ -70,18 +67,18 @@ class CubicBezier2d extends import_Polyline2d.Polyline2d {
|
|
|
70
67
|
return nearest;
|
|
71
68
|
}
|
|
72
69
|
getSvgPathData(first = true) {
|
|
73
|
-
const { a, b, c, d } = this;
|
|
70
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
74
71
|
return `${first ? `M ${a.toFixed()} ` : ``} C${b.toFixed()} ${c.toFixed()} ${d.toFixed()}`;
|
|
75
72
|
}
|
|
76
73
|
static GetAtT(segment, t) {
|
|
77
|
-
const { a, b, c, d } = segment;
|
|
74
|
+
const { _a: a, _b: b, _c: c, _d: d } = segment;
|
|
78
75
|
return new import_Vec.Vec(
|
|
79
76
|
(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,
|
|
80
77
|
(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
|
|
81
78
|
);
|
|
82
79
|
}
|
|
83
|
-
getLength(
|
|
84
|
-
let n1, p1 = this.
|
|
80
|
+
getLength(_filters, precision = 32) {
|
|
81
|
+
let n1, p1 = this._a, length = 0;
|
|
85
82
|
for (let i = 1; i <= precision; i++) {
|
|
86
83
|
n1 = CubicBezier2d.GetAtT(this, i / precision);
|
|
87
84
|
length += import_Vec.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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAE7B,wBAA2B;AAGpB,MAAM,sBAAsB,6BAAW;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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAE7B,wBAA2B;AAGpB,MAAM,sBAAsB,6BAAW;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACC,QAMC;AACD,UAAM,EAAE,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE,IAAI;AAC7C,UAAM,EAAE,GAAG,QAAQ,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;AAEnC,SAAK,KAAK;AACV,SAAK,KAAK;AACV,SAAK,KAAK;AACV,SAAK,KAAK;AAAA,EACX;AAAA,EAES,cAAc;AACtB,UAAM,WAAW,CAAC;AAClB,UAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,IAAI;AAEvC,aAAS,IAAI,GAAG,IAAI,IAAI,KAAK,GAAG,KAAK;AACpC,YAAM,IAAI,IAAI;AACd,eAAS;AAAA,QACR,IAAI;AAAA,WACF,IAAI,MAAM,IAAI,MAAM,IAAI,KAAK,EAAE,IAC/B,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,EAAE,IAChC,KAAK,IAAI,MAAM,IAAI,KAAK,EAAE,IAC1B,IAAI,IAAI,IAAI,EAAE;AAAA,WACd,IAAI,MAAM,IAAI,MAAM,IAAI,KAAK,EAAE,IA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B;AAAA,EACD;AAAA,EAES,UAAU,UAA8B,YAAY,IAAI;AAChE,QAAI,IACH,KAAK,KAAK,IACV,SAAS;AACV,aAAS,IAAI,GAAG,KAAK,WAAW,KAAK;AACpC,WAAK,cAAc,OAAO,MAAM,IAAI,SAAS;AAC7C,gBAAU,eAAI,KAAK,IAAI,EAAE;AACzB,WAAK;AAAA,IACN;AACA,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -25,18 +25,18 @@ var import_Vec = require("../Vec");
|
|
|
25
25
|
var import_CubicBezier2d = require("./CubicBezier2d");
|
|
26
26
|
var import_Geometry2d = require("./Geometry2d");
|
|
27
27
|
class CubicSpline2d extends import_Geometry2d.Geometry2d {
|
|
28
|
-
|
|
28
|
+
_points;
|
|
29
29
|
constructor(config) {
|
|
30
30
|
super({ ...config, isClosed: false, isFilled: false });
|
|
31
31
|
const { points } = config;
|
|
32
|
-
this.
|
|
32
|
+
this._points = points;
|
|
33
33
|
}
|
|
34
34
|
_segments;
|
|
35
35
|
// eslint-disable-next-line no-restricted-syntax
|
|
36
36
|
get segments() {
|
|
37
37
|
if (!this._segments) {
|
|
38
38
|
this._segments = [];
|
|
39
|
-
const { points } = this;
|
|
39
|
+
const { _points: points } = this;
|
|
40
40
|
const len = points.length;
|
|
41
41
|
const last = len - 2;
|
|
42
42
|
const k = 1.25;
|
|
@@ -58,7 +58,7 @@ class CubicSpline2d extends import_Geometry2d.Geometry2d {
|
|
|
58
58
|
const vertices = this.segments.reduce((acc, segment) => {
|
|
59
59
|
return acc.concat(segment.vertices);
|
|
60
60
|
}, []);
|
|
61
|
-
vertices.push(this.
|
|
61
|
+
vertices.push(this._points[this._points.length - 1]);
|
|
62
62
|
return vertices;
|
|
63
63
|
}
|
|
64
64
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,2BAA8B;AAC9B,wBAA8C;AAGvC,MAAM,sBAAsB,6BAAW;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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,2BAA8B;AAC9B,wBAA8C;AAGvC,MAAM,sBAAsB,6BAAW;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,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J,QAAI,OAAO;AACX,QAAI;AACJ,QAAI;AACJ,eAAW,WAAW,KAAK,UAAU;AACpC,UAAI,QAAQ,aAAa,CAAC;AAC1B,UAAI,eAAI,MAAM,GAAG,CAAC;AAClB,UAAI,IAAI,MAAM;AACb,kBAAU;AACV,eAAO;AAAA,MACR;AAAA,IACD;AACA,QAAI,CAAC,QAAS,OAAM,MAAM,yBAAyB;AACnD,WAAO;AAAA,EACR;AAAA,EAEA,mBAAmB,GAAY,GAAqB;AACnD,WAAO,KAAK,SAAS,KAAK,CAAC,YAAY,QAAQ,mBAAmB,GAAG,CAAC,CAAC;AAAA,EACxE;AAAA,EAEA,iBAAiB;AAChB,QAAI,IAAI,KAAK,SAAS,OAAO,CAACA,IAAG,SAAS,MAAM;AAC/C,aAAOA,KAAI,QAAQ,eAAe,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
|
}
|
|
@@ -24,31 +24,28 @@ module.exports = __toCommonJS(Edge2d_exports);
|
|
|
24
24
|
var import_Vec = require("../Vec");
|
|
25
25
|
var import_Geometry2d = require("./Geometry2d");
|
|
26
26
|
class Edge2d extends import_Geometry2d.Geometry2d {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
_start;
|
|
28
|
+
_end;
|
|
29
|
+
_d;
|
|
30
|
+
_u;
|
|
31
|
+
_ul;
|
|
32
32
|
constructor(config) {
|
|
33
33
|
super({ ...config, isClosed: false, isFilled: false });
|
|
34
34
|
const { start, end } = config;
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
35
|
+
this._start = start;
|
|
36
|
+
this._end = end;
|
|
37
|
+
this._d = start.clone().sub(end);
|
|
38
|
+
this._u = this._d.clone().uni();
|
|
39
|
+
this._ul = this._u.len();
|
|
40
40
|
}
|
|
41
41
|
getLength() {
|
|
42
|
-
return this.
|
|
43
|
-
}
|
|
44
|
-
midPoint() {
|
|
45
|
-
return this.start.lrp(this.end, 0.5);
|
|
42
|
+
return this._d.len();
|
|
46
43
|
}
|
|
47
44
|
getVertices() {
|
|
48
|
-
return [this.
|
|
45
|
+
return [this._start, this._end];
|
|
49
46
|
}
|
|
50
47
|
nearestPoint(point) {
|
|
51
|
-
const { start, end, d, u,
|
|
48
|
+
const { _start: start, _end: end, _d: d, _u: u, _ul: l } = this;
|
|
52
49
|
if (d.len() === 0) return start;
|
|
53
50
|
if (l === 0) return start;
|
|
54
51
|
const k = import_Vec.Vec.Sub(point, start).dpr(u) / l;
|
|
@@ -61,7 +58,7 @@ class Edge2d extends import_Geometry2d.Geometry2d {
|
|
|
61
58
|
return new import_Vec.Vec(cx, cy);
|
|
62
59
|
}
|
|
63
60
|
getSvgPathData(first = true) {
|
|
64
|
-
const { start, end } = this;
|
|
61
|
+
const { _start: start, _end: end } = this;
|
|
65
62
|
return `${first ? `M${start.toFixed()}` : ``} L${end.toFixed()}`;
|
|
66
63
|
}
|
|
67
64
|
}
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,wBAA2B;AAGpB,MAAM,eAAe,6BAAW;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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,wBAA2B;AAGpB,MAAM,eAAe,6BAAW;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,S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AAI,QAAQ,CAAC;AAAA,EAC/D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,11 +32,11 @@ class Ellipse2d extends import_Geometry2d.Geometry2d {
|
|
|
32
32
|
super({ ...config, isClosed: true });
|
|
33
33
|
this.config = config;
|
|
34
34
|
const { width, height } = config;
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
35
|
+
this._w = width;
|
|
36
|
+
this._h = height;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
_w;
|
|
39
|
+
_h;
|
|
40
40
|
_edges;
|
|
41
41
|
// eslint-disable-next-line no-restricted-syntax
|
|
42
42
|
get edges() {
|
|
@@ -52,8 +52,8 @@ class Ellipse2d extends import_Geometry2d.Geometry2d {
|
|
|
52
52
|
return this._edges;
|
|
53
53
|
}
|
|
54
54
|
getVertices() {
|
|
55
|
-
const w = Math.max(1, this.
|
|
56
|
-
const h = Math.max(1, this.
|
|
55
|
+
const w = Math.max(1, this._w);
|
|
56
|
+
const h = Math.max(1, this._h);
|
|
57
57
|
const cx = w / 2;
|
|
58
58
|
const cy = h / 2;
|
|
59
59
|
const q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2);
|
|
@@ -68,7 +68,7 @@ class Ellipse2d extends import_Geometry2d.Geometry2d {
|
|
|
68
68
|
let tc = 1;
|
|
69
69
|
const vertices = Array(len);
|
|
70
70
|
for (let i = 0; i < len; i++) {
|
|
71
|
-
vertices[i] = new import_Vec.Vec(cx + cx * cos, cy + cy * sin);
|
|
71
|
+
vertices[i] = new import_Vec.Vec((0, import_utils.clamp)(cx + cx * cos, 0, w), (0, import_utils.clamp)(cy + cy * sin, 0, h));
|
|
72
72
|
ts = b * cos + a * sin;
|
|
73
73
|
tc = a * cos - b * sin;
|
|
74
74
|
sin = ts;
|
|
@@ -96,10 +96,10 @@ class Ellipse2d extends import_Geometry2d.Geometry2d {
|
|
|
96
96
|
return this.edges.some((edge) => edge.hitTestLineSegment(A, B));
|
|
97
97
|
}
|
|
98
98
|
getBounds() {
|
|
99
|
-
return new import_Box.Box(0, 0, this.
|
|
99
|
+
return new import_Box.Box(0, 0, this._w, this._h);
|
|
100
100
|
}
|
|
101
101
|
getLength() {
|
|
102
|
-
const { w, h } = this;
|
|
102
|
+
const { _w: w, _h: h } = this;
|
|
103
103
|
const cx = w / 2;
|
|
104
104
|
const cy = h / 2;
|
|
105
105
|
const rx = Math.max(0, cx);
|
|
@@ -107,7 +107,7 @@ class Ellipse2d extends import_Geometry2d.Geometry2d {
|
|
|
107
107
|
return (0, import_utils.perimeterOfEllipse)(rx, ry);
|
|
108
108
|
}
|
|
109
109
|
getSvgPathData(first = false) {
|
|
110
|
-
const { w, h } = this;
|
|
110
|
+
const { _w: w, _h: h } = this;
|
|
111
111
|
const cx = w / 2;
|
|
112
112
|
const cy = h / 2;
|
|
113
113
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoB;AACpB,iBAA6B;AAC7B,
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoB;AACpB,iBAA6B;AAC7B,mBAAmD;AACnD,oBAAuB;AACvB,wBAA8C;AAC9C,gCAA0C;AAGnC,MAAM,kBAAkB,6BAAW;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;AAC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J,QAAI;AACJ,eAAW,QAAQ,KAAK,OAAO;AAC9B,UAAI,KAAK,aAAa,CAAC;AACvB,UAAI,eAAI,MAAM,GAAG,CAAC;AAClB,UAAI,IAAI,MAAM;AACb,kBAAU;AACV,eAAO;AAAA,MACR;AAAA,IACD;AACA,QAAI,CAAC,QAAS,OAAM,MAAM,yBAAyB;AACnD,WAAO;AAAA,EACR;AAAA,EAEA,mBAAmB,GAAY,GAAqB;AACnD,WAAO,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,mBAAmB,GAAG,CAAC,CAAC;AAAA,EAC/D;AAAA,EAEA,YAAY;AACX,WAAO,IAAI,eAAI,GAAG,GAAG,KAAK,IAAI,KAAK,EAAE;AAAA,EACtC;AAAA,EAEA,YAAoB;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,eAAO,iCAAmB,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
|
}
|
|
@@ -24,23 +24,23 @@ module.exports = __toCommonJS(Point2d_exports);
|
|
|
24
24
|
var import_Vec = require("../Vec");
|
|
25
25
|
var import_Geometry2d = require("./Geometry2d");
|
|
26
26
|
class Point2d extends import_Geometry2d.Geometry2d {
|
|
27
|
-
|
|
27
|
+
_point;
|
|
28
28
|
constructor(config) {
|
|
29
29
|
super({ ...config, isClosed: true, isFilled: true });
|
|
30
30
|
const { point } = config;
|
|
31
|
-
this.
|
|
31
|
+
this._point = point;
|
|
32
32
|
}
|
|
33
33
|
getVertices() {
|
|
34
|
-
return [this.
|
|
34
|
+
return [this._point];
|
|
35
35
|
}
|
|
36
36
|
nearestPoint() {
|
|
37
|
-
return this.
|
|
37
|
+
return this._point;
|
|
38
38
|
}
|
|
39
39
|
hitTestLineSegment(A, B, margin) {
|
|
40
|
-
return import_Vec.Vec.DistanceToLineSegment(A, B, this.
|
|
40
|
+
return import_Vec.Vec.DistanceToLineSegment(A, B, this._point) < margin;
|
|
41
41
|
}
|
|
42
42
|
getSvgPathData() {
|
|
43
|
-
const { point } = this;
|
|
43
|
+
const { _point: point } = this;
|
|
44
44
|
return `M${point.toFixed()}`;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,wBAA8C;AAGvC,MAAM,gBAAgB,6BAAW;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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6B;AAC7B,wBAA8C;AAGvC,MAAM,gBAAgB,6BAAW;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,eAAI,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
|
}
|
|
@@ -26,6 +26,9 @@ class Polygon2d extends import_Polyline2d.Polyline2d {
|
|
|
26
26
|
constructor(config) {
|
|
27
27
|
super({ ...config });
|
|
28
28
|
this.isClosed = true;
|
|
29
|
+
if (config.points.length < 3) {
|
|
30
|
+
throw new Error("Polygon2d: points must be an array of at least 3 points");
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
//# sourceMappingURL=Polygon2d.js.map
|
|
@@ -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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA2B;AAGpB,MAAM,kBAAkB,6BAAW;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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA2B;AAGpB,MAAM,kBAAkB,6BAAW;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
|
}
|