build-dxf 0.1.127 → 0.1.129

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-dxf",
3
- "version": "0.1.127",
3
+ "version": "0.1.129",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/build.js CHANGED
@@ -5850,299 +5850,6 @@ function smallestSurroundingRectangleByArea(geoJsonInput) {
5850
5850
  }
5851
5851
  return resultPolygon;
5852
5852
  }
5853
- const tmpPoint1 = [0, 0];
5854
- const tmpPoint2 = [0, 0];
5855
- function lineSegmentsIntersect(p1, p2, q1, q2) {
5856
- const dx = p2[0] - p1[0];
5857
- const dy = p2[1] - p1[1];
5858
- const da2 = q2[0] - q1[0];
5859
- const db = q2[1] - q1[1];
5860
- if (da2 * dy - db * dx === 0) {
5861
- return false;
5862
- }
5863
- const s = (dx * (q1[1] - p1[1]) + dy * (p1[0] - q1[0])) / (da2 * dy - db * dx);
5864
- const t2 = (da2 * (p1[1] - q1[1]) + db * (q1[0] - p1[0])) / (db * dx - da2 * dy);
5865
- return s >= 0 && s <= 1 && t2 >= 0 && t2 <= 1;
5866
- }
5867
- function triangleArea(a2, b4, c) {
5868
- return (b4[0] - a2[0]) * (c[1] - a2[1]) - (c[0] - a2[0]) * (b4[1] - a2[1]);
5869
- }
5870
- function isLeft(a2, b4, c) {
5871
- return triangleArea(a2, b4, c) > 0;
5872
- }
5873
- function isLeftOn(a2, b4, c) {
5874
- return triangleArea(a2, b4, c) >= 0;
5875
- }
5876
- function isRight(a2, b4, c) {
5877
- return triangleArea(a2, b4, c) < 0;
5878
- }
5879
- function isRightOn(a2, b4, c) {
5880
- return triangleArea(a2, b4, c) <= 0;
5881
- }
5882
- function collinear(a2, b4, c, thresholdAngle) {
5883
- if (thresholdAngle === void 0) {
5884
- thresholdAngle = 0;
5885
- }
5886
- if (!thresholdAngle) {
5887
- return triangleArea(a2, b4, c) === 0;
5888
- } else {
5889
- const ab = tmpPoint1;
5890
- const bc = tmpPoint2;
5891
- ab[0] = b4[0] - a2[0];
5892
- ab[1] = b4[1] - a2[1];
5893
- bc[0] = c[0] - b4[0];
5894
- bc[1] = c[1] - b4[1];
5895
- const dot = ab[0] * bc[0] + ab[1] * bc[1];
5896
- const magA = Math.sqrt(ab[0] * ab[0] + ab[1] * ab[1]);
5897
- const magB = Math.sqrt(bc[0] * bc[0] + bc[1] * bc[1]);
5898
- const angle = Math.acos(dot / (magA * magB));
5899
- return angle < thresholdAngle;
5900
- }
5901
- }
5902
- function sqdist(a2, b4) {
5903
- const dx = b4[0] - a2[0];
5904
- const dy = b4[1] - a2[1];
5905
- return dx * dx + dy * dy;
5906
- }
5907
- function polygonAt(polygon2, i) {
5908
- const s = polygon2.length;
5909
- return polygon2[i < 0 ? i % s + s : i % s];
5910
- }
5911
- function polygonAppend(polygon2, poly, from, to2) {
5912
- for (let i = from; i < to2; i++) {
5913
- polygon2.push(poly[i]);
5914
- }
5915
- }
5916
- function makeCCW(polygon2) {
5917
- let br2 = 0;
5918
- const v2 = polygon2;
5919
- for (let i = 1; i < polygon2.length; ++i) {
5920
- if (v2[i][1] < v2[br2][1] || v2[i][1] === v2[br2][1] && v2[i][0] > v2[br2][0]) {
5921
- br2 = i;
5922
- }
5923
- }
5924
- if (!isLeft(polygonAt(polygon2, br2 - 1), polygonAt(polygon2, br2), polygonAt(polygon2, br2 + 1))) {
5925
- polygonReverse(polygon2);
5926
- return true;
5927
- } else {
5928
- return false;
5929
- }
5930
- }
5931
- function polygonReverse(polygon2) {
5932
- const tmp = [];
5933
- const N = polygon2.length;
5934
- for (let i = 0; i !== N; i++) {
5935
- tmp.push(polygon2.pop());
5936
- }
5937
- for (let i = 0; i !== N; i++) {
5938
- polygon2[i] = tmp[i];
5939
- }
5940
- }
5941
- function polygonIsReflex(polygon2, i) {
5942
- return isRight(polygonAt(polygon2, i - 1), polygonAt(polygon2, i), polygonAt(polygon2, i + 1));
5943
- }
5944
- function polygonCanSee2(polygon2, a2, b4) {
5945
- for (let i = 0; i !== polygon2.length; ++i) {
5946
- if (i === a2 || i === b4 || (i + 1) % polygon2.length === a2 || (i + 1) % polygon2.length === b4) {
5947
- continue;
5948
- }
5949
- if (lineSegmentsIntersect(polygonAt(polygon2, a2), polygonAt(polygon2, b4), polygonAt(polygon2, i), polygonAt(polygon2, i + 1))) {
5950
- return false;
5951
- }
5952
- }
5953
- return true;
5954
- }
5955
- function getIntersectionPoint(p1, p2, q1, q2, delta) {
5956
- if (delta === void 0) {
5957
- delta = 0;
5958
- }
5959
- const a1 = p2[1] - p1[1];
5960
- const b1 = p1[0] - p2[0];
5961
- const c1 = a1 * p1[0] + b1 * p1[1];
5962
- const a2 = q2[1] - q1[1];
5963
- const b22 = q1[0] - q2[0];
5964
- const c22 = a2 * q1[0] + b22 * q1[1];
5965
- const det = a1 * b22 - a2 * b1;
5966
- if (!scalarsEqual(det, 0, delta)) {
5967
- return [(b22 * c1 - b1 * c22) / det, (a1 * c22 - a2 * c1) / det];
5968
- } else {
5969
- return [0, 0];
5970
- }
5971
- }
5972
- function quickDecomp(polygon2, result, reflexVertices, steinerPoints, delta, maxlevel, level) {
5973
- if (result === void 0) {
5974
- result = [];
5975
- }
5976
- if (reflexVertices === void 0) {
5977
- reflexVertices = [];
5978
- }
5979
- if (steinerPoints === void 0) {
5980
- steinerPoints = [];
5981
- }
5982
- if (delta === void 0) {
5983
- delta = 25;
5984
- }
5985
- if (maxlevel === void 0) {
5986
- maxlevel = 100;
5987
- }
5988
- if (level === void 0) {
5989
- level = 0;
5990
- }
5991
- let upperInt = [0, 0];
5992
- let lowerInt = [0, 0];
5993
- let p2 = [0, 0];
5994
- let upperDist = 0;
5995
- let lowerDist = 0;
5996
- let d2 = 0;
5997
- let closestDist = 0;
5998
- let upperIndex = 0;
5999
- let lowerIndex = 0;
6000
- let closestIndex = 0;
6001
- const lowerPoly = [];
6002
- const upperPoly = [];
6003
- const poly = polygon2;
6004
- const v2 = polygon2;
6005
- if (v2.length < 3) {
6006
- return result;
6007
- }
6008
- level++;
6009
- if (level > maxlevel) {
6010
- console.warn("quickDecomp: max level (" + maxlevel + ") reached.");
6011
- return result;
6012
- }
6013
- for (let i = 0; i < polygon2.length; ++i) {
6014
- if (polygonIsReflex(poly, i)) {
6015
- reflexVertices.push(poly[i]);
6016
- upperDist = lowerDist = Number.MAX_VALUE;
6017
- for (let j = 0; j < polygon2.length; ++j) {
6018
- if (isLeft(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j)) && isRightOn(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j - 1))) {
6019
- p2 = getIntersectionPoint(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j), polygonAt(poly, j - 1));
6020
- if (isRight(polygonAt(poly, i + 1), polygonAt(poly, i), p2)) {
6021
- d2 = sqdist(poly[i], p2);
6022
- if (d2 < lowerDist) {
6023
- lowerDist = d2;
6024
- lowerInt = p2;
6025
- lowerIndex = j;
6026
- }
6027
- }
6028
- }
6029
- if (isLeft(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j + 1)) && isRightOn(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j))) {
6030
- p2 = getIntersectionPoint(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j), polygonAt(poly, j + 1));
6031
- if (isLeft(polygonAt(poly, i - 1), polygonAt(poly, i), p2)) {
6032
- d2 = sqdist(poly[i], p2);
6033
- if (d2 < upperDist) {
6034
- upperDist = d2;
6035
- upperInt = p2;
6036
- upperIndex = j;
6037
- }
6038
- }
6039
- }
6040
- }
6041
- if (lowerIndex === (upperIndex + 1) % polygon2.length) {
6042
- p2[0] = (lowerInt[0] + upperInt[0]) / 2;
6043
- p2[1] = (lowerInt[1] + upperInt[1]) / 2;
6044
- steinerPoints.push(p2);
6045
- if (i < upperIndex) {
6046
- polygonAppend(lowerPoly, poly, i, upperIndex + 1);
6047
- lowerPoly.push(p2);
6048
- upperPoly.push(p2);
6049
- if (lowerIndex !== 0) {
6050
- polygonAppend(upperPoly, poly, lowerIndex, poly.length);
6051
- }
6052
- polygonAppend(upperPoly, poly, 0, i + 1);
6053
- } else {
6054
- if (i !== 0) {
6055
- polygonAppend(lowerPoly, poly, i, poly.length);
6056
- }
6057
- polygonAppend(lowerPoly, poly, 0, upperIndex + 1);
6058
- lowerPoly.push(p2);
6059
- upperPoly.push(p2);
6060
- polygonAppend(upperPoly, poly, lowerIndex, i + 1);
6061
- }
6062
- } else {
6063
- if (lowerIndex > upperIndex) {
6064
- upperIndex += polygon2.length;
6065
- }
6066
- closestDist = Number.MAX_VALUE;
6067
- if (upperIndex < lowerIndex) {
6068
- return result;
6069
- }
6070
- for (let j = lowerIndex; j <= upperIndex; ++j) {
6071
- if (isLeftOn(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j)) && isRightOn(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j))) {
6072
- d2 = sqdist(polygonAt(poly, i), polygonAt(poly, j));
6073
- if (d2 < closestDist && polygonCanSee2(poly, i, j)) {
6074
- closestDist = d2;
6075
- closestIndex = j % polygon2.length;
6076
- }
6077
- }
6078
- }
6079
- if (i < closestIndex) {
6080
- polygonAppend(lowerPoly, poly, i, closestIndex + 1);
6081
- if (closestIndex !== 0) {
6082
- polygonAppend(upperPoly, poly, closestIndex, v2.length);
6083
- }
6084
- polygonAppend(upperPoly, poly, 0, i + 1);
6085
- } else {
6086
- if (i !== 0) {
6087
- polygonAppend(lowerPoly, poly, i, v2.length);
6088
- }
6089
- polygonAppend(lowerPoly, poly, 0, closestIndex + 1);
6090
- polygonAppend(upperPoly, poly, closestIndex, i + 1);
6091
- }
6092
- }
6093
- if (lowerPoly.length < upperPoly.length) {
6094
- quickDecomp(lowerPoly, result, reflexVertices, steinerPoints, delta, maxlevel, level);
6095
- quickDecomp(upperPoly, result, reflexVertices, steinerPoints, delta, maxlevel, level);
6096
- } else {
6097
- quickDecomp(upperPoly, result, reflexVertices, steinerPoints, delta, maxlevel, level);
6098
- quickDecomp(lowerPoly, result, reflexVertices, steinerPoints, delta, maxlevel, level);
6099
- }
6100
- return result;
6101
- }
6102
- }
6103
- result.push(polygon2);
6104
- return result;
6105
- }
6106
- function removeCollinearPoints(polygon2, thresholdAngle) {
6107
- if (thresholdAngle === void 0) {
6108
- thresholdAngle = 0;
6109
- }
6110
- let num = 0;
6111
- for (let i = polygon2.length - 1; polygon2.length > 3 && i >= 0; --i) {
6112
- if (collinear(polygonAt(polygon2, i - 1), polygonAt(polygon2, i), polygonAt(polygon2, i + 1), thresholdAngle)) {
6113
- polygon2.splice(i % polygon2.length, 1);
6114
- num++;
6115
- }
6116
- }
6117
- return num;
6118
- }
6119
- function scalarsEqual(a2, b4, precision) {
6120
- if (precision === void 0) {
6121
- precision = 0;
6122
- }
6123
- precision = precision || 0;
6124
- return Math.abs(a2 - b4) <= precision;
6125
- }
6126
- function pointsEqual(a2, b4, precision) {
6127
- if (precision === void 0) {
6128
- precision = 0;
6129
- }
6130
- return scalarsEqual(a2[0], b4[0], precision) && scalarsEqual(a2[1], b4[1], precision);
6131
- }
6132
- function removeDuplicatePoints(polygon2, precision) {
6133
- if (precision === void 0) {
6134
- precision = 0;
6135
- }
6136
- for (let i = polygon2.length - 1; i >= 1; --i) {
6137
- const pi2 = polygon2[i];
6138
- for (let j = i - 1; j >= 0; --j) {
6139
- if (pointsEqual(pi2, polygon2[j], precision)) {
6140
- polygon2.splice(i, 1);
6141
- continue;
6142
- }
6143
- }
6144
- }
6145
- }
6146
5853
  class Polygon extends Array {
6147
5854
  [Symbol.iterator]() {
6148
5855
  return super[Symbol.iterator]();
@@ -6461,18 +6168,6 @@ class Polygon extends Array {
6461
6168
  this.set(polygons[0]);
6462
6169
  return true;
6463
6170
  }
6464
- /** 拆分为凸包
6465
- * @returns
6466
- */
6467
- splitConvexHull() {
6468
- const concavePolygon = this.toArrays();
6469
- makeCCW(concavePolygon);
6470
- removeDuplicatePoints(concavePolygon);
6471
- removeCollinearPoints(concavePolygon);
6472
- const optimalConvexPolygons = quickDecomp(concavePolygon);
6473
- if (!optimalConvexPolygons) return null;
6474
- return optimalConvexPolygons.map((array) => new Polygon(array.map((item) => Point.from(item))));
6475
- }
6476
6171
  /** 包围盒检测
6477
6172
  * @param box
6478
6173
  * @returns
@@ -7556,27 +7251,27 @@ class OBB2 extends OBB$1 {
7556
7251
  * @param box
7557
7252
  * @param position
7558
7253
  * @param rotation
7559
- * @param obb
7254
+ * @param out
7560
7255
  * @returns
7561
7256
  */
7562
- static from(box, position, rotation, obb2 = new OBB2()) {
7257
+ static from(box, position, rotation, out = new OBB2()) {
7563
7258
  if (rotation instanceof THREE.Euler) quat.setFromEuler(rotation);
7564
7259
  else if (rotation instanceof THREE.Quaternion) quat.copy(rotation);
7565
7260
  else throw new Error(`传入的旋转不是欧拉角或者四元数`);
7566
7261
  matrix4.compose(position, quat, scale);
7567
- obb2.center.copy(position);
7568
- obb2.halfSize.copy(box.multiplyScalar(0.5));
7569
- obb2.rotation.setFromMatrix4(matrix4);
7570
- return obb2;
7262
+ out.center.copy(position);
7263
+ out.halfSize.copy(box.multiplyScalar(0.5));
7264
+ out.rotation.setFromMatrix4(matrix4);
7265
+ return out;
7571
7266
  }
7572
7267
  /** 通过2d路径创建
7573
7268
  * @param path
7574
7269
  * @param origin
7575
7270
  * @param height
7576
- * @param obb_
7271
+ * @param out
7577
7272
  * @returns
7578
7273
  */
7579
- static fromByPath2D(path, origin, height, obb_ = new OBB2()) {
7274
+ static fromByPath2D(path, origin, height, out = new OBB2()) {
7580
7275
  const result = smallestSurroundingRectangleByArea({
7581
7276
  type: "Polygon",
7582
7277
  coordinates: [path.map((p2) => [p2.x, p2.y])]
@@ -7591,8 +7286,8 @@ class OBB2 extends OBB$1 {
7591
7286
  const [x, y] = getCenter(rectangle);
7592
7287
  origin.x = x;
7593
7288
  origin.y = y;
7594
- const obb2 = this.from(vec3, origin, euler, obb_);
7595
- return obb2;
7289
+ out = this.from(vec3, origin, euler, out);
7290
+ return out;
7596
7291
  }
7597
7292
  }
7598
7293
  const matrix4 = new THREE.Matrix4(), quat = new THREE.Quaternion(), euler = new THREE.Euler(), scale = new THREE.Vector3(1, 1, 1), vec3 = new THREE.Vector3(), box3$2 = new THREE.Box3();
@@ -10850,7 +10545,9 @@ class ThreeVJiaPipeline extends Pipeline {
10850
10545
  console.warn(`第${i}个物品轮廓为空`);
10851
10546
  return;
10852
10547
  }
10853
- const itemPoly = new Polygon(contour.map((p2) => Point.from(p2).rotate(json.center, json.angle))), center = itemPoly.getCenter(), index2 = roomPloys.findIndex((poly) => poly.pointWithin(center));
10548
+ const itemPoly = new Polygon(
10549
+ contour.map((p2) => Point.from(p2).rotate(json.center, json.angle))
10550
+ ), center = itemPoly.getCenter(), index2 = roomPloys.findIndex((poly) => poly.pointWithin(center));
10854
10551
  if (index2 < 0) return;
10855
10552
  try {
10856
10553
  const rect = itemPoly.getMinimumBoundingRectangle().map((p2) => p2.toJson2D());
@@ -22451,8 +22148,9 @@ class SceneAutoGenerat {
22451
22148
  await Promise.all(this.itemList.map(async (item) => await this.getModel(item)));
22452
22149
  }
22453
22150
  static itemParse(item) {
22454
- if (!Array.isArray(item.contour) || !item.contour.length) return null;
22455
- const contour = Point.fromByList(item.contour ?? []), rectangle = new Polygon(Qa(contour.map((p2) => [p2.x, p2.y])).map((p2) => Point.from(p2)));
22151
+ const contourData = item.quadContour ?? item.contour;
22152
+ if (!Array.isArray(contourData) || contourData.length) return null;
22153
+ const contour = Point.fromByList(contourData), rectangle = new Polygon(Qa(contour.map((p2) => [p2.x, p2.y])).map((p2) => Point.from(p2)));
22456
22154
  rectangle.pop();
22457
22155
  const z = item.box.min.z, height = Math.abs(item.box.max.z - z), max = rectangle.getMaxLengthInfo(), min = rectangle.getMinLengthInfo(), direction = max.start.y < max.end.y ? max.start.directionFrom(max.end) : max.end.directionFrom(max.start), shape = new THREE.Shape();
22458
22156
  rectangle.forEach((p2, i) => {
package/src/demo.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/src/index.css CHANGED
@@ -137,6 +137,10 @@
137
137
  position: absolute;
138
138
  }
139
139
 
140
+ .fixed {
141
+ position: fixed;
142
+ }
143
+
140
144
  .relative {
141
145
  position: relative;
142
146
  }
@@ -0,0 +1,17 @@
1
+ export declare class Variable {
2
+ value: number;
3
+ fixed: boolean;
4
+ constructor(value: number, fixed?: boolean);
5
+ }
6
+ export interface Constraint {
7
+ evaluate(): number[];
8
+ }
9
+ export declare class ConstraintSystem {
10
+ constraints: Constraint[];
11
+ variables: Variable[];
12
+ addConstraint(c: Constraint): void;
13
+ addVariable(v: Variable): void;
14
+ residuals(): number[];
15
+ jacobian(eps?: number): number[][];
16
+ solve(iterations?: number): void;
17
+ }
@@ -12,19 +12,19 @@ export declare class OBB extends OBB_ {
12
12
  * @param box
13
13
  * @param position
14
14
  * @param rotation
15
- * @param obb
15
+ * @param out
16
16
  * @returns
17
17
  */
18
- static from(box: THREE.Vector3, position: THREE.Vector3, rotation: THREE.Euler | THREE.Quaternion, obb?: OBB): OBB;
18
+ static from(box: THREE.Vector3, position: THREE.Vector3, rotation: THREE.Euler | THREE.Quaternion, out?: OBB): OBB;
19
19
  /** 通过2d路径创建
20
20
  * @param path
21
21
  * @param origin
22
22
  * @param height
23
- * @param obb_
23
+ * @param out
24
24
  * @returns
25
25
  */
26
26
  static fromByPath2D(path: {
27
27
  x: number;
28
28
  y: number;
29
- }[], origin: THREE.Vector3, height: number, obb_?: OBB): OBB;
29
+ }[], origin: THREE.Vector3, height: number, out?: OBB): OBB;
30
30
  }
@@ -91,10 +91,6 @@ export declare class Polygon<T = any> extends Array<Point<T>> {
91
91
  * @param polygon
92
92
  */
93
93
  difference(polygons: Polygon | Polygon[], scale?: number): boolean;
94
- /** 拆分为凸包
95
- * @returns
96
- */
97
- splitConvexHull(): Polygon<Record<string, any>>[] | null;
98
94
  /** 包围盒检测
99
95
  * @param box
100
96
  * @returns
@@ -0,0 +1,9 @@
1
+ import { LineSegment } from './LineSegment';
2
+ import { Polygon } from './Polygon';
3
+ export declare class PolygonUtils {
4
+ /** 拆分为凸包
5
+ * @returns
6
+ */
7
+ static splitConvexHull(ploy: Polygon): Polygon<Record<string, any>>[] | null;
8
+ static splitByLine(lines: LineSegment[], clipLine: LineSegment): LineSegment[][];
9
+ }
@@ -0,0 +1,2 @@
1
+ export declare class GeometryManager {
2
+ }