@vesium/geometry 1.0.1-beta.74 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,8 +21,6 @@
21
21
  <a href="https://github.com/vesiumjs/vesium/blob/main/README.md" target="__blank">English</a>
22
22
  </p>
23
23
 
24
- > 🚧 This project is under active development, and the API may change frequently. Any version may introduce breaking changes.
25
-
26
24
  ## Documentation
27
25
 
28
26
  To view the documentation, visit <a href="https://vesium.js.org" target="__blank">vesium.js.org</a>
package/dist/index.cjs CHANGED
@@ -1,5 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
2
  //#region src/helper.ts
4
3
  const FITTING_COUNT = 100;
5
4
  const HALF_PI = Math.PI / 2;
@@ -176,7 +175,7 @@ function getBisectorNormals(t, coord1, coord2, coord3) {
176
175
  const uY = normal[1] / dist;
177
176
  const d1 = mathDistance(coord1, coord2);
178
177
  const d2 = mathDistance(coord2, coord3);
179
- if (dist > ZERO_TOLERANCE) if (isClockWise(coord1, coord2, coord3)) {
178
+ if (dist > 1e-4) if (isClockWise(coord1, coord2, coord3)) {
180
179
  dt = t * d1;
181
180
  x = coord2[0] - dt * uY;
182
181
  y = coord2[1] + dt * uX;
@@ -239,7 +238,7 @@ function getLeftMostControlCoord(controlCoords, t) {
239
238
  ];
240
239
  const normalRight = getBisectorNormals(0, coord1, coord2, coord3)[0];
241
240
  const normal = getNormal(coord1, coord2, coord3);
242
- if (Math.hypot(normal[0], normal[1]) > ZERO_TOLERANCE) {
241
+ if (Math.hypot(normal[0], normal[1]) > 1e-4) {
243
242
  const midCoord = mid(coord1, coord2);
244
243
  const pX = coord1[0] - midCoord[0];
245
244
  const pY = coord1[1] - midCoord[1];
@@ -273,7 +272,7 @@ function getRightMostControlCoord(controlCoords, t) {
273
272
  const normal = getNormal(coord1, coord2, coord3);
274
273
  const dist = Math.hypot(normal[0], normal[1]);
275
274
  let [controlX, controlY] = [0, 0];
276
- if (dist > ZERO_TOLERANCE) {
275
+ if (dist > 1e-4) {
277
276
  const midCoord = mid(coord2, coord3);
278
277
  const pX = coord3[0] - midCoord[0];
279
278
  const pY = coord3[1] - midCoord[1];
@@ -317,8 +316,8 @@ function getCurveCoords(t, controlCoords) {
317
316
  coord1 = controlCoords[i];
318
317
  coord2 = controlCoords[i + 1];
319
318
  coords.push(coord1);
320
- for (let j = 0; j < FITTING_COUNT; j++) {
321
- const coord = getCubicValue(j / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
319
+ for (let j = 0; j < 100; j++) {
320
+ const coord = getCubicValue(j / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
322
321
  coords.push(coord);
323
322
  }
324
323
  coords.push(coord2);
@@ -416,7 +415,6 @@ function getQuadricBSplineFactor(k, t) {
416
415
  else if (k === 2) res = t ** 2 / 2;
417
416
  return res;
418
417
  }
419
-
420
418
  //#endregion
421
419
  //#region src/arc.ts
422
420
  /**
@@ -446,7 +444,6 @@ function arc(coords) {
446
444
  return getArcCoords(center, radius, startAngle, endAngle);
447
445
  }
448
446
  }
449
-
450
447
  //#endregion
451
448
  //#region src/arrowAttackDirection.ts
452
449
  /**
@@ -608,7 +605,6 @@ function getTempCoord4(lineCoord1, lineCoord2, coord) {
608
605
  }
609
606
  return symCoord;
610
607
  }
611
-
612
608
  //#endregion
613
609
  //#region src/arrowAttackDirectionTailed.ts
614
610
  /**
@@ -648,7 +644,6 @@ function arrowAttackDirectionTailed(coords, options = {}) {
648
644
  return leftCoords.concat(headCoords, rightCoords.reverse(), [swallowTailCoord, leftCoords[0]]);
649
645
  } else return [];
650
646
  }
651
-
652
647
  //#endregion
653
648
  //#region src/arrowClamped.ts
654
649
  /**
@@ -808,7 +803,6 @@ function getTempCoord4$1(lineCoord1, lineCoord2, coord) {
808
803
  return getThirdCoord(midCoord, getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true), HALF_PI, distance2, false);
809
804
  }
810
805
  }
811
-
812
806
  //#endregion
813
807
  //#region src/arrowStraightSharp.ts
814
808
  /**
@@ -837,7 +831,6 @@ function arrowStraightSharp(coords, options = {}) {
837
831
  tailRight
838
832
  ];
839
833
  }
840
-
841
834
  //#endregion
842
835
  //#region src/arrowStraight.ts
843
836
  /**
@@ -852,7 +845,6 @@ function arrowStraight(coords) {
852
845
  neckAngle: Math.PI * .17741
853
846
  });
854
847
  }
855
-
856
848
  //#endregion
857
849
  //#region src/arrowStraightFine.ts
858
850
  /**
@@ -873,7 +865,6 @@ function arrowStraightFine(coords) {
873
865
  getThirdCoord(coord1, coord2, Math.PI / 6, len, true)
874
866
  ];
875
867
  }
876
-
877
868
  //#endregion
878
869
  //#region src/arrowUnitCombatOperation.ts
879
870
  /**
@@ -909,7 +900,6 @@ function arrowUnitCombatOperation(coords, options = {}) {
909
900
  } else return [];
910
901
  }
911
902
  }
912
-
913
903
  //#endregion
914
904
  //#region src/arrowUnitCombatOperationTailed.ts
915
905
  /**
@@ -950,7 +940,6 @@ function arrowUnitCombatOperationTailed(coords, options = {}) {
950
940
  }
951
941
  return [];
952
942
  }
953
-
954
943
  //#endregion
955
944
  //#region src/assemblingPlace.ts
956
945
  /**
@@ -977,15 +966,14 @@ function assemblingPlace(coords) {
977
966
  const coord1 = coords[i];
978
967
  const coord2 = coords[i + 1];
979
968
  pList.push(coord1);
980
- for (let t = 0; t <= FITTING_COUNT; t++) {
981
- const coord = getCubicValue(t / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
969
+ for (let t = 0; t <= 100; t++) {
970
+ const coord = getCubicValue(t / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
982
971
  pList.push(coord);
983
972
  }
984
973
  pList.push(coord2);
985
974
  }
986
975
  return pList;
987
976
  }
988
-
989
977
  //#endregion
990
978
  //#region src/circle.ts
991
979
  /**
@@ -1009,7 +997,6 @@ function circle(coords) {
1009
997
  }
1010
998
  return _coords;
1011
999
  }
1012
-
1013
1000
  //#endregion
1014
1001
  //#region src/closedCurve.ts
1015
1002
  /**
@@ -1033,8 +1020,8 @@ function closedCurve(coords) {
1033
1020
  const coord1 = coords[i];
1034
1021
  const coord2 = coords[i + 1];
1035
1022
  pList.push(coord1);
1036
- for (let t = 0; t <= FITTING_COUNT; t++) {
1037
- const coord = getCubicValue(t / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
1023
+ for (let t = 0; t <= 100; t++) {
1024
+ const coord = getCubicValue(t / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
1038
1025
  pList.push(coord);
1039
1026
  }
1040
1027
  pList.push(coord2);
@@ -1042,7 +1029,6 @@ function closedCurve(coords) {
1042
1029
  return pList;
1043
1030
  }
1044
1031
  }
1045
-
1046
1032
  //#endregion
1047
1033
  //#region src/curve.ts
1048
1034
  /**
@@ -1053,7 +1039,6 @@ function curve(coords) {
1053
1039
  if (coords.length < 3) throw new Error("coords.length must >= 2");
1054
1040
  else return getCurveCoords(t, coords);
1055
1041
  }
1056
-
1057
1042
  //#endregion
1058
1043
  //#region src/ellipse.ts
1059
1044
  /**
@@ -1071,15 +1056,14 @@ function ellipse(coords) {
1071
1056
  0
1072
1057
  ];
1073
1058
  const _coords = [];
1074
- for (let i = 0; i <= FITTING_COUNT; i++) {
1075
- angle = Math.PI * 2 * i / FITTING_COUNT;
1059
+ for (let i = 0; i <= 100; i++) {
1060
+ angle = Math.PI * 2 * i / 100;
1076
1061
  x = center[0] + majorRadius * Math.cos(angle);
1077
1062
  y = center[1] + minorRadius * Math.sin(angle);
1078
1063
  coords.push([x, y]);
1079
1064
  }
1080
1065
  return _coords;
1081
1066
  }
1082
-
1083
1067
  //#endregion
1084
1068
  //#region src/lune.ts
1085
1069
  /**
@@ -1117,7 +1101,6 @@ function lune(coords) {
1117
1101
  coords.push(coords[0]);
1118
1102
  return coords;
1119
1103
  }
1120
-
1121
1104
  //#endregion
1122
1105
  //#region src/rectAngle.ts
1123
1106
  /**
@@ -1135,7 +1118,6 @@ function rectAngle(coords) {
1135
1118
  startCoord
1136
1119
  ];
1137
1120
  }
1138
-
1139
1121
  //#endregion
1140
1122
  //#region src/rectinclined1.ts
1141
1123
  /**
@@ -1222,7 +1204,77 @@ function calculatePerpendicularCoord(p1, p2, d) {
1222
1204
  }
1223
1205
  return [x, y];
1224
1206
  }
1225
-
1207
+ //#endregion
1208
+ //#region src/rectinclined2.ts
1209
+ /**
1210
+ * 斜矩形2
1211
+ *
1212
+ */
1213
+ function rectinclined2(coords) {
1214
+ if (coords.length < 3) throw new Error("coords.length must >= 3");
1215
+ else {
1216
+ const [coord1, coord2, mouse] = [
1217
+ coords[0],
1218
+ coords[1],
1219
+ coords[2]
1220
+ ];
1221
+ const intersect = calculateIntersectionCoord(coord1, coord2, mouse);
1222
+ const coord4 = calculateFourthCoord$1(coord1, intersect, mouse);
1223
+ const pList = [];
1224
+ pList.push(coord1, intersect, mouse, coord4, coord1);
1225
+ return pList;
1226
+ }
1227
+ }
1228
+ /**
1229
+ * 已知p1,p2,p3点求矩形的p4点
1230
+ * @param {*} p1
1231
+ * @param {*} p2
1232
+ * @param {*} p3
1233
+ */
1234
+ function calculateFourthCoord$1(p1, p2, p3) {
1235
+ return [p1[0] + p3[0] - p2[0], p1[1] + p3[1] - p2[1]];
1236
+ }
1237
+ /**
1238
+ * 已知p1点和p2点,求p3点到p1p2垂线的交点
1239
+ * @param {*} p1
1240
+ * @param {*} p2
1241
+ * @param {*} p3
1242
+ */
1243
+ function calculateIntersectionCoord(p1, p2, p3) {
1244
+ const v = {
1245
+ x: p2[0] - p1[0],
1246
+ y: p2[1] - p1[1]
1247
+ };
1248
+ const u = {
1249
+ x: p3[0] - p1[0],
1250
+ y: p3[1] - p1[1]
1251
+ };
1252
+ const projectionLength = (u.x * v.x + u.y * v.y) / (v.x * v.x + v.y * v.y);
1253
+ const intersectionCoord = {
1254
+ x: p1[0] + v.x * projectionLength,
1255
+ y: p1[1] + v.y * projectionLength
1256
+ };
1257
+ return [intersectionCoord.x, intersectionCoord.y];
1258
+ }
1259
+ //#endregion
1260
+ //#region src/sector.ts
1261
+ /**
1262
+ * 扇形
1263
+ *
1264
+ */
1265
+ function sector(coords) {
1266
+ if (coords.length < 3) throw new Error("coords.length must >= 2");
1267
+ else {
1268
+ const [center, coord2, coord3] = [
1269
+ coords[0],
1270
+ coords[1],
1271
+ coords[2]
1272
+ ];
1273
+ const pList = getArcCoords(center, mathDistance(coord2, center), getAzimuth(coord2, center), getAzimuth(coord3, center));
1274
+ pList.push(center, pList[0]);
1275
+ return pList;
1276
+ }
1277
+ }
1226
1278
  //#endregion
1227
1279
  exports.FITTING_COUNT = FITTING_COUNT;
1228
1280
  exports.HALF_PI = HALF_PI;
@@ -1239,6 +1291,7 @@ exports.arrowUnitCombatOperation = arrowUnitCombatOperation;
1239
1291
  exports.arrowUnitCombatOperationTailed = arrowUnitCombatOperationTailed;
1240
1292
  exports.assemblingPlace = assemblingPlace;
1241
1293
  exports.calculateFourthCoord = calculateFourthCoord;
1294
+ exports.calculateIntersectionCoord = calculateIntersectionCoord;
1242
1295
  exports.calculatePerpendicularCoord = calculatePerpendicularCoord;
1243
1296
  exports.calculatePerpendicularDistance = calculatePerpendicularDistance;
1244
1297
  exports.calculatePositionRelativeToLine = calculatePositionRelativeToLine;
@@ -1275,5 +1328,8 @@ exports.mathDistance = mathDistance;
1275
1328
  exports.mid = mid;
1276
1329
  exports.rectAngle = rectAngle;
1277
1330
  exports.rectinclined1 = rectinclined1;
1331
+ exports.rectinclined2 = rectinclined2;
1332
+ exports.sector = sector;
1278
1333
  exports.wholeDistance = wholeDistance;
1334
+
1279
1335
  //# sourceMappingURL=index.cjs.map