@joint/core 4.1.2 → 4.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/geometry.js +128 -123
- package/dist/geometry.min.js +2 -2
- package/dist/joint.d.ts +79 -16
- package/dist/joint.js +2249 -1730
- package/dist/joint.min.js +2 -2
- package/dist/joint.nowrap.js +2248 -1727
- package/dist/joint.nowrap.min.js +2 -2
- package/dist/vectorizer.js +469 -272
- package/dist/vectorizer.min.js +2 -2
- package/dist/version.mjs +1 -1
- package/package.json +28 -22
- package/src/V/create.mjs +51 -0
- package/src/V/index.mjs +69 -154
- package/src/V/namespace.mjs +9 -0
- package/src/V/transform.mjs +183 -0
- package/src/V/traverse.mjs +16 -0
- package/src/anchors/index.mjs +140 -33
- package/src/cellTools/Boundary.mjs +1 -1
- package/src/cellTools/Control.mjs +1 -1
- package/src/connectionPoints/index.mjs +24 -9
- package/src/connectionStrategies/index.mjs +1 -1
- package/src/connectors/jumpover.mjs +1 -1
- package/src/dia/Cell.mjs +6 -2
- package/src/dia/CellView.mjs +47 -39
- package/src/dia/Element.mjs +79 -35
- package/src/dia/ElementView.mjs +9 -3
- package/src/dia/HighlighterView.mjs +32 -11
- package/src/dia/Paper.mjs +134 -22
- package/src/dia/PaperLayer.mjs +9 -2
- package/src/dia/attributes/text.mjs +12 -3
- package/src/dia/layers/GridLayer.mjs +5 -0
- package/src/dia/ports.mjs +152 -39
- package/src/env/index.mjs +1 -1
- package/src/g/rect.mjs +7 -0
- package/src/highlighters/stroke.mjs +1 -1
- package/src/linkAnchors/index.mjs +2 -2
- package/src/linkTools/Anchor.mjs +2 -2
- package/src/linkTools/Vertices.mjs +4 -6
- package/src/mvc/Dom/methods.mjs +2 -2
- package/src/util/util.mjs +1 -1
- package/src/util/utilHelpers.mjs +2 -0
- package/types/geometry.d.ts +2 -0
- package/types/joint.d.ts +81 -20
- package/src/V/annotation.mjs +0 -0
package/README.md
CHANGED
|
@@ -157,4 +157,4 @@ The output for all unit tests will be saved in the `packages/joint-core/coverage
|
|
|
157
157
|
|
|
158
158
|
The *JointJS* library is licensed under the [Mozilla Public License 2.0](https://github.com/clientIO/joint/blob/master/LICENSE).
|
|
159
159
|
|
|
160
|
-
Copyright © 2013-
|
|
160
|
+
Copyright © 2013-2025 client IO
|
package/dist/geometry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! JointJS v4.
|
|
1
|
+
/*! JointJS v4.2.0-alpha.0 (2025-06-16) - JavaScript diagramming library
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
This Source Code Form is subject to the terms of the Mozilla Public
|
|
@@ -8,14 +8,14 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
8
8
|
(function (global, factory) {
|
|
9
9
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
10
10
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
11
|
-
(global = global || self, factory(global.g = {}));
|
|
12
|
-
}(this, function (exports) { 'use strict';
|
|
11
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.g = {}));
|
|
12
|
+
})(this, (function (exports) { 'use strict';
|
|
13
13
|
|
|
14
14
|
// Declare shorthands to the most used math functions.
|
|
15
15
|
const {
|
|
16
|
-
round,
|
|
16
|
+
round: round$3,
|
|
17
17
|
floor,
|
|
18
|
-
PI
|
|
18
|
+
PI: PI$1
|
|
19
19
|
} = Math;
|
|
20
20
|
const scale = {
|
|
21
21
|
// Return the `value` from the `domain` interval scaled to the `range` interval.
|
|
@@ -29,15 +29,15 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
29
29
|
return angle % 360 + (angle < 0 ? 360 : 0);
|
|
30
30
|
};
|
|
31
31
|
const snapToGrid = function (value, gridSize) {
|
|
32
|
-
return gridSize * round(value / gridSize);
|
|
32
|
+
return gridSize * round$3(value / gridSize);
|
|
33
33
|
};
|
|
34
34
|
const toDeg = function (rad) {
|
|
35
|
-
return 180 * rad / PI % 360;
|
|
35
|
+
return 180 * rad / PI$1 % 360;
|
|
36
36
|
};
|
|
37
37
|
const toRad = function (deg, over360) {
|
|
38
38
|
over360 = over360 || false;
|
|
39
39
|
deg = over360 ? deg : deg % 360;
|
|
40
|
-
return deg * PI / 180;
|
|
40
|
+
return deg * PI$1 / 180;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// Return a random integer from the interval [min,max], inclusive.
|
|
@@ -56,10 +56,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
// @return the bearing (cardinal direction) of the line. For example N, W, or SE.
|
|
59
|
+
// @returns {String} One of the following bearings : NE, E, SE, S, SW, W, NW, N.
|
|
59
60
|
const {
|
|
60
|
-
cos,
|
|
61
|
-
sin,
|
|
62
|
-
atan2
|
|
61
|
+
cos: cos$2,
|
|
62
|
+
sin: sin$2,
|
|
63
|
+
atan2: atan2$1
|
|
63
64
|
} = Math;
|
|
64
65
|
const bearing = function (p, q) {
|
|
65
66
|
var lat1 = toRad(p.y);
|
|
@@ -67,9 +68,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
67
68
|
var lon1 = p.x;
|
|
68
69
|
var lon2 = q.x;
|
|
69
70
|
var dLon = toRad(lon2 - lon1);
|
|
70
|
-
var y = sin(dLon) * cos(lat2);
|
|
71
|
-
var x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
|
|
72
|
-
var brng = toDeg(atan2(y, x));
|
|
71
|
+
var y = sin$2(dLon) * cos$2(lat2);
|
|
72
|
+
var x = cos$2(lat1) * sin$2(lat2) - sin$2(lat1) * cos$2(lat2) * cos$2(dLon);
|
|
73
|
+
var brng = toDeg(atan2$1(y, x));
|
|
73
74
|
var bearings = ['NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'];
|
|
74
75
|
var index = brng - 22.5;
|
|
75
76
|
if (index < 0) index += 360;
|
|
@@ -112,16 +113,16 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
112
113
|
* `Point(Point(10, 20))`
|
|
113
114
|
*/
|
|
114
115
|
const {
|
|
115
|
-
abs,
|
|
116
|
+
abs: abs$2,
|
|
116
117
|
cos: cos$1,
|
|
117
118
|
sin: sin$1,
|
|
118
|
-
sqrt,
|
|
119
|
-
min,
|
|
120
|
-
max,
|
|
121
|
-
atan2
|
|
122
|
-
round: round$
|
|
123
|
-
pow,
|
|
124
|
-
PI
|
|
119
|
+
sqrt: sqrt$2,
|
|
120
|
+
min: min$3,
|
|
121
|
+
max: max$3,
|
|
122
|
+
atan2,
|
|
123
|
+
round: round$2,
|
|
124
|
+
pow: pow$3,
|
|
125
|
+
PI
|
|
125
126
|
} = Math;
|
|
126
127
|
const Point = function (x, y) {
|
|
127
128
|
if (!(this instanceof Point)) {
|
|
@@ -145,8 +146,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
145
146
|
// @param {point} [optional] Origin.
|
|
146
147
|
Point.fromPolar = function (distance, angle, origin) {
|
|
147
148
|
origin = new Point(origin);
|
|
148
|
-
var x = abs(distance * cos$1(angle));
|
|
149
|
-
var y = abs(distance * sin$1(angle));
|
|
149
|
+
var x = abs$2(distance * cos$1(angle));
|
|
150
|
+
var y = abs$2(distance * sin$1(angle));
|
|
150
151
|
var deg = normalizeAngle(toDeg(angle));
|
|
151
152
|
if (deg < 90) {
|
|
152
153
|
y = -y;
|
|
@@ -187,8 +188,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
187
188
|
if (r.containsPoint(this)) {
|
|
188
189
|
return this;
|
|
189
190
|
}
|
|
190
|
-
this.x = min(max(this.x, r.x), r.x + r.width);
|
|
191
|
-
this.y = min(max(this.y, r.y), r.y + r.height);
|
|
191
|
+
this.x = min$3(max$3(this.x, r.x), r.x + r.width);
|
|
192
|
+
this.y = min$3(max$3(this.y, r.y), r.y + r.height);
|
|
192
193
|
return this;
|
|
193
194
|
},
|
|
194
195
|
// Compute the angle between vector from me to p1 and the vector from me to p2.
|
|
@@ -254,11 +255,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
254
255
|
return new Point((1 - t) * x + t * p.x, (1 - t) * y + t * p.y);
|
|
255
256
|
},
|
|
256
257
|
magnitude: function () {
|
|
257
|
-
return sqrt(this.x * this.x + this.y * this.y) || 0.01;
|
|
258
|
+
return sqrt$2(this.x * this.x + this.y * this.y) || 0.01;
|
|
258
259
|
},
|
|
259
260
|
// Returns a manhattan (taxi-cab) distance between me and point `p`.
|
|
260
261
|
manhattanDistance: function (p) {
|
|
261
|
-
return abs(p.x - this.x) + abs(p.y - this.y);
|
|
262
|
+
return abs$2(p.x - this.x) + abs$2(p.y - this.y);
|
|
262
263
|
},
|
|
263
264
|
// Move point on line starting from ref ending at me by
|
|
264
265
|
// distance distance.
|
|
@@ -315,12 +316,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
315
316
|
f = 1000;
|
|
316
317
|
break;
|
|
317
318
|
default:
|
|
318
|
-
f = pow(10, precision);
|
|
319
|
+
f = pow$3(10, precision);
|
|
319
320
|
break;
|
|
320
321
|
}
|
|
321
322
|
}
|
|
322
|
-
this.x = round$
|
|
323
|
-
this.y = round$
|
|
323
|
+
this.x = round$2(this.x * f) / f;
|
|
324
|
+
this.y = round$2(this.y * f) / f;
|
|
324
325
|
return this;
|
|
325
326
|
},
|
|
326
327
|
// Scale point with origin.
|
|
@@ -347,13 +348,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
347
348
|
// Invert the y-axis.
|
|
348
349
|
var y = -(p.y - this.y);
|
|
349
350
|
var x = p.x - this.x;
|
|
350
|
-
var rad = atan2
|
|
351
|
+
var rad = atan2(y, x); // defined for all 0 corner cases
|
|
351
352
|
|
|
352
353
|
// Correction for III. and IV. quadrant.
|
|
353
354
|
if (rad < 0) {
|
|
354
|
-
rad = 2 * PI
|
|
355
|
+
rad = 2 * PI + rad;
|
|
355
356
|
}
|
|
356
|
-
return 180 * rad / PI
|
|
357
|
+
return 180 * rad / PI;
|
|
357
358
|
},
|
|
358
359
|
toJSON: function () {
|
|
359
360
|
return {
|
|
@@ -367,7 +368,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
367
368
|
o = o && new Point(o) || new Point(0, 0);
|
|
368
369
|
var x = this.x;
|
|
369
370
|
var y = this.y;
|
|
370
|
-
this.x = sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y)); // r
|
|
371
|
+
this.x = sqrt$2((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y)); // r
|
|
371
372
|
this.y = toRad(o.theta(new Point(x, y)));
|
|
372
373
|
return this;
|
|
373
374
|
},
|
|
@@ -399,8 +400,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
399
400
|
const point = Point;
|
|
400
401
|
|
|
401
402
|
const {
|
|
402
|
-
max: max$
|
|
403
|
-
min: min$
|
|
403
|
+
max: max$2,
|
|
404
|
+
min: min$2
|
|
404
405
|
} = Math;
|
|
405
406
|
const Line = function (p1, p2) {
|
|
406
407
|
if (!(this instanceof Line)) {
|
|
@@ -420,10 +421,10 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
420
421
|
return this.start.angleBetween(this.end, horizontalPoint);
|
|
421
422
|
},
|
|
422
423
|
bbox: function () {
|
|
423
|
-
var left = min$
|
|
424
|
-
var top = min$
|
|
425
|
-
var right = max$
|
|
426
|
-
var bottom = max$
|
|
424
|
+
var left = min$2(this.start.x, this.end.x);
|
|
425
|
+
var top = min$2(this.start.y, this.end.y);
|
|
426
|
+
var right = max$2(this.start.x, this.end.x);
|
|
427
|
+
var bottom = max$2(this.start.y, this.end.y);
|
|
427
428
|
return new Rect(left, top, right - left, bottom - top);
|
|
428
429
|
},
|
|
429
430
|
// @return the bearing (cardinal direction) of the line. For example N, W, or SE.
|
|
@@ -444,7 +445,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
444
445
|
// @return {number} the normalized length of the closest point on the line to point `p`
|
|
445
446
|
closestPointNormalizedLength: function (p) {
|
|
446
447
|
var product = this.vector().dot(new Line(this.start, p).vector());
|
|
447
|
-
var cpNormalizedLength = min$
|
|
448
|
+
var cpNormalizedLength = min$2(1, max$2(0, product / this.squaredLength()));
|
|
448
449
|
|
|
449
450
|
// cpNormalizedLength returns `NaN` if this line has zero length
|
|
450
451
|
// we can work with that - if `NaN`, return 0
|
|
@@ -650,8 +651,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
650
651
|
|
|
651
652
|
const {
|
|
652
653
|
sqrt: sqrt$1,
|
|
653
|
-
round: round$
|
|
654
|
-
pow: pow$
|
|
654
|
+
round: round$1,
|
|
655
|
+
pow: pow$2
|
|
655
656
|
} = Math;
|
|
656
657
|
const Ellipse = function (c, a, b) {
|
|
657
658
|
if (!(this instanceof Ellipse)) {
|
|
@@ -799,14 +800,14 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
799
800
|
f = 1000;
|
|
800
801
|
break;
|
|
801
802
|
default:
|
|
802
|
-
f = pow$
|
|
803
|
+
f = pow$2(10, precision);
|
|
803
804
|
break;
|
|
804
805
|
}
|
|
805
806
|
}
|
|
806
|
-
this.x = round$
|
|
807
|
-
this.y = round$
|
|
808
|
-
this.a = round$
|
|
809
|
-
this.b = round$
|
|
807
|
+
this.x = round$1(this.x * f) / f;
|
|
808
|
+
this.y = round$1(this.y * f) / f;
|
|
809
|
+
this.a = round$1(this.a * f) / f;
|
|
810
|
+
this.b = round$1(this.b * f) / f;
|
|
810
811
|
return this;
|
|
811
812
|
},
|
|
812
813
|
/** Compute angle between tangent and x axis
|
|
@@ -844,12 +845,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
844
845
|
|
|
845
846
|
const {
|
|
846
847
|
abs: abs$1,
|
|
847
|
-
cos
|
|
848
|
-
sin
|
|
849
|
-
min: min$
|
|
850
|
-
max: max$
|
|
851
|
-
round
|
|
852
|
-
pow: pow$
|
|
848
|
+
cos,
|
|
849
|
+
sin,
|
|
850
|
+
min: min$1,
|
|
851
|
+
max: max$1,
|
|
852
|
+
round,
|
|
853
|
+
pow: pow$1
|
|
853
854
|
} = Math;
|
|
854
855
|
const Rect = function (x, y, w, h) {
|
|
855
856
|
if (!(this instanceof Rect)) {
|
|
@@ -870,14 +871,14 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
870
871
|
e = new Ellipse(e);
|
|
871
872
|
return new Rect(e.x - e.a, e.y - e.b, 2 * e.a, 2 * e.b);
|
|
872
873
|
};
|
|
873
|
-
Rect.fromPointUnion = function () {
|
|
874
|
-
if (
|
|
874
|
+
Rect.fromPointUnion = function (...points) {
|
|
875
|
+
if (points.length === 0) return null;
|
|
875
876
|
const p = new Point();
|
|
876
877
|
let minX, minY, maxX, maxY;
|
|
877
878
|
minX = minY = Infinity;
|
|
878
879
|
maxX = maxY = -Infinity;
|
|
879
|
-
for (let i = 0; i <
|
|
880
|
-
p.update(
|
|
880
|
+
for (let i = 0; i < points.length; i++) {
|
|
881
|
+
p.update(points[i]);
|
|
881
882
|
const x = p.x;
|
|
882
883
|
const y = p.y;
|
|
883
884
|
if (x < minX) minX = x;
|
|
@@ -887,14 +888,14 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
887
888
|
}
|
|
888
889
|
return new Rect(minX, minY, maxX - minX, maxY - minY);
|
|
889
890
|
};
|
|
890
|
-
Rect.fromRectUnion = function () {
|
|
891
|
-
if (
|
|
891
|
+
Rect.fromRectUnion = function (...rects) {
|
|
892
|
+
if (rects.length === 0) return null;
|
|
892
893
|
const r = new Rect();
|
|
893
894
|
let minX, minY, maxX, maxY;
|
|
894
895
|
minX = minY = Infinity;
|
|
895
896
|
maxX = maxY = -Infinity;
|
|
896
|
-
for (let i = 0; i <
|
|
897
|
-
r.update(
|
|
897
|
+
for (let i = 0; i < rects.length; i++) {
|
|
898
|
+
r.update(rects[i]);
|
|
898
899
|
const x = r.x;
|
|
899
900
|
const y = r.y;
|
|
900
901
|
const mX = x + r.width;
|
|
@@ -920,8 +921,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
920
921
|
height
|
|
921
922
|
} = this;
|
|
922
923
|
const theta = toRad(angle);
|
|
923
|
-
const st = abs$1(sin
|
|
924
|
-
const ct = abs$1(cos
|
|
924
|
+
const st = abs$1(sin(theta));
|
|
925
|
+
const ct = abs$1(cos(theta));
|
|
925
926
|
const w = width * ct + height * st;
|
|
926
927
|
const h = width * st + height * ct;
|
|
927
928
|
this.x += (width - w) / 2;
|
|
@@ -1022,9 +1023,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1022
1023
|
|
|
1023
1024
|
// No intersection found
|
|
1024
1025
|
if (rCorner.x <= myOrigin.x || rCorner.y <= myOrigin.y || rOrigin.x >= myCorner.x || rOrigin.y >= myCorner.y) return null;
|
|
1025
|
-
var x = max$
|
|
1026
|
-
var y = max$
|
|
1027
|
-
return new Rect(x, y, min$
|
|
1026
|
+
var x = max$1(myOrigin.x, rOrigin.x);
|
|
1027
|
+
var y = max$1(myOrigin.y, rOrigin.y);
|
|
1028
|
+
return new Rect(x, y, min$1(myCorner.x, rCorner.x) - x, min$1(myCorner.y, rCorner.y) - y);
|
|
1028
1029
|
},
|
|
1029
1030
|
intersectionWithLine: function (line) {
|
|
1030
1031
|
var r = this;
|
|
@@ -1115,13 +1116,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1115
1116
|
sy4 = (this.y + this.height - oy) / (p4.y - oy);
|
|
1116
1117
|
}
|
|
1117
1118
|
return {
|
|
1118
|
-
sx: min$
|
|
1119
|
-
sy: min$
|
|
1119
|
+
sx: min$1(sx1, sx2, sx3, sx4),
|
|
1120
|
+
sy: min$1(sy1, sy2, sy3, sy4)
|
|
1120
1121
|
};
|
|
1121
1122
|
},
|
|
1122
1123
|
maxRectUniformScaleToFit: function (rect, origin) {
|
|
1123
1124
|
var scale = this.maxRectScaleToFit(rect, origin);
|
|
1124
|
-
return min$
|
|
1125
|
+
return min$1(scale.sx, scale.sy);
|
|
1125
1126
|
},
|
|
1126
1127
|
// Move and expand me.
|
|
1127
1128
|
// @param r {rectangle} representing deltas
|
|
@@ -1132,6 +1133,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1132
1133
|
this.height += r.height || 0;
|
|
1133
1134
|
return this;
|
|
1134
1135
|
},
|
|
1136
|
+
moveAroundPoint: function (origin, angle) {
|
|
1137
|
+
const newCenter = this.center().rotate(origin, angle);
|
|
1138
|
+
this.x = newCenter.x - this.width / 2;
|
|
1139
|
+
this.y = newCenter.y - this.height / 2;
|
|
1140
|
+
return this;
|
|
1141
|
+
},
|
|
1135
1142
|
// Normalize the rectangle; i.e., make it so that it has a non-negative width and height.
|
|
1136
1143
|
// If width < 0 the function swaps the left and right corners,
|
|
1137
1144
|
// and it swaps the top and bottom corners if height < 0
|
|
@@ -1203,14 +1210,14 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1203
1210
|
f = 1000;
|
|
1204
1211
|
break;
|
|
1205
1212
|
default:
|
|
1206
|
-
f = pow$
|
|
1213
|
+
f = pow$1(10, precision);
|
|
1207
1214
|
break;
|
|
1208
1215
|
}
|
|
1209
1216
|
}
|
|
1210
|
-
this.x = round
|
|
1211
|
-
this.y = round
|
|
1212
|
-
this.width = round
|
|
1213
|
-
this.height = round
|
|
1217
|
+
this.x = round(this.x * f) / f;
|
|
1218
|
+
this.y = round(this.y * f) / f;
|
|
1219
|
+
this.width = round(this.width * f) / f;
|
|
1220
|
+
this.height = round(this.height * f) / f;
|
|
1214
1221
|
return this;
|
|
1215
1222
|
},
|
|
1216
1223
|
// Scale rectangle with origin.
|
|
@@ -1800,8 +1807,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1800
1807
|
}
|
|
1801
1808
|
return this;
|
|
1802
1809
|
},
|
|
1803
|
-
simplify: function () {
|
|
1804
|
-
let opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1810
|
+
simplify: function (opt = {}) {
|
|
1805
1811
|
const points = this.points;
|
|
1806
1812
|
if (points.length < 3) return this; // we need at least 3 points
|
|
1807
1813
|
|
|
@@ -1948,11 +1954,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
1948
1954
|
});
|
|
1949
1955
|
|
|
1950
1956
|
const {
|
|
1951
|
-
abs
|
|
1952
|
-
sqrt
|
|
1953
|
-
min
|
|
1954
|
-
max
|
|
1955
|
-
pow
|
|
1957
|
+
abs,
|
|
1958
|
+
sqrt,
|
|
1959
|
+
min,
|
|
1960
|
+
max,
|
|
1961
|
+
pow
|
|
1956
1962
|
} = Math;
|
|
1957
1963
|
const Curve = function (p1, p2, p3, p4) {
|
|
1958
1964
|
if (!(this instanceof Curve)) {
|
|
@@ -2101,9 +2107,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2101
2107
|
a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
|
2102
2108
|
c = 3 * y1 - 3 * y0;
|
|
2103
2109
|
}
|
|
2104
|
-
if (abs
|
|
2110
|
+
if (abs(a) < 1e-12) {
|
|
2105
2111
|
// Numerical robustness
|
|
2106
|
-
if (abs
|
|
2112
|
+
if (abs(b) < 1e-12) {
|
|
2107
2113
|
// Numerical robustness
|
|
2108
2114
|
continue;
|
|
2109
2115
|
}
|
|
@@ -2112,7 +2118,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2112
2118
|
continue;
|
|
2113
2119
|
}
|
|
2114
2120
|
b2ac = b * b - 4 * c * a;
|
|
2115
|
-
sqrtb2ac = sqrt
|
|
2121
|
+
sqrtb2ac = sqrt(b2ac);
|
|
2116
2122
|
if (b2ac < 0) continue;
|
|
2117
2123
|
t1 = (-b + sqrtb2ac) / (2 * a);
|
|
2118
2124
|
if (0 < t1 && t1 < 1) tvalues.push(t1);
|
|
@@ -2153,10 +2159,10 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2153
2159
|
bounds[0].length = jlen + 2;
|
|
2154
2160
|
bounds[1].length = jlen + 2;
|
|
2155
2161
|
points.length = jlen + 2;
|
|
2156
|
-
var left = min
|
|
2157
|
-
var top = min
|
|
2158
|
-
var right = max
|
|
2159
|
-
var bottom = max
|
|
2162
|
+
var left = min.apply(null, bounds[0]);
|
|
2163
|
+
var top = min.apply(null, bounds[1]);
|
|
2164
|
+
var right = max.apply(null, bounds[0]);
|
|
2165
|
+
var bottom = max.apply(null, bounds[1]);
|
|
2160
2166
|
return new Rect(left, top, right - left, bottom - top);
|
|
2161
2167
|
},
|
|
2162
2168
|
clone: function () {
|
|
@@ -2230,7 +2236,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2230
2236
|
minSumDist = sumDist;
|
|
2231
2237
|
}
|
|
2232
2238
|
}
|
|
2233
|
-
var precisionRatio = pow
|
|
2239
|
+
var precisionRatio = pow(10, -precision);
|
|
2234
2240
|
|
|
2235
2241
|
// recursively divide investigated subdivision:
|
|
2236
2242
|
// until distance between baselinePoint and closest path endpoint is within 10^(-precision)
|
|
@@ -2241,8 +2247,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2241
2247
|
// - note that this function is not monotonic = it doesn't converge stably but has "teeth"
|
|
2242
2248
|
// - the function decreases while one of the endpoints is fixed but "jumps" whenever we switch
|
|
2243
2249
|
// - this criterion works well for points lying far away from the curve
|
|
2244
|
-
var startPrecisionRatio = distFromStart ? abs
|
|
2245
|
-
var endPrecisionRatio = distFromEnd ? abs
|
|
2250
|
+
var startPrecisionRatio = distFromStart ? abs(distFromStart - distFromEnd) / distFromStart : 0;
|
|
2251
|
+
var endPrecisionRatio = distFromEnd ? abs(distFromStart - distFromEnd) / distFromEnd : 0;
|
|
2246
2252
|
var hasRequiredPrecision = startPrecisionRatio < precisionRatio || endPrecisionRatio < precisionRatio;
|
|
2247
2253
|
|
|
2248
2254
|
// check if we have reached at least one required minimal distance
|
|
@@ -2409,7 +2415,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2409
2415
|
var isPoint = !this.isDifferentiable();
|
|
2410
2416
|
if (isPoint) return subdivisions;
|
|
2411
2417
|
var previousLength = this.endpointDistance();
|
|
2412
|
-
var precisionRatio = pow
|
|
2418
|
+
var precisionRatio = pow(10, -precision);
|
|
2413
2419
|
|
|
2414
2420
|
// special case #2: sine-like curves may have the same observed length in iteration 0 and 1 - skip iteration 1
|
|
2415
2421
|
// - not a problem for further iterations because cubic curves cannot have more than two local extrema
|
|
@@ -2641,7 +2647,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2641
2647
|
// e.g. at precision 1, the length may be underestimated by up to 10% and cause this function to return 1
|
|
2642
2648
|
|
|
2643
2649
|
var curveLength = this.length(localOpt);
|
|
2644
|
-
var precisionRatio = pow
|
|
2650
|
+
var precisionRatio = pow(10, -precision);
|
|
2645
2651
|
|
|
2646
2652
|
// recursively divide investigated subdivision:
|
|
2647
2653
|
// until distance between baselinePoint and closest path endpoint is within 10^(-precision)
|
|
@@ -2776,6 +2782,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
2776
2782
|
}
|
|
2777
2783
|
|
|
2778
2784
|
// Accepts path data string, array of segments, array of Curves and/or Lines, or a Polyline.
|
|
2785
|
+
// Path created is not guaranteed to be a valid (serializable) path (might not start with an M).
|
|
2779
2786
|
const Path = function (arg) {
|
|
2780
2787
|
if (!(this instanceof Path)) {
|
|
2781
2788
|
return new Path(arg);
|
|
@@ -5080,8 +5087,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
5080
5087
|
}
|
|
5081
5088
|
});
|
|
5082
5089
|
}
|
|
5083
|
-
function _polylineWithLine(polyline, line) {
|
|
5084
|
-
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5090
|
+
function _polylineWithLine(polyline, line, opt = {}) {
|
|
5085
5091
|
const {
|
|
5086
5092
|
interior = false
|
|
5087
5093
|
} = opt;
|
|
@@ -5114,8 +5120,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
5114
5120
|
}
|
|
5115
5121
|
return false;
|
|
5116
5122
|
}
|
|
5117
|
-
function _polylineWithEllipse(polyline, ellipse) {
|
|
5118
|
-
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5123
|
+
function _polylineWithEllipse(polyline, ellipse, opt = {}) {
|
|
5119
5124
|
const {
|
|
5120
5125
|
start,
|
|
5121
5126
|
end,
|
|
@@ -5168,8 +5173,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
5168
5173
|
}
|
|
5169
5174
|
});
|
|
5170
5175
|
}
|
|
5171
|
-
function _polylineWithPolyline(polyline1, polyline2) {
|
|
5172
|
-
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5176
|
+
function _polylineWithPolyline(polyline1, polyline2, opt = {}) {
|
|
5173
5177
|
const {
|
|
5174
5178
|
interior = false
|
|
5175
5179
|
} = opt;
|
|
@@ -5261,32 +5265,35 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
5261
5265
|
return m[0][0] * m[1][1] * m[2][2] - m[0][0] * m[1][2] * m[2][1] - m[0][1] * m[1][0] * m[2][2] + m[0][1] * m[1][2] * m[2][0] + m[0][2] * m[1][0] * m[2][1] - m[0][2] * m[1][1] * m[2][0];
|
|
5262
5266
|
}
|
|
5263
5267
|
|
|
5264
|
-
var _intersection =
|
|
5268
|
+
var _intersection = {
|
|
5269
|
+
__proto__: null,
|
|
5270
|
+
ellipseWithEllipse: ellipseWithEllipse,
|
|
5271
|
+
ellipseWithLine: ellipseWithLine,
|
|
5265
5272
|
exists: exists,
|
|
5266
5273
|
lineWithLine: lineWithLine,
|
|
5267
|
-
ellipseWithLine: ellipseWithLine,
|
|
5268
|
-
ellipseWithEllipse: ellipseWithEllipse,
|
|
5269
|
-
rectWithLine: rectWithLine,
|
|
5270
|
-
rectWithEllipse: rectWithEllipse,
|
|
5271
|
-
rectWithRect: rectWithRect,
|
|
5272
|
-
polylineWithLine: polylineWithLine,
|
|
5273
|
-
polylineWithEllipse: polylineWithEllipse,
|
|
5274
|
-
polylineWithRect: polylineWithRect,
|
|
5275
|
-
polylineWithPolyline: polylineWithPolyline,
|
|
5276
|
-
polygonWithLine: polygonWithLine,
|
|
5277
|
-
polygonWithEllipse: polygonWithEllipse,
|
|
5278
|
-
polygonWithRect: polygonWithRect,
|
|
5279
|
-
polygonWithPolyline: polygonWithPolyline,
|
|
5280
|
-
polygonWithPolygon: polygonWithPolygon,
|
|
5281
|
-
pathWithLine: pathWithLine,
|
|
5282
5274
|
pathWithEllipse: pathWithEllipse,
|
|
5283
|
-
|
|
5284
|
-
|
|
5275
|
+
pathWithLine: pathWithLine,
|
|
5276
|
+
pathWithPath: pathWithPath,
|
|
5285
5277
|
pathWithPolygon: pathWithPolygon,
|
|
5286
|
-
|
|
5287
|
-
|
|
5278
|
+
pathWithPolyline: pathWithPolyline,
|
|
5279
|
+
pathWithRect: pathWithRect,
|
|
5280
|
+
polygonWithEllipse: polygonWithEllipse,
|
|
5281
|
+
polygonWithLine: polygonWithLine,
|
|
5282
|
+
polygonWithPolygon: polygonWithPolygon,
|
|
5283
|
+
polygonWithPolyline: polygonWithPolyline,
|
|
5284
|
+
polygonWithRect: polygonWithRect,
|
|
5285
|
+
polylineWithEllipse: polylineWithEllipse,
|
|
5286
|
+
polylineWithLine: polylineWithLine,
|
|
5287
|
+
polylineWithPolyline: polylineWithPolyline,
|
|
5288
|
+
polylineWithRect: polylineWithRect,
|
|
5289
|
+
rectWithEllipse: rectWithEllipse,
|
|
5290
|
+
rectWithLine: rectWithLine,
|
|
5291
|
+
rectWithRect: rectWithRect
|
|
5292
|
+
};
|
|
5288
5293
|
|
|
5289
5294
|
// Geometry library.
|
|
5295
|
+
// -----------------
|
|
5296
|
+
|
|
5290
5297
|
const intersection = _intersection;
|
|
5291
5298
|
|
|
5292
5299
|
exports.Curve = Curve;
|
|
@@ -5311,6 +5318,4 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
5311
5318
|
exports.toRad = toRad;
|
|
5312
5319
|
exports.types = types;
|
|
5313
5320
|
|
|
5314
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5315
|
-
|
|
5316
5321
|
}));
|