modern-path2d 0.1.7 → 0.1.9
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/index.cjs +319 -278
- package/dist/index.d.cts +143 -135
- package/dist/index.d.mts +143 -135
- package/dist/index.d.ts +143 -135
- package/dist/index.js +1 -1
- package/dist/index.mjs +319 -278
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
class
|
|
1
|
+
class Vector2 {
|
|
2
2
|
constructor(x = 0, y = 0) {
|
|
3
3
|
this.x = x;
|
|
4
4
|
this.y = y;
|
|
5
5
|
}
|
|
6
6
|
static get MAX() {
|
|
7
|
-
return new
|
|
7
|
+
return new Vector2(Infinity, Infinity);
|
|
8
8
|
}
|
|
9
9
|
static get MIN() {
|
|
10
|
-
return new
|
|
10
|
+
return new Vector2(-Infinity, -Infinity);
|
|
11
11
|
}
|
|
12
12
|
set(x, y) {
|
|
13
13
|
this.x = x;
|
|
14
14
|
this.y = y;
|
|
15
15
|
return this;
|
|
16
16
|
}
|
|
17
|
-
add(
|
|
18
|
-
this.x +=
|
|
19
|
-
this.y +=
|
|
17
|
+
add(vec) {
|
|
18
|
+
this.x += vec.x;
|
|
19
|
+
this.y += vec.y;
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
|
-
sub(
|
|
23
|
-
this.x -=
|
|
24
|
-
this.y -=
|
|
22
|
+
sub(vec) {
|
|
23
|
+
this.x -= vec.x;
|
|
24
|
+
this.y -= vec.y;
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
|
-
distanceTo(
|
|
28
|
-
return Math.sqrt(this.distanceToSquared(
|
|
27
|
+
distanceTo(vec) {
|
|
28
|
+
return Math.sqrt(this.distanceToSquared(vec));
|
|
29
29
|
}
|
|
30
|
-
distanceToSquared(
|
|
31
|
-
const dx = this.x -
|
|
32
|
-
const dy = this.y -
|
|
30
|
+
distanceToSquared(vec) {
|
|
31
|
+
const dx = this.x - vec.x;
|
|
32
|
+
const dy = this.y - vec.y;
|
|
33
33
|
return dx * dx + dy * dy;
|
|
34
34
|
}
|
|
35
35
|
length() {
|
|
@@ -56,8 +56,8 @@ class Point2D {
|
|
|
56
56
|
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
|
-
equals(
|
|
60
|
-
return this.x ===
|
|
59
|
+
equals(vec) {
|
|
60
|
+
return this.x === vec.x && this.y === vec.y;
|
|
61
61
|
}
|
|
62
62
|
applyMatrix3(m) {
|
|
63
63
|
const x = this.x;
|
|
@@ -67,13 +67,13 @@ class Point2D {
|
|
|
67
67
|
this.y = e[1] * x + e[4] * y + e[7];
|
|
68
68
|
return this;
|
|
69
69
|
}
|
|
70
|
-
copy(
|
|
71
|
-
this.x =
|
|
72
|
-
this.y =
|
|
70
|
+
copy(vec) {
|
|
71
|
+
this.x = vec.x;
|
|
72
|
+
this.y = vec.y;
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
75
|
clone() {
|
|
76
|
-
return new
|
|
76
|
+
return new Vector2(this.x, this.y);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -127,7 +127,7 @@ class BoundingBox {
|
|
|
127
127
|
return this;
|
|
128
128
|
}
|
|
129
129
|
getCenterPoint() {
|
|
130
|
-
return new
|
|
130
|
+
return new Vector2((this.left + this.right) / 2, (this.top + this.bottom) / 2);
|
|
131
131
|
}
|
|
132
132
|
clone() {
|
|
133
133
|
return new BoundingBox(this.left, this.top, this.width, this.height);
|
|
@@ -389,9 +389,9 @@ function getReflection(a, b) {
|
|
|
389
389
|
return a - (b - a);
|
|
390
390
|
}
|
|
391
391
|
function addPathCommandsToPath2D(commands, path) {
|
|
392
|
-
const point = new
|
|
393
|
-
const control = new
|
|
394
|
-
const firstPoint = new
|
|
392
|
+
const point = new Vector2();
|
|
393
|
+
const control = new Vector2();
|
|
394
|
+
const firstPoint = new Vector2();
|
|
395
395
|
let isFirstPoint = true;
|
|
396
396
|
let doSetFirstPoint = false;
|
|
397
397
|
for (let i = 0, l = commands.length; i < l; i++) {
|
|
@@ -918,7 +918,7 @@ class Curve {
|
|
|
918
918
|
__publicField$5(this, "_cacheArcLengths");
|
|
919
919
|
__publicField$5(this, "_needsUpdate", false);
|
|
920
920
|
}
|
|
921
|
-
getPointAt(u, output = new
|
|
921
|
+
getPointAt(u, output = new Vector2()) {
|
|
922
922
|
return this.getPoint(this.getUtoTmapping(u), output);
|
|
923
923
|
}
|
|
924
924
|
getPoints(divisions = 5) {
|
|
@@ -997,30 +997,28 @@ class Curve {
|
|
|
997
997
|
const segmentFraction = (targetArcLength - lengthBefore) / segmentLength;
|
|
998
998
|
return (i + segmentFraction) / (il - 1);
|
|
999
999
|
}
|
|
1000
|
-
getTangent(t, output = new
|
|
1000
|
+
getTangent(t, output = new Vector2()) {
|
|
1001
1001
|
const delta = 1e-4;
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
t2 = 1;
|
|
1008
|
-
return output.copy(this.getPoint(t2)).sub(this.getPoint(t1)).normalize();
|
|
1009
|
-
}
|
|
1010
|
-
getTangentAt(u, output = new Point2D()) {
|
|
1002
|
+
const t1 = Math.max(0, t - delta);
|
|
1003
|
+
const t2 = Math.min(1, t + delta);
|
|
1004
|
+
return output.copy(this.getPoint(t2).sub(this.getPoint(t1)).normalize());
|
|
1005
|
+
}
|
|
1006
|
+
getTangentAt(u, output) {
|
|
1011
1007
|
return this.getTangent(this.getUtoTmapping(u), output);
|
|
1012
1008
|
}
|
|
1013
1009
|
/** overrideable */
|
|
1014
1010
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
1011
|
+
transformPoint(cb) {
|
|
1012
|
+
return this;
|
|
1013
|
+
}
|
|
1015
1014
|
transform(matrix) {
|
|
1015
|
+
this.transformPoint((point) => point.applyMatrix3(matrix));
|
|
1016
1016
|
return this;
|
|
1017
1017
|
}
|
|
1018
|
-
/** overrideable */
|
|
1019
1018
|
getDivisions(divisions) {
|
|
1020
1019
|
return divisions;
|
|
1021
1020
|
}
|
|
1022
|
-
|
|
1023
|
-
getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
|
|
1021
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1024
1022
|
this.getPoints().forEach((point) => {
|
|
1025
1023
|
min.x = Math.min(min.x, point.x);
|
|
1026
1024
|
min.y = Math.min(min.y, point.y);
|
|
@@ -1033,9 +1031,14 @@ class Curve {
|
|
|
1033
1031
|
const { min, max } = this.getMinMax();
|
|
1034
1032
|
return new BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
|
|
1035
1033
|
}
|
|
1036
|
-
/** overrideable */
|
|
1037
1034
|
getCommands() {
|
|
1038
|
-
return
|
|
1035
|
+
return this.getPoints().map((point, i) => {
|
|
1036
|
+
if (i === 0) {
|
|
1037
|
+
return { type: "M", x: point.x, y: point.y };
|
|
1038
|
+
} else {
|
|
1039
|
+
return { type: "L", x: point.x, y: point.y };
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1039
1042
|
}
|
|
1040
1043
|
getData() {
|
|
1041
1044
|
return pathCommandsToPathData(this.getCommands());
|
|
@@ -1068,14 +1071,18 @@ class CircleCurve extends Curve {
|
|
|
1068
1071
|
}
|
|
1069
1072
|
getTangent(t) {
|
|
1070
1073
|
const { x, y } = this.getNormal(t);
|
|
1071
|
-
return new
|
|
1074
|
+
return new Vector2(-y, x);
|
|
1072
1075
|
}
|
|
1073
1076
|
getNormal(t) {
|
|
1074
1077
|
const { start, end } = this;
|
|
1075
1078
|
const _t = t * (end - start) + start - 0.5 * Math.PI;
|
|
1076
|
-
return new
|
|
1079
|
+
return new Vector2(Math.cos(_t), Math.sin(_t));
|
|
1080
|
+
}
|
|
1081
|
+
transformPoint(cb) {
|
|
1082
|
+
cb(this.center);
|
|
1083
|
+
return this;
|
|
1077
1084
|
}
|
|
1078
|
-
getMinMax(min =
|
|
1085
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1079
1086
|
min.x = Math.min(min.x, this.center.x - this.radius);
|
|
1080
1087
|
min.y = Math.min(min.y, this.center.y - this.radius);
|
|
1081
1088
|
max.x = Math.max(max.x, this.center.x + this.radius);
|
|
@@ -1123,54 +1130,54 @@ function cubicBezier(t, p0, p1, p2, p3) {
|
|
|
1123
1130
|
}
|
|
1124
1131
|
|
|
1125
1132
|
class CubicBezierCurve extends Curve {
|
|
1126
|
-
constructor(
|
|
1133
|
+
constructor(start = new Vector2(), startControl = new Vector2(), endControl = new Vector2(), end = new Vector2()) {
|
|
1127
1134
|
super();
|
|
1128
|
-
this.
|
|
1129
|
-
this.
|
|
1130
|
-
this.
|
|
1131
|
-
this.
|
|
1135
|
+
this.start = start;
|
|
1136
|
+
this.startControl = startControl;
|
|
1137
|
+
this.endControl = endControl;
|
|
1138
|
+
this.end = end;
|
|
1132
1139
|
}
|
|
1133
|
-
getPoint(t, output = new
|
|
1134
|
-
const {
|
|
1140
|
+
getPoint(t, output = new Vector2()) {
|
|
1141
|
+
const { start, startControl, endControl, end } = this;
|
|
1135
1142
|
output.set(
|
|
1136
|
-
cubicBezier(t,
|
|
1137
|
-
cubicBezier(t,
|
|
1143
|
+
cubicBezier(t, start.x, startControl.x, endControl.x, end.x),
|
|
1144
|
+
cubicBezier(t, start.y, startControl.y, endControl.y, end.y)
|
|
1138
1145
|
);
|
|
1139
1146
|
return output;
|
|
1140
1147
|
}
|
|
1141
|
-
|
|
1142
|
-
this.
|
|
1143
|
-
this.
|
|
1144
|
-
this.
|
|
1145
|
-
this.
|
|
1146
|
-
return this;
|
|
1147
|
-
}
|
|
1148
|
-
getMinMax(min =
|
|
1149
|
-
const {
|
|
1150
|
-
min.x = Math.min(min.x,
|
|
1151
|
-
min.y = Math.min(min.y,
|
|
1152
|
-
max.x = Math.max(max.x,
|
|
1153
|
-
max.y = Math.max(max.y,
|
|
1148
|
+
transformPoint(cb) {
|
|
1149
|
+
cb(this.start);
|
|
1150
|
+
cb(this.startControl);
|
|
1151
|
+
cb(this.endControl);
|
|
1152
|
+
cb(this.end);
|
|
1153
|
+
return this;
|
|
1154
|
+
}
|
|
1155
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1156
|
+
const { start, startControl, endControl, end } = this;
|
|
1157
|
+
min.x = Math.min(min.x, start.x, startControl.x, endControl.x, end.x);
|
|
1158
|
+
min.y = Math.min(min.y, start.y, startControl.y, endControl.y, end.y);
|
|
1159
|
+
max.x = Math.max(max.x, start.x, startControl.x, endControl.x, end.x);
|
|
1160
|
+
max.y = Math.max(max.y, start.y, startControl.y, endControl.y, end.y);
|
|
1154
1161
|
return { min, max };
|
|
1155
1162
|
}
|
|
1156
1163
|
getCommands() {
|
|
1157
|
-
const {
|
|
1164
|
+
const { start, startControl, endControl, end } = this;
|
|
1158
1165
|
return [
|
|
1159
|
-
{ type: "M", x:
|
|
1160
|
-
{ type: "C", x1:
|
|
1166
|
+
{ type: "M", x: start.x, y: start.y },
|
|
1167
|
+
{ type: "C", x1: startControl.x, y1: startControl.y, x2: endControl.x, y2: endControl.y, x: end.x, y: end.y }
|
|
1161
1168
|
];
|
|
1162
1169
|
}
|
|
1163
1170
|
drawTo(ctx) {
|
|
1164
|
-
const {
|
|
1165
|
-
ctx.bezierCurveTo(
|
|
1171
|
+
const { startControl, endControl, end } = this;
|
|
1172
|
+
ctx.bezierCurveTo(startControl.x, startControl.y, endControl.x, endControl.y, end.x, end.y);
|
|
1166
1173
|
return this;
|
|
1167
1174
|
}
|
|
1168
1175
|
copy(source) {
|
|
1169
1176
|
super.copy(source);
|
|
1170
|
-
this.
|
|
1171
|
-
this.
|
|
1172
|
-
this.
|
|
1173
|
-
this.
|
|
1177
|
+
this.start.copy(source.start);
|
|
1178
|
+
this.startControl.copy(source.startControl);
|
|
1179
|
+
this.endControl.copy(source.endControl);
|
|
1180
|
+
this.end.copy(source.end);
|
|
1174
1181
|
return this;
|
|
1175
1182
|
}
|
|
1176
1183
|
}
|
|
@@ -1178,12 +1185,11 @@ class CubicBezierCurve extends Curve {
|
|
|
1178
1185
|
const tempTransform0$1 = new Matrix3();
|
|
1179
1186
|
const tempTransform1$1 = new Matrix3();
|
|
1180
1187
|
const tempTransform2$1 = new Matrix3();
|
|
1181
|
-
const tempV2 = new
|
|
1188
|
+
const tempV2 = new Vector2();
|
|
1182
1189
|
class EllipseCurve extends Curve {
|
|
1183
|
-
constructor(
|
|
1190
|
+
constructor(center = new Vector2(), radiusX = 1, radiusY = 1, startAngle = 0, endAngle = Math.PI * 2, clockwise = false, rotation = 0) {
|
|
1184
1191
|
super();
|
|
1185
|
-
this.
|
|
1186
|
-
this.y = y;
|
|
1192
|
+
this.center = center;
|
|
1187
1193
|
this.radiusX = radiusX;
|
|
1188
1194
|
this.radiusY = radiusY;
|
|
1189
1195
|
this.startAngle = startAngle;
|
|
@@ -1191,7 +1197,7 @@ class EllipseCurve extends Curve {
|
|
|
1191
1197
|
this.clockwise = clockwise;
|
|
1192
1198
|
this.rotation = rotation;
|
|
1193
1199
|
}
|
|
1194
|
-
getPoint(t, output = new
|
|
1200
|
+
getPoint(t, output = new Vector2()) {
|
|
1195
1201
|
const twoPi = Math.PI * 2;
|
|
1196
1202
|
let deltaAngle = this.endAngle - this.startAngle;
|
|
1197
1203
|
const samePoints = Math.abs(deltaAngle) < Number.EPSILON;
|
|
@@ -1214,15 +1220,15 @@ class EllipseCurve extends Curve {
|
|
|
1214
1220
|
}
|
|
1215
1221
|
}
|
|
1216
1222
|
const angle = this.startAngle + t * deltaAngle;
|
|
1217
|
-
let _x = this.x + this.radiusX * Math.cos(angle);
|
|
1218
|
-
let _y = this.y + this.radiusY * Math.sin(angle);
|
|
1223
|
+
let _x = this.center.x + this.radiusX * Math.cos(angle);
|
|
1224
|
+
let _y = this.center.y + this.radiusY * Math.sin(angle);
|
|
1219
1225
|
if (this.rotation !== 0) {
|
|
1220
1226
|
const cos = Math.cos(this.rotation);
|
|
1221
1227
|
const sin = Math.sin(this.rotation);
|
|
1222
|
-
const tx = _x - this.x;
|
|
1223
|
-
const ty = _y - this.y;
|
|
1224
|
-
_x = tx * cos - ty * sin + this.x;
|
|
1225
|
-
_y = tx * sin + ty * cos + this.y;
|
|
1228
|
+
const tx = _x - this.center.x;
|
|
1229
|
+
const ty = _y - this.center.y;
|
|
1230
|
+
_x = tx * cos - ty * sin + this.center.x;
|
|
1231
|
+
_y = tx * sin + ty * cos + this.center.y;
|
|
1226
1232
|
}
|
|
1227
1233
|
return output.set(_x, _y);
|
|
1228
1234
|
}
|
|
@@ -1230,7 +1236,8 @@ class EllipseCurve extends Curve {
|
|
|
1230
1236
|
return divisions * 2;
|
|
1231
1237
|
}
|
|
1232
1238
|
getCommands() {
|
|
1233
|
-
const {
|
|
1239
|
+
const { center, radiusX: rx, radiusY: ry, startAngle, endAngle, clockwise, rotation } = this;
|
|
1240
|
+
const { x: cx, y: cy } = center;
|
|
1234
1241
|
const startX = cx + rx * Math.cos(startAngle) * Math.cos(rotation) - ry * Math.sin(startAngle) * Math.sin(rotation);
|
|
1235
1242
|
const startY = cy + rx * Math.cos(startAngle) * Math.sin(rotation) + ry * Math.sin(startAngle) * Math.cos(rotation);
|
|
1236
1243
|
const angleDiff = Math.abs(startAngle - endAngle);
|
|
@@ -1256,10 +1263,10 @@ class EllipseCurve extends Curve {
|
|
|
1256
1263
|
}
|
|
1257
1264
|
}
|
|
1258
1265
|
drawTo(ctx) {
|
|
1259
|
-
const {
|
|
1266
|
+
const { center, radiusX, radiusY, rotation, startAngle, endAngle, clockwise } = this;
|
|
1260
1267
|
ctx.ellipse(
|
|
1261
|
-
x,
|
|
1262
|
-
y,
|
|
1268
|
+
center.x,
|
|
1269
|
+
center.y,
|
|
1263
1270
|
radiusX,
|
|
1264
1271
|
radiusY,
|
|
1265
1272
|
rotation,
|
|
@@ -1270,10 +1277,10 @@ class EllipseCurve extends Curve {
|
|
|
1270
1277
|
return this;
|
|
1271
1278
|
}
|
|
1272
1279
|
transform(matrix) {
|
|
1273
|
-
tempV2.set(this.x, this.y);
|
|
1280
|
+
tempV2.set(this.center.x, this.center.y);
|
|
1274
1281
|
tempV2.applyMatrix3(matrix);
|
|
1275
|
-
this.x = tempV2.x;
|
|
1276
|
-
this.y = tempV2.y;
|
|
1282
|
+
this.center.x = tempV2.x;
|
|
1283
|
+
this.center.y = tempV2.y;
|
|
1277
1284
|
if (isTransformSkewed(matrix)) {
|
|
1278
1285
|
transfEllipseGeneric(this, matrix);
|
|
1279
1286
|
} else {
|
|
@@ -1281,8 +1288,13 @@ class EllipseCurve extends Curve {
|
|
|
1281
1288
|
}
|
|
1282
1289
|
return this;
|
|
1283
1290
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1291
|
+
transformPoint(cb) {
|
|
1292
|
+
cb(this.center);
|
|
1293
|
+
return this;
|
|
1294
|
+
}
|
|
1295
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1296
|
+
const { center, radiusX: rx, radiusY: ry, rotation: theta } = this;
|
|
1297
|
+
const { x: cx, y: cy } = center;
|
|
1286
1298
|
const cosTheta = Math.cos(theta);
|
|
1287
1299
|
const sinTheta = Math.sin(theta);
|
|
1288
1300
|
const halfWidth = Math.sqrt(
|
|
@@ -1299,8 +1311,8 @@ class EllipseCurve extends Curve {
|
|
|
1299
1311
|
}
|
|
1300
1312
|
copy(source) {
|
|
1301
1313
|
super.copy(source);
|
|
1302
|
-
this.x = source.x;
|
|
1303
|
-
this.y = source.y;
|
|
1314
|
+
this.center.x = source.center.x;
|
|
1315
|
+
this.center.y = source.center.y;
|
|
1304
1316
|
this.radiusX = source.radiusX;
|
|
1305
1317
|
this.radiusY = source.radiusY;
|
|
1306
1318
|
this.startAngle = source.startAngle;
|
|
@@ -1315,8 +1327,8 @@ function transfEllipseGeneric(curve, m) {
|
|
|
1315
1327
|
const b = curve.radiusY;
|
|
1316
1328
|
const cosTheta = Math.cos(curve.rotation);
|
|
1317
1329
|
const sinTheta = Math.sin(curve.rotation);
|
|
1318
|
-
const v1 = new
|
|
1319
|
-
const v2 = new
|
|
1330
|
+
const v1 = new Vector2(a * cosTheta, a * sinTheta);
|
|
1331
|
+
const v2 = new Vector2(-b * sinTheta, b * cosTheta);
|
|
1320
1332
|
const f1 = v1.applyMatrix3(m);
|
|
1321
1333
|
const f2 = v2.applyMatrix3(m);
|
|
1322
1334
|
const mF = tempTransform0$1.set(
|
|
@@ -1366,7 +1378,7 @@ function transfEllipseGeneric(curve, m) {
|
|
|
1366
1378
|
);
|
|
1367
1379
|
const mDRF = mDsqrt.multiply(mRT).multiply(mF);
|
|
1368
1380
|
const transformAngle = (phi) => {
|
|
1369
|
-
const { x: cosR, y: sinR } = new
|
|
1381
|
+
const { x: cosR, y: sinR } = new Vector2(Math.cos(phi), Math.sin(phi)).applyMatrix3(mDRF);
|
|
1370
1382
|
return Math.atan2(sinR, cosR);
|
|
1371
1383
|
};
|
|
1372
1384
|
curve.startAngle = transformAngle(curve.startAngle);
|
|
@@ -1451,61 +1463,64 @@ function eigenDecomposition(A, B, C) {
|
|
|
1451
1463
|
}
|
|
1452
1464
|
|
|
1453
1465
|
class LineCurve extends Curve {
|
|
1454
|
-
constructor(
|
|
1466
|
+
constructor(start = new Vector2(), end = new Vector2()) {
|
|
1455
1467
|
super();
|
|
1456
|
-
this.
|
|
1457
|
-
this.
|
|
1468
|
+
this.start = start;
|
|
1469
|
+
this.end = end;
|
|
1458
1470
|
}
|
|
1459
|
-
getPoint(t, output = new
|
|
1471
|
+
getPoint(t, output = new Vector2()) {
|
|
1460
1472
|
if (t === 1) {
|
|
1461
|
-
output.copy(this.
|
|
1473
|
+
output.copy(this.end);
|
|
1462
1474
|
} else {
|
|
1463
|
-
output.copy(this.
|
|
1464
|
-
output.multiplyScalar(t).add(this.v1);
|
|
1475
|
+
output.copy(this.end).sub(this.start).multiplyScalar(t).add(this.start);
|
|
1465
1476
|
}
|
|
1466
1477
|
return output;
|
|
1467
1478
|
}
|
|
1468
|
-
getPointAt(u, output = new
|
|
1479
|
+
getPointAt(u, output = new Vector2()) {
|
|
1469
1480
|
return this.getPoint(u, output);
|
|
1470
1481
|
}
|
|
1471
|
-
getTangent(
|
|
1472
|
-
return output.subVectors(this.
|
|
1482
|
+
getTangent(_t, output = new Vector2()) {
|
|
1483
|
+
return output.subVectors(this.end, this.start).normalize();
|
|
1473
1484
|
}
|
|
1474
|
-
getTangentAt(u, output = new
|
|
1485
|
+
getTangentAt(u, output = new Vector2()) {
|
|
1475
1486
|
return this.getTangent(u, output);
|
|
1476
1487
|
}
|
|
1477
|
-
|
|
1478
|
-
this.
|
|
1479
|
-
|
|
1488
|
+
getNormal(t, output = new Vector2()) {
|
|
1489
|
+
const { x, y } = this.getPoint(t).sub(this.start);
|
|
1490
|
+
return output.set(y, -x).normalize();
|
|
1491
|
+
}
|
|
1492
|
+
transformPoint(cb) {
|
|
1493
|
+
cb(this.start);
|
|
1494
|
+
cb(this.end);
|
|
1480
1495
|
return this;
|
|
1481
1496
|
}
|
|
1482
1497
|
getDivisions() {
|
|
1483
1498
|
return 1;
|
|
1484
1499
|
}
|
|
1485
|
-
getMinMax(min =
|
|
1486
|
-
const {
|
|
1487
|
-
min.x = Math.min(min.x,
|
|
1488
|
-
min.y = Math.min(min.y,
|
|
1489
|
-
max.x = Math.max(max.x,
|
|
1490
|
-
max.y = Math.max(max.y,
|
|
1500
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1501
|
+
const { start, end } = this;
|
|
1502
|
+
min.x = Math.min(min.x, start.x, end.x);
|
|
1503
|
+
min.y = Math.min(min.y, start.y, end.y);
|
|
1504
|
+
max.x = Math.max(max.x, start.x, end.x);
|
|
1505
|
+
max.y = Math.max(max.y, start.y, end.y);
|
|
1491
1506
|
return { min, max };
|
|
1492
1507
|
}
|
|
1493
1508
|
getCommands() {
|
|
1494
|
-
const {
|
|
1509
|
+
const { start, end } = this;
|
|
1495
1510
|
return [
|
|
1496
|
-
{ type: "M", x:
|
|
1497
|
-
{ type: "L", x:
|
|
1511
|
+
{ type: "M", x: start.x, y: start.y },
|
|
1512
|
+
{ type: "L", x: end.x, y: end.y }
|
|
1498
1513
|
];
|
|
1499
1514
|
}
|
|
1500
1515
|
drawTo(ctx) {
|
|
1501
|
-
const {
|
|
1502
|
-
ctx.lineTo(
|
|
1516
|
+
const { end } = this;
|
|
1517
|
+
ctx.lineTo(end.x, end.y);
|
|
1503
1518
|
return this;
|
|
1504
1519
|
}
|
|
1505
1520
|
copy(source) {
|
|
1506
1521
|
super.copy(source);
|
|
1507
|
-
this.
|
|
1508
|
-
this.
|
|
1522
|
+
this.start.copy(source.start);
|
|
1523
|
+
this.end.copy(source.end);
|
|
1509
1524
|
return this;
|
|
1510
1525
|
}
|
|
1511
1526
|
}
|
|
@@ -1523,66 +1538,68 @@ class HeartCurve extends Curve {
|
|
|
1523
1538
|
this.size = size;
|
|
1524
1539
|
this.start = start;
|
|
1525
1540
|
this.end = end;
|
|
1526
|
-
__publicField$4(this, "
|
|
1527
|
-
|
|
1541
|
+
__publicField$4(this, "curveT", 0);
|
|
1542
|
+
this.update();
|
|
1543
|
+
}
|
|
1544
|
+
update() {
|
|
1528
1545
|
const { x, y } = this.center;
|
|
1529
|
-
const A = new
|
|
1530
|
-
const t = new
|
|
1531
|
-
const i = new
|
|
1546
|
+
const A = new Vector2(x + 0.5 * this.size, y - 0.5 * this.size);
|
|
1547
|
+
const t = new Vector2(x - 0.5 * this.size, y - 0.5 * this.size);
|
|
1548
|
+
const i = new Vector2(x, y + 0.5 * this.size);
|
|
1532
1549
|
const curve1 = new CircleCurve(A, Math.SQRT1_2 * this.size, -0.25 * Math.PI, 0.75 * Math.PI);
|
|
1533
1550
|
const curve5 = new CircleCurve(t, Math.SQRT1_2 * this.size, -0.75 * Math.PI, 0.25 * Math.PI);
|
|
1534
1551
|
const curve3 = new CircleCurve(i, 0.5 * Math.SQRT1_2 * this.size, 0.75 * Math.PI, 1.25 * Math.PI);
|
|
1535
|
-
const e = new
|
|
1536
|
-
const l = new
|
|
1537
|
-
const c = new
|
|
1538
|
-
const h = new
|
|
1539
|
-
const a = new
|
|
1552
|
+
const e = new Vector2(x, y + this.size);
|
|
1553
|
+
const l = new Vector2(x + this.size, y);
|
|
1554
|
+
const c = new Vector2().lerpVectors(l, e, 0.75);
|
|
1555
|
+
const h = new Vector2(x - this.size, y);
|
|
1556
|
+
const a = new Vector2().lerpVectors(h, e, 0.75);
|
|
1540
1557
|
const curve2 = new LineCurve(l, c);
|
|
1541
1558
|
const curve4 = new LineCurve(a, h);
|
|
1542
1559
|
this.curves = [curve1, curve2, curve3, curve4, curve5];
|
|
1560
|
+
return this;
|
|
1543
1561
|
}
|
|
1544
|
-
getPoint(
|
|
1545
|
-
return this.
|
|
1562
|
+
getPoint(t) {
|
|
1563
|
+
return this.getCurve(t).getPoint(this.curveT);
|
|
1546
1564
|
}
|
|
1547
|
-
getPointAt(
|
|
1548
|
-
return this.getPoint(
|
|
1565
|
+
getPointAt(t) {
|
|
1566
|
+
return this.getPoint(t);
|
|
1549
1567
|
}
|
|
1550
|
-
|
|
1551
|
-
let val = (
|
|
1568
|
+
getCurve(t) {
|
|
1569
|
+
let val = (t * (this.end - this.start) + this.start) % 1;
|
|
1552
1570
|
val < 0 && (val += 1);
|
|
1553
1571
|
val *= 9 * Math.PI / 8 + 1.5;
|
|
1554
1572
|
let index;
|
|
1555
|
-
const
|
|
1556
|
-
if (val <
|
|
1573
|
+
const PI_1_2 = 0.5 * Math.PI;
|
|
1574
|
+
if (val < PI_1_2) {
|
|
1557
1575
|
index = 0;
|
|
1558
|
-
this.
|
|
1559
|
-
} else if (val <
|
|
1576
|
+
this.curveT = val / PI_1_2;
|
|
1577
|
+
} else if (val < PI_1_2 + 0.75) {
|
|
1560
1578
|
index = 1;
|
|
1561
|
-
this.
|
|
1579
|
+
this.curveT = (val - PI_1_2) / 0.75;
|
|
1562
1580
|
} else if (val < 5 * Math.PI / 8 + 0.75) {
|
|
1563
1581
|
index = 2;
|
|
1564
|
-
this.
|
|
1582
|
+
this.curveT = (val - PI_1_2 - 0.75) / (Math.PI / 8);
|
|
1565
1583
|
} else if (val < 5 * Math.PI / 8 + 1.5) {
|
|
1566
1584
|
index = 3;
|
|
1567
|
-
this.
|
|
1585
|
+
this.curveT = (val - 5 * Math.PI / 8 - 0.75) / 0.75;
|
|
1568
1586
|
} else {
|
|
1569
1587
|
index = 4;
|
|
1570
|
-
this.
|
|
1588
|
+
this.curveT = (val - 5 * Math.PI / 8 - 1.5) / PI_1_2;
|
|
1571
1589
|
}
|
|
1572
1590
|
return this.curves[index];
|
|
1573
1591
|
}
|
|
1574
|
-
getTangent(
|
|
1575
|
-
return this.
|
|
1592
|
+
getTangent(t) {
|
|
1593
|
+
return this.getCurve(t).getTangent(this.curveT);
|
|
1576
1594
|
}
|
|
1577
|
-
getNormal(
|
|
1578
|
-
|
|
1579
|
-
return new Point2D(line.v2.y - line.v1.y, -(line.v2.x - line.v1.x)).normalize();
|
|
1595
|
+
getNormal(t) {
|
|
1596
|
+
return this.getCurve(t).getNormal(this.curveT);
|
|
1580
1597
|
}
|
|
1581
|
-
|
|
1582
|
-
this.curves.forEach((curve) => curve.
|
|
1598
|
+
transformPoint(cb) {
|
|
1599
|
+
this.curves.forEach((curve) => curve.transformPoint(cb));
|
|
1583
1600
|
return this;
|
|
1584
1601
|
}
|
|
1585
|
-
getMinMax(min =
|
|
1602
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1586
1603
|
this.curves.forEach((curve) => curve.getMinMax(min, max));
|
|
1587
1604
|
return { min, max };
|
|
1588
1605
|
}
|
|
@@ -1602,54 +1619,59 @@ var __publicField$3 = (obj, key, value) => {
|
|
|
1602
1619
|
return value;
|
|
1603
1620
|
};
|
|
1604
1621
|
class PloygonCurve extends Curve {
|
|
1605
|
-
constructor(center, radius = 0,
|
|
1622
|
+
constructor(center, radius = 0, number = 0, start = 0, end = 1) {
|
|
1606
1623
|
super();
|
|
1607
1624
|
this.center = center;
|
|
1608
1625
|
this.radius = radius;
|
|
1609
|
-
this.
|
|
1626
|
+
this.number = number;
|
|
1610
1627
|
this.start = start;
|
|
1611
1628
|
this.end = end;
|
|
1612
1629
|
__publicField$3(this, "curves", []);
|
|
1630
|
+
__publicField$3(this, "curveT", 0);
|
|
1613
1631
|
__publicField$3(this, "points", []);
|
|
1614
|
-
|
|
1615
|
-
|
|
1632
|
+
this.update();
|
|
1633
|
+
}
|
|
1634
|
+
update() {
|
|
1635
|
+
for (let i = 0; i < this.number; i++) {
|
|
1636
|
+
let radian = i * 2 * Math.PI / this.number;
|
|
1616
1637
|
radian -= 0.5 * Math.PI;
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1638
|
+
this.points.push(
|
|
1639
|
+
new Vector2(
|
|
1640
|
+
this.radius * Math.cos(radian),
|
|
1641
|
+
this.radius * Math.sin(radian)
|
|
1642
|
+
).add(this.center)
|
|
1643
|
+
);
|
|
1620
1644
|
}
|
|
1621
|
-
for (let i = 0; i < this.
|
|
1622
|
-
this.curves.push(new LineCurve(this.points[i], this.points[(i + 1) % this.
|
|
1645
|
+
for (let i = 0; i < this.number; i++) {
|
|
1646
|
+
this.curves.push(new LineCurve(this.points[i], this.points[(i + 1) % this.number]));
|
|
1623
1647
|
}
|
|
1648
|
+
return this;
|
|
1624
1649
|
}
|
|
1625
|
-
|
|
1626
|
-
this.
|
|
1627
|
-
return this.currentLine.getPoint(this.pointK);
|
|
1628
|
-
}
|
|
1629
|
-
getPointAt(value) {
|
|
1630
|
-
return this.getPoint(value);
|
|
1631
|
-
}
|
|
1632
|
-
getCurrentLine(value) {
|
|
1633
|
-
let pos = (value * (this.end - this.start) + this.start) % 1;
|
|
1650
|
+
getCurve(t) {
|
|
1651
|
+
let pos = (t * (this.end - this.start) + this.start) % 1;
|
|
1634
1652
|
pos < 0 && (pos += 1);
|
|
1635
|
-
const v = pos * this.
|
|
1653
|
+
const v = pos * this.number;
|
|
1636
1654
|
const index = Math.floor(v);
|
|
1637
|
-
this.
|
|
1638
|
-
|
|
1639
|
-
return this.currentLine;
|
|
1655
|
+
this.curveT = v - index;
|
|
1656
|
+
return this.curves[index];
|
|
1640
1657
|
}
|
|
1641
|
-
|
|
1642
|
-
return this.
|
|
1658
|
+
getPoint(t, output) {
|
|
1659
|
+
return this.getCurve(t).getPoint(this.curveT, output);
|
|
1643
1660
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
return new Point2D(line.v2.y - line.v1.y, -(line.v2.x - line.v1.x)).normalize();
|
|
1661
|
+
getPointAt(u, output) {
|
|
1662
|
+
return this.getPoint(u, output);
|
|
1647
1663
|
}
|
|
1648
|
-
|
|
1649
|
-
this.
|
|
1664
|
+
getTangent(t, output) {
|
|
1665
|
+
return this.getCurve(t).getTangent(this.curveT, output);
|
|
1666
|
+
}
|
|
1667
|
+
getNormal(t, output) {
|
|
1668
|
+
return this.getCurve(t).getNormal(this.curveT, output);
|
|
1669
|
+
}
|
|
1670
|
+
transformPoint(cb) {
|
|
1671
|
+
this.curves.forEach((curve) => curve.transformPoint(cb));
|
|
1650
1672
|
return this;
|
|
1651
1673
|
}
|
|
1652
|
-
getMinMax(min =
|
|
1674
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1653
1675
|
this.curves.forEach((curve) => curve.getMinMax(min, max));
|
|
1654
1676
|
return { min, max };
|
|
1655
1677
|
}
|
|
@@ -1663,55 +1685,55 @@ class PloygonCurve extends Curve {
|
|
|
1663
1685
|
}
|
|
1664
1686
|
|
|
1665
1687
|
class QuadraticBezierCurve extends Curve {
|
|
1666
|
-
constructor(
|
|
1688
|
+
constructor(start = new Vector2(), control = new Vector2(), end = new Vector2()) {
|
|
1667
1689
|
super();
|
|
1668
|
-
this.
|
|
1669
|
-
this.
|
|
1670
|
-
this.
|
|
1690
|
+
this.start = start;
|
|
1691
|
+
this.control = control;
|
|
1692
|
+
this.end = end;
|
|
1671
1693
|
}
|
|
1672
|
-
getPoint(t, output = new
|
|
1673
|
-
const {
|
|
1694
|
+
getPoint(t, output = new Vector2()) {
|
|
1695
|
+
const { start, control, end } = this;
|
|
1674
1696
|
output.set(
|
|
1675
|
-
quadraticBezier(t,
|
|
1676
|
-
quadraticBezier(t,
|
|
1697
|
+
quadraticBezier(t, start.x, control.x, end.x),
|
|
1698
|
+
quadraticBezier(t, start.y, control.y, end.y)
|
|
1677
1699
|
);
|
|
1678
1700
|
return output;
|
|
1679
1701
|
}
|
|
1680
|
-
|
|
1681
|
-
this.
|
|
1682
|
-
this.
|
|
1683
|
-
this.
|
|
1684
|
-
return this;
|
|
1685
|
-
}
|
|
1686
|
-
getMinMax(min =
|
|
1687
|
-
const {
|
|
1688
|
-
const x1 = 0.5 * (
|
|
1689
|
-
const y1 = 0.5 * (
|
|
1690
|
-
const x2 = 0.5 * (
|
|
1691
|
-
const y2 = 0.5 * (
|
|
1692
|
-
min.x = Math.min(min.x,
|
|
1693
|
-
min.y = Math.min(min.y,
|
|
1694
|
-
max.x = Math.max(max.x,
|
|
1695
|
-
max.y = Math.max(max.y,
|
|
1702
|
+
transformPoint(cb) {
|
|
1703
|
+
cb(this.start);
|
|
1704
|
+
cb(this.control);
|
|
1705
|
+
cb(this.end);
|
|
1706
|
+
return this;
|
|
1707
|
+
}
|
|
1708
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1709
|
+
const { start, control, end } = this;
|
|
1710
|
+
const x1 = 0.5 * (start.x + control.x);
|
|
1711
|
+
const y1 = 0.5 * (start.y + control.y);
|
|
1712
|
+
const x2 = 0.5 * (start.x + end.x);
|
|
1713
|
+
const y2 = 0.5 * (start.y + end.y);
|
|
1714
|
+
min.x = Math.min(min.x, start.x, end.x, x1, x2);
|
|
1715
|
+
min.y = Math.min(min.y, start.y, end.y, y1, y2);
|
|
1716
|
+
max.x = Math.max(max.x, start.x, end.x, x1, x2);
|
|
1717
|
+
max.y = Math.max(max.y, start.y, end.y, y1, y2);
|
|
1696
1718
|
return { min, max };
|
|
1697
1719
|
}
|
|
1698
1720
|
getCommands() {
|
|
1699
|
-
const {
|
|
1721
|
+
const { start, control, end } = this;
|
|
1700
1722
|
return [
|
|
1701
|
-
{ type: "M", x:
|
|
1702
|
-
{ type: "Q", x1:
|
|
1723
|
+
{ type: "M", x: start.x, y: start.y },
|
|
1724
|
+
{ type: "Q", x1: control.x, y1: control.y, x: end.x, y: end.y }
|
|
1703
1725
|
];
|
|
1704
1726
|
}
|
|
1705
1727
|
drawTo(ctx) {
|
|
1706
|
-
const {
|
|
1707
|
-
ctx.quadraticCurveTo(
|
|
1728
|
+
const { control, end } = this;
|
|
1729
|
+
ctx.quadraticCurveTo(control.x, control.y, end.x, end.y);
|
|
1708
1730
|
return this;
|
|
1709
1731
|
}
|
|
1710
1732
|
copy(source) {
|
|
1711
1733
|
super.copy(source);
|
|
1712
|
-
this.
|
|
1713
|
-
this.
|
|
1714
|
-
this.
|
|
1734
|
+
this.start.copy(source.start);
|
|
1735
|
+
this.control.copy(source.control);
|
|
1736
|
+
this.end.copy(source.end);
|
|
1715
1737
|
return this;
|
|
1716
1738
|
}
|
|
1717
1739
|
}
|
|
@@ -1731,19 +1753,8 @@ class RectangularCurve extends Curve {
|
|
|
1731
1753
|
this.start = start;
|
|
1732
1754
|
this.end = end;
|
|
1733
1755
|
__publicField$2(this, "curves", []);
|
|
1734
|
-
__publicField$2(this, "
|
|
1735
|
-
|
|
1736
|
-
const offsetX = this.rx;
|
|
1737
|
-
const offsetY = this.rx / this.aspectRatio;
|
|
1738
|
-
const points = [
|
|
1739
|
-
new Point2D(x - offsetX, y - offsetY),
|
|
1740
|
-
new Point2D(x + offsetX, y - offsetY),
|
|
1741
|
-
new Point2D(x + offsetX, y + offsetY),
|
|
1742
|
-
new Point2D(x - offsetX, y + offsetY)
|
|
1743
|
-
];
|
|
1744
|
-
for (let i = 0; i < 4; i++) {
|
|
1745
|
-
this.curves.push(new LineCurve(points[i].clone(), points[(i + 1) % 4].clone()));
|
|
1746
|
-
}
|
|
1756
|
+
__publicField$2(this, "curveT", 0);
|
|
1757
|
+
this.update();
|
|
1747
1758
|
}
|
|
1748
1759
|
get x() {
|
|
1749
1760
|
return this.center.x - this.rx;
|
|
@@ -1757,44 +1768,58 @@ class RectangularCurve extends Curve {
|
|
|
1757
1768
|
get height() {
|
|
1758
1769
|
return this.rx / this.aspectRatio * 2;
|
|
1759
1770
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1771
|
+
update() {
|
|
1772
|
+
const { x, y } = this.center;
|
|
1773
|
+
const offsetX = this.rx;
|
|
1774
|
+
const offsetY = this.rx / this.aspectRatio;
|
|
1775
|
+
const points = [
|
|
1776
|
+
new Vector2(x - offsetX, y - offsetY),
|
|
1777
|
+
new Vector2(x + offsetX, y - offsetY),
|
|
1778
|
+
new Vector2(x + offsetX, y + offsetY),
|
|
1779
|
+
new Vector2(x - offsetX, y + offsetY)
|
|
1780
|
+
];
|
|
1781
|
+
for (let i = 0; i < 4; i++) {
|
|
1782
|
+
this.curves.push(new LineCurve(points[i].clone(), points[(i + 1) % 4].clone()));
|
|
1783
|
+
}
|
|
1784
|
+
return this;
|
|
1765
1785
|
}
|
|
1766
|
-
|
|
1767
|
-
let
|
|
1768
|
-
|
|
1769
|
-
|
|
1786
|
+
getCurve(t) {
|
|
1787
|
+
let current = (t * (this.end - this.start) + this.start) % 1;
|
|
1788
|
+
current < 0 && (current += 1);
|
|
1789
|
+
current *= (1 + this.aspectRatio) * 2;
|
|
1770
1790
|
let i;
|
|
1771
|
-
if (
|
|
1791
|
+
if (current < this.aspectRatio) {
|
|
1772
1792
|
i = 0;
|
|
1773
|
-
this.
|
|
1774
|
-
} else if (
|
|
1793
|
+
this.curveT = current / this.aspectRatio;
|
|
1794
|
+
} else if (current < this.aspectRatio + 1) {
|
|
1775
1795
|
i = 1;
|
|
1776
|
-
this.
|
|
1777
|
-
} else if (
|
|
1796
|
+
this.curveT = (current - this.aspectRatio) / 1;
|
|
1797
|
+
} else if (current < 2 * this.aspectRatio + 1) {
|
|
1778
1798
|
i = 2;
|
|
1779
|
-
this.
|
|
1799
|
+
this.curveT = (current - this.aspectRatio - 1) / this.aspectRatio;
|
|
1780
1800
|
} else {
|
|
1781
1801
|
i = 3;
|
|
1782
|
-
this.
|
|
1802
|
+
this.curveT = (current - 2 * this.aspectRatio - 1) / 1;
|
|
1783
1803
|
}
|
|
1784
1804
|
return this.curves[i];
|
|
1785
1805
|
}
|
|
1786
|
-
|
|
1787
|
-
return this.
|
|
1806
|
+
getPoint(t, output) {
|
|
1807
|
+
return this.getCurve(t).getPoint(this.curveT, output);
|
|
1788
1808
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
return new Point2D(v2.y - v1.y, -(v2.x - v1.x)).normalize();
|
|
1809
|
+
getPointAt(u, output) {
|
|
1810
|
+
return this.getPoint(u, output);
|
|
1792
1811
|
}
|
|
1793
|
-
|
|
1794
|
-
this.
|
|
1812
|
+
getTangent(t, output) {
|
|
1813
|
+
return this.getCurve(t).getTangent(this.curveT, output);
|
|
1814
|
+
}
|
|
1815
|
+
getNormal(t, output) {
|
|
1816
|
+
return this.getCurve(t).getNormal(this.curveT, output);
|
|
1817
|
+
}
|
|
1818
|
+
transformPoint(cb) {
|
|
1819
|
+
this.curves.forEach((curve) => curve.transformPoint(cb));
|
|
1795
1820
|
return this;
|
|
1796
1821
|
}
|
|
1797
|
-
getMinMax(min =
|
|
1822
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
1798
1823
|
this.curves.forEach((curve) => curve.getMinMax(min, max));
|
|
1799
1824
|
return { min, max };
|
|
1800
1825
|
}
|
|
@@ -1815,7 +1840,7 @@ class SplineCurve extends Curve {
|
|
|
1815
1840
|
getDivisions(divisions = 12) {
|
|
1816
1841
|
return divisions * this.points.length;
|
|
1817
1842
|
}
|
|
1818
|
-
getPoint(t, output = new
|
|
1843
|
+
getPoint(t, output = new Vector2()) {
|
|
1819
1844
|
const { points } = this;
|
|
1820
1845
|
const p = (points.length - 1) * t;
|
|
1821
1846
|
const _p = Math.floor(p);
|
|
@@ -1830,6 +1855,10 @@ class SplineCurve extends Curve {
|
|
|
1830
1855
|
);
|
|
1831
1856
|
return output;
|
|
1832
1857
|
}
|
|
1858
|
+
transformPoint(cb) {
|
|
1859
|
+
this.points.forEach((point) => cb(point));
|
|
1860
|
+
return this;
|
|
1861
|
+
}
|
|
1833
1862
|
copy(source) {
|
|
1834
1863
|
super.copy(source);
|
|
1835
1864
|
this.points = [];
|
|
@@ -1850,7 +1879,7 @@ class CurvePath extends Curve {
|
|
|
1850
1879
|
constructor(points) {
|
|
1851
1880
|
super();
|
|
1852
1881
|
__publicField$1(this, "curves", []);
|
|
1853
|
-
__publicField$1(this, "currentPoint", new
|
|
1882
|
+
__publicField$1(this, "currentPoint", new Vector2());
|
|
1854
1883
|
__publicField$1(this, "autoClose", false);
|
|
1855
1884
|
__publicField$1(this, "_cacheLengths", []);
|
|
1856
1885
|
if (points) {
|
|
@@ -1869,7 +1898,7 @@ class CurvePath extends Curve {
|
|
|
1869
1898
|
}
|
|
1870
1899
|
return this;
|
|
1871
1900
|
}
|
|
1872
|
-
getPoint(position, output = new
|
|
1901
|
+
getPoint(position, output = new Vector2()) {
|
|
1873
1902
|
const d = position * this.getLength();
|
|
1874
1903
|
const curveLengths = this.getCurveLengths();
|
|
1875
1904
|
let i = 0;
|
|
@@ -1921,10 +1950,10 @@ class CurvePath extends Curve {
|
|
|
1921
1950
|
let last;
|
|
1922
1951
|
for (let i = 0, curves = this.curves; i < curves.length; i++) {
|
|
1923
1952
|
const curve = curves[i];
|
|
1924
|
-
const
|
|
1925
|
-
for (let i2 = 0; i2 <
|
|
1926
|
-
const point =
|
|
1927
|
-
if (last
|
|
1953
|
+
const curvePoints = curve.getPoints(curve.getDivisions(divisions));
|
|
1954
|
+
for (let i2 = 0; i2 < curvePoints.length; i2++) {
|
|
1955
|
+
const point = curvePoints[i2];
|
|
1956
|
+
if (last?.equals(point))
|
|
1928
1957
|
continue;
|
|
1929
1958
|
points.push(point);
|
|
1930
1959
|
last = point;
|
|
@@ -1946,9 +1975,9 @@ class CurvePath extends Curve {
|
|
|
1946
1975
|
this.curves.push(
|
|
1947
1976
|
new CubicBezierCurve(
|
|
1948
1977
|
this.currentPoint.clone(),
|
|
1949
|
-
new
|
|
1950
|
-
new
|
|
1951
|
-
new
|
|
1978
|
+
new Vector2(cp1x, cp1y),
|
|
1979
|
+
new Vector2(cp2x, cp2y),
|
|
1980
|
+
new Vector2(x, y)
|
|
1952
1981
|
)
|
|
1953
1982
|
);
|
|
1954
1983
|
this.currentPoint.set(x, y);
|
|
@@ -1958,7 +1987,7 @@ class CurvePath extends Curve {
|
|
|
1958
1987
|
this.curves.push(
|
|
1959
1988
|
new LineCurve(
|
|
1960
1989
|
this.currentPoint.clone(),
|
|
1961
|
-
new
|
|
1990
|
+
new Vector2(x, y)
|
|
1962
1991
|
)
|
|
1963
1992
|
);
|
|
1964
1993
|
this.currentPoint.set(x, y);
|
|
@@ -1972,8 +2001,8 @@ class CurvePath extends Curve {
|
|
|
1972
2001
|
this.curves.push(
|
|
1973
2002
|
new QuadraticBezierCurve(
|
|
1974
2003
|
this.currentPoint.clone(),
|
|
1975
|
-
new
|
|
1976
|
-
new
|
|
2004
|
+
new Vector2(cpx, cpy),
|
|
2005
|
+
new Vector2(x, y)
|
|
1977
2006
|
)
|
|
1978
2007
|
);
|
|
1979
2008
|
this.currentPoint.set(x, y);
|
|
@@ -1982,7 +2011,7 @@ class CurvePath extends Curve {
|
|
|
1982
2011
|
rect(x, y, w, h) {
|
|
1983
2012
|
this.curves.push(
|
|
1984
2013
|
new RectangularCurve(
|
|
1985
|
-
new
|
|
2014
|
+
new Vector2(x + w / 2, y + h / 2),
|
|
1986
2015
|
w / 2,
|
|
1987
2016
|
w / h
|
|
1988
2017
|
)
|
|
@@ -2011,11 +2040,19 @@ class CurvePath extends Curve {
|
|
|
2011
2040
|
return this;
|
|
2012
2041
|
}
|
|
2013
2042
|
absellipse(x, y, radiusX, radiusY, startAngle, endAngle, clockwise = false, rotation = 0) {
|
|
2014
|
-
const curve = new EllipseCurve(
|
|
2043
|
+
const curve = new EllipseCurve(
|
|
2044
|
+
new Vector2(x, y),
|
|
2045
|
+
radiusX,
|
|
2046
|
+
radiusY,
|
|
2047
|
+
startAngle,
|
|
2048
|
+
endAngle,
|
|
2049
|
+
clockwise,
|
|
2050
|
+
rotation
|
|
2051
|
+
);
|
|
2015
2052
|
if (this.curves.length > 0) {
|
|
2016
|
-
const
|
|
2017
|
-
if (!
|
|
2018
|
-
this.lineTo(
|
|
2053
|
+
const first = curve.getPoint(0);
|
|
2054
|
+
if (!first.equals(this.currentPoint)) {
|
|
2055
|
+
this.lineTo(first.x, first.y);
|
|
2019
2056
|
}
|
|
2020
2057
|
}
|
|
2021
2058
|
this.curves.push(curve);
|
|
@@ -2025,7 +2062,7 @@ class CurvePath extends Curve {
|
|
|
2025
2062
|
getCommands() {
|
|
2026
2063
|
return this.curves.flatMap((curve) => curve.getCommands());
|
|
2027
2064
|
}
|
|
2028
|
-
getMinMax(min =
|
|
2065
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
2029
2066
|
this.curves.forEach((curve) => curve.getMinMax(min, max));
|
|
2030
2067
|
return { min, max };
|
|
2031
2068
|
}
|
|
@@ -2143,11 +2180,15 @@ class Path2D {
|
|
|
2143
2180
|
this.paths.forEach((path) => path.curves.forEach((curve) => cb(curve)));
|
|
2144
2181
|
return this;
|
|
2145
2182
|
}
|
|
2183
|
+
transformPoint(cb) {
|
|
2184
|
+
this.forEachCurve((curve) => curve.transformPoint(cb));
|
|
2185
|
+
return this;
|
|
2186
|
+
}
|
|
2146
2187
|
transform(matrix) {
|
|
2147
2188
|
this.forEachCurve((curve) => curve.transform(matrix));
|
|
2148
2189
|
return this;
|
|
2149
2190
|
}
|
|
2150
|
-
getMinMax(min =
|
|
2191
|
+
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
2151
2192
|
this.forEachCurve((curve) => curve.getMinMax(min, max));
|
|
2152
2193
|
return { min, max };
|
|
2153
2194
|
}
|
|
@@ -2733,4 +2774,4 @@ function parseSvg(svg) {
|
|
|
2733
2774
|
});
|
|
2734
2775
|
}
|
|
2735
2776
|
|
|
2736
|
-
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve,
|
|
2777
|
+
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, QuadraticBezierCurve, RectangularCurve, SplineCurve, Vector2, parseSvg, parseSvgToDom };
|