@bitbybit-dev/base 1.4.1 → 1.5.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/color-space.d.ts +14 -0
- package/lib/api/color-space.js +24 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +2 -0
- package/lib/api/inputs/base-inputs.d.ts +382 -5
- package/lib/api/inputs/base-inputs.js +0 -3
- package/lib/api/inputs/color-inputs.d.ts +1 -1
- package/lib/api/inputs/color-inputs.js +0 -1
- package/lib/api/inputs/dates-inputs.js +0 -1
- package/lib/api/inputs/frame-inputs.d.ts +1 -1
- package/lib/api/inputs/inputs.js +0 -1
- package/lib/api/inputs/io-inputs.d.ts +1 -1
- package/lib/api/inputs/line-inputs.d.ts +1 -1
- package/lib/api/inputs/lists-inputs.js +0 -1
- package/lib/api/inputs/logic-inputs.d.ts +1 -1
- package/lib/api/inputs/logic-inputs.js +0 -1
- package/lib/api/inputs/math-inputs.js +0 -1
- package/lib/api/inputs/mesh-inputs.d.ts +29 -1
- package/lib/api/inputs/mesh-inputs.js +25 -1
- package/lib/api/inputs/point-inputs.d.ts +30 -1
- package/lib/api/inputs/point-inputs.js +28 -0
- package/lib/api/inputs/polyline-inputs.d.ts +1 -1
- package/lib/api/inputs/transforms-inputs.d.ts +1 -1
- package/lib/api/inputs/vector-inputs.d.ts +1 -1
- package/lib/api/kernel-calls/describe-failure.d.ts +3 -2
- package/lib/api/kernel-calls/describe-failure.js +9 -17
- package/lib/api/kernel-calls/failure-message.d.ts +1 -1
- package/lib/api/kernel-calls/hashing.d.ts +14 -0
- package/lib/api/kernel-calls/hashing.js +47 -0
- package/lib/api/kernel-calls/index.d.ts +3 -0
- package/lib/api/kernel-calls/index.js +3 -0
- package/lib/api/kernel-calls/input-rules.d.ts +1 -1
- package/lib/api/kernel-calls/input-rules.js +10 -5
- package/lib/api/kernel-calls/input-validation.d.ts +3 -3
- package/lib/api/kernel-calls/input-validation.js +24 -14
- package/lib/api/kernel-calls/kernel-steps.d.ts +19 -0
- package/lib/api/kernel-calls/kernel-steps.js +19 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +5 -3
- package/lib/api/kernel-calls/resolve-dto.js +9 -4
- package/lib/api/kernel-calls/unknown-values.d.ts +12 -0
- package/lib/api/kernel-calls/unknown-values.js +16 -0
- package/lib/api/kernel-calls/with-defaults.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/text/vector-char-data.d.ts +1 -1
- package/lib/api/models/text/vector-text-data.d.ts +1 -1
- package/lib/api/recipes/checker-types.d.ts +14 -0
- package/lib/api/recipes/checker-types.js +1 -0
- package/lib/api/recipes/index.d.ts +4 -0
- package/lib/api/recipes/index.js +3 -0
- package/lib/api/recipes/limits.constants.d.ts +23 -0
- package/lib/api/recipes/limits.constants.js +23 -0
- package/lib/api/recipes/recipe-types.d.ts +48 -0
- package/lib/api/recipes/recipe-types.js +1 -0
- package/lib/api/recipes/sources.d.ts +16 -0
- package/lib/api/recipes/sources.js +23 -0
- package/lib/api/recipes/surface-mesh.d.ts +16 -0
- package/lib/api/recipes/surface-mesh.js +86 -0
- package/lib/api/recipes/validate.d.ts +36 -0
- package/lib/api/recipes/validate.js +427 -0
- package/lib/api/resolved-inputs/index.d.ts +3 -0
- package/lib/api/services/color.d.ts +1 -1
- package/lib/api/services/frame.d.ts +3 -95
- package/lib/api/services/frame.js +24 -135
- package/lib/api/services/geometry-helper.d.ts +1 -1
- package/lib/api/services/helpers/arcs.d.ts +6 -0
- package/lib/api/services/helpers/arcs.js +30 -0
- package/lib/api/services/helpers/crc32.d.ts +1 -0
- package/lib/api/services/helpers/crc32.js +21 -0
- package/lib/api/services/helpers/dxf/dxf-generator.d.ts +0 -83
- package/lib/api/services/helpers/dxf/dxf-generator.js +5 -86
- package/lib/api/services/helpers/frame-axes.d.ts +9 -1
- package/lib/api/services/helpers/frame-axes.js +34 -0
- package/lib/api/services/helpers/helper-types.d.ts +34 -0
- package/lib/api/services/helpers/helper-types.js +1 -0
- package/lib/api/services/helpers/inflate.constants.d.ts +41 -0
- package/lib/api/services/helpers/inflate.constants.js +41 -0
- package/lib/api/services/helpers/inflate.d.ts +3 -0
- package/lib/api/services/helpers/inflate.js +228 -0
- package/lib/api/services/helpers/matrices.constants.d.ts +2 -0
- package/lib/api/services/helpers/matrices.constants.js +2 -0
- package/lib/api/services/helpers/matrices.d.ts +9 -1
- package/lib/api/services/helpers/matrices.js +18 -0
- package/lib/api/services/helpers/mesh-measures.d.ts +1 -0
- package/lib/api/services/helpers/mesh-measures.js +28 -0
- package/lib/api/services/helpers/mesh-normals.d.ts +2 -0
- package/lib/api/services/helpers/mesh-normals.js +118 -26
- package/lib/api/services/helpers/mesh-primitives.constants.d.ts +2 -0
- package/lib/api/services/helpers/mesh-primitives.constants.js +12 -0
- package/lib/api/services/helpers/mesh-primitives.d.ts +3 -0
- package/lib/api/services/helpers/mesh-primitives.js +46 -0
- package/lib/api/services/helpers/nurbs.d.ts +7 -0
- package/lib/api/services/helpers/nurbs.js +50 -0
- package/lib/api/services/helpers/paths.d.ts +8 -0
- package/lib/api/services/helpers/paths.js +96 -0
- package/lib/api/services/helpers/polygons.d.ts +8 -0
- package/lib/api/services/helpers/polygons.js +59 -0
- package/lib/api/services/helpers/surface-triangulation.d.ts +6 -0
- package/lib/api/services/helpers/surface-triangulation.js +298 -0
- package/lib/api/services/helpers/triangulation.d.ts +2 -0
- package/lib/api/services/helpers/triangulation.js +295 -0
- package/lib/api/services/helpers/vectors.d.ts +18 -0
- package/lib/api/services/helpers/vectors.js +17 -0
- package/lib/api/services/helpers/zip.constants.d.ts +34 -0
- package/lib/api/services/helpers/zip.constants.js +34 -0
- package/lib/api/services/helpers/zip.d.ts +4 -0
- package/lib/api/services/helpers/zip.js +89 -0
- package/lib/api/services/line.d.ts +3 -3
- package/lib/api/services/mesh.d.ts +37 -2
- package/lib/api/services/mesh.js +60 -3
- package/lib/api/services/point.d.ts +22 -10
- package/lib/api/services/point.js +42 -13
- package/lib/api/services/polyline.d.ts +39 -4
- package/lib/api/services/polyline.js +56 -6
- package/lib/api/services/text.d.ts +2 -2
- package/lib/api/services/text.js +10 -5
- package/lib/api/services/transforms.d.ts +3 -9
- package/lib/api/services/transforms.js +0 -6
- package/lib/api/services/vector.d.ts +2 -2
- package/lib/api/services/vector.js +2 -5
- package/package.json +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { InputError, resolveDto } from "../kernel-calls";
|
|
3
|
-
import { isFrameShaped, isTriple, PARALLEL_SINE, squareFrame, unitOf } from "./helpers/frame-axes";
|
|
3
|
+
import { composeAxes, isFrameShaped, isTriple, PARALLEL_SINE, pointToLocal, pointToWorld, relativeAxes, squareFrame, unitOf, vectorToLocal, vectorToWorld, WORLD_AXES } from "./helpers/frame-axes";
|
|
4
4
|
import { composed, symmetricEigen } from "./helpers/matrices";
|
|
5
|
-
const
|
|
6
|
-
/** The largest absolute coordinate in a list of vectors, by a loop, so a long list cannot overflow the call stack. */
|
|
5
|
+
const EQUAL_COMPONENT_TOLERANCE = 1e-12;
|
|
7
6
|
const reachOf = (vectors) => {
|
|
8
7
|
let reach = 0;
|
|
9
8
|
for (const vector of vectors) {
|
|
@@ -65,7 +64,7 @@ export class Frame {
|
|
|
65
64
|
* ```
|
|
66
65
|
*/
|
|
67
66
|
world() {
|
|
68
|
-
return this.frameOf(
|
|
67
|
+
return this.frameOf(WORLD_AXES);
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* Builds a frame lying in the XY plane: its X axis along the world X, its Y axis along the
|
|
@@ -82,7 +81,7 @@ export class Frame {
|
|
|
82
81
|
*/
|
|
83
82
|
xy(inputs) {
|
|
84
83
|
const resolved = resolveDto(Inputs.Frame.OriginDto, inputs);
|
|
85
|
-
return this.frameOf(Object.assign(Object.assign({},
|
|
84
|
+
return this.frameOf(Object.assign(Object.assign({}, WORLD_AXES), { origin: this.pointOf(resolved.origin, "origin") }));
|
|
86
85
|
}
|
|
87
86
|
/**
|
|
88
87
|
* Builds a frame lying in the YZ plane: its X axis along the world Y, its Y axis along the
|
|
@@ -443,7 +442,7 @@ export class Frame {
|
|
|
443
442
|
*/
|
|
444
443
|
frameToWorld(inputs) {
|
|
445
444
|
const parent = this.axesOf(inputs.parent, "parent");
|
|
446
|
-
return this.
|
|
445
|
+
return this.frameOf(composeAxes(parent, this.axesOf(inputs.child, "child")));
|
|
447
446
|
}
|
|
448
447
|
/**
|
|
449
448
|
* Places frames given in one parent frame's coordinates into the world, as `frameToWorld`
|
|
@@ -462,7 +461,7 @@ export class Frame {
|
|
|
462
461
|
*/
|
|
463
462
|
framesToWorld(inputs) {
|
|
464
463
|
const parent = this.axesOf(inputs.parent, "parent");
|
|
465
|
-
return this.axesOfEach(inputs.children, "children").map(child => this.
|
|
464
|
+
return this.axesOfEach(inputs.children, "children").map(child => this.frameOf(composeAxes(parent, child)));
|
|
466
465
|
}
|
|
467
466
|
/**
|
|
468
467
|
* Describes a frame given in world coordinates in another frame's coordinates, the reverse of
|
|
@@ -483,7 +482,7 @@ export class Frame {
|
|
|
483
482
|
*/
|
|
484
483
|
frameToLocal(inputs) {
|
|
485
484
|
const parent = this.axesOf(inputs.parent, "parent");
|
|
486
|
-
return this.
|
|
485
|
+
return this.frameOf(relativeAxes(parent, this.axesOf(inputs.child, "child")));
|
|
487
486
|
}
|
|
488
487
|
/**
|
|
489
488
|
* Describes frames given in world coordinates in one parent frame's coordinates, the reverse
|
|
@@ -501,7 +500,7 @@ export class Frame {
|
|
|
501
500
|
*/
|
|
502
501
|
framesToLocal(inputs) {
|
|
503
502
|
const parent = this.axesOf(inputs.parent, "parent");
|
|
504
|
-
return this.axesOfEach(inputs.children, "children").map(child => this.
|
|
503
|
+
return this.axesOfEach(inputs.children, "children").map(child => this.frameOf(relativeAxes(parent, child)));
|
|
505
504
|
}
|
|
506
505
|
/**
|
|
507
506
|
* Converts a point given in a frame's coordinates into world coordinates.
|
|
@@ -520,7 +519,7 @@ export class Frame {
|
|
|
520
519
|
*/
|
|
521
520
|
pointToWorld(inputs) {
|
|
522
521
|
const axes = this.axesOf(inputs.frame, "frame");
|
|
523
|
-
return
|
|
522
|
+
return pointToWorld(axes, this.pointOf(inputs.point, "point"));
|
|
524
523
|
}
|
|
525
524
|
/**
|
|
526
525
|
* Converts a point given in world coordinates into a frame's coordinates, the reverse of
|
|
@@ -539,7 +538,7 @@ export class Frame {
|
|
|
539
538
|
*/
|
|
540
539
|
pointToLocal(inputs) {
|
|
541
540
|
const axes = this.axesOf(inputs.frame, "frame");
|
|
542
|
-
return
|
|
541
|
+
return pointToLocal(axes, this.pointOf(inputs.point, "point"));
|
|
543
542
|
}
|
|
544
543
|
/**
|
|
545
544
|
* Converts points given in a frame's coordinates into world coordinates, as `pointToWorld` does
|
|
@@ -556,7 +555,7 @@ export class Frame {
|
|
|
556
555
|
*/
|
|
557
556
|
pointsToWorld(inputs) {
|
|
558
557
|
const axes = this.axesOf(inputs.frame, "frame");
|
|
559
|
-
return this.pointsOf(inputs.points, "points").map(point =>
|
|
558
|
+
return this.pointsOf(inputs.points, "points").map(point => pointToWorld(axes, point));
|
|
560
559
|
}
|
|
561
560
|
/**
|
|
562
561
|
* Converts points given in world coordinates into a frame's coordinates, as `pointToLocal` does
|
|
@@ -573,7 +572,7 @@ export class Frame {
|
|
|
573
572
|
*/
|
|
574
573
|
pointsToLocal(inputs) {
|
|
575
574
|
const axes = this.axesOf(inputs.frame, "frame");
|
|
576
|
-
return this.pointsOf(inputs.points, "points").map(point =>
|
|
575
|
+
return this.pointsOf(inputs.points, "points").map(point => pointToLocal(axes, point));
|
|
577
576
|
}
|
|
578
577
|
/**
|
|
579
578
|
* Turns a vector given along a frame's axes into one along the world axes; the frame's origin
|
|
@@ -589,7 +588,7 @@ export class Frame {
|
|
|
589
588
|
* ```
|
|
590
589
|
*/
|
|
591
590
|
vectorToWorld(inputs) {
|
|
592
|
-
return
|
|
591
|
+
return vectorToWorld(this.axesOf(inputs.frame, "frame"), this.vectorOf(inputs.vector, "vector"));
|
|
593
592
|
}
|
|
594
593
|
/**
|
|
595
594
|
* Turns a vector given along the world axes into one along a frame's axes, the reverse of
|
|
@@ -605,7 +604,7 @@ export class Frame {
|
|
|
605
604
|
* ```
|
|
606
605
|
*/
|
|
607
606
|
vectorToLocal(inputs) {
|
|
608
|
-
return
|
|
607
|
+
return vectorToLocal(this.axesOf(inputs.frame, "frame"), this.vectorOf(inputs.vector, "vector"));
|
|
609
608
|
}
|
|
610
609
|
/**
|
|
611
610
|
* Gives the transformation that moves anything from the world frame onto a frame.
|
|
@@ -624,7 +623,7 @@ export class Frame {
|
|
|
624
623
|
* ```
|
|
625
624
|
*/
|
|
626
625
|
toMatrix(inputs) {
|
|
627
|
-
return [this.matrixBetween(
|
|
626
|
+
return [this.matrixBetween(WORLD_AXES, this.axesOf(inputs.frame, "frame"))];
|
|
628
627
|
}
|
|
629
628
|
/**
|
|
630
629
|
* Reads the frame a transformation puts the world frame on: where it moves the world origin
|
|
@@ -682,7 +681,7 @@ export class Frame {
|
|
|
682
681
|
* ```
|
|
683
682
|
*/
|
|
684
683
|
matrixFromTo(inputs) {
|
|
685
|
-
const from = inputs.from === undefined ?
|
|
684
|
+
const from = inputs.from === undefined ? WORLD_AXES : this.axesOf(inputs.from, "from");
|
|
686
685
|
return [this.matrixBetween(from, this.axesOf(inputs.to, "to"))];
|
|
687
686
|
}
|
|
688
687
|
/**
|
|
@@ -703,7 +702,7 @@ export class Frame {
|
|
|
703
702
|
*/
|
|
704
703
|
grid(inputs) {
|
|
705
704
|
const resolved = resolveDto(Inputs.Frame.GridDto, inputs);
|
|
706
|
-
const axes = resolved.frame === undefined ?
|
|
705
|
+
const axes = resolved.frame === undefined ? WORLD_AXES : this.axesOf(resolved.frame, "frame");
|
|
707
706
|
const countX = this.countOf(resolved.countX, "countX");
|
|
708
707
|
const countY = this.countOf(resolved.countY, "countY");
|
|
709
708
|
const spacingX = this.numberOf(resolved.spacingX, "spacingX");
|
|
@@ -713,7 +712,7 @@ export class Frame {
|
|
|
713
712
|
const frames = [];
|
|
714
713
|
for (let row = 0; row < countY; row++) {
|
|
715
714
|
for (let column = 0; column < countX; column++) {
|
|
716
|
-
frames.push(this.frameOf(Object.assign(Object.assign({}, axes), { origin:
|
|
715
|
+
frames.push(this.frameOf(Object.assign(Object.assign({}, axes), { origin: pointToWorld(axes, [column * spacingX - shiftX, row * spacingY - shiftY, 0]) })));
|
|
717
716
|
}
|
|
718
717
|
}
|
|
719
718
|
return frames;
|
|
@@ -736,7 +735,7 @@ export class Frame {
|
|
|
736
735
|
*/
|
|
737
736
|
polar(inputs) {
|
|
738
737
|
const resolved = resolveDto(Inputs.Frame.PolarDto, inputs);
|
|
739
|
-
const axes = resolved.frame === undefined ?
|
|
738
|
+
const axes = resolved.frame === undefined ? WORLD_AXES : this.axesOf(resolved.frame, "frame");
|
|
740
739
|
const count = this.countOf(resolved.count, "count");
|
|
741
740
|
const radius = this.numberOf(resolved.radius, "radius");
|
|
742
741
|
if (radius < 0) {
|
|
@@ -778,7 +777,7 @@ export class Frame {
|
|
|
778
777
|
*/
|
|
779
778
|
hexGrid(inputs) {
|
|
780
779
|
const resolved = resolveDto(Inputs.Frame.HexGridDto, inputs);
|
|
781
|
-
const axes = resolved.frame === undefined ?
|
|
780
|
+
const axes = resolved.frame === undefined ? WORLD_AXES : this.axesOf(resolved.frame, "frame");
|
|
782
781
|
const countX = this.countOf(resolved.countX, "countX");
|
|
783
782
|
const countY = this.countOf(resolved.countY, "countY");
|
|
784
783
|
const radius = this.numberOf(resolved.radius, "radius");
|
|
@@ -793,16 +792,11 @@ export class Frame {
|
|
|
793
792
|
for (let row = 0; row < countY; row++) {
|
|
794
793
|
for (let column = 0; column < countX; column++) {
|
|
795
794
|
const u = column * columnSpacing + (row % 2 === 1 ? columnSpacing / 2 : 0);
|
|
796
|
-
frames.push(this.frameOf(Object.assign(Object.assign({}, axes), { origin:
|
|
795
|
+
frames.push(this.frameOf(Object.assign(Object.assign({}, axes), { origin: pointToWorld(axes, [u - shiftU, row * rowSpacing - shiftV, 0]) })));
|
|
797
796
|
}
|
|
798
797
|
}
|
|
799
798
|
return frames;
|
|
800
799
|
}
|
|
801
|
-
/**
|
|
802
|
-
* The widest spread's axis, pointing toward the first point, or with its largest component
|
|
803
|
-
* positive when the first point lies across it.
|
|
804
|
-
* @ignore true
|
|
805
|
-
*/
|
|
806
800
|
alongWidest(widest, first, spread) {
|
|
807
801
|
const toFirst = this.vector.dot({ first, second: widest });
|
|
808
802
|
if (!(Math.abs(toFirst) > 1e-9 * Math.sqrt(spread))) {
|
|
@@ -810,32 +804,17 @@ export class Frame {
|
|
|
810
804
|
}
|
|
811
805
|
return toFirst < 0 ? this.vector.neg({ vector: widest }) : widest;
|
|
812
806
|
}
|
|
813
|
-
/**
|
|
814
|
-
* Where the first point lies from the center, in the fitted plane, or the next point that does
|
|
815
|
-
* not sit on the center: the X axis of points that spread evenly every way in their plane.
|
|
816
|
-
* @ignore true
|
|
817
|
-
*/
|
|
818
807
|
towardFirstPoint(offsets, normal, spread) {
|
|
819
808
|
return offsets
|
|
820
809
|
.map(offset => this.vector.sub({ first: offset, second: this.vector.mul({ vector: normal, scalar: this.vector.dot({ first: offset, second: normal }) }) }))
|
|
821
810
|
.find(inPlane => this.vector.length({ vector: inPlane }) > 1e-9 * Math.sqrt(spread));
|
|
822
811
|
}
|
|
823
|
-
/**
|
|
824
|
-
* @ignore true
|
|
825
|
-
*/
|
|
826
812
|
translated(axes, translation) {
|
|
827
813
|
return this.frameOf(Object.assign(Object.assign({}, axes), { origin: this.vector.add({ first: axes.origin, second: translation }) }));
|
|
828
814
|
}
|
|
829
|
-
/**
|
|
830
|
-
* @ignore true
|
|
831
|
-
*/
|
|
832
815
|
offsetBy(axes, distance) {
|
|
833
816
|
return this.frameOf(Object.assign(Object.assign({}, axes), { origin: this.vector.add({ first: axes.origin, second: this.vector.mul({ vector: axes.z, scalar: distance }) }) }));
|
|
834
817
|
}
|
|
835
|
-
/**
|
|
836
|
-
* The axes turned about one of their own by `angle` radians, through their origin.
|
|
837
|
-
* @ignore true
|
|
838
|
-
*/
|
|
839
818
|
turned(axes, axis, angle) {
|
|
840
819
|
const c = Math.cos(angle);
|
|
841
820
|
const s = Math.sin(angle);
|
|
@@ -855,78 +834,24 @@ export class Frame {
|
|
|
855
834
|
}
|
|
856
835
|
}
|
|
857
836
|
}
|
|
858
|
-
/**
|
|
859
|
-
* @ignore true
|
|
860
|
-
*/
|
|
861
837
|
flipped(axes) {
|
|
862
838
|
return this.frameOf({ origin: axes.origin, x: axes.x, y: this.vector.neg({ vector: axes.y }), z: this.vector.neg({ vector: axes.z }) });
|
|
863
839
|
}
|
|
864
|
-
/**
|
|
865
|
-
* @ignore true
|
|
866
|
-
*/
|
|
867
|
-
childToWorld(parent, child) {
|
|
868
|
-
return this.frameOf({
|
|
869
|
-
origin: this.vector.add({ first: parent.origin, second: this.along(parent, ...child.origin) }),
|
|
870
|
-
x: this.along(parent, ...child.x),
|
|
871
|
-
y: this.along(parent, ...child.y),
|
|
872
|
-
z: this.along(parent, ...child.z),
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* @ignore true
|
|
877
|
-
*/
|
|
878
|
-
childToLocal(parent, child) {
|
|
879
|
-
return this.frameOf({
|
|
880
|
-
origin: this.against(parent, this.vector.sub({ first: child.origin, second: parent.origin })),
|
|
881
|
-
x: this.against(parent, child.x),
|
|
882
|
-
y: this.against(parent, child.y),
|
|
883
|
-
z: this.against(parent, child.z),
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* The vector `u` along `x`, `v` along `y` and `w` along `z` of the axes, from their origin.
|
|
888
|
-
* @ignore true
|
|
889
|
-
*/
|
|
890
|
-
along(axes, u, v, w) {
|
|
891
|
-
return this.vector.add({ first: this.combined(axes.x, u, axes.y, v), second: this.vector.mul({ vector: axes.z, scalar: w }) });
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* The same vector read against the axes: its components along `x`, `y` and `z`.
|
|
895
|
-
* @ignore true
|
|
896
|
-
*/
|
|
897
|
-
against(axes, vector) {
|
|
898
|
-
return [this.vector.dot({ first: vector, second: axes.x }), this.vector.dot({ first: vector, second: axes.y }), this.vector.dot({ first: vector, second: axes.z })];
|
|
899
|
-
}
|
|
900
|
-
/**
|
|
901
|
-
* `first` scaled by `a` plus `second` scaled by `b`.
|
|
902
|
-
* @ignore true
|
|
903
|
-
*/
|
|
904
840
|
combined(first, a, second, b) {
|
|
905
841
|
return this.vector.add({ first: this.vector.mul({ vector: first, scalar: a }), second: this.vector.mul({ vector: second, scalar: b }) });
|
|
906
842
|
}
|
|
907
|
-
/**
|
|
908
|
-
* Flips a unit vector whose largest component is negative, so a sign the data leaves open is
|
|
909
|
-
* decided the same way every time. Components within 1e-12 of each other count as equal and the
|
|
910
|
-
* first of them decides, so rounding cannot tip the choice; OCCT's frames break the tie the
|
|
911
|
-
* same way.
|
|
912
|
-
* @ignore true
|
|
913
|
-
*/
|
|
914
843
|
withLargestPositive(vector) {
|
|
915
844
|
let largest = 0;
|
|
916
845
|
for (let i = 1; i < 3; i++) {
|
|
917
|
-
if (Math.abs(vector[i]) > Math.abs(vector[largest]) +
|
|
846
|
+
if (Math.abs(vector[i]) > Math.abs(vector[largest]) + EQUAL_COMPONENT_TOLERANCE) {
|
|
918
847
|
largest = i;
|
|
919
848
|
}
|
|
920
849
|
}
|
|
921
850
|
return vector[largest] < 0 ? this.vector.neg({ vector }) : vector;
|
|
922
851
|
}
|
|
923
|
-
/**
|
|
924
|
-
* The column-major matrix carrying the `from` axes onto the `to` axes.
|
|
925
|
-
* @ignore true
|
|
926
|
-
*/
|
|
927
852
|
matrixBetween(from, to) {
|
|
928
|
-
const columns = [0, 1, 2].map(i =>
|
|
929
|
-
const origin =
|
|
853
|
+
const columns = [0, 1, 2].map(i => vectorToWorld(to, [from.x[i], from.y[i], from.z[i]]));
|
|
854
|
+
const origin = pointToWorld(to, this.vector.neg({ vector: vectorToLocal(from, from.origin) }));
|
|
930
855
|
return [
|
|
931
856
|
...columns[0], 0,
|
|
932
857
|
...columns[1], 0,
|
|
@@ -934,10 +859,6 @@ export class Frame {
|
|
|
934
859
|
...origin, 1,
|
|
935
860
|
];
|
|
936
861
|
}
|
|
937
|
-
/**
|
|
938
|
-
* The axes of a frame a caller handed in, squared, or an error naming the input at fault.
|
|
939
|
-
* @ignore true
|
|
940
|
-
*/
|
|
941
862
|
axesOf(frame, property, subject = `\`${property}\``) {
|
|
942
863
|
if (!isFrameShaped(frame)) {
|
|
943
864
|
throw new InputError(`${subject} is not a frame: it needs \`origin\`, \`normal\` and \`direction\`, three finite numbers each.`, property);
|
|
@@ -948,31 +869,18 @@ export class Frame {
|
|
|
948
869
|
property,
|
|
949
870
|
});
|
|
950
871
|
}
|
|
951
|
-
/**
|
|
952
|
-
* The axes of every frame in a list a caller handed in, or an error naming the list and the
|
|
953
|
-
* position at fault.
|
|
954
|
-
* @ignore true
|
|
955
|
-
*/
|
|
956
872
|
axesOfEach(frames, property) {
|
|
957
873
|
if (!Array.isArray(frames)) {
|
|
958
874
|
throw new InputError(`\`${property}\` is not a list of frames.`, property);
|
|
959
875
|
}
|
|
960
876
|
return frames.map((frame, index) => this.axesOf(frame, property, `\`${property}\` at position ${index}`));
|
|
961
877
|
}
|
|
962
|
-
/**
|
|
963
|
-
* @ignore true
|
|
964
|
-
*/
|
|
965
878
|
axisOf(axis) {
|
|
966
879
|
if (axis !== Inputs.Frame.frameAxisEnum.x && axis !== Inputs.Frame.frameAxisEnum.y && axis !== Inputs.Frame.frameAxisEnum.z) {
|
|
967
880
|
throw new InputError(`\`axis\` must be x, y or z; it is ${String(axis)}.`, "axis");
|
|
968
881
|
}
|
|
969
882
|
return axis;
|
|
970
883
|
}
|
|
971
|
-
/**
|
|
972
|
-
* An origin with a unit normal and a unit X axis square to it, or an error with the message for
|
|
973
|
-
* the part that cannot be squared, naming `property`, or that part when none is given.
|
|
974
|
-
* @ignore true
|
|
975
|
-
*/
|
|
976
884
|
squared(origin, normal, direction, faults) {
|
|
977
885
|
var _a;
|
|
978
886
|
const axes = squareFrame(origin, normal, direction);
|
|
@@ -981,34 +889,21 @@ export class Frame {
|
|
|
981
889
|
}
|
|
982
890
|
return axes;
|
|
983
891
|
}
|
|
984
|
-
/**
|
|
985
|
-
* The frame the axes describe, as new arrays.
|
|
986
|
-
* @ignore true
|
|
987
|
-
*/
|
|
988
892
|
frameOf(axes) {
|
|
989
893
|
return { origin: [...axes.origin], normal: [...axes.z], direction: [...axes.x] };
|
|
990
894
|
}
|
|
991
|
-
/**
|
|
992
|
-
* @ignore true
|
|
993
|
-
*/
|
|
994
895
|
pointOf(value, property) {
|
|
995
896
|
if (!isTriple(value)) {
|
|
996
897
|
throw new InputError(`\`${property}\` is not a point: it needs three finite numbers.`, property);
|
|
997
898
|
}
|
|
998
899
|
return [...value];
|
|
999
900
|
}
|
|
1000
|
-
/**
|
|
1001
|
-
* @ignore true
|
|
1002
|
-
*/
|
|
1003
901
|
vectorOf(value, property) {
|
|
1004
902
|
if (!isTriple(value)) {
|
|
1005
903
|
throw new InputError(`\`${property}\` is not a vector: it needs three finite numbers.`, property);
|
|
1006
904
|
}
|
|
1007
905
|
return [...value];
|
|
1008
906
|
}
|
|
1009
|
-
/**
|
|
1010
|
-
* @ignore true
|
|
1011
|
-
*/
|
|
1012
907
|
pointsOf(value, property) {
|
|
1013
908
|
if (!Array.isArray(value)) {
|
|
1014
909
|
throw new InputError(`\`${property}\` is not a list of points.`, property);
|
|
@@ -1019,18 +914,12 @@ export class Frame {
|
|
|
1019
914
|
}
|
|
1020
915
|
return value.map(point => [...point]);
|
|
1021
916
|
}
|
|
1022
|
-
/**
|
|
1023
|
-
* @ignore true
|
|
1024
|
-
*/
|
|
1025
917
|
numberOf(value, property) {
|
|
1026
918
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1027
919
|
throw new InputError(`\`${property}\` is not a finite number.`, property);
|
|
1028
920
|
}
|
|
1029
921
|
return value;
|
|
1030
922
|
}
|
|
1031
|
-
/**
|
|
1032
|
-
* @ignore true
|
|
1033
|
-
*/
|
|
1034
923
|
countOf(value, property) {
|
|
1035
924
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
1036
925
|
throw new InputError(`\`${property}\` must be a whole number of at least 1.`, property);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as Inputs from "../../inputs";
|
|
2
|
+
import type { ThreePointArc } from "./helper-types";
|
|
3
|
+
type Point3 = Inputs.Base.Point3;
|
|
4
|
+
export declare const arcThroughThreePoints: (start: Point3, middle: Point3, end: Point3) => ThreePointArc | undefined;
|
|
5
|
+
export declare const pointsOnArc: (arc: ThreePointArc, start: Point3, end: Point3, segments: number) => Point3[];
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { add3, cross3, dot3, length3, scale3, subtract3 } from "./vectors";
|
|
2
|
+
const FULL_TURN = 2 * Math.PI;
|
|
3
|
+
const COLLINEAR_RATIO = 1e-12;
|
|
4
|
+
export const arcThroughThreePoints = (start, middle, end) => {
|
|
5
|
+
const toMiddle = subtract3(middle, start);
|
|
6
|
+
const toEnd = subtract3(end, start);
|
|
7
|
+
const normal = cross3(toMiddle, toEnd);
|
|
8
|
+
const twiceArea = length3(normal);
|
|
9
|
+
const reach = Math.max(dot3(toMiddle, toMiddle), dot3(toEnd, toEnd));
|
|
10
|
+
if (!(twiceArea > COLLINEAR_RATIO * reach)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const offset = scale3(add3(scale3(cross3(normal, toMiddle), dot3(toEnd, toEnd)), scale3(cross3(toEnd, normal), dot3(toMiddle, toMiddle))), 1 / (2 * twiceArea * twiceArea));
|
|
14
|
+
const center = add3(start, offset);
|
|
15
|
+
const radius = length3(offset);
|
|
16
|
+
const x = scale3(offset, -1 / radius);
|
|
17
|
+
const y = scale3(cross3(normal, x), 1 / twiceArea);
|
|
18
|
+
const towardEnd = subtract3(end, center);
|
|
19
|
+
const angle = Math.atan2(dot3(towardEnd, y), dot3(towardEnd, x));
|
|
20
|
+
return { center, x, y, radius, sweep: angle > 0 ? angle : angle + FULL_TURN };
|
|
21
|
+
};
|
|
22
|
+
export const pointsOnArc = (arc, start, end, segments) => {
|
|
23
|
+
const points = [start];
|
|
24
|
+
for (let step = 1; step < segments; step++) {
|
|
25
|
+
const angle = arc.sweep * step / segments;
|
|
26
|
+
points.push(add3(arc.center, add3(scale3(arc.x, arc.radius * Math.cos(angle)), scale3(arc.y, arc.radius * Math.sin(angle)))));
|
|
27
|
+
}
|
|
28
|
+
points.push(end);
|
|
29
|
+
return points;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function crc32(data: Uint8Array): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BYTE_BITS, BYTE_MASK, BYTE_VALUES, CRC32_ALL_ONES, CRC32_POLYNOMIAL } from "./zip.constants";
|
|
2
|
+
let table;
|
|
3
|
+
function crcTable() {
|
|
4
|
+
const values = new Uint32Array(BYTE_VALUES);
|
|
5
|
+
for (let byte = 0; byte < BYTE_VALUES; byte++) {
|
|
6
|
+
let value = byte;
|
|
7
|
+
for (let bit = 0; bit < BYTE_BITS; bit++) {
|
|
8
|
+
value = value & 1 ? CRC32_POLYNOMIAL ^ (value >>> 1) : value >>> 1;
|
|
9
|
+
}
|
|
10
|
+
values[byte] = value >>> 0;
|
|
11
|
+
}
|
|
12
|
+
return values;
|
|
13
|
+
}
|
|
14
|
+
export function crc32(data) {
|
|
15
|
+
const values = (table !== null && table !== void 0 ? table : (table = crcTable()));
|
|
16
|
+
let crc = CRC32_ALL_ONES;
|
|
17
|
+
for (let at = 0; at < data.length; at++) {
|
|
18
|
+
crc = values[(crc ^ data[at]) & BYTE_MASK] ^ (crc >>> BYTE_BITS);
|
|
19
|
+
}
|
|
20
|
+
return (crc ^ CRC32_ALL_ONES) >>> 0;
|
|
21
|
+
}
|
|
@@ -7,114 +7,31 @@ export declare class DxfGenerator {
|
|
|
7
7
|
* Generate a complete DXF file content from path-based entities
|
|
8
8
|
*/
|
|
9
9
|
generateDxf(dxfInputs: Inputs.IO.DxfModelDto): string;
|
|
10
|
-
/**
|
|
11
|
-
* Generate DXF header section
|
|
12
|
-
*/
|
|
13
10
|
private generateHeader;
|
|
14
|
-
/**
|
|
15
|
-
* Generate DXF tables section (layers, line types, etc.)
|
|
16
|
-
*/
|
|
17
11
|
private generateTables;
|
|
18
|
-
/**
|
|
19
|
-
* Generate line type table
|
|
20
|
-
*/
|
|
21
12
|
private generateLineTypeTable;
|
|
22
|
-
/**
|
|
23
|
-
* Generate text style table
|
|
24
|
-
*/
|
|
25
13
|
private generateStyleTable;
|
|
26
|
-
/**
|
|
27
|
-
* Generate VPORT table (viewport configuration)
|
|
28
|
-
*/
|
|
29
14
|
private generateVportTable;
|
|
30
|
-
/**
|
|
31
|
-
* Generate VIEW table (empty but required for AC1009)
|
|
32
|
-
*/
|
|
33
15
|
private generateViewTable;
|
|
34
|
-
/**
|
|
35
|
-
* Generate UCS table (user coordinate system - empty but required for AC1009)
|
|
36
|
-
*/
|
|
37
16
|
private generateUcsTable;
|
|
38
|
-
/**
|
|
39
|
-
* Generate APPID table (application ID - required for AC1009)
|
|
40
|
-
*/
|
|
41
17
|
private generateAppidTable;
|
|
42
|
-
/**
|
|
43
|
-
* Generate DIMSTYLE table (dimension style - empty but required for AC1009)
|
|
44
|
-
*/
|
|
45
18
|
private generateDimstyleTable;
|
|
46
|
-
/**
|
|
47
|
-
* Generate blocks section (empty but required)
|
|
48
|
-
*/
|
|
49
19
|
private generateBlocks;
|
|
50
|
-
/**
|
|
51
|
-
* Generate layer table based on unique layers in all parts
|
|
52
|
-
*/
|
|
53
20
|
private generateLayerTable;
|
|
54
|
-
/**
|
|
55
|
-
* Generate DXF entities section with all path segments
|
|
56
|
-
*/
|
|
57
21
|
private generateEntities;
|
|
58
|
-
/**
|
|
59
|
-
* Generate entity for a single segment based on its type
|
|
60
|
-
*/
|
|
61
22
|
private generateSegmentEntity;
|
|
62
|
-
/**
|
|
63
|
-
* Type guard for line segments
|
|
64
|
-
*/
|
|
65
23
|
private isLineSegment;
|
|
66
|
-
/**
|
|
67
|
-
* Type guard for arc segments
|
|
68
|
-
*/
|
|
69
24
|
private isArcSegment;
|
|
70
|
-
/**
|
|
71
|
-
* Type guard for circle segments
|
|
72
|
-
*/
|
|
73
25
|
private isCircleSegment;
|
|
74
|
-
/**
|
|
75
|
-
* Type guard for polyline segments
|
|
76
|
-
*/
|
|
77
26
|
private isPolylineSegment;
|
|
78
|
-
/**
|
|
79
|
-
* Type guard for spline segments
|
|
80
|
-
*/
|
|
81
27
|
private isSplineSegment;
|
|
82
|
-
/**
|
|
83
|
-
* Generate a LINE entity
|
|
84
|
-
*/
|
|
85
28
|
private generateLineEntity;
|
|
86
|
-
/**
|
|
87
|
-
* Generate a CIRCLE entity
|
|
88
|
-
*/
|
|
89
29
|
private generateCircleEntity;
|
|
90
|
-
/**
|
|
91
|
-
* Generate an ARC entity
|
|
92
|
-
*/
|
|
93
30
|
private generateArcEntity;
|
|
94
|
-
/**
|
|
95
|
-
* Generate a LWPOLYLINE entity
|
|
96
|
-
*/
|
|
97
31
|
private generatePolylineEntity;
|
|
98
|
-
/**
|
|
99
|
-
* Generate a SPLINE entity
|
|
100
|
-
*/
|
|
101
32
|
private generateSplineEntity;
|
|
102
|
-
/**
|
|
103
|
-
* Check if polyline should be closed (first and last points are the same)
|
|
104
|
-
*/
|
|
105
33
|
private isClosedPolyline;
|
|
106
|
-
/**
|
|
107
|
-
* Get next entity handle as hex string
|
|
108
|
-
*/
|
|
109
34
|
private getNextHandle;
|
|
110
|
-
/**
|
|
111
|
-
* Convert a hex color (#RRGGBB) to DXF color codes, as the nearest ACI index or as true color
|
|
112
|
-
* depending on the colorFormat setting; anything else is written as ACI 7
|
|
113
|
-
*/
|
|
114
35
|
private convertColorToDxf;
|
|
115
|
-
/**
|
|
116
|
-
* Convert RGB values to nearest AutoCAD Color Index (ACI)
|
|
117
|
-
* Uses a simplified mapping to standard ACI colors
|
|
118
|
-
*/
|
|
119
36
|
private rgbToAciColorIndex;
|
|
120
37
|
}
|