@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/dist/index.mjs CHANGED
@@ -174,7 +174,7 @@ function getBisectorNormals(t, coord1, coord2, coord3) {
174
174
  const uY = normal[1] / dist;
175
175
  const d1 = mathDistance(coord1, coord2);
176
176
  const d2 = mathDistance(coord2, coord3);
177
- if (dist > ZERO_TOLERANCE) if (isClockWise(coord1, coord2, coord3)) {
177
+ if (dist > 1e-4) if (isClockWise(coord1, coord2, coord3)) {
178
178
  dt = t * d1;
179
179
  x = coord2[0] - dt * uY;
180
180
  y = coord2[1] + dt * uX;
@@ -237,7 +237,7 @@ function getLeftMostControlCoord(controlCoords, t) {
237
237
  ];
238
238
  const normalRight = getBisectorNormals(0, coord1, coord2, coord3)[0];
239
239
  const normal = getNormal(coord1, coord2, coord3);
240
- if (Math.hypot(normal[0], normal[1]) > ZERO_TOLERANCE) {
240
+ if (Math.hypot(normal[0], normal[1]) > 1e-4) {
241
241
  const midCoord = mid(coord1, coord2);
242
242
  const pX = coord1[0] - midCoord[0];
243
243
  const pY = coord1[1] - midCoord[1];
@@ -271,7 +271,7 @@ function getRightMostControlCoord(controlCoords, t) {
271
271
  const normal = getNormal(coord1, coord2, coord3);
272
272
  const dist = Math.hypot(normal[0], normal[1]);
273
273
  let [controlX, controlY] = [0, 0];
274
- if (dist > ZERO_TOLERANCE) {
274
+ if (dist > 1e-4) {
275
275
  const midCoord = mid(coord2, coord3);
276
276
  const pX = coord3[0] - midCoord[0];
277
277
  const pY = coord3[1] - midCoord[1];
@@ -315,8 +315,8 @@ function getCurveCoords(t, controlCoords) {
315
315
  coord1 = controlCoords[i];
316
316
  coord2 = controlCoords[i + 1];
317
317
  coords.push(coord1);
318
- for (let j = 0; j < FITTING_COUNT; j++) {
319
- const coord = getCubicValue(j / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
318
+ for (let j = 0; j < 100; j++) {
319
+ const coord = getCubicValue(j / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
320
320
  coords.push(coord);
321
321
  }
322
322
  coords.push(coord2);
@@ -414,7 +414,6 @@ function getQuadricBSplineFactor(k, t) {
414
414
  else if (k === 2) res = t ** 2 / 2;
415
415
  return res;
416
416
  }
417
-
418
417
  //#endregion
419
418
  //#region src/arc.ts
420
419
  /**
@@ -444,7 +443,6 @@ function arc(coords) {
444
443
  return getArcCoords(center, radius, startAngle, endAngle);
445
444
  }
446
445
  }
447
-
448
446
  //#endregion
449
447
  //#region src/arrowAttackDirection.ts
450
448
  /**
@@ -606,7 +604,6 @@ function getTempCoord4(lineCoord1, lineCoord2, coord) {
606
604
  }
607
605
  return symCoord;
608
606
  }
609
-
610
607
  //#endregion
611
608
  //#region src/arrowAttackDirectionTailed.ts
612
609
  /**
@@ -646,7 +643,6 @@ function arrowAttackDirectionTailed(coords, options = {}) {
646
643
  return leftCoords.concat(headCoords, rightCoords.reverse(), [swallowTailCoord, leftCoords[0]]);
647
644
  } else return [];
648
645
  }
649
-
650
646
  //#endregion
651
647
  //#region src/arrowClamped.ts
652
648
  /**
@@ -806,7 +802,6 @@ function getTempCoord4$1(lineCoord1, lineCoord2, coord) {
806
802
  return getThirdCoord(midCoord, getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true), HALF_PI, distance2, false);
807
803
  }
808
804
  }
809
-
810
805
  //#endregion
811
806
  //#region src/arrowStraightSharp.ts
812
807
  /**
@@ -835,7 +830,6 @@ function arrowStraightSharp(coords, options = {}) {
835
830
  tailRight
836
831
  ];
837
832
  }
838
-
839
833
  //#endregion
840
834
  //#region src/arrowStraight.ts
841
835
  /**
@@ -850,7 +844,6 @@ function arrowStraight(coords) {
850
844
  neckAngle: Math.PI * .17741
851
845
  });
852
846
  }
853
-
854
847
  //#endregion
855
848
  //#region src/arrowStraightFine.ts
856
849
  /**
@@ -871,7 +864,6 @@ function arrowStraightFine(coords) {
871
864
  getThirdCoord(coord1, coord2, Math.PI / 6, len, true)
872
865
  ];
873
866
  }
874
-
875
867
  //#endregion
876
868
  //#region src/arrowUnitCombatOperation.ts
877
869
  /**
@@ -907,7 +899,6 @@ function arrowUnitCombatOperation(coords, options = {}) {
907
899
  } else return [];
908
900
  }
909
901
  }
910
-
911
902
  //#endregion
912
903
  //#region src/arrowUnitCombatOperationTailed.ts
913
904
  /**
@@ -948,7 +939,6 @@ function arrowUnitCombatOperationTailed(coords, options = {}) {
948
939
  }
949
940
  return [];
950
941
  }
951
-
952
942
  //#endregion
953
943
  //#region src/assemblingPlace.ts
954
944
  /**
@@ -975,15 +965,14 @@ function assemblingPlace(coords) {
975
965
  const coord1 = coords[i];
976
966
  const coord2 = coords[i + 1];
977
967
  pList.push(coord1);
978
- for (let t = 0; t <= FITTING_COUNT; t++) {
979
- const coord = getCubicValue(t / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
968
+ for (let t = 0; t <= 100; t++) {
969
+ const coord = getCubicValue(t / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
980
970
  pList.push(coord);
981
971
  }
982
972
  pList.push(coord2);
983
973
  }
984
974
  return pList;
985
975
  }
986
-
987
976
  //#endregion
988
977
  //#region src/circle.ts
989
978
  /**
@@ -1007,7 +996,6 @@ function circle(coords) {
1007
996
  }
1008
997
  return _coords;
1009
998
  }
1010
-
1011
999
  //#endregion
1012
1000
  //#region src/closedCurve.ts
1013
1001
  /**
@@ -1031,8 +1019,8 @@ function closedCurve(coords) {
1031
1019
  const coord1 = coords[i];
1032
1020
  const coord2 = coords[i + 1];
1033
1021
  pList.push(coord1);
1034
- for (let t = 0; t <= FITTING_COUNT; t++) {
1035
- const coord = getCubicValue(t / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
1022
+ for (let t = 0; t <= 100; t++) {
1023
+ const coord = getCubicValue(t / 100, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
1036
1024
  pList.push(coord);
1037
1025
  }
1038
1026
  pList.push(coord2);
@@ -1040,7 +1028,6 @@ function closedCurve(coords) {
1040
1028
  return pList;
1041
1029
  }
1042
1030
  }
1043
-
1044
1031
  //#endregion
1045
1032
  //#region src/curve.ts
1046
1033
  /**
@@ -1051,7 +1038,6 @@ function curve(coords) {
1051
1038
  if (coords.length < 3) throw new Error("coords.length must >= 2");
1052
1039
  else return getCurveCoords(t, coords);
1053
1040
  }
1054
-
1055
1041
  //#endregion
1056
1042
  //#region src/ellipse.ts
1057
1043
  /**
@@ -1069,15 +1055,14 @@ function ellipse(coords) {
1069
1055
  0
1070
1056
  ];
1071
1057
  const _coords = [];
1072
- for (let i = 0; i <= FITTING_COUNT; i++) {
1073
- angle = Math.PI * 2 * i / FITTING_COUNT;
1058
+ for (let i = 0; i <= 100; i++) {
1059
+ angle = Math.PI * 2 * i / 100;
1074
1060
  x = center[0] + majorRadius * Math.cos(angle);
1075
1061
  y = center[1] + minorRadius * Math.sin(angle);
1076
1062
  coords.push([x, y]);
1077
1063
  }
1078
1064
  return _coords;
1079
1065
  }
1080
-
1081
1066
  //#endregion
1082
1067
  //#region src/lune.ts
1083
1068
  /**
@@ -1115,7 +1100,6 @@ function lune(coords) {
1115
1100
  coords.push(coords[0]);
1116
1101
  return coords;
1117
1102
  }
1118
-
1119
1103
  //#endregion
1120
1104
  //#region src/rectAngle.ts
1121
1105
  /**
@@ -1133,7 +1117,6 @@ function rectAngle(coords) {
1133
1117
  startCoord
1134
1118
  ];
1135
1119
  }
1136
-
1137
1120
  //#endregion
1138
1121
  //#region src/rectinclined1.ts
1139
1122
  /**
@@ -1220,7 +1203,78 @@ function calculatePerpendicularCoord(p1, p2, d) {
1220
1203
  }
1221
1204
  return [x, y];
1222
1205
  }
1223
-
1224
1206
  //#endregion
1225
- export { FITTING_COUNT, HALF_PI, TWO_PI, ZERO_TOLERANCE, arc, arrowAttackDirection, arrowAttackDirectionTailed, arrowClamped, arrowStraight, arrowStraightFine, arrowStraightSharp, arrowUnitCombatOperation, arrowUnitCombatOperationTailed, assemblingPlace, calculateFourthCoord, calculatePerpendicularCoord, calculatePerpendicularDistance, calculatePositionRelativeToLine, circle, closedCurve, curve, ellipse, getAngleOfThreeCoords, getArcCoords, getArrowBodyCoords, getArrowCoords, getArrowHeadCoords, getAzimuth, getBaseLength, getBezierCoords, getBinomialFactor, getBisectorNormals, getCircleCenterOfThreeCoords, getCoordOnLine, getCubicValue, getCurveCoords, getFactorial, getIntersectCoord, getLeftMostControlCoord, getNormal, getQBSplineCoords, getQuadricBSplineFactor, getRightMostControlCoord, getTempCoord4, getThirdCoord, isClockWise, lune, mathDistance, mid, rectAngle, rectinclined1, wholeDistance };
1207
+ //#region src/rectinclined2.ts
1208
+ /**
1209
+ * 斜矩形2
1210
+ *
1211
+ */
1212
+ function rectinclined2(coords) {
1213
+ if (coords.length < 3) throw new Error("coords.length must >= 3");
1214
+ else {
1215
+ const [coord1, coord2, mouse] = [
1216
+ coords[0],
1217
+ coords[1],
1218
+ coords[2]
1219
+ ];
1220
+ const intersect = calculateIntersectionCoord(coord1, coord2, mouse);
1221
+ const coord4 = calculateFourthCoord$1(coord1, intersect, mouse);
1222
+ const pList = [];
1223
+ pList.push(coord1, intersect, mouse, coord4, coord1);
1224
+ return pList;
1225
+ }
1226
+ }
1227
+ /**
1228
+ * 已知p1,p2,p3点求矩形的p4点
1229
+ * @param {*} p1
1230
+ * @param {*} p2
1231
+ * @param {*} p3
1232
+ */
1233
+ function calculateFourthCoord$1(p1, p2, p3) {
1234
+ return [p1[0] + p3[0] - p2[0], p1[1] + p3[1] - p2[1]];
1235
+ }
1236
+ /**
1237
+ * 已知p1点和p2点,求p3点到p1p2垂线的交点
1238
+ * @param {*} p1
1239
+ * @param {*} p2
1240
+ * @param {*} p3
1241
+ */
1242
+ function calculateIntersectionCoord(p1, p2, p3) {
1243
+ const v = {
1244
+ x: p2[0] - p1[0],
1245
+ y: p2[1] - p1[1]
1246
+ };
1247
+ const u = {
1248
+ x: p3[0] - p1[0],
1249
+ y: p3[1] - p1[1]
1250
+ };
1251
+ const projectionLength = (u.x * v.x + u.y * v.y) / (v.x * v.x + v.y * v.y);
1252
+ const intersectionCoord = {
1253
+ x: p1[0] + v.x * projectionLength,
1254
+ y: p1[1] + v.y * projectionLength
1255
+ };
1256
+ return [intersectionCoord.x, intersectionCoord.y];
1257
+ }
1258
+ //#endregion
1259
+ //#region src/sector.ts
1260
+ /**
1261
+ * 扇形
1262
+ *
1263
+ */
1264
+ function sector(coords) {
1265
+ if (coords.length < 3) throw new Error("coords.length must >= 2");
1266
+ else {
1267
+ const [center, coord2, coord3] = [
1268
+ coords[0],
1269
+ coords[1],
1270
+ coords[2]
1271
+ ];
1272
+ const pList = getArcCoords(center, mathDistance(coord2, center), getAzimuth(coord2, center), getAzimuth(coord3, center));
1273
+ pList.push(center, pList[0]);
1274
+ return pList;
1275
+ }
1276
+ }
1277
+ //#endregion
1278
+ export { FITTING_COUNT, HALF_PI, TWO_PI, ZERO_TOLERANCE, arc, arrowAttackDirection, arrowAttackDirectionTailed, arrowClamped, arrowStraight, arrowStraightFine, arrowStraightSharp, arrowUnitCombatOperation, arrowUnitCombatOperationTailed, assemblingPlace, calculateFourthCoord, calculateIntersectionCoord, calculatePerpendicularCoord, calculatePerpendicularDistance, calculatePositionRelativeToLine, circle, closedCurve, curve, ellipse, getAngleOfThreeCoords, getArcCoords, getArrowBodyCoords, getArrowCoords, getArrowHeadCoords, getAzimuth, getBaseLength, getBezierCoords, getBinomialFactor, getBisectorNormals, getCircleCenterOfThreeCoords, getCoordOnLine, getCubicValue, getCurveCoords, getFactorial, getIntersectCoord, getLeftMostControlCoord, getNormal, getQBSplineCoords, getQuadricBSplineFactor, getRightMostControlCoord, getTempCoord4, getThirdCoord, isClockWise, lune, mathDistance, mid, rectAngle, rectinclined1, rectinclined2, sector, wholeDistance };
1279
+
1226
1280
  //# sourceMappingURL=index.mjs.map