modern-canvas 0.1.2 → 0.1.3
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 +378 -2701
- package/dist/index.d.cts +40 -368
- package/dist/index.d.mts +40 -368
- package/dist/index.d.ts +40 -368
- package/dist/index.js +48 -48
- package/dist/index.mjs +379 -2677
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const colord = require('colord');
|
|
4
4
|
const namesPlugin = require('colord/plugins/names');
|
|
5
|
-
const
|
|
5
|
+
const modernPath2d = require('modern-path2d');
|
|
6
6
|
const modernIdoc = require('modern-idoc');
|
|
7
7
|
const modernText = require('modern-text');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
10
|
|
|
11
11
|
const namesPlugin__default = /*#__PURE__*/_interopDefaultCompat(namesPlugin);
|
|
12
|
-
const earcut__default = /*#__PURE__*/_interopDefaultCompat(earcut);
|
|
13
12
|
|
|
14
13
|
const PI = Math.PI;
|
|
15
14
|
const PI_2 = PI * 2;
|
|
@@ -624,13 +623,13 @@ class Geometry extends Resource {
|
|
|
624
623
|
}
|
|
625
624
|
}
|
|
626
625
|
|
|
627
|
-
var __defProp$
|
|
628
|
-
var __decorateClass$
|
|
626
|
+
var __defProp$A = Object.defineProperty;
|
|
627
|
+
var __decorateClass$A = (decorators, target, key, kind) => {
|
|
629
628
|
var result = void 0 ;
|
|
630
629
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
631
630
|
if (decorator = decorators[i])
|
|
632
631
|
result = (decorator(target, key, result) ) || result;
|
|
633
|
-
if (result) __defProp$
|
|
632
|
+
if (result) __defProp$A(target, key, result);
|
|
634
633
|
return result;
|
|
635
634
|
};
|
|
636
635
|
class IndexBuffer extends Resource {
|
|
@@ -674,20 +673,20 @@ class IndexBuffer extends Resource {
|
|
|
674
673
|
return result;
|
|
675
674
|
}
|
|
676
675
|
}
|
|
677
|
-
__decorateClass$
|
|
676
|
+
__decorateClass$A([
|
|
678
677
|
protectedProperty({ default: null })
|
|
679
678
|
], IndexBuffer.prototype, "data");
|
|
680
|
-
__decorateClass$
|
|
679
|
+
__decorateClass$A([
|
|
681
680
|
protectedProperty({ default: false })
|
|
682
681
|
], IndexBuffer.prototype, "dynamic");
|
|
683
682
|
|
|
684
|
-
var __defProp$
|
|
685
|
-
var __decorateClass$
|
|
683
|
+
var __defProp$z = Object.defineProperty;
|
|
684
|
+
var __decorateClass$z = (decorators, target, key, kind) => {
|
|
686
685
|
var result = void 0 ;
|
|
687
686
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
688
687
|
if (decorator = decorators[i])
|
|
689
688
|
result = (decorator(target, key, result) ) || result;
|
|
690
|
-
if (result) __defProp$
|
|
689
|
+
if (result) __defProp$z(target, key, result);
|
|
691
690
|
return result;
|
|
692
691
|
};
|
|
693
692
|
class VertexBuffer extends Resource {
|
|
@@ -731,20 +730,20 @@ class VertexBuffer extends Resource {
|
|
|
731
730
|
return result;
|
|
732
731
|
}
|
|
733
732
|
}
|
|
734
|
-
__decorateClass$
|
|
733
|
+
__decorateClass$z([
|
|
735
734
|
protectedProperty({ default: null })
|
|
736
735
|
], VertexBuffer.prototype, "data");
|
|
737
|
-
__decorateClass$
|
|
736
|
+
__decorateClass$z([
|
|
738
737
|
protectedProperty({ default: false })
|
|
739
738
|
], VertexBuffer.prototype, "dynamic");
|
|
740
739
|
|
|
741
|
-
var __defProp$
|
|
742
|
-
var __decorateClass$
|
|
740
|
+
var __defProp$y = Object.defineProperty;
|
|
741
|
+
var __decorateClass$y = (decorators, target, key, kind) => {
|
|
743
742
|
var result = void 0 ;
|
|
744
743
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
745
744
|
if (decorator = decorators[i])
|
|
746
745
|
result = (decorator(target, key, result) ) || result;
|
|
747
|
-
if (result) __defProp$
|
|
746
|
+
if (result) __defProp$y(target, key, result);
|
|
748
747
|
return result;
|
|
749
748
|
};
|
|
750
749
|
class VertexAttribute extends Resource {
|
|
@@ -781,25 +780,25 @@ class VertexAttribute extends Resource {
|
|
|
781
780
|
return result;
|
|
782
781
|
}
|
|
783
782
|
}
|
|
784
|
-
__decorateClass$
|
|
783
|
+
__decorateClass$y([
|
|
785
784
|
protectedProperty()
|
|
786
785
|
], VertexAttribute.prototype, "buffer");
|
|
787
|
-
__decorateClass$
|
|
786
|
+
__decorateClass$y([
|
|
788
787
|
protectedProperty({ default: 0 })
|
|
789
788
|
], VertexAttribute.prototype, "size");
|
|
790
|
-
__decorateClass$
|
|
789
|
+
__decorateClass$y([
|
|
791
790
|
protectedProperty({ default: false })
|
|
792
791
|
], VertexAttribute.prototype, "normalized");
|
|
793
|
-
__decorateClass$
|
|
792
|
+
__decorateClass$y([
|
|
794
793
|
protectedProperty({ default: "float" })
|
|
795
794
|
], VertexAttribute.prototype, "type");
|
|
796
|
-
__decorateClass$
|
|
795
|
+
__decorateClass$y([
|
|
797
796
|
protectedProperty()
|
|
798
797
|
], VertexAttribute.prototype, "stride");
|
|
799
|
-
__decorateClass$
|
|
798
|
+
__decorateClass$y([
|
|
800
799
|
protectedProperty()
|
|
801
800
|
], VertexAttribute.prototype, "offset");
|
|
802
|
-
__decorateClass$
|
|
801
|
+
__decorateClass$y([
|
|
803
802
|
protectedProperty()
|
|
804
803
|
], VertexAttribute.prototype, "divisor");
|
|
805
804
|
|
|
@@ -983,13 +982,13 @@ class UvGeometry extends Geometry {
|
|
|
983
982
|
}
|
|
984
983
|
}
|
|
985
984
|
|
|
986
|
-
var __defProp$
|
|
987
|
-
var __decorateClass$
|
|
985
|
+
var __defProp$x = Object.defineProperty;
|
|
986
|
+
var __decorateClass$x = (decorators, target, key, kind) => {
|
|
988
987
|
var result = void 0 ;
|
|
989
988
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
990
989
|
if (decorator = decorators[i])
|
|
991
990
|
result = (decorator(target, key, result) ) || result;
|
|
992
|
-
if (result) __defProp$
|
|
991
|
+
if (result) __defProp$x(target, key, result);
|
|
993
992
|
return result;
|
|
994
993
|
};
|
|
995
994
|
class MainLoop extends _Object {
|
|
@@ -1030,1731 +1029,182 @@ class MainLoop extends _Object {
|
|
|
1030
1029
|
}
|
|
1031
1030
|
}
|
|
1032
1031
|
}
|
|
1033
|
-
__decorateClass$
|
|
1032
|
+
__decorateClass$x([
|
|
1034
1033
|
property({ default: 24 })
|
|
1035
1034
|
], MainLoop.prototype, "fps");
|
|
1036
|
-
__decorateClass$
|
|
1035
|
+
__decorateClass$x([
|
|
1037
1036
|
property({ default: 1 })
|
|
1038
1037
|
], MainLoop.prototype, "speed");
|
|
1039
1038
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
)
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
points.push(x1234, y1234);
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1039
|
+
class Vector extends EventEmitter {
|
|
1040
|
+
constructor(dim) {
|
|
1041
|
+
super();
|
|
1042
|
+
this.dim = dim;
|
|
1043
|
+
}
|
|
1044
|
+
_array = [];
|
|
1045
|
+
get length() {
|
|
1046
|
+
return this.dim;
|
|
1047
|
+
}
|
|
1048
|
+
_operate(operator, target, output) {
|
|
1049
|
+
const { dim: length, _array: array } = this;
|
|
1050
|
+
let targetArray;
|
|
1051
|
+
if (typeof target === "number") {
|
|
1052
|
+
targetArray = Array.from({ length }, () => target);
|
|
1053
|
+
} else if (target instanceof Matrix || target instanceof Vector) {
|
|
1054
|
+
targetArray = target.toArray();
|
|
1055
|
+
} else {
|
|
1056
|
+
targetArray = target;
|
|
1057
|
+
}
|
|
1058
|
+
let outputObject;
|
|
1059
|
+
let outputArray = [];
|
|
1060
|
+
if (!output) {
|
|
1061
|
+
outputObject = this;
|
|
1062
|
+
} else if (output instanceof Vector) {
|
|
1063
|
+
outputObject = output;
|
|
1064
|
+
} else {
|
|
1065
|
+
outputArray = output;
|
|
1066
|
+
}
|
|
1067
|
+
if (target instanceof Matrix) {
|
|
1068
|
+
const { cols } = target;
|
|
1069
|
+
switch (operator) {
|
|
1070
|
+
case "*":
|
|
1071
|
+
for (let x = 0; x < length; x++) {
|
|
1072
|
+
let val = 0;
|
|
1073
|
+
for (let y = 0; y < length; y++) {
|
|
1074
|
+
val += array[x] * targetArray[y * cols + x];
|
|
1075
|
+
}
|
|
1076
|
+
outputArray[x] = val;
|
|
1077
|
+
}
|
|
1078
|
+
break;
|
|
1079
|
+
default:
|
|
1080
|
+
throw new Error(`Not support operator in '${this.toName()} ${operator} ${target.toName()}'`);
|
|
1085
1081
|
}
|
|
1086
|
-
} else
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1082
|
+
} else {
|
|
1083
|
+
switch (operator) {
|
|
1084
|
+
case "+":
|
|
1085
|
+
for (let i = 0; i < length; i++) {
|
|
1086
|
+
outputArray[i] = array[i] + targetArray[i];
|
|
1087
|
+
}
|
|
1088
|
+
break;
|
|
1089
|
+
case "-":
|
|
1090
|
+
for (let i = 0; i < length; i++) {
|
|
1091
|
+
outputArray[i] = array[i] - targetArray[i];
|
|
1092
|
+
}
|
|
1093
|
+
break;
|
|
1094
|
+
case "*":
|
|
1095
|
+
for (let i = 0; i < length; i++) {
|
|
1096
|
+
outputArray[i] = array[i] * targetArray[i];
|
|
1097
|
+
}
|
|
1098
|
+
break;
|
|
1099
|
+
case "/":
|
|
1100
|
+
for (let i = 0; i < length; i++) {
|
|
1101
|
+
outputArray[i] = array[i] / targetArray[i];
|
|
1102
|
+
}
|
|
1103
|
+
break;
|
|
1104
|
+
case "rot": {
|
|
1105
|
+
const c = Math.cos(targetArray[0]);
|
|
1106
|
+
const s = Math.sin(targetArray[0]);
|
|
1107
|
+
outputArray[0] = array[0] * c - array[1] * s;
|
|
1108
|
+
outputArray[1] = array[1] * c + array[0] * s;
|
|
1109
|
+
break;
|
|
1091
1110
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
return;
|
|
1111
|
+
case "==": {
|
|
1112
|
+
let flag = true;
|
|
1113
|
+
for (let i = 0; i < length; i++) {
|
|
1114
|
+
flag = flag && array[i] === targetArray[i];
|
|
1115
|
+
}
|
|
1116
|
+
return flag;
|
|
1098
1117
|
}
|
|
1118
|
+
case "=":
|
|
1119
|
+
for (let i = 0; i < length; i++) {
|
|
1120
|
+
const val = targetArray[i];
|
|
1121
|
+
if (val !== void 0) {
|
|
1122
|
+
array[i] = val;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
this._emitUpdate(array);
|
|
1126
|
+
return this;
|
|
1127
|
+
default:
|
|
1128
|
+
throw new Error(`Not support operator in '${this.toName()} ${operator} Vector'`);
|
|
1099
1129
|
}
|
|
1100
|
-
} else {
|
|
1101
|
-
dx = x1234 - (x1 + x4) / 2;
|
|
1102
|
-
dy = y1234 - (y1 + y4) / 2;
|
|
1103
|
-
if (dx * dx + dy * dy <= distanceTolerance) {
|
|
1104
|
-
points.push(x1234, y1234);
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
recursive$1(x1, y1, x12, y12, x123, y123, x1234, y1234, points, distanceTolerance, level + 1);
|
|
1110
|
-
recursive$1(x1234, y1234, x234, y234, x34, y34, x4, y4, points, distanceTolerance, level + 1);
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
const RECURSION_LIMIT = 8;
|
|
1114
|
-
const FLT_EPSILON = 11920929e-14;
|
|
1115
|
-
const PATH_DISTANCE_EPSILON = 1;
|
|
1116
|
-
function buildAdaptiveQuadratic(points, sX, sY, cp1x, cp1y, eX, eY, smoothness = 0.5) {
|
|
1117
|
-
const scale = 1;
|
|
1118
|
-
const smoothing = Math.min(
|
|
1119
|
-
0.99,
|
|
1120
|
-
// a value of 1.0 actually inverts smoothing, so we cap it at 0.99
|
|
1121
|
-
Math.max(0, smoothness)
|
|
1122
|
-
);
|
|
1123
|
-
let distanceTolerance = (PATH_DISTANCE_EPSILON - smoothing) / scale;
|
|
1124
|
-
distanceTolerance *= distanceTolerance;
|
|
1125
|
-
begin(sX, sY, cp1x, cp1y, eX, eY, points, distanceTolerance);
|
|
1126
|
-
return points;
|
|
1127
|
-
}
|
|
1128
|
-
function begin(sX, sY, cp1x, cp1y, eX, eY, points, distanceTolerance) {
|
|
1129
|
-
recursive(points, sX, sY, cp1x, cp1y, eX, eY, distanceTolerance, 0);
|
|
1130
|
-
points.push(eX, eY);
|
|
1131
|
-
}
|
|
1132
|
-
function recursive(points, x1, y1, x2, y2, x3, y3, distanceTolerance, level) {
|
|
1133
|
-
if (level > RECURSION_LIMIT)
|
|
1134
|
-
return;
|
|
1135
|
-
const x12 = (x1 + x2) / 2;
|
|
1136
|
-
const y12 = (y1 + y2) / 2;
|
|
1137
|
-
const x23 = (x2 + x3) / 2;
|
|
1138
|
-
const y23 = (y2 + y3) / 2;
|
|
1139
|
-
const x123 = (x12 + x23) / 2;
|
|
1140
|
-
const y123 = (y12 + y23) / 2;
|
|
1141
|
-
let dx = x3 - x1;
|
|
1142
|
-
let dy = y3 - y1;
|
|
1143
|
-
const d = Math.abs((x2 - x3) * dy - (y2 - y3) * dx);
|
|
1144
|
-
if (d > FLT_EPSILON) {
|
|
1145
|
-
if (d * d <= distanceTolerance * (dx * dx + dy * dy)) {
|
|
1146
|
-
{
|
|
1147
|
-
points.push(x123, y123);
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
} else {
|
|
1152
|
-
dx = x123 - (x1 + x3) / 2;
|
|
1153
|
-
dy = y123 - (y1 + y3) / 2;
|
|
1154
|
-
if (dx * dx + dy * dy <= distanceTolerance) {
|
|
1155
|
-
points.push(x123, y123);
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
recursive(points, x1, y1, x12, y12, x123, y123, distanceTolerance, level + 1);
|
|
1160
|
-
recursive(points, x123, y123, x23, y23, x3, y3, distanceTolerance, level + 1);
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
function buildArc(points, x, y, radius, start, end, clockwise, steps) {
|
|
1164
|
-
let dist = Math.abs(start - end);
|
|
1165
|
-
if (!clockwise && start > end) {
|
|
1166
|
-
dist = 2 * Math.PI - dist;
|
|
1167
|
-
} else if (clockwise && end > start) {
|
|
1168
|
-
dist = 2 * Math.PI - dist;
|
|
1169
|
-
}
|
|
1170
|
-
steps = steps || Math.max(6, Math.floor(6 * radius ** (1 / 3) * (dist / Math.PI)));
|
|
1171
|
-
steps = Math.max(steps, 3);
|
|
1172
|
-
let f = dist / steps;
|
|
1173
|
-
let t = start;
|
|
1174
|
-
f *= clockwise ? -1 : 1;
|
|
1175
|
-
for (let i = 0; i < steps + 1; i++) {
|
|
1176
|
-
const cs = Math.cos(t);
|
|
1177
|
-
const sn = Math.sin(t);
|
|
1178
|
-
const nx = x + cs * radius;
|
|
1179
|
-
const ny = y + sn * radius;
|
|
1180
|
-
points.push(nx, ny);
|
|
1181
|
-
t += f;
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
function buildArcTo(points, x1, y1, x2, y2, radius) {
|
|
1186
|
-
const fromX = points[points.length - 2];
|
|
1187
|
-
const fromY = points[points.length - 1];
|
|
1188
|
-
const a1 = fromY - y1;
|
|
1189
|
-
const b1 = fromX - x1;
|
|
1190
|
-
const a2 = y2 - y1;
|
|
1191
|
-
const b2 = x2 - x1;
|
|
1192
|
-
const mm = Math.abs(a1 * b2 - b1 * a2);
|
|
1193
|
-
if (mm < 1e-8 || radius === 0) {
|
|
1194
|
-
if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
|
|
1195
|
-
points.push(x1, y1);
|
|
1196
|
-
}
|
|
1197
|
-
return;
|
|
1198
|
-
}
|
|
1199
|
-
const dd = a1 * a1 + b1 * b1;
|
|
1200
|
-
const cc = a2 * a2 + b2 * b2;
|
|
1201
|
-
const tt = a1 * a2 + b1 * b2;
|
|
1202
|
-
const k1 = radius * Math.sqrt(dd) / mm;
|
|
1203
|
-
const k2 = radius * Math.sqrt(cc) / mm;
|
|
1204
|
-
const j1 = k1 * tt / dd;
|
|
1205
|
-
const j2 = k2 * tt / cc;
|
|
1206
|
-
const cx = k1 * b2 + k2 * b1;
|
|
1207
|
-
const cy = k1 * a2 + k2 * a1;
|
|
1208
|
-
const px = b1 * (k2 + j1);
|
|
1209
|
-
const py = a1 * (k2 + j1);
|
|
1210
|
-
const qx = b2 * (k1 + j2);
|
|
1211
|
-
const qy = a2 * (k1 + j2);
|
|
1212
|
-
const startAngle = Math.atan2(py - cy, px - cx);
|
|
1213
|
-
const endAngle = Math.atan2(qy - cy, qx - cx);
|
|
1214
|
-
buildArc(points, cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1);
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
const TAU = Math.PI * 2;
|
|
1218
|
-
const out = {
|
|
1219
|
-
centerX: 0,
|
|
1220
|
-
centerY: 0,
|
|
1221
|
-
ang1: 0,
|
|
1222
|
-
ang2: 0
|
|
1223
|
-
};
|
|
1224
|
-
function mapToEllipse({ x, y }, rx, ry, cosPhi, sinPhi, centerX, centerY, out2) {
|
|
1225
|
-
x *= rx;
|
|
1226
|
-
y *= ry;
|
|
1227
|
-
const xp = cosPhi * x - sinPhi * y;
|
|
1228
|
-
const yp = sinPhi * x + cosPhi * y;
|
|
1229
|
-
out2.x = xp + centerX;
|
|
1230
|
-
out2.y = yp + centerY;
|
|
1231
|
-
return out2;
|
|
1232
|
-
}
|
|
1233
|
-
function approxUnitArc(ang1, ang2) {
|
|
1234
|
-
const a1 = ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
|
|
1235
|
-
const a = ang2 === 1.5707963267948966 ? 0.551915024494 : a1;
|
|
1236
|
-
const x1 = Math.cos(ang1);
|
|
1237
|
-
const y1 = Math.sin(ang1);
|
|
1238
|
-
const x2 = Math.cos(ang1 + ang2);
|
|
1239
|
-
const y2 = Math.sin(ang1 + ang2);
|
|
1240
|
-
return [
|
|
1241
|
-
{
|
|
1242
|
-
x: x1 - y1 * a,
|
|
1243
|
-
y: y1 + x1 * a
|
|
1244
|
-
},
|
|
1245
|
-
{
|
|
1246
|
-
x: x2 + y2 * a,
|
|
1247
|
-
y: y2 - x2 * a
|
|
1248
|
-
},
|
|
1249
|
-
{
|
|
1250
|
-
x: x2,
|
|
1251
|
-
y: y2
|
|
1252
1130
|
}
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
function vectorAngle(ux, uy, vx, vy) {
|
|
1256
|
-
const sign = ux * vy - uy * vx < 0 ? -1 : 1;
|
|
1257
|
-
let dot = ux * vx + uy * vy;
|
|
1258
|
-
if (dot > 1) {
|
|
1259
|
-
dot = 1;
|
|
1260
|
-
}
|
|
1261
|
-
if (dot < -1) {
|
|
1262
|
-
dot = -1;
|
|
1263
|
-
}
|
|
1264
|
-
return sign * Math.acos(dot);
|
|
1265
|
-
}
|
|
1266
|
-
function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinPhi, cosPhi, pxp, pyp, out2) {
|
|
1267
|
-
const rxSq = rx ** 2;
|
|
1268
|
-
const rySq = ry ** 2;
|
|
1269
|
-
const pxpSq = pxp ** 2;
|
|
1270
|
-
const pypSq = pyp ** 2;
|
|
1271
|
-
let radicant = rxSq * rySq - rxSq * pypSq - rySq * pxpSq;
|
|
1272
|
-
if (radicant < 0) {
|
|
1273
|
-
radicant = 0;
|
|
1274
|
-
}
|
|
1275
|
-
radicant /= rxSq * pypSq + rySq * pxpSq;
|
|
1276
|
-
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
|
|
1277
|
-
const centerXp = radicant * rx / ry * pyp;
|
|
1278
|
-
const centerYp = radicant * -ry / rx * pxp;
|
|
1279
|
-
const centerX = cosPhi * centerXp - sinPhi * centerYp + (px + cx) / 2;
|
|
1280
|
-
const centerY = sinPhi * centerXp + cosPhi * centerYp + (py + cy) / 2;
|
|
1281
|
-
const vx1 = (pxp - centerXp) / rx;
|
|
1282
|
-
const vy1 = (pyp - centerYp) / ry;
|
|
1283
|
-
const vx2 = (-pxp - centerXp) / rx;
|
|
1284
|
-
const vy2 = (-pyp - centerYp) / ry;
|
|
1285
|
-
const ang1 = vectorAngle(1, 0, vx1, vy1);
|
|
1286
|
-
let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
|
|
1287
|
-
if (sweepFlag === 0 && ang2 > 0) {
|
|
1288
|
-
ang2 -= TAU;
|
|
1289
|
-
}
|
|
1290
|
-
if (sweepFlag === 1 && ang2 < 0) {
|
|
1291
|
-
ang2 += TAU;
|
|
1292
|
-
}
|
|
1293
|
-
out2.centerX = centerX;
|
|
1294
|
-
out2.centerY = centerY;
|
|
1295
|
-
out2.ang1 = ang1;
|
|
1296
|
-
out2.ang2 = ang2;
|
|
1297
|
-
}
|
|
1298
|
-
function buildArcToSvg(points, px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0) {
|
|
1299
|
-
if (rx === 0 || ry === 0) {
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
const sinPhi = Math.sin(xAxisRotation * TAU / 360);
|
|
1303
|
-
const cosPhi = Math.cos(xAxisRotation * TAU / 360);
|
|
1304
|
-
const pxp = cosPhi * (px - cx) / 2 + sinPhi * (py - cy) / 2;
|
|
1305
|
-
const pyp = -sinPhi * (px - cx) / 2 + cosPhi * (py - cy) / 2;
|
|
1306
|
-
if (pxp === 0 && pyp === 0) {
|
|
1307
|
-
return;
|
|
1308
|
-
}
|
|
1309
|
-
rx = Math.abs(rx);
|
|
1310
|
-
ry = Math.abs(ry);
|
|
1311
|
-
const lambda = pxp ** 2 / rx ** 2 + pyp ** 2 / ry ** 2;
|
|
1312
|
-
if (lambda > 1) {
|
|
1313
|
-
rx *= Math.sqrt(lambda);
|
|
1314
|
-
ry *= Math.sqrt(lambda);
|
|
1315
|
-
}
|
|
1316
|
-
getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinPhi, cosPhi, pxp, pyp, out);
|
|
1317
|
-
let { ang1, ang2 } = out;
|
|
1318
|
-
const { centerX, centerY } = out;
|
|
1319
|
-
let ratio = Math.abs(ang2) / (TAU / 4);
|
|
1320
|
-
if (Math.abs(1 - ratio) < 1e-7) {
|
|
1321
|
-
ratio = 1;
|
|
1322
|
-
}
|
|
1323
|
-
const segments = Math.max(Math.ceil(ratio), 1);
|
|
1324
|
-
ang2 /= segments;
|
|
1325
|
-
let lastX = points[points.length - 2];
|
|
1326
|
-
let lastY = points[points.length - 1];
|
|
1327
|
-
const outCurvePoint = { x: 0, y: 0 };
|
|
1328
|
-
for (let i = 0; i < segments; i++) {
|
|
1329
|
-
const curve = approxUnitArc(ang1, ang2);
|
|
1330
|
-
const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
|
|
1331
|
-
const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
|
|
1332
|
-
const { x, y } = mapToEllipse(curve[2], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
|
|
1333
|
-
buildAdaptiveBezier(points, lastX, lastY, x1, y1, x2, y2, x, y);
|
|
1334
|
-
lastX = x;
|
|
1335
|
-
lastY = y;
|
|
1336
|
-
ang1 += ang2;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
class Circle {
|
|
1341
|
-
constructor(x = 0, y = 0, radius = 0) {
|
|
1342
|
-
this.x = x;
|
|
1343
|
-
this.y = y;
|
|
1344
|
-
this.radius = radius;
|
|
1345
|
-
}
|
|
1346
|
-
contains(x, y) {
|
|
1347
|
-
if (this.radius <= 0)
|
|
1348
|
-
return false;
|
|
1349
|
-
const r2 = this.radius * this.radius;
|
|
1350
|
-
let dx = this.x - x;
|
|
1351
|
-
let dy = this.y - y;
|
|
1352
|
-
dx *= dx;
|
|
1353
|
-
dy *= dy;
|
|
1354
|
-
return dx + dy <= r2;
|
|
1355
|
-
}
|
|
1356
|
-
strokeContains(x, y, width) {
|
|
1357
|
-
if (this.radius === 0)
|
|
1358
|
-
return false;
|
|
1359
|
-
const dx = this.x - x;
|
|
1360
|
-
const dy = this.y - y;
|
|
1361
|
-
const r = this.radius;
|
|
1362
|
-
const w2 = width / 2;
|
|
1363
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1364
|
-
return distance < r + w2 && distance > r - w2;
|
|
1365
|
-
}
|
|
1366
|
-
clone() {
|
|
1367
|
-
return new Circle(this.x, this.y, this.radius);
|
|
1368
|
-
}
|
|
1369
|
-
copyFrom(circle) {
|
|
1370
|
-
this.x = circle.x;
|
|
1371
|
-
this.y = circle.y;
|
|
1372
|
-
this.radius = circle.radius;
|
|
1373
|
-
return this;
|
|
1131
|
+
return outputObject?.set(outputArray) ?? outputArray;
|
|
1374
1132
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
return circle;
|
|
1133
|
+
add(value, output) {
|
|
1134
|
+
return this._operate("+", value, output);
|
|
1378
1135
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
out.x = this.x - this.radius;
|
|
1382
|
-
out.y = this.y - this.radius;
|
|
1383
|
-
out.width = this.radius * 2;
|
|
1384
|
-
out.height = this.radius * 2;
|
|
1385
|
-
return out;
|
|
1136
|
+
sub(value, output) {
|
|
1137
|
+
return this._operate("-", value, output);
|
|
1386
1138
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1139
|
+
multiply(value, output) {
|
|
1140
|
+
return this._operate("*", value, output);
|
|
1389
1141
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
this.buildOutline(points);
|
|
1393
|
-
buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
|
|
1142
|
+
divide(value, output) {
|
|
1143
|
+
return this._operate("/", value, output);
|
|
1394
1144
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
class Ellipse {
|
|
1398
|
-
constructor(x = 0, y = 0, halfWidth = 0, halfHeight = 0) {
|
|
1399
|
-
this.x = x;
|
|
1400
|
-
this.y = y;
|
|
1401
|
-
this.halfWidth = halfWidth;
|
|
1402
|
-
this.halfHeight = halfHeight;
|
|
1145
|
+
rotate(angle) {
|
|
1146
|
+
return this._operate("rot", angle);
|
|
1403
1147
|
}
|
|
1404
|
-
|
|
1405
|
-
if (
|
|
1406
|
-
|
|
1148
|
+
set(value, ...args) {
|
|
1149
|
+
if (args.length && typeof value === "number") {
|
|
1150
|
+
value = [value, ...args];
|
|
1407
1151
|
}
|
|
1408
|
-
|
|
1409
|
-
let normy = (y - this.y) / this.halfHeight;
|
|
1410
|
-
normx *= normx;
|
|
1411
|
-
normy *= normy;
|
|
1412
|
-
return normx + normy <= 1;
|
|
1152
|
+
return this._operate("=", value);
|
|
1413
1153
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
if (halfWidth <= 0 || halfHeight <= 0) {
|
|
1417
|
-
return false;
|
|
1418
|
-
}
|
|
1419
|
-
const halfStrokeWidth = width / 2;
|
|
1420
|
-
const innerA = halfWidth - halfStrokeWidth;
|
|
1421
|
-
const innerB = halfHeight - halfStrokeWidth;
|
|
1422
|
-
const outerA = halfWidth + halfStrokeWidth;
|
|
1423
|
-
const outerB = halfHeight + halfStrokeWidth;
|
|
1424
|
-
const normalizedX = x - this.x;
|
|
1425
|
-
const normalizedY = y - this.y;
|
|
1426
|
-
const innerEllipse = normalizedX * normalizedX / (innerA * innerA) + normalizedY * normalizedY / (innerB * innerB);
|
|
1427
|
-
const outerEllipse = normalizedX * normalizedX / (outerA * outerA) + normalizedY * normalizedY / (outerB * outerB);
|
|
1428
|
-
return innerEllipse > 1 && outerEllipse <= 1;
|
|
1154
|
+
equals(value) {
|
|
1155
|
+
return this._operate("==", value);
|
|
1429
1156
|
}
|
|
1430
1157
|
clone() {
|
|
1431
|
-
|
|
1158
|
+
const cloned = new this.constructor();
|
|
1159
|
+
cloned.set(this.toArray());
|
|
1160
|
+
return cloned;
|
|
1432
1161
|
}
|
|
1433
|
-
|
|
1434
|
-
this.
|
|
1435
|
-
this.y = ellipse.y;
|
|
1436
|
-
this.halfWidth = ellipse.halfWidth;
|
|
1437
|
-
this.halfHeight = ellipse.halfHeight;
|
|
1162
|
+
onUpdate(callback) {
|
|
1163
|
+
this.on("update", callback);
|
|
1438
1164
|
return this;
|
|
1439
1165
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
return ellipse;
|
|
1443
|
-
}
|
|
1444
|
-
getBounds() {
|
|
1445
|
-
return new Rectangle(this.x - this.halfWidth, this.y - this.halfHeight, this.halfWidth * 2, this.halfHeight * 2);
|
|
1446
|
-
}
|
|
1447
|
-
buildOutline(points) {
|
|
1448
|
-
buildCircle.build(this, points);
|
|
1449
|
-
}
|
|
1450
|
-
buildGeometry(vertices, indices) {
|
|
1451
|
-
const points = [];
|
|
1452
|
-
this.buildOutline(points);
|
|
1453
|
-
buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
function squaredDistanceToLineSegment(x, y, x1, y1, x2, y2) {
|
|
1458
|
-
const a = x - x1;
|
|
1459
|
-
const b = y - y1;
|
|
1460
|
-
const c = x2 - x1;
|
|
1461
|
-
const d = y2 - y1;
|
|
1462
|
-
const dot = a * c + b * d;
|
|
1463
|
-
const lenSq = c * c + d * d;
|
|
1464
|
-
let param = -1;
|
|
1465
|
-
if (lenSq !== 0) {
|
|
1466
|
-
param = dot / lenSq;
|
|
1467
|
-
}
|
|
1468
|
-
let xx;
|
|
1469
|
-
let yy;
|
|
1470
|
-
if (param < 0) {
|
|
1471
|
-
xx = x1;
|
|
1472
|
-
yy = y1;
|
|
1473
|
-
} else if (param > 1) {
|
|
1474
|
-
xx = x2;
|
|
1475
|
-
yy = y2;
|
|
1476
|
-
} else {
|
|
1477
|
-
xx = x1 + param * c;
|
|
1478
|
-
yy = y1 + param * d;
|
|
1479
|
-
}
|
|
1480
|
-
const dx = x - xx;
|
|
1481
|
-
const dy = y - yy;
|
|
1482
|
-
return dx * dx + dy * dy;
|
|
1483
|
-
}
|
|
1484
|
-
class Triangle {
|
|
1485
|
-
constructor(x = 0, y = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0) {
|
|
1486
|
-
this.x = x;
|
|
1487
|
-
this.y = y;
|
|
1488
|
-
this.x2 = x2;
|
|
1489
|
-
this.y2 = y2;
|
|
1490
|
-
this.x3 = x3;
|
|
1491
|
-
this.y3 = y3;
|
|
1492
|
-
}
|
|
1493
|
-
contains(x, y) {
|
|
1494
|
-
const s = (this.x - this.x3) * (y - this.y3) - (this.y - this.y3) * (x - this.x3);
|
|
1495
|
-
const t = (this.x2 - this.x) * (y - this.y) - (this.y2 - this.y) * (x - this.x);
|
|
1496
|
-
if (s < 0 !== t < 0 && s !== 0 && t !== 0)
|
|
1497
|
-
return false;
|
|
1498
|
-
const d = (this.x3 - this.x2) * (y - this.y2) - (this.y3 - this.y2) * (x - this.x2);
|
|
1499
|
-
return d === 0 || d < 0 === s + t <= 0;
|
|
1500
|
-
}
|
|
1501
|
-
strokeContains(pointX, pointY, strokeWidth) {
|
|
1502
|
-
const halfStrokeWidth = strokeWidth / 2;
|
|
1503
|
-
const halfStrokeWidthSquared = halfStrokeWidth * halfStrokeWidth;
|
|
1504
|
-
const { x, x2, x3, y, y2, y3 } = this;
|
|
1505
|
-
if (squaredDistanceToLineSegment(pointX, pointY, x, y, x2, y3) <= halfStrokeWidthSquared || squaredDistanceToLineSegment(pointX, pointY, x2, y2, x3, y3) <= halfStrokeWidthSquared || squaredDistanceToLineSegment(pointX, pointY, x3, y3, x, y) <= halfStrokeWidthSquared) {
|
|
1506
|
-
return true;
|
|
1507
|
-
}
|
|
1508
|
-
return false;
|
|
1509
|
-
}
|
|
1510
|
-
clone() {
|
|
1511
|
-
return new Triangle(this.x, this.y, this.x2, this.y2, this.x3, this.y3);
|
|
1512
|
-
}
|
|
1513
|
-
copyFrom(triangle) {
|
|
1514
|
-
this.x = triangle.x;
|
|
1515
|
-
this.y = triangle.y;
|
|
1516
|
-
this.x2 = triangle.x2;
|
|
1517
|
-
this.y2 = triangle.y2;
|
|
1518
|
-
this.x3 = triangle.x3;
|
|
1519
|
-
this.y3 = triangle.y3;
|
|
1166
|
+
offUpdate(callback) {
|
|
1167
|
+
this.off("update", callback);
|
|
1520
1168
|
return this;
|
|
1521
1169
|
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1170
|
+
_emitUpdate(array) {
|
|
1171
|
+
this._onUpdate(array);
|
|
1172
|
+
this.emit("update", array);
|
|
1525
1173
|
}
|
|
1526
|
-
|
|
1527
|
-
out = out || new Rectangle();
|
|
1528
|
-
const minX = Math.min(this.x, this.x2, this.x3);
|
|
1529
|
-
const maxX = Math.max(this.x, this.x2, this.x3);
|
|
1530
|
-
const minY = Math.min(this.y, this.y2, this.y3);
|
|
1531
|
-
const maxY = Math.max(this.y, this.y2, this.y3);
|
|
1532
|
-
out.x = minX;
|
|
1533
|
-
out.y = minY;
|
|
1534
|
-
out.width = maxX - minX;
|
|
1535
|
-
out.height = maxY - minY;
|
|
1536
|
-
return out;
|
|
1174
|
+
_onUpdate(_array) {
|
|
1537
1175
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1176
|
+
toArray() {
|
|
1177
|
+
return this._array.slice();
|
|
1540
1178
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
this.buildOutline(points);
|
|
1544
|
-
buildTriangle.triangulate(points, vertices, 2, 0, indices, 0);
|
|
1179
|
+
toName() {
|
|
1180
|
+
return `Vector${this.dim}`;
|
|
1545
1181
|
}
|
|
1546
1182
|
}
|
|
1547
1183
|
|
|
1548
|
-
class
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
get x() {
|
|
1558
|
-
return this.points[this.points.length - 2];
|
|
1559
|
-
}
|
|
1560
|
-
get y() {
|
|
1561
|
-
return this.points[this.points.length - 1];
|
|
1562
|
-
}
|
|
1563
|
-
constructor(...points) {
|
|
1564
|
-
let flat = Array.isArray(points[0]) ? points[0] : points;
|
|
1565
|
-
if (typeof flat[0] !== "number") {
|
|
1566
|
-
const p = [];
|
|
1567
|
-
for (let i = 0, il = flat.length; i < il; i++) {
|
|
1568
|
-
p.push(flat[i].x, flat[i].y);
|
|
1569
|
-
}
|
|
1570
|
-
flat = p;
|
|
1184
|
+
class Matrix extends EventEmitter {
|
|
1185
|
+
constructor(rows, cols, array) {
|
|
1186
|
+
super();
|
|
1187
|
+
this.rows = rows;
|
|
1188
|
+
this.cols = cols;
|
|
1189
|
+
if (array) {
|
|
1190
|
+
this.set(array);
|
|
1191
|
+
} else {
|
|
1192
|
+
this.identity();
|
|
1571
1193
|
}
|
|
1572
|
-
this.points = flat;
|
|
1573
|
-
this.closed = true;
|
|
1574
1194
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
return this;
|
|
1195
|
+
_array = [];
|
|
1196
|
+
get length() {
|
|
1197
|
+
return this.cols * this.rows;
|
|
1578
1198
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
if (intersect) {
|
|
1589
|
-
inside = !inside;
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
return inside;
|
|
1593
|
-
}
|
|
1594
|
-
strokeContains(x, y, strokeWidth) {
|
|
1595
|
-
const halfStrokeWidth = strokeWidth / 2;
|
|
1596
|
-
const halfStrokeWidthSqrd = halfStrokeWidth * halfStrokeWidth;
|
|
1597
|
-
const { points } = this;
|
|
1598
|
-
const iterationLength = points.length - (this.closed ? 0 : 2);
|
|
1599
|
-
for (let i = 0; i < iterationLength; i += 2) {
|
|
1600
|
-
const x1 = points[i];
|
|
1601
|
-
const y1 = points[i + 1];
|
|
1602
|
-
const x2 = points[(i + 2) % points.length];
|
|
1603
|
-
const y2 = points[(i + 3) % points.length];
|
|
1604
|
-
const distanceSqrd = squaredDistanceToLineSegment(x, y, x1, y1, x2, y2);
|
|
1605
|
-
if (distanceSqrd <= halfStrokeWidthSqrd) {
|
|
1606
|
-
return true;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
return false;
|
|
1610
|
-
}
|
|
1611
|
-
clone() {
|
|
1612
|
-
const points = this.points.slice();
|
|
1613
|
-
const polygon = new Polygon(points);
|
|
1614
|
-
polygon.closed = this.closed;
|
|
1615
|
-
return polygon;
|
|
1616
|
-
}
|
|
1617
|
-
copyFrom(polygon) {
|
|
1618
|
-
this.points = polygon.points.slice();
|
|
1619
|
-
this.closed = polygon.closed;
|
|
1620
|
-
return this;
|
|
1621
|
-
}
|
|
1622
|
-
copyTo(polygon) {
|
|
1623
|
-
polygon.copyFrom(this);
|
|
1624
|
-
return polygon;
|
|
1625
|
-
}
|
|
1626
|
-
getBounds(out) {
|
|
1627
|
-
out = out || new Rectangle();
|
|
1628
|
-
const points = this.points;
|
|
1629
|
-
let minX = Infinity;
|
|
1630
|
-
let maxX = -Infinity;
|
|
1631
|
-
let minY = Infinity;
|
|
1632
|
-
let maxY = -Infinity;
|
|
1633
|
-
for (let i = 0, n = points.length; i < n; i += 2) {
|
|
1634
|
-
const x = points[i];
|
|
1635
|
-
const y = points[i + 1];
|
|
1636
|
-
minX = x < minX ? x : minX;
|
|
1637
|
-
maxX = x > maxX ? x : maxX;
|
|
1638
|
-
minY = y < minY ? y : minY;
|
|
1639
|
-
maxY = y > maxY ? y : maxY;
|
|
1640
|
-
}
|
|
1641
|
-
out.x = minX;
|
|
1642
|
-
out.width = maxX - minX;
|
|
1643
|
-
out.y = minY;
|
|
1644
|
-
out.height = maxY - minY;
|
|
1645
|
-
return out;
|
|
1646
|
-
}
|
|
1647
|
-
buildOutline(points) {
|
|
1648
|
-
buildPolygon.build(this, points);
|
|
1649
|
-
}
|
|
1650
|
-
buildGeometry(vertices, indices) {
|
|
1651
|
-
const points = [];
|
|
1652
|
-
this.buildOutline(points);
|
|
1653
|
-
buildPolygon.triangulate(points, vertices, 2, 0, indices, 0);
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
function isCornerWithinStroke(pX, pY, cornerX, cornerY, radius, halfStrokeWidth) {
|
|
1658
|
-
const dx = pX - cornerX;
|
|
1659
|
-
const dy = pY - cornerY;
|
|
1660
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1661
|
-
return distance >= radius - halfStrokeWidth && distance <= radius + halfStrokeWidth;
|
|
1662
|
-
}
|
|
1663
|
-
class RoundedRectangle {
|
|
1664
|
-
constructor(x = 0, y = 0, width = 0, height = 0, radius = width / 4) {
|
|
1665
|
-
this.x = x;
|
|
1666
|
-
this.y = y;
|
|
1667
|
-
this.width = width;
|
|
1668
|
-
this.height = height;
|
|
1669
|
-
this.radius = radius;
|
|
1670
|
-
}
|
|
1671
|
-
getBounds(out) {
|
|
1672
|
-
out = out || new Rectangle();
|
|
1673
|
-
out.x = this.x;
|
|
1674
|
-
out.y = this.y;
|
|
1675
|
-
out.width = this.width;
|
|
1676
|
-
out.height = this.height;
|
|
1677
|
-
return out;
|
|
1678
|
-
}
|
|
1679
|
-
clone() {
|
|
1680
|
-
return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
|
|
1681
|
-
}
|
|
1682
|
-
copyFrom(rectangle) {
|
|
1683
|
-
this.x = rectangle.x;
|
|
1684
|
-
this.y = rectangle.y;
|
|
1685
|
-
this.width = rectangle.width;
|
|
1686
|
-
this.height = rectangle.height;
|
|
1687
|
-
return this;
|
|
1688
|
-
}
|
|
1689
|
-
copyTo(rectangle) {
|
|
1690
|
-
rectangle.copyFrom(this);
|
|
1691
|
-
return rectangle;
|
|
1692
|
-
}
|
|
1693
|
-
contains(x, y) {
|
|
1694
|
-
if (this.width <= 0 || this.height <= 0) {
|
|
1695
|
-
return false;
|
|
1696
|
-
}
|
|
1697
|
-
if (x >= this.x && x <= this.x + this.width) {
|
|
1698
|
-
if (y >= this.y && y <= this.y + this.height) {
|
|
1699
|
-
const radius = Math.max(0, Math.min(this.radius, Math.min(this.width, this.height) / 2));
|
|
1700
|
-
if (y >= this.y + radius && y <= this.y + this.height - radius || x >= this.x + radius && x <= this.x + this.width - radius) {
|
|
1701
|
-
return true;
|
|
1702
|
-
}
|
|
1703
|
-
let dx = x - (this.x + radius);
|
|
1704
|
-
let dy = y - (this.y + radius);
|
|
1705
|
-
const radius2 = radius * radius;
|
|
1706
|
-
if (dx * dx + dy * dy <= radius2) {
|
|
1707
|
-
return true;
|
|
1708
|
-
}
|
|
1709
|
-
dx = x - (this.x + this.width - radius);
|
|
1710
|
-
if (dx * dx + dy * dy <= radius2) {
|
|
1711
|
-
return true;
|
|
1712
|
-
}
|
|
1713
|
-
dy = y - (this.y + this.height - radius);
|
|
1714
|
-
if (dx * dx + dy * dy <= radius2) {
|
|
1715
|
-
return true;
|
|
1716
|
-
}
|
|
1717
|
-
dx = x - (this.x + radius);
|
|
1718
|
-
if (dx * dx + dy * dy <= radius2) {
|
|
1719
|
-
return true;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
return false;
|
|
1724
|
-
}
|
|
1725
|
-
strokeContains(pX, pY, strokeWidth) {
|
|
1726
|
-
const { x, y, width, height, radius } = this;
|
|
1727
|
-
const halfStrokeWidth = strokeWidth / 2;
|
|
1728
|
-
const innerX = x + radius;
|
|
1729
|
-
const innerY = y + radius;
|
|
1730
|
-
const innerWidth = width - radius * 2;
|
|
1731
|
-
const innerHeight = height - radius * 2;
|
|
1732
|
-
const rightBound = x + width;
|
|
1733
|
-
const bottomBound = y + height;
|
|
1734
|
-
if ((pX >= x - halfStrokeWidth && pX <= x + halfStrokeWidth || pX >= rightBound - halfStrokeWidth && pX <= rightBound + halfStrokeWidth) && pY >= innerY && pY <= innerY + innerHeight) {
|
|
1735
|
-
return true;
|
|
1736
|
-
}
|
|
1737
|
-
if ((pY >= y - halfStrokeWidth && pY <= y + halfStrokeWidth || pY >= bottomBound - halfStrokeWidth && pY <= bottomBound + halfStrokeWidth) && pX >= innerX && pX <= innerX + innerWidth) {
|
|
1738
|
-
return true;
|
|
1739
|
-
}
|
|
1740
|
-
return (
|
|
1741
|
-
// Top-left
|
|
1742
|
-
pX < innerX && pY < innerY && isCornerWithinStroke(pX, pY, innerX, innerY, radius, halfStrokeWidth) || pX > rightBound - radius && pY < innerY && isCornerWithinStroke(pX, pY, rightBound - radius, innerY, radius, halfStrokeWidth) || pX > rightBound - radius && pY > bottomBound - radius && isCornerWithinStroke(pX, pY, rightBound - radius, bottomBound - radius, radius, halfStrokeWidth) || pX < innerX && pY > bottomBound - radius && isCornerWithinStroke(pX, pY, innerX, bottomBound - radius, radius, halfStrokeWidth)
|
|
1743
|
-
);
|
|
1744
|
-
}
|
|
1745
|
-
buildOutline(points) {
|
|
1746
|
-
buildCircle.build(this, points);
|
|
1747
|
-
}
|
|
1748
|
-
buildGeometry(vertices, indices) {
|
|
1749
|
-
const points = [];
|
|
1750
|
-
this.buildOutline(points);
|
|
1751
|
-
buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
class Star extends Polygon {
|
|
1756
|
-
constructor(x = 0, y = 0, points = 5, radius = 1, innerRadius, rotation = 0) {
|
|
1757
|
-
innerRadius = innerRadius || radius / 2;
|
|
1758
|
-
const startAngle = -1 * Math.PI / 2 + rotation;
|
|
1759
|
-
const len = points * 2;
|
|
1760
|
-
const delta = PI_2 / len;
|
|
1761
|
-
const polygon = [];
|
|
1762
|
-
for (let i = 0; i < len; i++) {
|
|
1763
|
-
const r = i % 2 ? innerRadius : radius;
|
|
1764
|
-
const angle = i * delta + startAngle;
|
|
1765
|
-
polygon.push(
|
|
1766
|
-
x + r * Math.cos(angle),
|
|
1767
|
-
y + r * Math.sin(angle)
|
|
1768
|
-
);
|
|
1769
|
-
}
|
|
1770
|
-
super(polygon);
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
const buildCircle = {
|
|
1775
|
-
build(shape, points) {
|
|
1776
|
-
let x;
|
|
1777
|
-
let y;
|
|
1778
|
-
let dx;
|
|
1779
|
-
let dy;
|
|
1780
|
-
let rx;
|
|
1781
|
-
let ry;
|
|
1782
|
-
if (shape instanceof Circle) {
|
|
1783
|
-
x = shape.x;
|
|
1784
|
-
y = shape.y;
|
|
1785
|
-
rx = ry = shape.radius;
|
|
1786
|
-
dx = dy = 0;
|
|
1787
|
-
} else if (shape instanceof Ellipse) {
|
|
1788
|
-
x = shape.x;
|
|
1789
|
-
y = shape.y;
|
|
1790
|
-
rx = shape.halfWidth;
|
|
1791
|
-
ry = shape.halfHeight;
|
|
1792
|
-
dx = dy = 0;
|
|
1793
|
-
} else {
|
|
1794
|
-
const roundedRect = shape;
|
|
1795
|
-
const halfWidth = roundedRect.width / 2;
|
|
1796
|
-
const halfHeight = roundedRect.height / 2;
|
|
1797
|
-
x = roundedRect.x + halfWidth;
|
|
1798
|
-
y = roundedRect.y + halfHeight;
|
|
1799
|
-
rx = ry = Math.max(0, Math.min(roundedRect.radius, Math.min(halfWidth, halfHeight)));
|
|
1800
|
-
dx = halfWidth - rx;
|
|
1801
|
-
dy = halfHeight - ry;
|
|
1802
|
-
}
|
|
1803
|
-
if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
|
|
1804
|
-
return points;
|
|
1805
|
-
}
|
|
1806
|
-
const n = Math.ceil(2.3 * Math.sqrt(rx + ry));
|
|
1807
|
-
const m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
|
|
1808
|
-
if (m === 0) {
|
|
1809
|
-
return points;
|
|
1810
|
-
}
|
|
1811
|
-
if (n === 0) {
|
|
1812
|
-
points[0] = points[6] = x + dx;
|
|
1813
|
-
points[1] = points[3] = y + dy;
|
|
1814
|
-
points[2] = points[4] = x - dx;
|
|
1815
|
-
points[5] = points[7] = y - dy;
|
|
1816
|
-
return points;
|
|
1817
|
-
}
|
|
1818
|
-
let j1 = 0;
|
|
1819
|
-
let j2 = n * 4 + (dx ? 2 : 0) + 2;
|
|
1820
|
-
let j3 = j2;
|
|
1821
|
-
let j4 = m;
|
|
1822
|
-
let x0 = dx + rx;
|
|
1823
|
-
let y0 = dy;
|
|
1824
|
-
let x1 = x + x0;
|
|
1825
|
-
let x2 = x - x0;
|
|
1826
|
-
let y1 = y + y0;
|
|
1827
|
-
points[j1++] = x1;
|
|
1828
|
-
points[j1++] = y1;
|
|
1829
|
-
points[--j2] = y1;
|
|
1830
|
-
points[--j2] = x2;
|
|
1831
|
-
if (dy) {
|
|
1832
|
-
const y22 = y - y0;
|
|
1833
|
-
points[j3++] = x2;
|
|
1834
|
-
points[j3++] = y22;
|
|
1835
|
-
points[--j4] = y22;
|
|
1836
|
-
points[--j4] = x1;
|
|
1837
|
-
}
|
|
1838
|
-
for (let i = 1; i < n; i++) {
|
|
1839
|
-
const a = Math.PI / 2 * (i / n);
|
|
1840
|
-
const x02 = dx + Math.cos(a) * rx;
|
|
1841
|
-
const y02 = dy + Math.sin(a) * ry;
|
|
1842
|
-
const x12 = x + x02;
|
|
1843
|
-
const x22 = x - x02;
|
|
1844
|
-
const y12 = y + y02;
|
|
1845
|
-
const y22 = y - y02;
|
|
1846
|
-
points[j1++] = x12;
|
|
1847
|
-
points[j1++] = y12;
|
|
1848
|
-
points[--j2] = y12;
|
|
1849
|
-
points[--j2] = x22;
|
|
1850
|
-
points[j3++] = x22;
|
|
1851
|
-
points[j3++] = y22;
|
|
1852
|
-
points[--j4] = y22;
|
|
1853
|
-
points[--j4] = x12;
|
|
1854
|
-
}
|
|
1855
|
-
x0 = dx;
|
|
1856
|
-
y0 = dy + ry;
|
|
1857
|
-
x1 = x + x0;
|
|
1858
|
-
x2 = x - x0;
|
|
1859
|
-
y1 = y + y0;
|
|
1860
|
-
const y2 = y - y0;
|
|
1861
|
-
points[j1++] = x1;
|
|
1862
|
-
points[j1++] = y1;
|
|
1863
|
-
points[--j4] = y2;
|
|
1864
|
-
points[--j4] = x1;
|
|
1865
|
-
if (dx) {
|
|
1866
|
-
points[j1++] = x2;
|
|
1867
|
-
points[j1++] = y1;
|
|
1868
|
-
points[--j4] = y2;
|
|
1869
|
-
points[--j4] = x2;
|
|
1870
|
-
}
|
|
1871
|
-
return points;
|
|
1872
|
-
},
|
|
1873
|
-
triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
|
|
1874
|
-
if (points.length === 0) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
let centerX = 0;
|
|
1878
|
-
let centerY = 0;
|
|
1879
|
-
for (let i = 0; i < points.length; i += 2) {
|
|
1880
|
-
centerX += points[i];
|
|
1881
|
-
centerY += points[i + 1];
|
|
1882
|
-
}
|
|
1883
|
-
centerX /= points.length / 2;
|
|
1884
|
-
centerY /= points.length / 2;
|
|
1885
|
-
let count = verticesOffset;
|
|
1886
|
-
vertices[count * verticesStride] = centerX;
|
|
1887
|
-
vertices[count * verticesStride + 1] = centerY;
|
|
1888
|
-
const centerIndex = count++;
|
|
1889
|
-
for (let i = 0; i < points.length; i += 2) {
|
|
1890
|
-
vertices[count * verticesStride] = points[i];
|
|
1891
|
-
vertices[count * verticesStride + 1] = points[i + 1];
|
|
1892
|
-
if (i > 0) {
|
|
1893
|
-
indices[indicesOffset++] = count;
|
|
1894
|
-
indices[indicesOffset++] = centerIndex;
|
|
1895
|
-
indices[indicesOffset++] = count - 1;
|
|
1896
|
-
}
|
|
1897
|
-
count++;
|
|
1898
|
-
}
|
|
1899
|
-
indices[indicesOffset++] = centerIndex + 1;
|
|
1900
|
-
indices[indicesOffset++] = centerIndex;
|
|
1901
|
-
indices[indicesOffset++] = count - 1;
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
|
|
1905
|
-
class Point {
|
|
1906
|
-
constructor(x = 0, y = 0) {
|
|
1907
|
-
this.x = x;
|
|
1908
|
-
this.y = y;
|
|
1909
|
-
}
|
|
1910
|
-
static _shared;
|
|
1911
|
-
static get shared() {
|
|
1912
|
-
const point = this._shared ?? new Point();
|
|
1913
|
-
point.x = 0;
|
|
1914
|
-
point.y = 0;
|
|
1915
|
-
return point;
|
|
1916
|
-
}
|
|
1917
|
-
copyFrom(p) {
|
|
1918
|
-
this.set(p.x, p.y);
|
|
1919
|
-
return this;
|
|
1920
|
-
}
|
|
1921
|
-
copyTo(p) {
|
|
1922
|
-
p.set(this.x, this.y);
|
|
1923
|
-
return p;
|
|
1924
|
-
}
|
|
1925
|
-
equals(p) {
|
|
1926
|
-
return p.x === this.x && p.y === this.y;
|
|
1927
|
-
}
|
|
1928
|
-
set(x = 0, y = x) {
|
|
1929
|
-
this.x = x;
|
|
1930
|
-
this.y = y;
|
|
1931
|
-
return this;
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
function getOrientationOfPoints(points) {
|
|
1936
|
-
const m = points.length;
|
|
1937
|
-
if (m < 6) {
|
|
1938
|
-
return 1;
|
|
1939
|
-
}
|
|
1940
|
-
let area = 0;
|
|
1941
|
-
for (let i = 0, x1 = points[m - 2], y1 = points[m - 1]; i < m; i += 2) {
|
|
1942
|
-
const x2 = points[i];
|
|
1943
|
-
const y2 = points[i + 1];
|
|
1944
|
-
area += (x2 - x1) * (y2 + y1);
|
|
1945
|
-
x1 = x2;
|
|
1946
|
-
y1 = y2;
|
|
1947
|
-
}
|
|
1948
|
-
if (area < 0) {
|
|
1949
|
-
return -1;
|
|
1950
|
-
}
|
|
1951
|
-
return 1;
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
function triangulateWithHoles(points, holes, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
|
|
1955
|
-
const triangles = earcut__default(points, holes, 2);
|
|
1956
|
-
if (!triangles) {
|
|
1957
|
-
return;
|
|
1958
|
-
}
|
|
1959
|
-
for (let i = 0; i < triangles.length; i += 3) {
|
|
1960
|
-
indices[indicesOffset++] = triangles[i] + verticesOffset;
|
|
1961
|
-
indices[indicesOffset++] = triangles[i + 1] + verticesOffset;
|
|
1962
|
-
indices[indicesOffset++] = triangles[i + 2] + verticesOffset;
|
|
1963
|
-
}
|
|
1964
|
-
let index = verticesOffset * verticesStride;
|
|
1965
|
-
for (let i = 0; i < points.length; i += 2) {
|
|
1966
|
-
vertices[index] = points[i];
|
|
1967
|
-
vertices[index + 1] = points[i + 1];
|
|
1968
|
-
index += verticesStride;
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
const closePointEps = 1e-4;
|
|
1973
|
-
const curveEps = 1e-4;
|
|
1974
|
-
function square(x, y, nx, ny, innerWeight, outerWeight, clockwise, verts) {
|
|
1975
|
-
const ix = x - nx * innerWeight;
|
|
1976
|
-
const iy = y - ny * innerWeight;
|
|
1977
|
-
const ox = x + nx * outerWeight;
|
|
1978
|
-
const oy = y + ny * outerWeight;
|
|
1979
|
-
let exx;
|
|
1980
|
-
let eyy;
|
|
1981
|
-
if (clockwise) {
|
|
1982
|
-
exx = ny;
|
|
1983
|
-
eyy = -nx;
|
|
1984
|
-
} else {
|
|
1985
|
-
exx = -ny;
|
|
1986
|
-
eyy = nx;
|
|
1987
|
-
}
|
|
1988
|
-
const eix = ix + exx;
|
|
1989
|
-
const eiy = iy + eyy;
|
|
1990
|
-
const eox = ox + exx;
|
|
1991
|
-
const eoy = oy + eyy;
|
|
1992
|
-
verts.push(eix, eiy);
|
|
1993
|
-
verts.push(eox, eoy);
|
|
1994
|
-
return 2;
|
|
1995
|
-
}
|
|
1996
|
-
function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
|
|
1997
|
-
const cx2p0x = sx - cx;
|
|
1998
|
-
const cy2p0y = sy - cy;
|
|
1999
|
-
let angle0 = Math.atan2(cx2p0x, cy2p0y);
|
|
2000
|
-
let angle1 = Math.atan2(ex - cx, ey - cy);
|
|
2001
|
-
if (clockwise && angle0 < angle1) {
|
|
2002
|
-
angle0 += Math.PI * 2;
|
|
2003
|
-
} else if (!clockwise && angle0 > angle1) {
|
|
2004
|
-
angle1 += Math.PI * 2;
|
|
2005
|
-
}
|
|
2006
|
-
let startAngle = angle0;
|
|
2007
|
-
const angleDiff = angle1 - angle0;
|
|
2008
|
-
const absAngleDiff = Math.abs(angleDiff);
|
|
2009
|
-
const radius = Math.sqrt(cx2p0x * cx2p0x + cy2p0y * cy2p0y);
|
|
2010
|
-
const segCount = (15 * absAngleDiff * Math.sqrt(radius) / Math.PI >> 0) + 1;
|
|
2011
|
-
const angleInc = angleDiff / segCount;
|
|
2012
|
-
startAngle += angleInc;
|
|
2013
|
-
if (clockwise) {
|
|
2014
|
-
verts.push(cx, cy);
|
|
2015
|
-
verts.push(sx, sy);
|
|
2016
|
-
for (let i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
|
|
2017
|
-
verts.push(cx, cy);
|
|
2018
|
-
verts.push(cx + Math.sin(angle) * radius, cy + Math.cos(angle) * radius);
|
|
2019
|
-
}
|
|
2020
|
-
verts.push(cx, cy);
|
|
2021
|
-
verts.push(ex, ey);
|
|
2022
|
-
} else {
|
|
2023
|
-
verts.push(sx, sy);
|
|
2024
|
-
verts.push(cx, cy);
|
|
2025
|
-
for (let i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
|
|
2026
|
-
verts.push(cx + Math.sin(angle) * radius, cy + Math.cos(angle) * radius);
|
|
2027
|
-
verts.push(cx, cy);
|
|
2028
|
-
}
|
|
2029
|
-
verts.push(ex, ey);
|
|
2030
|
-
verts.push(cx, cy);
|
|
2031
|
-
}
|
|
2032
|
-
return segCount * 2;
|
|
2033
|
-
}
|
|
2034
|
-
function buildLine(points, lineStyle, flipAlignment, closed, vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
|
|
2035
|
-
const eps = closePointEps;
|
|
2036
|
-
if (points.length === 0) {
|
|
2037
|
-
return;
|
|
2038
|
-
}
|
|
2039
|
-
const style = lineStyle;
|
|
2040
|
-
let alignment = style.alignment;
|
|
2041
|
-
if (lineStyle.alignment !== 0.5) {
|
|
2042
|
-
let orientation = getOrientationOfPoints(points);
|
|
2043
|
-
if (flipAlignment)
|
|
2044
|
-
orientation *= -1;
|
|
2045
|
-
alignment = (alignment - 0.5) * orientation + 0.5;
|
|
2046
|
-
}
|
|
2047
|
-
const firstPoint = new Point(points[0], points[1]);
|
|
2048
|
-
const lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
|
|
2049
|
-
const closedShape = closed;
|
|
2050
|
-
const closedPath = Math.abs(firstPoint.x - lastPoint.x) < eps && Math.abs(firstPoint.y - lastPoint.y) < eps;
|
|
2051
|
-
if (closedShape) {
|
|
2052
|
-
points = points.slice();
|
|
2053
|
-
if (closedPath) {
|
|
2054
|
-
points.pop();
|
|
2055
|
-
points.pop();
|
|
2056
|
-
lastPoint.set(points[points.length - 2], points[points.length - 1]);
|
|
2057
|
-
}
|
|
2058
|
-
const midPointX = (firstPoint.x + lastPoint.x) * 0.5;
|
|
2059
|
-
const midPointY = (lastPoint.y + firstPoint.y) * 0.5;
|
|
2060
|
-
points.unshift(midPointX, midPointY);
|
|
2061
|
-
points.push(midPointX, midPointY);
|
|
2062
|
-
}
|
|
2063
|
-
const verts = vertices;
|
|
2064
|
-
const length = points.length / 2;
|
|
2065
|
-
let indexCount = points.length;
|
|
2066
|
-
const indexStart = verts.length / 2;
|
|
2067
|
-
const width = style.width / 2;
|
|
2068
|
-
const widthSquared = width * width;
|
|
2069
|
-
const miterLimitSquared = style.miterLimit * style.miterLimit;
|
|
2070
|
-
let x0 = points[0];
|
|
2071
|
-
let y0 = points[1];
|
|
2072
|
-
let x1 = points[2];
|
|
2073
|
-
let y1 = points[3];
|
|
2074
|
-
let x2 = 0;
|
|
2075
|
-
let y2 = 0;
|
|
2076
|
-
let perpX = -(y0 - y1);
|
|
2077
|
-
let perpY = x0 - x1;
|
|
2078
|
-
let perp1x = 0;
|
|
2079
|
-
let perp1y = 0;
|
|
2080
|
-
let dist = Math.sqrt(perpX * perpX + perpY * perpY);
|
|
2081
|
-
perpX /= dist;
|
|
2082
|
-
perpY /= dist;
|
|
2083
|
-
perpX *= width;
|
|
2084
|
-
perpY *= width;
|
|
2085
|
-
const ratio = alignment;
|
|
2086
|
-
const innerWeight = (1 - ratio) * 2;
|
|
2087
|
-
const outerWeight = ratio * 2;
|
|
2088
|
-
if (!closedShape) {
|
|
2089
|
-
if (style.cap === "round") {
|
|
2090
|
-
indexCount += round(
|
|
2091
|
-
x0 - perpX * (innerWeight - outerWeight) * 0.5,
|
|
2092
|
-
y0 - perpY * (innerWeight - outerWeight) * 0.5,
|
|
2093
|
-
x0 - perpX * innerWeight,
|
|
2094
|
-
y0 - perpY * innerWeight,
|
|
2095
|
-
x0 + perpX * outerWeight,
|
|
2096
|
-
y0 + perpY * outerWeight,
|
|
2097
|
-
verts,
|
|
2098
|
-
true
|
|
2099
|
-
) + 2;
|
|
2100
|
-
} else if (style.cap === "square") {
|
|
2101
|
-
indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
verts.push(
|
|
2105
|
-
x0 - perpX * innerWeight,
|
|
2106
|
-
y0 - perpY * innerWeight
|
|
2107
|
-
);
|
|
2108
|
-
verts.push(
|
|
2109
|
-
x0 + perpX * outerWeight,
|
|
2110
|
-
y0 + perpY * outerWeight
|
|
2111
|
-
);
|
|
2112
|
-
for (let i = 1; i < length - 1; ++i) {
|
|
2113
|
-
x0 = points[(i - 1) * 2];
|
|
2114
|
-
y0 = points[(i - 1) * 2 + 1];
|
|
2115
|
-
x1 = points[i * 2];
|
|
2116
|
-
y1 = points[i * 2 + 1];
|
|
2117
|
-
x2 = points[(i + 1) * 2];
|
|
2118
|
-
y2 = points[(i + 1) * 2 + 1];
|
|
2119
|
-
perpX = -(y0 - y1);
|
|
2120
|
-
perpY = x0 - x1;
|
|
2121
|
-
dist = Math.sqrt(perpX * perpX + perpY * perpY);
|
|
2122
|
-
perpX /= dist;
|
|
2123
|
-
perpY /= dist;
|
|
2124
|
-
perpX *= width;
|
|
2125
|
-
perpY *= width;
|
|
2126
|
-
perp1x = -(y1 - y2);
|
|
2127
|
-
perp1y = x1 - x2;
|
|
2128
|
-
dist = Math.sqrt(perp1x * perp1x + perp1y * perp1y);
|
|
2129
|
-
perp1x /= dist;
|
|
2130
|
-
perp1y /= dist;
|
|
2131
|
-
perp1x *= width;
|
|
2132
|
-
perp1y *= width;
|
|
2133
|
-
const dx0 = x1 - x0;
|
|
2134
|
-
const dy0 = y0 - y1;
|
|
2135
|
-
const dx1 = x1 - x2;
|
|
2136
|
-
const dy1 = y2 - y1;
|
|
2137
|
-
const dot = dx0 * dx1 + dy0 * dy1;
|
|
2138
|
-
const cross = dy0 * dx1 - dy1 * dx0;
|
|
2139
|
-
const clockwise = cross < 0;
|
|
2140
|
-
if (Math.abs(cross) < 1e-3 * Math.abs(dot)) {
|
|
2141
|
-
verts.push(
|
|
2142
|
-
x1 - perpX * innerWeight,
|
|
2143
|
-
y1 - perpY * innerWeight
|
|
2144
|
-
);
|
|
2145
|
-
verts.push(
|
|
2146
|
-
x1 + perpX * outerWeight,
|
|
2147
|
-
y1 + perpY * outerWeight
|
|
2148
|
-
);
|
|
2149
|
-
if (dot >= 0) {
|
|
2150
|
-
if (style.join === "round") {
|
|
2151
|
-
indexCount += round(
|
|
2152
|
-
x1,
|
|
2153
|
-
y1,
|
|
2154
|
-
x1 - perpX * innerWeight,
|
|
2155
|
-
y1 - perpY * innerWeight,
|
|
2156
|
-
x1 - perp1x * innerWeight,
|
|
2157
|
-
y1 - perp1y * innerWeight,
|
|
2158
|
-
verts,
|
|
2159
|
-
false
|
|
2160
|
-
) + 4;
|
|
2161
|
-
} else {
|
|
2162
|
-
indexCount += 2;
|
|
2163
|
-
}
|
|
2164
|
-
verts.push(
|
|
2165
|
-
x1 - perp1x * outerWeight,
|
|
2166
|
-
y1 - perp1y * outerWeight
|
|
2167
|
-
);
|
|
2168
|
-
verts.push(
|
|
2169
|
-
x1 + perp1x * innerWeight,
|
|
2170
|
-
y1 + perp1y * innerWeight
|
|
2171
|
-
);
|
|
2172
|
-
}
|
|
2173
|
-
continue;
|
|
2174
|
-
}
|
|
2175
|
-
const c1 = (-perpX + x0) * (-perpY + y1) - (-perpX + x1) * (-perpY + y0);
|
|
2176
|
-
const c2 = (-perp1x + x2) * (-perp1y + y1) - (-perp1x + x1) * (-perp1y + y2);
|
|
2177
|
-
const px = (dx0 * c2 - dx1 * c1) / cross;
|
|
2178
|
-
const py = (dy1 * c1 - dy0 * c2) / cross;
|
|
2179
|
-
const pDist = (px - x1) * (px - x1) + (py - y1) * (py - y1);
|
|
2180
|
-
const imx = x1 + (px - x1) * innerWeight;
|
|
2181
|
-
const imy = y1 + (py - y1) * innerWeight;
|
|
2182
|
-
const omx = x1 - (px - x1) * outerWeight;
|
|
2183
|
-
const omy = y1 - (py - y1) * outerWeight;
|
|
2184
|
-
const smallerInsideSegmentSq = Math.min(dx0 * dx0 + dy0 * dy0, dx1 * dx1 + dy1 * dy1);
|
|
2185
|
-
const insideWeight = clockwise ? innerWeight : outerWeight;
|
|
2186
|
-
const smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
|
|
2187
|
-
const insideMiterOk = pDist <= smallerInsideDiagonalSq;
|
|
2188
|
-
if (insideMiterOk) {
|
|
2189
|
-
if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
|
|
2190
|
-
if (clockwise) {
|
|
2191
|
-
verts.push(imx, imy);
|
|
2192
|
-
verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
|
|
2193
|
-
verts.push(imx, imy);
|
|
2194
|
-
verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
|
|
2195
|
-
} else {
|
|
2196
|
-
verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
|
|
2197
|
-
verts.push(omx, omy);
|
|
2198
|
-
verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
|
|
2199
|
-
verts.push(omx, omy);
|
|
2200
|
-
}
|
|
2201
|
-
indexCount += 2;
|
|
2202
|
-
} else if (style.join === "round") {
|
|
2203
|
-
if (clockwise) {
|
|
2204
|
-
verts.push(imx, imy);
|
|
2205
|
-
verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
|
|
2206
|
-
indexCount += round(
|
|
2207
|
-
x1,
|
|
2208
|
-
y1,
|
|
2209
|
-
x1 + perpX * outerWeight,
|
|
2210
|
-
y1 + perpY * outerWeight,
|
|
2211
|
-
x1 + perp1x * outerWeight,
|
|
2212
|
-
y1 + perp1y * outerWeight,
|
|
2213
|
-
verts,
|
|
2214
|
-
true
|
|
2215
|
-
) + 4;
|
|
2216
|
-
verts.push(imx, imy);
|
|
2217
|
-
verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
|
|
2218
|
-
} else {
|
|
2219
|
-
verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
|
|
2220
|
-
verts.push(omx, omy);
|
|
2221
|
-
indexCount += round(
|
|
2222
|
-
x1,
|
|
2223
|
-
y1,
|
|
2224
|
-
x1 - perpX * innerWeight,
|
|
2225
|
-
y1 - perpY * innerWeight,
|
|
2226
|
-
x1 - perp1x * innerWeight,
|
|
2227
|
-
y1 - perp1y * innerWeight,
|
|
2228
|
-
verts,
|
|
2229
|
-
false
|
|
2230
|
-
) + 4;
|
|
2231
|
-
verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
|
|
2232
|
-
verts.push(omx, omy);
|
|
2233
|
-
}
|
|
2234
|
-
} else {
|
|
2235
|
-
verts.push(imx, imy);
|
|
2236
|
-
verts.push(omx, omy);
|
|
2237
|
-
}
|
|
2238
|
-
} else {
|
|
2239
|
-
verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
|
|
2240
|
-
verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
|
|
2241
|
-
if (style.join === "round") {
|
|
2242
|
-
if (clockwise) {
|
|
2243
|
-
indexCount += round(
|
|
2244
|
-
x1,
|
|
2245
|
-
y1,
|
|
2246
|
-
x1 + perpX * outerWeight,
|
|
2247
|
-
y1 + perpY * outerWeight,
|
|
2248
|
-
x1 + perp1x * outerWeight,
|
|
2249
|
-
y1 + perp1y * outerWeight,
|
|
2250
|
-
verts,
|
|
2251
|
-
true
|
|
2252
|
-
) + 2;
|
|
2253
|
-
} else {
|
|
2254
|
-
indexCount += round(
|
|
2255
|
-
x1,
|
|
2256
|
-
y1,
|
|
2257
|
-
x1 - perpX * innerWeight,
|
|
2258
|
-
y1 - perpY * innerWeight,
|
|
2259
|
-
x1 - perp1x * innerWeight,
|
|
2260
|
-
y1 - perp1y * innerWeight,
|
|
2261
|
-
verts,
|
|
2262
|
-
false
|
|
2263
|
-
) + 2;
|
|
2264
|
-
}
|
|
2265
|
-
} else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
|
|
2266
|
-
if (clockwise) {
|
|
2267
|
-
verts.push(omx, omy);
|
|
2268
|
-
verts.push(omx, omy);
|
|
2269
|
-
} else {
|
|
2270
|
-
verts.push(imx, imy);
|
|
2271
|
-
verts.push(imx, imy);
|
|
2272
|
-
}
|
|
2273
|
-
indexCount += 2;
|
|
2274
|
-
}
|
|
2275
|
-
verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
|
|
2276
|
-
verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
|
|
2277
|
-
indexCount += 2;
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
x0 = points[(length - 2) * 2];
|
|
2281
|
-
y0 = points[(length - 2) * 2 + 1];
|
|
2282
|
-
x1 = points[(length - 1) * 2];
|
|
2283
|
-
y1 = points[(length - 1) * 2 + 1];
|
|
2284
|
-
perpX = -(y0 - y1);
|
|
2285
|
-
perpY = x0 - x1;
|
|
2286
|
-
dist = Math.sqrt(perpX * perpX + perpY * perpY);
|
|
2287
|
-
perpX /= dist;
|
|
2288
|
-
perpY /= dist;
|
|
2289
|
-
perpX *= width;
|
|
2290
|
-
perpY *= width;
|
|
2291
|
-
verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
|
|
2292
|
-
verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
|
|
2293
|
-
if (!closedShape) {
|
|
2294
|
-
if (style.cap === "round") {
|
|
2295
|
-
indexCount += round(
|
|
2296
|
-
x1 - perpX * (innerWeight - outerWeight) * 0.5,
|
|
2297
|
-
y1 - perpY * (innerWeight - outerWeight) * 0.5,
|
|
2298
|
-
x1 - perpX * innerWeight,
|
|
2299
|
-
y1 - perpY * innerWeight,
|
|
2300
|
-
x1 + perpX * outerWeight,
|
|
2301
|
-
y1 + perpY * outerWeight,
|
|
2302
|
-
verts,
|
|
2303
|
-
false
|
|
2304
|
-
) + 2;
|
|
2305
|
-
} else if (style.cap === "square") {
|
|
2306
|
-
indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
const eps2 = curveEps * curveEps;
|
|
2310
|
-
for (let i = indexStart; i < indexCount + indexStart - 2; ++i) {
|
|
2311
|
-
x0 = verts[i * 2];
|
|
2312
|
-
y0 = verts[i * 2 + 1];
|
|
2313
|
-
x1 = verts[(i + 1) * 2];
|
|
2314
|
-
y1 = verts[(i + 1) * 2 + 1];
|
|
2315
|
-
x2 = verts[(i + 2) * 2];
|
|
2316
|
-
y2 = verts[(i + 2) * 2 + 1];
|
|
2317
|
-
if (Math.abs(x0 * (y1 - y2) + x1 * (y2 - y0) + x2 * (y0 - y1)) < eps2) {
|
|
2318
|
-
continue;
|
|
2319
|
-
}
|
|
2320
|
-
indices.push(i, i + 1, i + 2);
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
const emptyArray = [];
|
|
2325
|
-
const buildPolygon = {
|
|
2326
|
-
build(shape, points) {
|
|
2327
|
-
for (let i = 0; i < shape.points.length; i++) {
|
|
2328
|
-
points[i] = shape.points[i];
|
|
2329
|
-
}
|
|
2330
|
-
return points;
|
|
2331
|
-
},
|
|
2332
|
-
triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
|
|
2333
|
-
triangulateWithHoles(points, emptyArray, vertices, verticesStride, verticesOffset, indices, indicesOffset);
|
|
2334
|
-
}
|
|
2335
|
-
};
|
|
2336
|
-
|
|
2337
|
-
const buildRectangle = {
|
|
2338
|
-
build(shape, points) {
|
|
2339
|
-
const rectData = shape;
|
|
2340
|
-
const x = rectData.x;
|
|
2341
|
-
const y = rectData.y;
|
|
2342
|
-
const width = rectData.width;
|
|
2343
|
-
const height = rectData.height;
|
|
2344
|
-
if (!(width >= 0 && height >= 0)) {
|
|
2345
|
-
return points;
|
|
2346
|
-
}
|
|
2347
|
-
points[0] = x;
|
|
2348
|
-
points[1] = y;
|
|
2349
|
-
points[2] = x + width;
|
|
2350
|
-
points[3] = y;
|
|
2351
|
-
points[4] = x + width;
|
|
2352
|
-
points[5] = y + height;
|
|
2353
|
-
points[6] = x;
|
|
2354
|
-
points[7] = y + height;
|
|
2355
|
-
return points;
|
|
2356
|
-
},
|
|
2357
|
-
triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
|
|
2358
|
-
let count = 0;
|
|
2359
|
-
verticesOffset *= verticesStride;
|
|
2360
|
-
vertices[verticesOffset + count] = points[0];
|
|
2361
|
-
vertices[verticesOffset + count + 1] = points[1];
|
|
2362
|
-
count += verticesStride;
|
|
2363
|
-
vertices[verticesOffset + count] = points[2];
|
|
2364
|
-
vertices[verticesOffset + count + 1] = points[3];
|
|
2365
|
-
count += verticesStride;
|
|
2366
|
-
vertices[verticesOffset + count] = points[6];
|
|
2367
|
-
vertices[verticesOffset + count + 1] = points[7];
|
|
2368
|
-
count += verticesStride;
|
|
2369
|
-
vertices[verticesOffset + count] = points[4];
|
|
2370
|
-
vertices[verticesOffset + count + 1] = points[5];
|
|
2371
|
-
count += verticesStride;
|
|
2372
|
-
const verticesIndex = verticesOffset / verticesStride;
|
|
2373
|
-
indices[indicesOffset++] = verticesIndex;
|
|
2374
|
-
indices[indicesOffset++] = verticesIndex + 1;
|
|
2375
|
-
indices[indicesOffset++] = verticesIndex + 2;
|
|
2376
|
-
indices[indicesOffset++] = verticesIndex + 1;
|
|
2377
|
-
indices[indicesOffset++] = verticesIndex + 3;
|
|
2378
|
-
indices[indicesOffset++] = verticesIndex + 2;
|
|
2379
|
-
}
|
|
2380
|
-
};
|
|
2381
|
-
|
|
2382
|
-
const buildTriangle = {
|
|
2383
|
-
build(shape, points) {
|
|
2384
|
-
points[0] = shape.x;
|
|
2385
|
-
points[1] = shape.y;
|
|
2386
|
-
points[2] = shape.x2;
|
|
2387
|
-
points[3] = shape.y2;
|
|
2388
|
-
points[4] = shape.x3;
|
|
2389
|
-
points[5] = shape.y3;
|
|
2390
|
-
return points;
|
|
2391
|
-
},
|
|
2392
|
-
triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
|
|
2393
|
-
let count = 0;
|
|
2394
|
-
verticesOffset *= verticesStride;
|
|
2395
|
-
vertices[verticesOffset + count] = points[0];
|
|
2396
|
-
vertices[verticesOffset + count + 1] = points[1];
|
|
2397
|
-
count += verticesStride;
|
|
2398
|
-
vertices[verticesOffset + count] = points[2];
|
|
2399
|
-
vertices[verticesOffset + count + 1] = points[3];
|
|
2400
|
-
count += verticesStride;
|
|
2401
|
-
vertices[verticesOffset + count] = points[4];
|
|
2402
|
-
vertices[verticesOffset + count + 1] = points[5];
|
|
2403
|
-
const verticesIndex = verticesOffset / verticesStride;
|
|
2404
|
-
indices[indicesOffset++] = verticesIndex;
|
|
2405
|
-
indices[indicesOffset++] = verticesIndex + 1;
|
|
2406
|
-
indices[indicesOffset++] = verticesIndex + 2;
|
|
2407
|
-
}
|
|
2408
|
-
};
|
|
2409
|
-
|
|
2410
|
-
const tempPoints = [new Point(), new Point(), new Point(), new Point()];
|
|
2411
|
-
class Rectangle {
|
|
2412
|
-
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
2413
|
-
this.x = x;
|
|
2414
|
-
this.y = y;
|
|
2415
|
-
this.width = width;
|
|
2416
|
-
this.height = height;
|
|
2417
|
-
}
|
|
2418
|
-
get left() {
|
|
2419
|
-
return this.x;
|
|
2420
|
-
}
|
|
2421
|
-
get right() {
|
|
2422
|
-
return this.x + this.width;
|
|
2423
|
-
}
|
|
2424
|
-
get top() {
|
|
2425
|
-
return this.y;
|
|
2426
|
-
}
|
|
2427
|
-
get bottom() {
|
|
2428
|
-
return this.y + this.height;
|
|
2429
|
-
}
|
|
2430
|
-
isEmpty() {
|
|
2431
|
-
return this.left === this.right || this.top === this.bottom;
|
|
2432
|
-
}
|
|
2433
|
-
copyFromBounds(bounds) {
|
|
2434
|
-
this.x = bounds.minX;
|
|
2435
|
-
this.y = bounds.minY;
|
|
2436
|
-
this.width = bounds.maxX - bounds.minX;
|
|
2437
|
-
this.height = bounds.maxY - bounds.minY;
|
|
2438
|
-
return this;
|
|
2439
|
-
}
|
|
2440
|
-
contains(x, y) {
|
|
2441
|
-
if (this.width <= 0 || this.height <= 0) {
|
|
2442
|
-
return false;
|
|
2443
|
-
}
|
|
2444
|
-
if (x >= this.x && x < this.x + this.width) {
|
|
2445
|
-
if (y >= this.y && y < this.y + this.height) {
|
|
2446
|
-
return true;
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
return false;
|
|
2450
|
-
}
|
|
2451
|
-
strokeContains(x, y, strokeWidth) {
|
|
2452
|
-
const { width, height } = this;
|
|
2453
|
-
if (width <= 0 || height <= 0)
|
|
2454
|
-
return false;
|
|
2455
|
-
const _x = this.x;
|
|
2456
|
-
const _y = this.y;
|
|
2457
|
-
const outerLeft = _x - strokeWidth / 2;
|
|
2458
|
-
const outerRight = _x + width + strokeWidth / 2;
|
|
2459
|
-
const outerTop = _y - strokeWidth / 2;
|
|
2460
|
-
const outerBottom = _y + height + strokeWidth / 2;
|
|
2461
|
-
const innerLeft = _x + strokeWidth / 2;
|
|
2462
|
-
const innerRight = _x + width - strokeWidth / 2;
|
|
2463
|
-
const innerTop = _y + strokeWidth / 2;
|
|
2464
|
-
const innerBottom = _y + height - strokeWidth / 2;
|
|
2465
|
-
return x >= outerLeft && x <= outerRight && y >= outerTop && y <= outerBottom && !(x > innerLeft && x < innerRight && y > innerTop && y < innerBottom);
|
|
2466
|
-
}
|
|
2467
|
-
clone() {
|
|
2468
|
-
return new Rectangle(this.x, this.y, this.width, this.height);
|
|
2469
|
-
}
|
|
2470
|
-
copyFrom(rectangle) {
|
|
2471
|
-
this.x = rectangle.x;
|
|
2472
|
-
this.y = rectangle.y;
|
|
2473
|
-
this.width = rectangle.width;
|
|
2474
|
-
this.height = rectangle.height;
|
|
2475
|
-
}
|
|
2476
|
-
copyTo(rectangle) {
|
|
2477
|
-
rectangle.copyFrom(this);
|
|
2478
|
-
}
|
|
2479
|
-
intersects(other, transform) {
|
|
2480
|
-
if (!transform) {
|
|
2481
|
-
const x02 = this.x < other.x ? other.x : this.x;
|
|
2482
|
-
const x12 = this.right > other.right ? other.right : this.right;
|
|
2483
|
-
if (x12 <= x02) {
|
|
2484
|
-
return false;
|
|
2485
|
-
}
|
|
2486
|
-
const y02 = this.y < other.y ? other.y : this.y;
|
|
2487
|
-
const y12 = this.bottom > other.bottom ? other.bottom : this.bottom;
|
|
2488
|
-
return y12 > y02;
|
|
2489
|
-
}
|
|
2490
|
-
const x0 = this.left;
|
|
2491
|
-
const x1 = this.right;
|
|
2492
|
-
const y0 = this.top;
|
|
2493
|
-
const y1 = this.bottom;
|
|
2494
|
-
if (x1 <= x0 || y1 <= y0) {
|
|
2495
|
-
return false;
|
|
2496
|
-
}
|
|
2497
|
-
const lt = tempPoints[0].set(other.left, other.top);
|
|
2498
|
-
const lb = tempPoints[1].set(other.left, other.bottom);
|
|
2499
|
-
const rt = tempPoints[2].set(other.right, other.top);
|
|
2500
|
-
const rb = tempPoints[3].set(other.right, other.bottom);
|
|
2501
|
-
if (rt.x <= lt.x || lb.y <= lt.y) {
|
|
2502
|
-
return false;
|
|
2503
|
-
}
|
|
2504
|
-
const { a, d, b, c } = transform.toObject();
|
|
2505
|
-
const s = Math.sign(a * d - b * c);
|
|
2506
|
-
if (s === 0) {
|
|
2507
|
-
return false;
|
|
2508
|
-
}
|
|
2509
|
-
[lt.x, lt.y] = transform.applyToPoint(lt.x, lt.y);
|
|
2510
|
-
[lb.x, lb.y] = transform.applyToPoint(lb.x, lb.y);
|
|
2511
|
-
[rt.x, rt.y] = transform.applyToPoint(rt.x, rt.y);
|
|
2512
|
-
[rb.x, rb.y] = transform.applyToPoint(rb.x, lt.y);
|
|
2513
|
-
if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0 || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1 || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0 || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
|
|
2514
|
-
return false;
|
|
2515
|
-
}
|
|
2516
|
-
const nx = s * (lb.y - lt.y);
|
|
2517
|
-
const ny = s * (lt.x - lb.x);
|
|
2518
|
-
const n00 = nx * x0 + ny * y0;
|
|
2519
|
-
const n10 = nx * x1 + ny * y0;
|
|
2520
|
-
const n01 = nx * x0 + ny * y1;
|
|
2521
|
-
const n11 = nx * x1 + ny * y1;
|
|
2522
|
-
if (Math.max(n00, n10, n01, n11) <= nx * lt.x + ny * lt.y || Math.min(n00, n10, n01, n11) >= nx * rb.x + ny * rb.y) {
|
|
2523
|
-
return false;
|
|
2524
|
-
}
|
|
2525
|
-
const mx = s * (lt.y - rt.y);
|
|
2526
|
-
const my = s * (rt.x - lt.x);
|
|
2527
|
-
const m00 = mx * x0 + my * y0;
|
|
2528
|
-
const m10 = mx * x1 + my * y0;
|
|
2529
|
-
const m01 = mx * x0 + my * y1;
|
|
2530
|
-
const m11 = mx * x1 + my * y1;
|
|
2531
|
-
if (Math.max(m00, m10, m01, m11) <= mx * lt.x + my * lt.y || Math.min(m00, m10, m01, m11) >= mx * rb.x + my * rb.y) {
|
|
2532
|
-
return false;
|
|
2533
|
-
}
|
|
2534
|
-
return true;
|
|
2535
|
-
}
|
|
2536
|
-
pad(paddingX = 0, paddingY = paddingX) {
|
|
2537
|
-
this.x -= paddingX;
|
|
2538
|
-
this.y -= paddingY;
|
|
2539
|
-
this.width += paddingX * 2;
|
|
2540
|
-
this.height += paddingY * 2;
|
|
2541
|
-
return this;
|
|
2542
|
-
}
|
|
2543
|
-
fit(rectangle) {
|
|
2544
|
-
const x1 = Math.max(this.x, rectangle.x);
|
|
2545
|
-
const x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
|
|
2546
|
-
const y1 = Math.max(this.y, rectangle.y);
|
|
2547
|
-
const y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
|
|
2548
|
-
this.x = x1;
|
|
2549
|
-
this.width = Math.max(x2 - x1, 0);
|
|
2550
|
-
this.y = y1;
|
|
2551
|
-
this.height = Math.max(y2 - y1, 0);
|
|
2552
|
-
return this;
|
|
2553
|
-
}
|
|
2554
|
-
ceil(resolution = 1, eps = 1e-3) {
|
|
2555
|
-
const x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
|
|
2556
|
-
const y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
|
|
2557
|
-
this.x = Math.floor((this.x + eps) * resolution) / resolution;
|
|
2558
|
-
this.y = Math.floor((this.y + eps) * resolution) / resolution;
|
|
2559
|
-
this.width = x2 - this.x;
|
|
2560
|
-
this.height = y2 - this.y;
|
|
2561
|
-
return this;
|
|
2562
|
-
}
|
|
2563
|
-
enlarge(rectangle) {
|
|
2564
|
-
const x1 = Math.min(this.x, rectangle.x);
|
|
2565
|
-
const x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
|
|
2566
|
-
const y1 = Math.min(this.y, rectangle.y);
|
|
2567
|
-
const y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
|
|
2568
|
-
this.x = x1;
|
|
2569
|
-
this.width = x2 - x1;
|
|
2570
|
-
this.y = y1;
|
|
2571
|
-
this.height = y2 - y1;
|
|
2572
|
-
return this;
|
|
2573
|
-
}
|
|
2574
|
-
getBounds(out) {
|
|
2575
|
-
out = out || new Rectangle();
|
|
2576
|
-
out.copyFrom(this);
|
|
2577
|
-
return out;
|
|
2578
|
-
}
|
|
2579
|
-
buildOutline(points) {
|
|
2580
|
-
buildRectangle.build(this, points);
|
|
2581
|
-
}
|
|
2582
|
-
buildGeometry(vertices, indices) {
|
|
2583
|
-
const points = [];
|
|
2584
|
-
this.buildOutline(points);
|
|
2585
|
-
buildRectangle.triangulate(points, vertices, 2, 0, indices, 0);
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
class Vector extends EventEmitter {
|
|
2590
|
-
constructor(dim) {
|
|
2591
|
-
super();
|
|
2592
|
-
this.dim = dim;
|
|
2593
|
-
}
|
|
2594
|
-
_array = [];
|
|
2595
|
-
get length() {
|
|
2596
|
-
return this.dim;
|
|
2597
|
-
}
|
|
2598
|
-
_operate(operator, target, output) {
|
|
2599
|
-
const { dim: length, _array: array } = this;
|
|
2600
|
-
let targetArray;
|
|
2601
|
-
if (typeof target === "number") {
|
|
2602
|
-
targetArray = Array.from({ length }, () => target);
|
|
2603
|
-
} else if (target instanceof Matrix || target instanceof Vector) {
|
|
2604
|
-
targetArray = target.toArray();
|
|
2605
|
-
} else {
|
|
2606
|
-
targetArray = target;
|
|
2607
|
-
}
|
|
2608
|
-
let outputObject;
|
|
2609
|
-
let outputArray = [];
|
|
2610
|
-
if (!output) {
|
|
2611
|
-
outputObject = this;
|
|
2612
|
-
} else if (output instanceof Vector) {
|
|
2613
|
-
outputObject = output;
|
|
2614
|
-
} else {
|
|
2615
|
-
outputArray = output;
|
|
2616
|
-
}
|
|
2617
|
-
if (target instanceof Matrix) {
|
|
2618
|
-
const { cols } = target;
|
|
2619
|
-
switch (operator) {
|
|
2620
|
-
case "*":
|
|
2621
|
-
for (let x = 0; x < length; x++) {
|
|
2622
|
-
let val = 0;
|
|
2623
|
-
for (let y = 0; y < length; y++) {
|
|
2624
|
-
val += array[x] * targetArray[y * cols + x];
|
|
2625
|
-
}
|
|
2626
|
-
outputArray[x] = val;
|
|
2627
|
-
}
|
|
2628
|
-
break;
|
|
2629
|
-
default:
|
|
2630
|
-
throw new Error(`Not support operator in '${this.toName()} ${operator} ${target.toName()}'`);
|
|
2631
|
-
}
|
|
2632
|
-
} else {
|
|
2633
|
-
switch (operator) {
|
|
2634
|
-
case "+":
|
|
2635
|
-
for (let i = 0; i < length; i++) {
|
|
2636
|
-
outputArray[i] = array[i] + targetArray[i];
|
|
2637
|
-
}
|
|
2638
|
-
break;
|
|
2639
|
-
case "-":
|
|
2640
|
-
for (let i = 0; i < length; i++) {
|
|
2641
|
-
outputArray[i] = array[i] - targetArray[i];
|
|
2642
|
-
}
|
|
2643
|
-
break;
|
|
2644
|
-
case "*":
|
|
2645
|
-
for (let i = 0; i < length; i++) {
|
|
2646
|
-
outputArray[i] = array[i] * targetArray[i];
|
|
2647
|
-
}
|
|
2648
|
-
break;
|
|
2649
|
-
case "/":
|
|
2650
|
-
for (let i = 0; i < length; i++) {
|
|
2651
|
-
outputArray[i] = array[i] / targetArray[i];
|
|
2652
|
-
}
|
|
2653
|
-
break;
|
|
2654
|
-
case "rot": {
|
|
2655
|
-
const c = Math.cos(targetArray[0]);
|
|
2656
|
-
const s = Math.sin(targetArray[0]);
|
|
2657
|
-
outputArray[0] = array[0] * c - array[1] * s;
|
|
2658
|
-
outputArray[1] = array[1] * c + array[0] * s;
|
|
2659
|
-
break;
|
|
2660
|
-
}
|
|
2661
|
-
case "==": {
|
|
2662
|
-
let flag = true;
|
|
2663
|
-
for (let i = 0; i < length; i++) {
|
|
2664
|
-
flag = flag && array[i] === targetArray[i];
|
|
2665
|
-
}
|
|
2666
|
-
return flag;
|
|
2667
|
-
}
|
|
2668
|
-
case "=":
|
|
2669
|
-
for (let i = 0; i < length; i++) {
|
|
2670
|
-
const val = targetArray[i];
|
|
2671
|
-
if (val !== void 0) {
|
|
2672
|
-
array[i] = val;
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
this._emitUpdate(array);
|
|
2676
|
-
return this;
|
|
2677
|
-
default:
|
|
2678
|
-
throw new Error(`Not support operator in '${this.toName()} ${operator} Vector'`);
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
return outputObject?.set(outputArray) ?? outputArray;
|
|
2682
|
-
}
|
|
2683
|
-
add(value, output) {
|
|
2684
|
-
return this._operate("+", value, output);
|
|
2685
|
-
}
|
|
2686
|
-
sub(value, output) {
|
|
2687
|
-
return this._operate("-", value, output);
|
|
2688
|
-
}
|
|
2689
|
-
multiply(value, output) {
|
|
2690
|
-
return this._operate("*", value, output);
|
|
2691
|
-
}
|
|
2692
|
-
divide(value, output) {
|
|
2693
|
-
return this._operate("/", value, output);
|
|
2694
|
-
}
|
|
2695
|
-
rotate(angle) {
|
|
2696
|
-
return this._operate("rot", angle);
|
|
2697
|
-
}
|
|
2698
|
-
set(value, ...args) {
|
|
2699
|
-
if (args.length && typeof value === "number") {
|
|
2700
|
-
value = [value, ...args];
|
|
2701
|
-
}
|
|
2702
|
-
return this._operate("=", value);
|
|
2703
|
-
}
|
|
2704
|
-
equals(value) {
|
|
2705
|
-
return this._operate("==", value);
|
|
2706
|
-
}
|
|
2707
|
-
clone() {
|
|
2708
|
-
const cloned = new this.constructor();
|
|
2709
|
-
cloned.set(this.toArray());
|
|
2710
|
-
return cloned;
|
|
2711
|
-
}
|
|
2712
|
-
onUpdate(callback) {
|
|
2713
|
-
this.on("update", callback);
|
|
2714
|
-
return this;
|
|
2715
|
-
}
|
|
2716
|
-
offUpdate(callback) {
|
|
2717
|
-
this.off("update", callback);
|
|
2718
|
-
return this;
|
|
2719
|
-
}
|
|
2720
|
-
_emitUpdate(array) {
|
|
2721
|
-
this._onUpdate(array);
|
|
2722
|
-
this.emit("update", array);
|
|
2723
|
-
}
|
|
2724
|
-
_onUpdate(_array) {
|
|
2725
|
-
}
|
|
2726
|
-
toArray() {
|
|
2727
|
-
return this._array.slice();
|
|
2728
|
-
}
|
|
2729
|
-
toName() {
|
|
2730
|
-
return `Vector${this.dim}`;
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
|
|
2734
|
-
class Matrix extends EventEmitter {
|
|
2735
|
-
constructor(rows, cols, array) {
|
|
2736
|
-
super();
|
|
2737
|
-
this.rows = rows;
|
|
2738
|
-
this.cols = cols;
|
|
2739
|
-
if (array) {
|
|
2740
|
-
this.set(array);
|
|
2741
|
-
} else {
|
|
2742
|
-
this.identity();
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
_array = [];
|
|
2746
|
-
get length() {
|
|
2747
|
-
return this.cols * this.rows;
|
|
2748
|
-
}
|
|
2749
|
-
_operate(operator, target, output) {
|
|
2750
|
-
const { cols, rows, length, _array: array } = this;
|
|
2751
|
-
let targetArray;
|
|
2752
|
-
if (typeof target === "number") {
|
|
2753
|
-
targetArray = Array.from({ length }, () => target);
|
|
2754
|
-
} else if (target instanceof Vector || target instanceof Matrix) {
|
|
2755
|
-
targetArray = target.toArray();
|
|
2756
|
-
} else {
|
|
2757
|
-
targetArray = target;
|
|
1199
|
+
_operate(operator, target, output) {
|
|
1200
|
+
const { cols, rows, length, _array: array } = this;
|
|
1201
|
+
let targetArray;
|
|
1202
|
+
if (typeof target === "number") {
|
|
1203
|
+
targetArray = Array.from({ length }, () => target);
|
|
1204
|
+
} else if (target instanceof Vector || target instanceof Matrix) {
|
|
1205
|
+
targetArray = target.toArray();
|
|
1206
|
+
} else {
|
|
1207
|
+
targetArray = target;
|
|
2758
1208
|
}
|
|
2759
1209
|
let outputObject;
|
|
2760
1210
|
let outputArray = [];
|
|
@@ -2877,6 +1327,12 @@ class Matrix extends EventEmitter {
|
|
|
2877
1327
|
}
|
|
2878
1328
|
}
|
|
2879
1329
|
|
|
1330
|
+
class Matrix2 extends Matrix {
|
|
1331
|
+
constructor(array) {
|
|
1332
|
+
super(2, 2, array);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
2880
1336
|
class Matrix3 extends Matrix {
|
|
2881
1337
|
constructor(array) {
|
|
2882
1338
|
super(3, 3, array);
|
|
@@ -2915,6 +1371,72 @@ class Matrix3 extends Matrix {
|
|
|
2915
1371
|
}
|
|
2916
1372
|
}
|
|
2917
1373
|
|
|
1374
|
+
class Matrix4 extends Matrix {
|
|
1375
|
+
constructor(array) {
|
|
1376
|
+
super(4, 4, array);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
class Projection2D extends Matrix3 {
|
|
1381
|
+
constructor(_x = 0, _y = 0, _width = 0, _height = 0, _flipY = false) {
|
|
1382
|
+
super();
|
|
1383
|
+
this._x = _x;
|
|
1384
|
+
this._y = _y;
|
|
1385
|
+
this._width = _width;
|
|
1386
|
+
this._height = _height;
|
|
1387
|
+
this._flipY = _flipY;
|
|
1388
|
+
this._performUpdateArray();
|
|
1389
|
+
}
|
|
1390
|
+
flipY(flipY) {
|
|
1391
|
+
if (this._flipY !== flipY) {
|
|
1392
|
+
this._flipY = flipY;
|
|
1393
|
+
this._performUpdateArray();
|
|
1394
|
+
}
|
|
1395
|
+
return this;
|
|
1396
|
+
}
|
|
1397
|
+
translate(x, y) {
|
|
1398
|
+
if (this._x !== x || this._y !== y) {
|
|
1399
|
+
this._x = x;
|
|
1400
|
+
this._y = y;
|
|
1401
|
+
this._performUpdateArray();
|
|
1402
|
+
}
|
|
1403
|
+
return this;
|
|
1404
|
+
}
|
|
1405
|
+
resize(width, height) {
|
|
1406
|
+
if (this._width !== width || this._height !== height) {
|
|
1407
|
+
this._width = width;
|
|
1408
|
+
this._height = height;
|
|
1409
|
+
this._performUpdateArray();
|
|
1410
|
+
}
|
|
1411
|
+
return this;
|
|
1412
|
+
}
|
|
1413
|
+
_performUpdateArray() {
|
|
1414
|
+
const width = this._width;
|
|
1415
|
+
const height = this._height;
|
|
1416
|
+
if (!width || !height) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
const x = this._x;
|
|
1420
|
+
const y = this._y;
|
|
1421
|
+
const sign = !this._flipY ? 1 : -1;
|
|
1422
|
+
const a = 1 / width * 2;
|
|
1423
|
+
const d = sign * (1 / height * 2);
|
|
1424
|
+
const tx = -1 - x * a;
|
|
1425
|
+
const ty = -sign - y * d;
|
|
1426
|
+
this.set([
|
|
1427
|
+
a,
|
|
1428
|
+
0,
|
|
1429
|
+
tx,
|
|
1430
|
+
0,
|
|
1431
|
+
d,
|
|
1432
|
+
ty,
|
|
1433
|
+
0,
|
|
1434
|
+
0,
|
|
1435
|
+
1
|
|
1436
|
+
]);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
2918
1440
|
class Transform2D extends Matrix3 {
|
|
2919
1441
|
constructor(autoUpdate = true) {
|
|
2920
1442
|
super();
|
|
@@ -3035,869 +1557,106 @@ class Transform2D extends Matrix3 {
|
|
|
3035
1557
|
translateY(y) {
|
|
3036
1558
|
return this.translate(this._translateX, y);
|
|
3037
1559
|
}
|
|
3038
|
-
translateZ(z) {
|
|
3039
|
-
return this.translate(this._translateX, this._translateY, z);
|
|
3040
|
-
}
|
|
3041
|
-
translate3d(x, y, z) {
|
|
3042
|
-
return this.translate(x, y, z);
|
|
3043
|
-
}
|
|
3044
|
-
scale(x, y, _z = 1) {
|
|
3045
|
-
this._scaleX = x;
|
|
3046
|
-
this._scaleY = y;
|
|
3047
|
-
this._requestUpdateArray();
|
|
3048
|
-
return this;
|
|
3049
|
-
}
|
|
3050
|
-
scaleX(x) {
|
|
3051
|
-
return this.scale(x, this._scaleY);
|
|
3052
|
-
}
|
|
3053
|
-
scaleY(y) {
|
|
3054
|
-
return this.scale(this._scaleX, y);
|
|
3055
|
-
}
|
|
3056
|
-
scale3d(x, y, z) {
|
|
3057
|
-
return this.scale(x, y, z);
|
|
3058
|
-
}
|
|
3059
|
-
rotate(rad) {
|
|
3060
|
-
this._rotate = rad;
|
|
3061
|
-
this._updateSkew();
|
|
3062
|
-
this._requestUpdateArray();
|
|
3063
|
-
return this;
|
|
3064
|
-
}
|
|
3065
|
-
rotateX(x) {
|
|
3066
|
-
return this.scaleY(this._rotateToScale(x));
|
|
3067
|
-
}
|
|
3068
|
-
rotateY(y) {
|
|
3069
|
-
return this.scaleX(this._rotateToScale(y));
|
|
3070
|
-
}
|
|
3071
|
-
rotateZ(z) {
|
|
3072
|
-
return this.rotate(z);
|
|
3073
|
-
}
|
|
3074
|
-
rotate3d(x, y, z, rad) {
|
|
3075
|
-
const [rx, ry, rz] = this._rotate3d(x, y, z, rad);
|
|
3076
|
-
rx && this.rotateX(rx);
|
|
3077
|
-
ry && this.rotateY(ry);
|
|
3078
|
-
rz && this.rotateZ(rz);
|
|
3079
|
-
return this;
|
|
3080
|
-
}
|
|
3081
|
-
_rotateToScale(rad) {
|
|
3082
|
-
const val = rad / PI_2;
|
|
3083
|
-
return val <= 0.5 ? val * -4 + 1 : (val - 1) * 4 + 1;
|
|
3084
|
-
}
|
|
3085
|
-
_rotate3d(x, y, z, rad) {
|
|
3086
|
-
if (x === 1 && y === 0 && z === 0) {
|
|
3087
|
-
return [rad, 0, 0];
|
|
3088
|
-
} else if (x === 0 && y === 1 && z === 0) {
|
|
3089
|
-
return [0, rad, 0];
|
|
3090
|
-
} else if (x === 0 && y === 0) {
|
|
3091
|
-
return [0, 0, rad];
|
|
3092
|
-
} else {
|
|
3093
|
-
const cos = Math.cos(rad);
|
|
3094
|
-
const sin = Math.sin(rad);
|
|
3095
|
-
const m11 = cos + x * x * (1 - cos);
|
|
3096
|
-
const m12 = x * y * (1 - cos) - z * sin;
|
|
3097
|
-
const m13 = x * z * (1 - cos) + y * sin;
|
|
3098
|
-
const m22 = cos + y * y * (1 - cos);
|
|
3099
|
-
const m23 = y * z * (1 - cos) - x * sin;
|
|
3100
|
-
const m33 = cos + z * z * (1 - cos);
|
|
3101
|
-
const rotateX = -Math.atan2(-m23, m22);
|
|
3102
|
-
const rotateY = -Math.atan2(m13, Math.sqrt(m23 * m23 + m33 * m33));
|
|
3103
|
-
const rotateZ = -Math.atan2(-m12, m11);
|
|
3104
|
-
return [rotateX, rotateY, rotateZ];
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
applyToPoint(x, y) {
|
|
3108
|
-
const { a, c, tx, b, d, ty } = this.toObject();
|
|
3109
|
-
return [
|
|
3110
|
-
a * x + c * y + tx,
|
|
3111
|
-
b * x + d * y + ty
|
|
3112
|
-
];
|
|
3113
|
-
}
|
|
3114
|
-
inverse() {
|
|
3115
|
-
return this.clone().invert();
|
|
3116
|
-
}
|
|
3117
|
-
update() {
|
|
3118
|
-
let updated = false;
|
|
3119
|
-
if (this._needsUpdateArray) {
|
|
3120
|
-
this._needsUpdateArray = false;
|
|
3121
|
-
this._performUpdateArray();
|
|
3122
|
-
updated = true;
|
|
3123
|
-
}
|
|
3124
|
-
if (this._needsUpdateFields) {
|
|
3125
|
-
this._needsUpdateFields = false;
|
|
3126
|
-
this._performUpdateFields();
|
|
3127
|
-
updated = true;
|
|
3128
|
-
}
|
|
3129
|
-
return updated;
|
|
3130
|
-
}
|
|
3131
|
-
isIdentity() {
|
|
3132
|
-
const { a, b, c, d, tx, ty } = this.toObject();
|
|
3133
|
-
return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
|
|
3134
|
-
}
|
|
3135
|
-
toObject() {
|
|
3136
|
-
const [a, c, tx, b, d, ty, , , tz] = this._array;
|
|
3137
|
-
return { a, c, tx, b, d, ty, tz };
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
|
|
3141
|
-
const defaultMatrix = new Transform2D();
|
|
3142
|
-
class Bounds {
|
|
3143
|
-
constructor(minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity) {
|
|
3144
|
-
this.minX = minX;
|
|
3145
|
-
this.minY = minY;
|
|
3146
|
-
this.maxX = maxX;
|
|
3147
|
-
this.maxY = maxY;
|
|
3148
|
-
}
|
|
3149
|
-
matrix = defaultMatrix;
|
|
3150
|
-
_rectangle;
|
|
3151
|
-
get x() {
|
|
3152
|
-
return this.minX;
|
|
3153
|
-
}
|
|
3154
|
-
set x(value) {
|
|
3155
|
-
const width = this.maxX - this.minX;
|
|
3156
|
-
this.minX = value;
|
|
3157
|
-
this.maxX = value + width;
|
|
3158
|
-
}
|
|
3159
|
-
get y() {
|
|
3160
|
-
return this.minY;
|
|
3161
|
-
}
|
|
3162
|
-
set y(value) {
|
|
3163
|
-
const height = this.maxY - this.minY;
|
|
3164
|
-
this.minY = value;
|
|
3165
|
-
this.maxY = value + height;
|
|
3166
|
-
}
|
|
3167
|
-
get width() {
|
|
3168
|
-
return this.maxX - this.minX;
|
|
3169
|
-
}
|
|
3170
|
-
set width(value) {
|
|
3171
|
-
this.maxX = this.minX + value;
|
|
3172
|
-
}
|
|
3173
|
-
get height() {
|
|
3174
|
-
return this.maxY - this.minY;
|
|
3175
|
-
}
|
|
3176
|
-
set height(value) {
|
|
3177
|
-
this.maxY = this.minY + value;
|
|
3178
|
-
}
|
|
3179
|
-
get left() {
|
|
3180
|
-
return this.minX;
|
|
3181
|
-
}
|
|
3182
|
-
get right() {
|
|
3183
|
-
return this.maxX;
|
|
3184
|
-
}
|
|
3185
|
-
get top() {
|
|
3186
|
-
return this.minY;
|
|
3187
|
-
}
|
|
3188
|
-
get bottom() {
|
|
3189
|
-
return this.maxY;
|
|
3190
|
-
}
|
|
3191
|
-
get isPositive() {
|
|
3192
|
-
return this.maxX - this.minX > 0 && this.maxY - this.minY > 0;
|
|
3193
|
-
}
|
|
3194
|
-
get isValid() {
|
|
3195
|
-
return this.minX + this.minY !== Infinity;
|
|
3196
|
-
}
|
|
3197
|
-
isEmpty() {
|
|
3198
|
-
return this.minX > this.maxX || this.minY > this.maxY;
|
|
3199
|
-
}
|
|
3200
|
-
get rectangle() {
|
|
3201
|
-
if (!this._rectangle) {
|
|
3202
|
-
this._rectangle = new Rectangle();
|
|
3203
|
-
}
|
|
3204
|
-
const rectangle = this._rectangle;
|
|
3205
|
-
if (this.minX > this.maxX || this.minY > this.maxY) {
|
|
3206
|
-
rectangle.x = 0;
|
|
3207
|
-
rectangle.y = 0;
|
|
3208
|
-
rectangle.width = 0;
|
|
3209
|
-
rectangle.height = 0;
|
|
3210
|
-
} else {
|
|
3211
|
-
rectangle.copyFromBounds(this);
|
|
3212
|
-
}
|
|
3213
|
-
return rectangle;
|
|
3214
|
-
}
|
|
3215
|
-
clear() {
|
|
3216
|
-
this.minX = Infinity;
|
|
3217
|
-
this.minY = Infinity;
|
|
3218
|
-
this.maxX = -Infinity;
|
|
3219
|
-
this.maxY = -Infinity;
|
|
3220
|
-
this.matrix = defaultMatrix;
|
|
3221
|
-
return this;
|
|
3222
|
-
}
|
|
3223
|
-
set(x0, y0, x1, y1) {
|
|
3224
|
-
this.minX = x0;
|
|
3225
|
-
this.minY = y0;
|
|
3226
|
-
this.maxX = x1;
|
|
3227
|
-
this.maxY = y1;
|
|
3228
|
-
return this;
|
|
3229
|
-
}
|
|
3230
|
-
addFrame(x0, y0, x1, y1, matrix) {
|
|
3231
|
-
matrix ||= this.matrix;
|
|
3232
|
-
const { a, b, c, d, tx, ty } = matrix.toObject();
|
|
3233
|
-
let minX = this.minX;
|
|
3234
|
-
let minY = this.minY;
|
|
3235
|
-
let maxX = this.maxX;
|
|
3236
|
-
let maxY = this.maxY;
|
|
3237
|
-
let x = a * x0 + c * y0 + tx;
|
|
3238
|
-
let y = b * x0 + d * y0 + ty;
|
|
3239
|
-
if (x < minX)
|
|
3240
|
-
minX = x;
|
|
3241
|
-
if (y < minY)
|
|
3242
|
-
minY = y;
|
|
3243
|
-
if (x > maxX)
|
|
3244
|
-
maxX = x;
|
|
3245
|
-
if (y > maxY)
|
|
3246
|
-
maxY = y;
|
|
3247
|
-
x = a * x1 + c * y0 + tx;
|
|
3248
|
-
y = b * x1 + d * y0 + ty;
|
|
3249
|
-
if (x < minX)
|
|
3250
|
-
minX = x;
|
|
3251
|
-
if (y < minY)
|
|
3252
|
-
minY = y;
|
|
3253
|
-
if (x > maxX)
|
|
3254
|
-
maxX = x;
|
|
3255
|
-
if (y > maxY)
|
|
3256
|
-
maxY = y;
|
|
3257
|
-
x = a * x0 + c * y1 + tx;
|
|
3258
|
-
y = b * x0 + d * y1 + ty;
|
|
3259
|
-
if (x < minX)
|
|
3260
|
-
minX = x;
|
|
3261
|
-
if (y < minY)
|
|
3262
|
-
minY = y;
|
|
3263
|
-
if (x > maxX)
|
|
3264
|
-
maxX = x;
|
|
3265
|
-
if (y > maxY)
|
|
3266
|
-
maxY = y;
|
|
3267
|
-
x = a * x1 + c * y1 + tx;
|
|
3268
|
-
y = b * x1 + d * y1 + ty;
|
|
3269
|
-
if (x < minX)
|
|
3270
|
-
minX = x;
|
|
3271
|
-
if (y < minY)
|
|
3272
|
-
minY = y;
|
|
3273
|
-
if (x > maxX)
|
|
3274
|
-
maxX = x;
|
|
3275
|
-
if (y > maxY)
|
|
3276
|
-
maxY = y;
|
|
3277
|
-
this.minX = minX;
|
|
3278
|
-
this.minY = minY;
|
|
3279
|
-
this.maxX = maxX;
|
|
3280
|
-
this.maxY = maxY;
|
|
3281
|
-
}
|
|
3282
|
-
addRect(rect, matrix) {
|
|
3283
|
-
this.addFrame(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, matrix);
|
|
3284
|
-
return this;
|
|
3285
|
-
}
|
|
3286
|
-
addBounds(bounds, matrix) {
|
|
3287
|
-
this.addFrame(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, matrix);
|
|
3288
|
-
return this;
|
|
3289
|
-
}
|
|
3290
|
-
addBoundsMask(mask) {
|
|
3291
|
-
this.minX = this.minX > mask.minX ? this.minX : mask.minX;
|
|
3292
|
-
this.minY = this.minY > mask.minY ? this.minY : mask.minY;
|
|
3293
|
-
this.maxX = this.maxX < mask.maxX ? this.maxX : mask.maxX;
|
|
3294
|
-
this.maxY = this.maxY < mask.maxY ? this.maxY : mask.maxY;
|
|
3295
|
-
}
|
|
3296
|
-
applyMatrix(matrix) {
|
|
3297
|
-
const minX = this.minX;
|
|
3298
|
-
const minY = this.minY;
|
|
3299
|
-
const maxX = this.maxX;
|
|
3300
|
-
const maxY = this.maxY;
|
|
3301
|
-
const { a, b, c, d, tx, ty } = matrix.toObject();
|
|
3302
|
-
let x = a * minX + c * minY + tx;
|
|
3303
|
-
let y = b * minX + d * minY + ty;
|
|
3304
|
-
this.minX = x;
|
|
3305
|
-
this.minY = y;
|
|
3306
|
-
this.maxX = x;
|
|
3307
|
-
this.maxY = y;
|
|
3308
|
-
x = a * maxX + c * minY + tx;
|
|
3309
|
-
y = b * maxX + d * minY + ty;
|
|
3310
|
-
this.minX = x < this.minX ? x : this.minX;
|
|
3311
|
-
this.minY = y < this.minY ? y : this.minY;
|
|
3312
|
-
this.maxX = x > this.maxX ? x : this.maxX;
|
|
3313
|
-
this.maxY = y > this.maxY ? y : this.maxY;
|
|
3314
|
-
x = a * minX + c * maxY + tx;
|
|
3315
|
-
y = b * minX + d * maxY + ty;
|
|
3316
|
-
this.minX = x < this.minX ? x : this.minX;
|
|
3317
|
-
this.minY = y < this.minY ? y : this.minY;
|
|
3318
|
-
this.maxX = x > this.maxX ? x : this.maxX;
|
|
3319
|
-
this.maxY = y > this.maxY ? y : this.maxY;
|
|
3320
|
-
x = a * maxX + c * maxY + tx;
|
|
3321
|
-
y = b * maxX + d * maxY + ty;
|
|
3322
|
-
this.minX = x < this.minX ? x : this.minX;
|
|
3323
|
-
this.minY = y < this.minY ? y : this.minY;
|
|
3324
|
-
this.maxX = x > this.maxX ? x : this.maxX;
|
|
3325
|
-
this.maxY = y > this.maxY ? y : this.maxY;
|
|
3326
|
-
}
|
|
3327
|
-
fit(rect) {
|
|
3328
|
-
if (this.minX < rect.left)
|
|
3329
|
-
this.minX = rect.left;
|
|
3330
|
-
if (this.maxX > rect.right)
|
|
3331
|
-
this.maxX = rect.right;
|
|
3332
|
-
if (this.minY < rect.top)
|
|
3333
|
-
this.minY = rect.top;
|
|
3334
|
-
if (this.maxY > rect.bottom)
|
|
3335
|
-
this.maxY = rect.bottom;
|
|
3336
|
-
return this;
|
|
3337
|
-
}
|
|
3338
|
-
fitBounds(left, right, top, bottom) {
|
|
3339
|
-
if (this.minX < left)
|
|
3340
|
-
this.minX = left;
|
|
3341
|
-
if (this.maxX > right)
|
|
3342
|
-
this.maxX = right;
|
|
3343
|
-
if (this.minY < top)
|
|
3344
|
-
this.minY = top;
|
|
3345
|
-
if (this.maxY > bottom)
|
|
3346
|
-
this.maxY = bottom;
|
|
3347
|
-
return this;
|
|
3348
|
-
}
|
|
3349
|
-
pad(paddingX, paddingY = paddingX) {
|
|
3350
|
-
this.minX -= paddingX;
|
|
3351
|
-
this.maxX += paddingX;
|
|
3352
|
-
this.minY -= paddingY;
|
|
3353
|
-
this.maxY += paddingY;
|
|
3354
|
-
return this;
|
|
3355
|
-
}
|
|
3356
|
-
ceil() {
|
|
3357
|
-
this.minX = Math.floor(this.minX);
|
|
3358
|
-
this.minY = Math.floor(this.minY);
|
|
3359
|
-
this.maxX = Math.ceil(this.maxX);
|
|
3360
|
-
this.maxY = Math.ceil(this.maxY);
|
|
3361
|
-
return this;
|
|
3362
|
-
}
|
|
3363
|
-
clone() {
|
|
3364
|
-
return new Bounds(this.minX, this.minY, this.maxX, this.maxY);
|
|
3365
|
-
}
|
|
3366
|
-
scale(x, y = x) {
|
|
3367
|
-
this.minX *= x;
|
|
3368
|
-
this.minY *= y;
|
|
3369
|
-
this.maxX *= x;
|
|
3370
|
-
this.maxY *= y;
|
|
3371
|
-
return this;
|
|
3372
|
-
}
|
|
3373
|
-
addVertexData(vertexData, beginOffset, endOffset, matrix) {
|
|
3374
|
-
let minX = this.minX;
|
|
3375
|
-
let minY = this.minY;
|
|
3376
|
-
let maxX = this.maxX;
|
|
3377
|
-
let maxY = this.maxY;
|
|
3378
|
-
matrix ||= this.matrix;
|
|
3379
|
-
const { a, b, c, d, tx, ty } = matrix.toObject();
|
|
3380
|
-
for (let i = beginOffset; i < endOffset; i += 2) {
|
|
3381
|
-
const localX = vertexData[i];
|
|
3382
|
-
const localY = vertexData[i + 1];
|
|
3383
|
-
const x = a * localX + c * localY + tx;
|
|
3384
|
-
const y = b * localX + d * localY + ty;
|
|
3385
|
-
minX = x < minX ? x : minX;
|
|
3386
|
-
minY = y < minY ? y : minY;
|
|
3387
|
-
maxX = x > maxX ? x : maxX;
|
|
3388
|
-
maxY = y > maxY ? y : maxY;
|
|
3389
|
-
}
|
|
3390
|
-
this.minX = minX;
|
|
3391
|
-
this.minY = minY;
|
|
3392
|
-
this.maxX = maxX;
|
|
3393
|
-
this.maxY = maxY;
|
|
3394
|
-
}
|
|
3395
|
-
containsPoint(x, y) {
|
|
3396
|
-
if (this.minX <= x && this.minY <= y && this.maxX >= x && this.maxY >= y) {
|
|
3397
|
-
return true;
|
|
3398
|
-
}
|
|
3399
|
-
return false;
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
const dSegmentRE = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
|
|
3404
|
-
const dNumberRE = /-?\d*\.?\d+(?:e[-+]?\d+)?/gi;
|
|
3405
|
-
const dLengthMap = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 };
|
|
3406
|
-
class SVGPath {
|
|
3407
|
-
defines = [];
|
|
3408
|
-
_calls = [];
|
|
3409
|
-
_dirty = false;
|
|
3410
|
-
get path2D() {
|
|
3411
|
-
const path2D = new Path2D();
|
|
3412
|
-
if (this._dirty) {
|
|
3413
|
-
this._dirty = false;
|
|
3414
|
-
this._calls.forEach((call) => {
|
|
3415
|
-
path2D[call.method](...call.args);
|
|
3416
|
-
});
|
|
3417
|
-
}
|
|
3418
|
-
return path2D;
|
|
3419
|
-
}
|
|
3420
|
-
constructor(d) {
|
|
3421
|
-
if (typeof d === "string") {
|
|
3422
|
-
this.defines = this._parseDefines(d);
|
|
3423
|
-
} else {
|
|
3424
|
-
this.defines = d.defines.slice();
|
|
3425
|
-
}
|
|
3426
|
-
this.update();
|
|
3427
|
-
}
|
|
3428
|
-
_addCall(method, args = [], dirty = true) {
|
|
3429
|
-
this._calls.push({ method, args });
|
|
3430
|
-
if (dirty) {
|
|
3431
|
-
this._dirty = true;
|
|
3432
|
-
}
|
|
3433
|
-
return this;
|
|
3434
|
-
}
|
|
3435
|
-
_parseDefines(d) {
|
|
3436
|
-
const defines = [];
|
|
3437
|
-
d.replace(dSegmentRE, (_, rawCommand, rawArgs) => {
|
|
3438
|
-
const args = rawArgs.match(dNumberRE)?.map(Number) ?? [];
|
|
3439
|
-
let command = rawCommand.toLowerCase();
|
|
3440
|
-
if (command === "m" && args.length > 2) {
|
|
3441
|
-
defines.push({ command: rawCommand, args: args.splice(0, 2) });
|
|
3442
|
-
command = "l";
|
|
3443
|
-
rawCommand = rawCommand === "m" ? "l" : "L";
|
|
3444
|
-
}
|
|
3445
|
-
while (true) {
|
|
3446
|
-
if (args.length === dLengthMap[command]) {
|
|
3447
|
-
defines.push({ command: rawCommand, args });
|
|
3448
|
-
return "";
|
|
3449
|
-
}
|
|
3450
|
-
if (args.length < dLengthMap[command])
|
|
3451
|
-
throw new Error("malformed path defines");
|
|
3452
|
-
defines.push({ command: rawCommand, args: args.splice(0, dLengthMap[command]) });
|
|
3453
|
-
}
|
|
3454
|
-
});
|
|
3455
|
-
return defines;
|
|
3456
|
-
}
|
|
3457
|
-
update() {
|
|
3458
|
-
const subpaths = [];
|
|
3459
|
-
let currentSubPath = null;
|
|
3460
|
-
let lastX = 0;
|
|
3461
|
-
let lastY = 0;
|
|
3462
|
-
for (let i = 0; i < this.defines.length; i++) {
|
|
3463
|
-
const { command, args } = this.defines[i];
|
|
3464
|
-
switch (command) {
|
|
3465
|
-
case "M":
|
|
3466
|
-
this._addCall("moveTo", [lastX = args[0], lastY = args[1]]);
|
|
3467
|
-
break;
|
|
3468
|
-
case "m":
|
|
3469
|
-
this._addCall("moveTo", [lastX += args[0], lastY += args[1]]);
|
|
3470
|
-
break;
|
|
3471
|
-
case "H":
|
|
3472
|
-
this._addCall("lineTo", [lastX = args[0], lastY]);
|
|
3473
|
-
break;
|
|
3474
|
-
case "h":
|
|
3475
|
-
this._addCall("lineTo", [lastX += args[0], lastY]);
|
|
3476
|
-
break;
|
|
3477
|
-
case "V":
|
|
3478
|
-
this._addCall("lineTo", [lastX, lastY = args[0]]);
|
|
3479
|
-
break;
|
|
3480
|
-
case "v":
|
|
3481
|
-
this._addCall("lineTo", [lastX, lastY += args[0]]);
|
|
3482
|
-
break;
|
|
3483
|
-
case "L":
|
|
3484
|
-
this._addCall("lineTo", [lastX = args[0], lastY = args[1]]);
|
|
3485
|
-
break;
|
|
3486
|
-
case "l":
|
|
3487
|
-
this._addCall("lineTo", [lastX += args[0], lastY += args[1]]);
|
|
3488
|
-
break;
|
|
3489
|
-
case "C":
|
|
3490
|
-
this._addCall("bezierCurveTo", [args[0], args[1], args[2], args[3], args[4], args[5]]);
|
|
3491
|
-
lastX = args[4];
|
|
3492
|
-
lastY = args[5];
|
|
3493
|
-
break;
|
|
3494
|
-
case "c":
|
|
3495
|
-
this._addCall("bezierCurveTo", [
|
|
3496
|
-
lastX + args[0],
|
|
3497
|
-
lastY + args[1],
|
|
3498
|
-
lastX + args[2],
|
|
3499
|
-
lastY + args[3],
|
|
3500
|
-
lastX + args[4],
|
|
3501
|
-
lastY + args[5]
|
|
3502
|
-
]);
|
|
3503
|
-
lastX += args[4];
|
|
3504
|
-
lastY += args[5];
|
|
3505
|
-
break;
|
|
3506
|
-
case "Q":
|
|
3507
|
-
this._addCall("quadraticCurveTo", [args[0], args[1], args[2], args[3]]);
|
|
3508
|
-
lastX = args[2];
|
|
3509
|
-
lastY = args[3];
|
|
3510
|
-
break;
|
|
3511
|
-
case "q":
|
|
3512
|
-
this._addCall("quadraticCurveTo", [
|
|
3513
|
-
lastX + args[0],
|
|
3514
|
-
lastY + args[1],
|
|
3515
|
-
lastX + args[2],
|
|
3516
|
-
lastY + args[3]
|
|
3517
|
-
]);
|
|
3518
|
-
lastX += args[2];
|
|
3519
|
-
lastY += args[3];
|
|
3520
|
-
break;
|
|
3521
|
-
case "S":
|
|
3522
|
-
this._smoothBezierCurveTo(args[0], args[1], args[2], args[3]);
|
|
3523
|
-
lastX = args[2];
|
|
3524
|
-
lastY = args[3];
|
|
3525
|
-
break;
|
|
3526
|
-
case "s":
|
|
3527
|
-
this._smoothBezierCurveTo(
|
|
3528
|
-
lastX + args[0],
|
|
3529
|
-
lastY + args[1],
|
|
3530
|
-
lastX + args[2],
|
|
3531
|
-
lastY + args[3]
|
|
3532
|
-
);
|
|
3533
|
-
lastX += args[2];
|
|
3534
|
-
lastY += args[3];
|
|
3535
|
-
break;
|
|
3536
|
-
case "T":
|
|
3537
|
-
this._smoothQuadraticCurveTo(lastX = args[0], lastY = args[1]);
|
|
3538
|
-
break;
|
|
3539
|
-
case "t":
|
|
3540
|
-
this._smoothQuadraticCurveTo(lastX += args[0], lastY += args[1]);
|
|
3541
|
-
break;
|
|
3542
|
-
case "A":
|
|
3543
|
-
this._addCall("ellipticalArc", [args[0], args[1], args[2], args[3], args[4], args[5], args[6]]);
|
|
3544
|
-
lastX = args[5];
|
|
3545
|
-
lastY = args[6];
|
|
3546
|
-
break;
|
|
3547
|
-
case "a":
|
|
3548
|
-
this._addCall("ellipticalArc", [args[0], args[1], args[2], args[3], args[4], args[5], args[6]]);
|
|
3549
|
-
lastX += args[5];
|
|
3550
|
-
lastY += args[6];
|
|
3551
|
-
break;
|
|
3552
|
-
case "Z":
|
|
3553
|
-
case "z":
|
|
3554
|
-
this._addCall("closePath");
|
|
3555
|
-
if (subpaths.length > 0) {
|
|
3556
|
-
currentSubPath = subpaths.pop();
|
|
3557
|
-
if (currentSubPath) {
|
|
3558
|
-
lastX = currentSubPath.startX;
|
|
3559
|
-
lastY = currentSubPath.startY;
|
|
3560
|
-
} else {
|
|
3561
|
-
lastX = 0;
|
|
3562
|
-
lastY = 0;
|
|
3563
|
-
}
|
|
3564
|
-
}
|
|
3565
|
-
currentSubPath = null;
|
|
3566
|
-
break;
|
|
3567
|
-
default:
|
|
3568
|
-
console.warn(`Unknown SVG path command: ${command}`);
|
|
3569
|
-
}
|
|
3570
|
-
if (command !== "Z" && command !== "z") {
|
|
3571
|
-
if (currentSubPath === null) {
|
|
3572
|
-
currentSubPath = { startX: lastX, startY: lastY };
|
|
3573
|
-
subpaths.push(currentSubPath);
|
|
3574
|
-
}
|
|
3575
|
-
}
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
_getLastPoint(out) {
|
|
3579
|
-
let index = this._calls.length - 1;
|
|
3580
|
-
let call = this._calls[index];
|
|
3581
|
-
if (!call) {
|
|
3582
|
-
out.x = 0;
|
|
3583
|
-
out.y = 0;
|
|
3584
|
-
return out;
|
|
3585
|
-
}
|
|
3586
|
-
while (call.method === "closePath") {
|
|
3587
|
-
index--;
|
|
3588
|
-
if (index < 0) {
|
|
3589
|
-
out.x = 0;
|
|
3590
|
-
out.y = 0;
|
|
3591
|
-
return out;
|
|
3592
|
-
}
|
|
3593
|
-
call = this._calls[index];
|
|
3594
|
-
}
|
|
3595
|
-
switch (call.method) {
|
|
3596
|
-
case "moveTo":
|
|
3597
|
-
case "lineTo":
|
|
3598
|
-
out.set(call.args[0], call.args[1]);
|
|
3599
|
-
break;
|
|
3600
|
-
case "quadraticCurveTo":
|
|
3601
|
-
out.set(call.args[2], call.args[3]);
|
|
3602
|
-
break;
|
|
3603
|
-
case "bezierCurveTo":
|
|
3604
|
-
out.set(call.args[4], call.args[5]);
|
|
3605
|
-
break;
|
|
3606
|
-
case "arc":
|
|
3607
|
-
case "ellipticalArc":
|
|
3608
|
-
out.set(call.args[5], call.args[6]);
|
|
3609
|
-
break;
|
|
3610
|
-
case "addPath":
|
|
3611
|
-
call.args[0]._getLastPoint(out);
|
|
3612
|
-
break;
|
|
3613
|
-
}
|
|
3614
|
-
return out;
|
|
3615
|
-
}
|
|
3616
|
-
_smoothBezierCurveTo(cp2x, cp2y, x, y, smoothness) {
|
|
3617
|
-
const last = this._calls[this._calls.length - 1];
|
|
3618
|
-
const lastPoint = this._getLastPoint(Point.shared);
|
|
3619
|
-
let cp1x;
|
|
3620
|
-
let cp1y;
|
|
3621
|
-
if (!last || last.method !== "bezierCurveTo") {
|
|
3622
|
-
cp1x = lastPoint.x;
|
|
3623
|
-
cp1y = lastPoint.y;
|
|
3624
|
-
} else {
|
|
3625
|
-
cp1x = last.args[2];
|
|
3626
|
-
cp1y = last.args[3];
|
|
3627
|
-
const currentX = lastPoint.x;
|
|
3628
|
-
const currentY = lastPoint.y;
|
|
3629
|
-
cp1x = currentX + (currentX - cp1x);
|
|
3630
|
-
cp1y = currentY + (currentY - cp1y);
|
|
3631
|
-
}
|
|
3632
|
-
this._addCall("bezierCurveTo", [cp1x, cp1y, cp2x, cp2y, x, y, smoothness]);
|
|
3633
|
-
return this;
|
|
3634
|
-
}
|
|
3635
|
-
_smoothQuadraticCurveTo(x, y, smoothness) {
|
|
3636
|
-
const last = this._calls[this._calls.length - 1];
|
|
3637
|
-
const lastPoint = this._getLastPoint(Point.shared);
|
|
3638
|
-
let cpx1;
|
|
3639
|
-
let cpy1;
|
|
3640
|
-
if (!last || last.method !== "quadraticCurveTo") {
|
|
3641
|
-
cpx1 = lastPoint.x;
|
|
3642
|
-
cpy1 = lastPoint.y;
|
|
3643
|
-
} else {
|
|
3644
|
-
cpx1 = last.args[0];
|
|
3645
|
-
cpy1 = last.args[1];
|
|
3646
|
-
const currentX = lastPoint.x;
|
|
3647
|
-
const currentY = lastPoint.y;
|
|
3648
|
-
cpx1 = currentX + (currentX - cpx1);
|
|
3649
|
-
cpy1 = currentY + (currentY - cpy1);
|
|
3650
|
-
}
|
|
3651
|
-
this._addCall("quadraticCurveTo", [cpx1, cpy1, x, y, smoothness]);
|
|
3652
|
-
return this;
|
|
3653
|
-
}
|
|
3654
|
-
}
|
|
3655
|
-
|
|
3656
|
-
const tempRectangle = new Rectangle();
|
|
3657
|
-
class Path2D {
|
|
3658
|
-
_polygon;
|
|
3659
|
-
_bounds = new Bounds();
|
|
3660
|
-
shapes = [];
|
|
3661
|
-
get bounds() {
|
|
3662
|
-
const bounds = this._bounds;
|
|
3663
|
-
bounds.clear();
|
|
3664
|
-
const shapes = this.shapes;
|
|
3665
|
-
for (let i = 0; i < shapes.length; i++) {
|
|
3666
|
-
const shape = shapes[i];
|
|
3667
|
-
const boundsRect = shape.shape.getBounds(tempRectangle);
|
|
3668
|
-
if (shape.transform) {
|
|
3669
|
-
bounds.addRect(boundsRect, shape.transform);
|
|
3670
|
-
} else {
|
|
3671
|
-
bounds.addRect(boundsRect);
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
return bounds;
|
|
3675
|
-
}
|
|
3676
|
-
startPolygon(x, y) {
|
|
3677
|
-
if (this._polygon) {
|
|
3678
|
-
this.endPolygon();
|
|
3679
|
-
}
|
|
3680
|
-
this._polygon = new Polygon([x, y]);
|
|
3681
|
-
return this;
|
|
3682
|
-
}
|
|
3683
|
-
endPolygon(closePath = false) {
|
|
3684
|
-
const polygon = this._polygon;
|
|
3685
|
-
if (polygon && polygon.points.length > 2) {
|
|
3686
|
-
polygon.closed = closePath;
|
|
3687
|
-
this.shapes.push({
|
|
3688
|
-
shape: polygon
|
|
3689
|
-
});
|
|
3690
|
-
}
|
|
3691
|
-
this._polygon = void 0;
|
|
3692
|
-
return this;
|
|
3693
|
-
}
|
|
3694
|
-
ensurePolygon(start = true) {
|
|
3695
|
-
if (this._polygon)
|
|
3696
|
-
return;
|
|
3697
|
-
this._polygon = new Polygon();
|
|
3698
|
-
if (start) {
|
|
3699
|
-
const lastShape = this.shapes[this.shapes.length - 1];
|
|
3700
|
-
if (lastShape) {
|
|
3701
|
-
let lx = lastShape.shape.x;
|
|
3702
|
-
let ly = lastShape.shape.y;
|
|
3703
|
-
if (!lastShape.transform?.isIdentity()) {
|
|
3704
|
-
const t = lastShape.transform.toObject();
|
|
3705
|
-
const tempX = lx;
|
|
3706
|
-
lx = t.a * lx + t.c * ly + t.tx;
|
|
3707
|
-
ly = t.b * tempX + t.d * ly + t.ty;
|
|
3708
|
-
}
|
|
3709
|
-
this._polygon.points.push(lx, ly);
|
|
3710
|
-
} else {
|
|
3711
|
-
this._polygon.points.push(0, 0);
|
|
3712
|
-
}
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
beginPath() {
|
|
3716
|
-
return this;
|
|
3717
|
-
}
|
|
3718
|
-
moveTo(x, y) {
|
|
3719
|
-
this.startPolygon(x, y);
|
|
3720
|
-
return this;
|
|
3721
|
-
}
|
|
3722
|
-
lineTo(x, y) {
|
|
3723
|
-
this.ensurePolygon();
|
|
3724
|
-
const points = this._polygon.points;
|
|
3725
|
-
const fromX = points[points.length - 2];
|
|
3726
|
-
const fromY = points[points.length - 1];
|
|
3727
|
-
if (fromX !== x || fromY !== y) {
|
|
3728
|
-
points.push(x, y);
|
|
3729
|
-
}
|
|
3730
|
-
return this;
|
|
3731
|
-
}
|
|
3732
|
-
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y, smoothness) {
|
|
3733
|
-
this.ensurePolygon();
|
|
3734
|
-
buildAdaptiveBezier(
|
|
3735
|
-
this._polygon.points,
|
|
3736
|
-
this._polygon.lastX,
|
|
3737
|
-
this._polygon.lastY,
|
|
3738
|
-
cp1x,
|
|
3739
|
-
cp1y,
|
|
3740
|
-
cp2x,
|
|
3741
|
-
cp2y,
|
|
3742
|
-
x,
|
|
3743
|
-
y,
|
|
3744
|
-
smoothness
|
|
3745
|
-
);
|
|
3746
|
-
return this;
|
|
3747
|
-
}
|
|
3748
|
-
quadraticCurveTo(cp1x, cp1y, x, y, smoothing) {
|
|
3749
|
-
this.ensurePolygon();
|
|
3750
|
-
buildAdaptiveQuadratic(
|
|
3751
|
-
this._polygon.points,
|
|
3752
|
-
this._polygon.lastX,
|
|
3753
|
-
this._polygon.lastY,
|
|
3754
|
-
cp1x,
|
|
3755
|
-
cp1y,
|
|
3756
|
-
x,
|
|
3757
|
-
y,
|
|
3758
|
-
smoothing
|
|
3759
|
-
);
|
|
3760
|
-
return this;
|
|
3761
|
-
}
|
|
3762
|
-
rect(x, y, width, height, transform) {
|
|
3763
|
-
this.addShape(new Rectangle(x, y, width, height), transform);
|
|
3764
|
-
}
|
|
3765
|
-
roundRect(x, y, width, height, radii, transform) {
|
|
3766
|
-
this.addShape(new RoundedRectangle(x, y, width, height, radii), transform);
|
|
1560
|
+
translateZ(z) {
|
|
1561
|
+
return this.translate(this._translateX, this._translateY, z);
|
|
3767
1562
|
}
|
|
3768
|
-
|
|
3769
|
-
this.
|
|
1563
|
+
translate3d(x, y, z) {
|
|
1564
|
+
return this.translate(x, y, z);
|
|
3770
1565
|
}
|
|
3771
|
-
|
|
3772
|
-
this.
|
|
3773
|
-
|
|
3774
|
-
|
|
1566
|
+
scale(x, y, _z = 1) {
|
|
1567
|
+
this._scaleX = x;
|
|
1568
|
+
this._scaleY = y;
|
|
1569
|
+
this._requestUpdateArray();
|
|
3775
1570
|
return this;
|
|
3776
1571
|
}
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
this._polygon.points,
|
|
3780
|
-
this._polygon.lastX,
|
|
3781
|
-
this._polygon.lastY,
|
|
3782
|
-
x,
|
|
3783
|
-
y,
|
|
3784
|
-
rx,
|
|
3785
|
-
ry,
|
|
3786
|
-
xAxisRotation,
|
|
3787
|
-
largeArcFlag,
|
|
3788
|
-
sweepFlag
|
|
3789
|
-
);
|
|
3790
|
-
return this;
|
|
1572
|
+
scaleX(x) {
|
|
1573
|
+
return this.scale(x, this._scaleY);
|
|
3791
1574
|
}
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
polygon.closed = close;
|
|
3795
|
-
this.addShape(polygon, transform);
|
|
3796
|
-
return this;
|
|
1575
|
+
scaleY(y) {
|
|
1576
|
+
return this.scale(this._scaleX, y);
|
|
3797
1577
|
}
|
|
3798
|
-
|
|
3799
|
-
this.
|
|
3800
|
-
this.shapes.push({ shape, transform });
|
|
3801
|
-
return this;
|
|
1578
|
+
scale3d(x, y, z) {
|
|
1579
|
+
return this.scale(x, y, z);
|
|
3802
1580
|
}
|
|
3803
|
-
|
|
3804
|
-
this.
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
this.shapes.push(shape);
|
|
3808
|
-
});
|
|
1581
|
+
rotate(rad) {
|
|
1582
|
+
this._rotate = rad;
|
|
1583
|
+
this._updateSkew();
|
|
1584
|
+
this._requestUpdateArray();
|
|
3809
1585
|
return this;
|
|
3810
1586
|
}
|
|
3811
|
-
|
|
3812
|
-
this.
|
|
3813
|
-
return this;
|
|
1587
|
+
rotateX(x) {
|
|
1588
|
+
return this.scaleY(this._rotateToScale(x));
|
|
3814
1589
|
}
|
|
3815
|
-
|
|
3816
|
-
this.
|
|
3817
|
-
return this;
|
|
1590
|
+
rotateY(y) {
|
|
1591
|
+
return this.scaleX(this._rotateToScale(y));
|
|
3818
1592
|
}
|
|
3819
|
-
|
|
3820
|
-
this.
|
|
3821
|
-
return points;
|
|
1593
|
+
rotateZ(z) {
|
|
1594
|
+
return this.rotate(z);
|
|
3822
1595
|
}
|
|
3823
|
-
|
|
3824
|
-
this.
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
1596
|
+
rotate3d(x, y, z, rad) {
|
|
1597
|
+
const [rx, ry, rz] = this._rotate3d(x, y, z, rad);
|
|
1598
|
+
rx && this.rotateX(rx);
|
|
1599
|
+
ry && this.rotateY(ry);
|
|
1600
|
+
rz && this.rotateZ(rz);
|
|
1601
|
+
return this;
|
|
3829
1602
|
}
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
constructor(array) {
|
|
3834
|
-
super(2, 2, array);
|
|
1603
|
+
_rotateToScale(rad) {
|
|
1604
|
+
const val = rad / PI_2;
|
|
1605
|
+
return val <= 0.5 ? val * -4 + 1 : (val - 1) * 4 + 1;
|
|
3835
1606
|
}
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
1607
|
+
_rotate3d(x, y, z, rad) {
|
|
1608
|
+
if (x === 1 && y === 0 && z === 0) {
|
|
1609
|
+
return [rad, 0, 0];
|
|
1610
|
+
} else if (x === 0 && y === 1 && z === 0) {
|
|
1611
|
+
return [0, rad, 0];
|
|
1612
|
+
} else if (x === 0 && y === 0) {
|
|
1613
|
+
return [0, 0, rad];
|
|
1614
|
+
} else {
|
|
1615
|
+
const cos = Math.cos(rad);
|
|
1616
|
+
const sin = Math.sin(rad);
|
|
1617
|
+
const m11 = cos + x * x * (1 - cos);
|
|
1618
|
+
const m12 = x * y * (1 - cos) - z * sin;
|
|
1619
|
+
const m13 = x * z * (1 - cos) + y * sin;
|
|
1620
|
+
const m22 = cos + y * y * (1 - cos);
|
|
1621
|
+
const m23 = y * z * (1 - cos) - x * sin;
|
|
1622
|
+
const m33 = cos + z * z * (1 - cos);
|
|
1623
|
+
const rotateX = -Math.atan2(-m23, m22);
|
|
1624
|
+
const rotateY = -Math.atan2(m13, Math.sqrt(m23 * m23 + m33 * m33));
|
|
1625
|
+
const rotateZ = -Math.atan2(-m12, m11);
|
|
1626
|
+
return [rotateX, rotateY, rotateZ];
|
|
1627
|
+
}
|
|
3841
1628
|
}
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
this._y = _y;
|
|
3849
|
-
this._width = _width;
|
|
3850
|
-
this._height = _height;
|
|
3851
|
-
this._flipY = _flipY;
|
|
3852
|
-
this._performUpdateArray();
|
|
1629
|
+
applyToPoint(x, y) {
|
|
1630
|
+
const { a, c, tx, b, d, ty } = this.toObject();
|
|
1631
|
+
return [
|
|
1632
|
+
a * x + c * y + tx,
|
|
1633
|
+
b * x + d * y + ty
|
|
1634
|
+
];
|
|
3853
1635
|
}
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
this._flipY = flipY;
|
|
3857
|
-
this._performUpdateArray();
|
|
3858
|
-
}
|
|
3859
|
-
return this;
|
|
1636
|
+
inverse() {
|
|
1637
|
+
return this.clone().invert();
|
|
3860
1638
|
}
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
this.
|
|
1639
|
+
update() {
|
|
1640
|
+
let updated = false;
|
|
1641
|
+
if (this._needsUpdateArray) {
|
|
1642
|
+
this._needsUpdateArray = false;
|
|
3865
1643
|
this._performUpdateArray();
|
|
1644
|
+
updated = true;
|
|
3866
1645
|
}
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
this._width = width;
|
|
3872
|
-
this._height = height;
|
|
3873
|
-
this._performUpdateArray();
|
|
1646
|
+
if (this._needsUpdateFields) {
|
|
1647
|
+
this._needsUpdateFields = false;
|
|
1648
|
+
this._performUpdateFields();
|
|
1649
|
+
updated = true;
|
|
3874
1650
|
}
|
|
3875
|
-
return
|
|
1651
|
+
return updated;
|
|
3876
1652
|
}
|
|
3877
|
-
|
|
3878
|
-
const
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
const y = this._y;
|
|
3885
|
-
const sign = !this._flipY ? 1 : -1;
|
|
3886
|
-
const a = 1 / width * 2;
|
|
3887
|
-
const d = sign * (1 / height * 2);
|
|
3888
|
-
const tx = -1 - x * a;
|
|
3889
|
-
const ty = -sign - y * d;
|
|
3890
|
-
this.set([
|
|
3891
|
-
a,
|
|
3892
|
-
0,
|
|
3893
|
-
tx,
|
|
3894
|
-
0,
|
|
3895
|
-
d,
|
|
3896
|
-
ty,
|
|
3897
|
-
0,
|
|
3898
|
-
0,
|
|
3899
|
-
1
|
|
3900
|
-
]);
|
|
1653
|
+
isIdentity() {
|
|
1654
|
+
const { a, b, c, d, tx, ty } = this.toObject();
|
|
1655
|
+
return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
|
|
1656
|
+
}
|
|
1657
|
+
toObject() {
|
|
1658
|
+
const [a, c, tx, b, d, ty, , , tz] = this._array;
|
|
1659
|
+
return { a, c, tx, b, d, ty, tz };
|
|
3901
1660
|
}
|
|
3902
1661
|
}
|
|
3903
1662
|
|
|
@@ -4006,14 +1765,14 @@ class Vector4 extends Vector {
|
|
|
4006
1765
|
}
|
|
4007
1766
|
}
|
|
4008
1767
|
|
|
4009
|
-
var __defProp$
|
|
1768
|
+
var __defProp$w = Object.defineProperty;
|
|
4010
1769
|
var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
|
|
4011
|
-
var __decorateClass$
|
|
1770
|
+
var __decorateClass$w = (decorators, target, key, kind) => {
|
|
4012
1771
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
|
|
4013
1772
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
4014
1773
|
if (decorator = decorators[i])
|
|
4015
1774
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
4016
|
-
if (kind && result) __defProp$
|
|
1775
|
+
if (kind && result) __defProp$w(target, key, result);
|
|
4017
1776
|
return result;
|
|
4018
1777
|
};
|
|
4019
1778
|
var InternalMode = /* @__PURE__ */ ((InternalMode2) => {
|
|
@@ -4411,22 +2170,22 @@ exports.Node = class Node extends Reference {
|
|
|
4411
2170
|
return node;
|
|
4412
2171
|
}
|
|
4413
2172
|
};
|
|
4414
|
-
__decorateClass$
|
|
2173
|
+
__decorateClass$w([
|
|
4415
2174
|
property()
|
|
4416
2175
|
], exports.Node.prototype, "name", 2);
|
|
4417
|
-
__decorateClass$
|
|
2176
|
+
__decorateClass$w([
|
|
4418
2177
|
property()
|
|
4419
2178
|
], exports.Node.prototype, "mask", 2);
|
|
4420
|
-
__decorateClass$
|
|
2179
|
+
__decorateClass$w([
|
|
4421
2180
|
property({ default: "visible" })
|
|
4422
2181
|
], exports.Node.prototype, "visibility", 2);
|
|
4423
|
-
__decorateClass$
|
|
2182
|
+
__decorateClass$w([
|
|
4424
2183
|
property({ default: 0 })
|
|
4425
2184
|
], exports.Node.prototype, "visibleDelay", 2);
|
|
4426
|
-
__decorateClass$
|
|
2185
|
+
__decorateClass$w([
|
|
4427
2186
|
property({ default: Number.MAX_SAFE_INTEGER })
|
|
4428
2187
|
], exports.Node.prototype, "visibleDuration", 2);
|
|
4429
|
-
exports.Node = __decorateClass$
|
|
2188
|
+
exports.Node = __decorateClass$w([
|
|
4430
2189
|
customNode("Node")
|
|
4431
2190
|
], exports.Node);
|
|
4432
2191
|
|
|
@@ -4456,14 +2215,14 @@ class RenderStack {
|
|
|
4456
2215
|
}
|
|
4457
2216
|
}
|
|
4458
2217
|
|
|
4459
|
-
var __defProp$
|
|
2218
|
+
var __defProp$v = Object.defineProperty;
|
|
4460
2219
|
var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
|
|
4461
|
-
var __decorateClass$
|
|
2220
|
+
var __decorateClass$v = (decorators, target, key, kind) => {
|
|
4462
2221
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
|
|
4463
2222
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
4464
2223
|
if (decorator = decorators[i])
|
|
4465
2224
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
4466
|
-
if (kind && result) __defProp$
|
|
2225
|
+
if (kind && result) __defProp$v(target, key, result);
|
|
4467
2226
|
return result;
|
|
4468
2227
|
};
|
|
4469
2228
|
exports.Timer = class Timer extends exports.Node {
|
|
@@ -4505,29 +2264,29 @@ exports.Timer = class Timer extends exports.Node {
|
|
|
4505
2264
|
this.addTime(delta);
|
|
4506
2265
|
}
|
|
4507
2266
|
};
|
|
4508
|
-
__decorateClass$
|
|
2267
|
+
__decorateClass$v([
|
|
4509
2268
|
property({ default: 0 })
|
|
4510
2269
|
], exports.Timer.prototype, "start", 2);
|
|
4511
|
-
__decorateClass$
|
|
2270
|
+
__decorateClass$v([
|
|
4512
2271
|
property({ default: 0 })
|
|
4513
2272
|
], exports.Timer.prototype, "current", 2);
|
|
4514
|
-
__decorateClass$
|
|
2273
|
+
__decorateClass$v([
|
|
4515
2274
|
property({ default: Number.MAX_SAFE_INTEGER })
|
|
4516
2275
|
], exports.Timer.prototype, "end", 2);
|
|
4517
|
-
__decorateClass$
|
|
2276
|
+
__decorateClass$v([
|
|
4518
2277
|
property({ default: false })
|
|
4519
2278
|
], exports.Timer.prototype, "loop", 2);
|
|
4520
|
-
exports.Timer = __decorateClass$
|
|
2279
|
+
exports.Timer = __decorateClass$v([
|
|
4521
2280
|
customNode("Timer")
|
|
4522
2281
|
], exports.Timer);
|
|
4523
2282
|
|
|
4524
|
-
var __defProp$
|
|
4525
|
-
var __decorateClass$
|
|
2283
|
+
var __defProp$u = Object.defineProperty;
|
|
2284
|
+
var __decorateClass$u = (decorators, target, key, kind) => {
|
|
4526
2285
|
var result = void 0 ;
|
|
4527
2286
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
4528
2287
|
if (decorator = decorators[i])
|
|
4529
2288
|
result = (decorator(target, key, result) ) || result;
|
|
4530
|
-
if (result) __defProp$
|
|
2289
|
+
if (result) __defProp$u(target, key, result);
|
|
4531
2290
|
return result;
|
|
4532
2291
|
};
|
|
4533
2292
|
class Texture extends Resource {
|
|
@@ -4653,22 +2412,22 @@ class Texture extends Resource {
|
|
|
4653
2412
|
}
|
|
4654
2413
|
}
|
|
4655
2414
|
}
|
|
4656
|
-
__decorateClass$
|
|
2415
|
+
__decorateClass$u([
|
|
4657
2416
|
protectedProperty()
|
|
4658
2417
|
], Texture.prototype, "source");
|
|
4659
|
-
__decorateClass$
|
|
2418
|
+
__decorateClass$u([
|
|
4660
2419
|
protectedProperty({ default: 0 })
|
|
4661
2420
|
], Texture.prototype, "width");
|
|
4662
|
-
__decorateClass$
|
|
2421
|
+
__decorateClass$u([
|
|
4663
2422
|
protectedProperty({ default: 0 })
|
|
4664
2423
|
], Texture.prototype, "height");
|
|
4665
|
-
__decorateClass$
|
|
2424
|
+
__decorateClass$u([
|
|
4666
2425
|
protectedProperty({ default: "linear" })
|
|
4667
2426
|
], Texture.prototype, "filterMode");
|
|
4668
|
-
__decorateClass$
|
|
2427
|
+
__decorateClass$u([
|
|
4669
2428
|
protectedProperty({ default: "clamp_to_edge" })
|
|
4670
2429
|
], Texture.prototype, "wrapMode");
|
|
4671
|
-
__decorateClass$
|
|
2430
|
+
__decorateClass$u([
|
|
4672
2431
|
protectedProperty({ default: 1 })
|
|
4673
2432
|
], Texture.prototype, "pixelRatio");
|
|
4674
2433
|
|
|
@@ -4804,13 +2563,13 @@ class PixelsTexture extends Texture {
|
|
|
4804
2563
|
}
|
|
4805
2564
|
}
|
|
4806
2565
|
|
|
4807
|
-
var __defProp$
|
|
4808
|
-
var __decorateClass$
|
|
2566
|
+
var __defProp$t = Object.defineProperty;
|
|
2567
|
+
var __decorateClass$t = (decorators, target, key, kind) => {
|
|
4809
2568
|
var result = void 0 ;
|
|
4810
2569
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
4811
2570
|
if (decorator = decorators[i])
|
|
4812
2571
|
result = (decorator(target, key, result) ) || result;
|
|
4813
|
-
if (result) __defProp$
|
|
2572
|
+
if (result) __defProp$t(target, key, result);
|
|
4814
2573
|
return result;
|
|
4815
2574
|
};
|
|
4816
2575
|
function resolveOptions(options) {
|
|
@@ -5053,10 +2812,10 @@ const _VideoTexture = class _VideoTexture extends Texture {
|
|
|
5053
2812
|
}
|
|
5054
2813
|
}
|
|
5055
2814
|
};
|
|
5056
|
-
__decorateClass$
|
|
2815
|
+
__decorateClass$t([
|
|
5057
2816
|
protectedProperty({ default: true })
|
|
5058
2817
|
], _VideoTexture.prototype, "autoUpdate");
|
|
5059
|
-
__decorateClass$
|
|
2818
|
+
__decorateClass$t([
|
|
5060
2819
|
protectedProperty({ default: 0 })
|
|
5061
2820
|
], _VideoTexture.prototype, "fps");
|
|
5062
2821
|
let VideoTexture = _VideoTexture;
|
|
@@ -5065,14 +2824,14 @@ class ViewportTexture extends PixelsTexture {
|
|
|
5065
2824
|
//
|
|
5066
2825
|
}
|
|
5067
2826
|
|
|
5068
|
-
var __defProp$
|
|
2827
|
+
var __defProp$s = Object.defineProperty;
|
|
5069
2828
|
var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
|
|
5070
|
-
var __decorateClass$
|
|
2829
|
+
var __decorateClass$s = (decorators, target, key, kind) => {
|
|
5071
2830
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
|
|
5072
2831
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
5073
2832
|
if (decorator = decorators[i])
|
|
5074
2833
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
5075
|
-
if (kind && result) __defProp$
|
|
2834
|
+
if (kind && result) __defProp$s(target, key, result);
|
|
5076
2835
|
return result;
|
|
5077
2836
|
};
|
|
5078
2837
|
exports.Viewport = class Viewport extends exports.Node {
|
|
@@ -5193,19 +2952,19 @@ exports.Viewport = class Viewport extends exports.Node {
|
|
|
5193
2952
|
return this._projection.toArray(transpose);
|
|
5194
2953
|
}
|
|
5195
2954
|
};
|
|
5196
|
-
__decorateClass$
|
|
2955
|
+
__decorateClass$s([
|
|
5197
2956
|
property({ default: 0 })
|
|
5198
2957
|
], exports.Viewport.prototype, "x", 2);
|
|
5199
|
-
__decorateClass$
|
|
2958
|
+
__decorateClass$s([
|
|
5200
2959
|
property({ default: 0 })
|
|
5201
2960
|
], exports.Viewport.prototype, "y", 2);
|
|
5202
|
-
__decorateClass$
|
|
2961
|
+
__decorateClass$s([
|
|
5203
2962
|
property({ default: 0 })
|
|
5204
2963
|
], exports.Viewport.prototype, "width", 2);
|
|
5205
|
-
__decorateClass$
|
|
2964
|
+
__decorateClass$s([
|
|
5206
2965
|
property({ default: 0 })
|
|
5207
2966
|
], exports.Viewport.prototype, "height", 2);
|
|
5208
|
-
exports.Viewport = __decorateClass$
|
|
2967
|
+
exports.Viewport = __decorateClass$s([
|
|
5209
2968
|
customNode({
|
|
5210
2969
|
tag: "Viewport",
|
|
5211
2970
|
renderable: true
|
|
@@ -5624,30 +3383,7 @@ class ColorTexture extends Texture {
|
|
|
5624
3383
|
}
|
|
5625
3384
|
}
|
|
5626
3385
|
|
|
5627
|
-
|
|
5628
|
-
var __decorateClass$s = (decorators, target, key, kind) => {
|
|
5629
|
-
var result = void 0 ;
|
|
5630
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
5631
|
-
if (decorator = decorators[i])
|
|
5632
|
-
result = (decorator(target, key, result) ) || result;
|
|
5633
|
-
if (result) __defProp$s(target, key, result);
|
|
5634
|
-
return result;
|
|
5635
|
-
};
|
|
5636
|
-
function proxy$1() {
|
|
5637
|
-
return function(target, method) {
|
|
5638
|
-
Object.defineProperty(target.constructor.prototype, method, {
|
|
5639
|
-
get() {
|
|
5640
|
-
return (...args) => {
|
|
5641
|
-
this._path2D[method](...args);
|
|
5642
|
-
return this;
|
|
5643
|
-
};
|
|
5644
|
-
},
|
|
5645
|
-
configurable: true,
|
|
5646
|
-
enumerable: true
|
|
5647
|
-
});
|
|
5648
|
-
};
|
|
5649
|
-
}
|
|
5650
|
-
class CanvasContext {
|
|
3386
|
+
class CanvasContext extends modernPath2d.Path2D {
|
|
5651
3387
|
textureTransform;
|
|
5652
3388
|
fillStyle;
|
|
5653
3389
|
strokeStyle;
|
|
@@ -5655,7 +3391,6 @@ class CanvasContext {
|
|
|
5655
3391
|
lineJoin;
|
|
5656
3392
|
lineWidth;
|
|
5657
3393
|
miterLimit;
|
|
5658
|
-
_path2D = new Path2D();
|
|
5659
3394
|
_defaultStyle = Texture.EMPTY;
|
|
5660
3395
|
_stroked = [];
|
|
5661
3396
|
_filled = [];
|
|
@@ -5668,10 +3403,9 @@ class CanvasContext {
|
|
|
5668
3403
|
texture = new ColorTexture(this.strokeStyle);
|
|
5669
3404
|
}
|
|
5670
3405
|
}
|
|
5671
|
-
this.
|
|
5672
|
-
if (this._path2D.shapes.length) {
|
|
3406
|
+
if (this.curves.length) {
|
|
5673
3407
|
this._stroked.push({
|
|
5674
|
-
shapes: this.
|
|
3408
|
+
shapes: this.curves.slice(),
|
|
5675
3409
|
texture,
|
|
5676
3410
|
textureTransform: this.textureTransform,
|
|
5677
3411
|
style: {
|
|
@@ -5682,7 +3416,7 @@ class CanvasContext {
|
|
|
5682
3416
|
miterLimit: this.miterLimit ?? 10
|
|
5683
3417
|
}
|
|
5684
3418
|
});
|
|
5685
|
-
this.
|
|
3419
|
+
this.curves.length = 0;
|
|
5686
3420
|
}
|
|
5687
3421
|
}
|
|
5688
3422
|
fillRect(x, y, width, height) {
|
|
@@ -5701,11 +3435,11 @@ class CanvasContext {
|
|
|
5701
3435
|
}
|
|
5702
3436
|
}
|
|
5703
3437
|
this._filled.push({
|
|
5704
|
-
shapes: this.
|
|
3438
|
+
shapes: this.curves.slice(),
|
|
5705
3439
|
texture,
|
|
5706
3440
|
textureTransform: this.textureTransform
|
|
5707
3441
|
});
|
|
5708
|
-
this.
|
|
3442
|
+
this.curves.length = 0;
|
|
5709
3443
|
}
|
|
5710
3444
|
reset() {
|
|
5711
3445
|
this.strokeStyle = void 0;
|
|
@@ -5715,8 +3449,7 @@ class CanvasContext {
|
|
|
5715
3449
|
this.lineJoin = void 0;
|
|
5716
3450
|
this.lineWidth = void 0;
|
|
5717
3451
|
this.miterLimit = void 0;
|
|
5718
|
-
this.
|
|
5719
|
-
this._path2D.shapes.length = 0;
|
|
3452
|
+
this.curves.length = 0;
|
|
5720
3453
|
this._stroked.length = 0;
|
|
5721
3454
|
this._filled.length = 0;
|
|
5722
3455
|
}
|
|
@@ -5757,14 +3490,20 @@ class CanvasContext {
|
|
|
5757
3490
|
texture = void 0;
|
|
5758
3491
|
};
|
|
5759
3492
|
for (let len = this._stroked.length, i = 0; i < len; i++) {
|
|
3493
|
+
startUv = vertices.length;
|
|
5760
3494
|
const graphics = this._stroked[i];
|
|
5761
3495
|
texture ??= graphics.texture;
|
|
5762
3496
|
const points = [];
|
|
5763
3497
|
for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
|
|
5764
|
-
graphics.shapes[i2].
|
|
3498
|
+
graphics.shapes[i2].getAdaptivePointArray(points);
|
|
5765
3499
|
}
|
|
5766
|
-
|
|
5767
|
-
|
|
3500
|
+
modernPath2d.strokeTriangulate(points, {
|
|
3501
|
+
vertices,
|
|
3502
|
+
indices,
|
|
3503
|
+
lineStyle: graphics.style,
|
|
3504
|
+
flipAlignment: false,
|
|
3505
|
+
closed: true
|
|
3506
|
+
});
|
|
5768
3507
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
5769
3508
|
push("stroke");
|
|
5770
3509
|
}
|
|
@@ -5776,7 +3515,10 @@ class CanvasContext {
|
|
|
5776
3515
|
}
|
|
5777
3516
|
startUv = vertices.length;
|
|
5778
3517
|
for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
|
|
5779
|
-
graphics.shapes[i2].
|
|
3518
|
+
graphics.shapes[i2].fillTriangulate({
|
|
3519
|
+
vertices,
|
|
3520
|
+
indices
|
|
3521
|
+
});
|
|
5780
3522
|
}
|
|
5781
3523
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
5782
3524
|
}
|
|
@@ -5786,48 +3528,6 @@ class CanvasContext {
|
|
|
5786
3528
|
return batchables;
|
|
5787
3529
|
}
|
|
5788
3530
|
}
|
|
5789
|
-
__decorateClass$s([
|
|
5790
|
-
proxy$1()
|
|
5791
|
-
], CanvasContext.prototype, "moveTo");
|
|
5792
|
-
__decorateClass$s([
|
|
5793
|
-
proxy$1()
|
|
5794
|
-
], CanvasContext.prototype, "lineTo");
|
|
5795
|
-
__decorateClass$s([
|
|
5796
|
-
proxy$1()
|
|
5797
|
-
], CanvasContext.prototype, "bezierCurveTo");
|
|
5798
|
-
__decorateClass$s([
|
|
5799
|
-
proxy$1()
|
|
5800
|
-
], CanvasContext.prototype, "quadraticCurveTo");
|
|
5801
|
-
__decorateClass$s([
|
|
5802
|
-
proxy$1()
|
|
5803
|
-
], CanvasContext.prototype, "ellipticalArc");
|
|
5804
|
-
__decorateClass$s([
|
|
5805
|
-
proxy$1()
|
|
5806
|
-
], CanvasContext.prototype, "rect");
|
|
5807
|
-
__decorateClass$s([
|
|
5808
|
-
proxy$1()
|
|
5809
|
-
], CanvasContext.prototype, "roundRect");
|
|
5810
|
-
__decorateClass$s([
|
|
5811
|
-
proxy$1()
|
|
5812
|
-
], CanvasContext.prototype, "ellipse");
|
|
5813
|
-
__decorateClass$s([
|
|
5814
|
-
proxy$1()
|
|
5815
|
-
], CanvasContext.prototype, "arc");
|
|
5816
|
-
__decorateClass$s([
|
|
5817
|
-
proxy$1()
|
|
5818
|
-
], CanvasContext.prototype, "poly");
|
|
5819
|
-
__decorateClass$s([
|
|
5820
|
-
proxy$1()
|
|
5821
|
-
], CanvasContext.prototype, "addShape");
|
|
5822
|
-
__decorateClass$s([
|
|
5823
|
-
proxy$1()
|
|
5824
|
-
], CanvasContext.prototype, "addPath");
|
|
5825
|
-
__decorateClass$s([
|
|
5826
|
-
proxy$1()
|
|
5827
|
-
], CanvasContext.prototype, "addSvgPath");
|
|
5828
|
-
__decorateClass$s([
|
|
5829
|
-
proxy$1()
|
|
5830
|
-
], CanvasContext.prototype, "closePath");
|
|
5831
3531
|
|
|
5832
3532
|
class Loader {
|
|
5833
3533
|
}
|
|
@@ -7030,7 +4730,7 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
|
|
|
7030
4730
|
width = newWidth;
|
|
7031
4731
|
height = newHeight;
|
|
7032
4732
|
}
|
|
7033
|
-
return new
|
|
4733
|
+
return new modernPath2d.BoundingBox(left, top, width, height);
|
|
7034
4734
|
}
|
|
7035
4735
|
_onUpdateStyleProperty(key, value, oldValue) {
|
|
7036
4736
|
super._onUpdateStyleProperty(key, value, oldValue);
|
|
@@ -7534,6 +5234,7 @@ exports.Text2D = class Text2D extends exports.Node2D {
|
|
|
7534
5234
|
switch (key) {
|
|
7535
5235
|
case "content":
|
|
7536
5236
|
case "effects":
|
|
5237
|
+
case "measureDom":
|
|
7537
5238
|
case "fonts":
|
|
7538
5239
|
case "split":
|
|
7539
5240
|
this._updateSplit();
|
|
@@ -13838,16 +11539,13 @@ exports.Assets = Assets;
|
|
|
13838
11539
|
exports.AudioPipeline = AudioPipeline;
|
|
13839
11540
|
exports.AudioProcessor = AudioProcessor;
|
|
13840
11541
|
exports.AudioSpectrum = AudioSpectrum;
|
|
13841
|
-
exports.Bounds = Bounds;
|
|
13842
11542
|
exports.CanvasContext = CanvasContext;
|
|
13843
|
-
exports.Circle = Circle;
|
|
13844
11543
|
exports.Color = Color;
|
|
13845
11544
|
exports.ColorMatrix = ColorMatrix;
|
|
13846
11545
|
exports.ColorTexture = ColorTexture;
|
|
13847
11546
|
exports.DEG_TO_RAD = DEG_TO_RAD;
|
|
13848
11547
|
exports.DEVICE_PIXEL_RATIO = DEVICE_PIXEL_RATIO;
|
|
13849
11548
|
exports.EffectMaterial = EffectMaterial;
|
|
13850
|
-
exports.Ellipse = Ellipse;
|
|
13851
11549
|
exports.Engine = Engine;
|
|
13852
11550
|
exports.EventEmitter = EventEmitter;
|
|
13853
11551
|
exports.FontLoader = FontLoader;
|
|
@@ -13874,21 +11572,16 @@ exports.Matrix4 = Matrix4;
|
|
|
13874
11572
|
exports.MouseInputEvent = MouseInputEvent;
|
|
13875
11573
|
exports.PI = PI;
|
|
13876
11574
|
exports.PI_2 = PI_2;
|
|
13877
|
-
exports.Path2D = Path2D;
|
|
13878
11575
|
exports.PixelsTexture = PixelsTexture;
|
|
13879
|
-
exports.Point = Point;
|
|
13880
11576
|
exports.PointerInputEvent = PointerInputEvent;
|
|
13881
|
-
exports.Polygon = Polygon;
|
|
13882
11577
|
exports.Projection2D = Projection2D;
|
|
13883
11578
|
exports.QuadGeometry = QuadGeometry;
|
|
13884
11579
|
exports.QuadUvGeometry = QuadUvGeometry;
|
|
13885
11580
|
exports.RAD_TO_DEG = RAD_TO_DEG;
|
|
13886
|
-
exports.Rectangle = Rectangle;
|
|
13887
11581
|
exports.Reference = Reference;
|
|
13888
11582
|
exports.RenderStack = RenderStack;
|
|
13889
11583
|
exports.Renderer = Renderer;
|
|
13890
11584
|
exports.Resource = Resource;
|
|
13891
|
-
exports.RoundedRectangle = RoundedRectangle;
|
|
13892
11585
|
exports.SUPPORTS_AUDIO_CONTEXT = SUPPORTS_AUDIO_CONTEXT;
|
|
13893
11586
|
exports.SUPPORTS_CLICK_EVENTS = SUPPORTS_CLICK_EVENTS;
|
|
13894
11587
|
exports.SUPPORTS_CREATE_IMAGE_BITMAP = SUPPORTS_CREATE_IMAGE_BITMAP;
|
|
@@ -13903,9 +11596,7 @@ exports.SUPPORTS_WEBKIT_AUDIO_CONTEXT = SUPPORTS_WEBKIT_AUDIO_CONTEXT;
|
|
|
13903
11596
|
exports.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT = SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT;
|
|
13904
11597
|
exports.SUPPORTS_WEB_AUDIO = SUPPORTS_WEB_AUDIO;
|
|
13905
11598
|
exports.SUPPORTS_WHEEL_EVENTS = SUPPORTS_WHEEL_EVENTS;
|
|
13906
|
-
exports.SVGPath = SVGPath;
|
|
13907
11599
|
exports.SceneTree = SceneTree;
|
|
13908
|
-
exports.Star = Star;
|
|
13909
11600
|
exports.Style2D = Style2D;
|
|
13910
11601
|
exports.Style2DBackgroundModule = Style2DBackgroundModule;
|
|
13911
11602
|
exports.Style2DFilterModule = Style2DFilterModule;
|
|
@@ -13917,7 +11608,6 @@ exports.Texture = Texture;
|
|
|
13917
11608
|
exports.TextureLoader = TextureLoader;
|
|
13918
11609
|
exports.Ticker = Ticker;
|
|
13919
11610
|
exports.Transform2D = Transform2D;
|
|
13920
|
-
exports.Triangle = Triangle;
|
|
13921
11611
|
exports.UIInputEvent = UIInputEvent;
|
|
13922
11612
|
exports.UvGeometry = UvGeometry;
|
|
13923
11613
|
exports.UvMaterial = UvMaterial;
|
|
@@ -13951,23 +11641,11 @@ exports.WebSound = WebSound;
|
|
|
13951
11641
|
exports.WheelInputEvent = WheelInputEvent;
|
|
13952
11642
|
exports._Object = _Object;
|
|
13953
11643
|
exports.assets = assets;
|
|
13954
|
-
exports.buildAdaptiveBezier = buildAdaptiveBezier;
|
|
13955
|
-
exports.buildAdaptiveQuadratic = buildAdaptiveQuadratic;
|
|
13956
|
-
exports.buildArc = buildArc;
|
|
13957
|
-
exports.buildArcTo = buildArcTo;
|
|
13958
|
-
exports.buildArcToSvg = buildArcToSvg;
|
|
13959
|
-
exports.buildCircle = buildCircle;
|
|
13960
|
-
exports.buildLine = buildLine;
|
|
13961
|
-
exports.buildPolygon = buildPolygon;
|
|
13962
|
-
exports.buildRectangle = buildRectangle;
|
|
13963
|
-
exports.buildTriangle = buildTriangle;
|
|
13964
11644
|
exports.clamp = clamp;
|
|
13965
|
-
exports.closePointEps = closePointEps;
|
|
13966
11645
|
exports.createHTMLCanvas = createHTMLCanvas;
|
|
13967
11646
|
exports.createNode = createNode;
|
|
13968
11647
|
exports.crossOrigin = crossOrigin;
|
|
13969
11648
|
exports.cubicBezier = cubicBezier;
|
|
13970
|
-
exports.curveEps = curveEps;
|
|
13971
11649
|
exports.curves = curves;
|
|
13972
11650
|
exports.customNode = customNode;
|
|
13973
11651
|
exports.customNodes = customNodes;
|
|
@@ -13997,6 +11675,5 @@ exports.parseCssProperty = parseCssProperty;
|
|
|
13997
11675
|
exports.property = property;
|
|
13998
11676
|
exports.protectedProperty = protectedProperty;
|
|
13999
11677
|
exports.render = render;
|
|
14000
|
-
exports.squaredDistanceToLineSegment = squaredDistanceToLineSegment;
|
|
14001
11678
|
exports.timingFunctions = timingFunctions;
|
|
14002
11679
|
exports.uid = uid;
|