@bitbybit-dev/base 0.19.8 → 0.19.9
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/babel.config.cjs +1 -0
- package/babel.config.d.cts +5 -0
- package/index.d.ts +1 -0
- package/{index.ts → index.js} +1 -2
- package/lib/api/index.js +1 -0
- package/lib/api/inputs/base-inputs.d.ts +35 -0
- package/lib/api/inputs/base-inputs.js +1 -0
- package/lib/api/inputs/{color-inputs.ts → color-inputs.d.ts} +26 -48
- package/lib/api/inputs/color-inputs.js +164 -0
- package/lib/api/inputs/index.js +9 -0
- package/lib/api/inputs/inputs.js +9 -0
- package/lib/api/inputs/{lists-inputs.ts → lists-inputs.d.ts} +91 -190
- package/lib/api/inputs/lists-inputs.js +576 -0
- package/lib/api/inputs/{logic-inputs.ts → logic-inputs.d.ts} +24 -46
- package/lib/api/inputs/logic-inputs.js +111 -0
- package/lib/api/inputs/{math-inputs.ts → math-inputs.d.ts} +53 -97
- package/lib/api/inputs/math-inputs.js +391 -0
- package/lib/api/inputs/{point-inputs.ts → point-inputs.d.ts} +77 -168
- package/lib/api/inputs/point-inputs.js +521 -0
- package/lib/api/inputs/text-inputs.d.ts +83 -0
- package/lib/api/inputs/text-inputs.js +120 -0
- package/lib/api/inputs/{transforms-inputs.ts → transforms-inputs.d.ts} +35 -64
- package/lib/api/inputs/transforms-inputs.js +200 -0
- package/lib/api/inputs/{vector-inputs.ts → vector-inputs.d.ts} +48 -104
- package/lib/api/inputs/vector-inputs.js +304 -0
- package/lib/api/services/color.d.ts +114 -0
- package/lib/api/services/{color.ts → color.js} +15 -34
- package/lib/api/services/geometry-helper.d.ts +15 -0
- package/lib/api/services/{geometry-helper.ts → geometry-helper.js} +31 -43
- package/lib/api/services/{index.ts → index.d.ts} +1 -1
- package/lib/api/services/index.js +9 -0
- package/lib/api/services/lists.d.ts +287 -0
- package/lib/api/services/{lists.ts → lists.js} +59 -83
- package/lib/api/services/logic.d.ts +99 -0
- package/lib/api/services/{logic.ts → logic.js} +24 -32
- package/lib/api/services/math.d.ts +349 -0
- package/lib/api/services/{math.ts → math.js} +71 -136
- package/lib/api/services/point.d.ts +222 -0
- package/lib/api/services/{point.ts → point.js} +32 -67
- package/lib/api/services/text.d.ts +69 -0
- package/lib/api/services/{text.ts → text.js} +7 -17
- package/lib/api/services/transforms.d.ts +122 -0
- package/lib/api/services/{transforms.ts → transforms.js} +37 -83
- package/lib/api/services/vector.d.ts +320 -0
- package/lib/api/services/{vector.ts → vector.js} +42 -80
- package/lib/{index.ts → index.d.ts} +0 -1
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/lib/api/inputs/base-inputs.ts +0 -18
- package/lib/api/inputs/text-inputs.ts +0 -108
- package/lib/api/services/color.test.ts +0 -86
- package/lib/api/services/lists.test.ts +0 -612
- package/lib/api/services/logic.test.ts +0 -187
- package/lib/api/services/math.test.ts +0 -622
- package/lib/api/services/text.test.ts +0 -55
- package/lib/api/services/vector.test.ts +0 -360
- package/tsconfig.bitbybit.json +0 -26
- package/tsconfig.json +0 -24
- /package/lib/api/{index.ts → index.d.ts} +0 -0
- /package/lib/api/inputs/{index.ts → index.d.ts} +0 -0
- /package/lib/api/inputs/{inputs.ts → inputs.d.ts} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
import { MathBitByBit } from "./math";
|
|
3
|
+
export declare class Color {
|
|
4
|
+
private readonly math;
|
|
5
|
+
constructor(math: MathBitByBit);
|
|
6
|
+
/**
|
|
7
|
+
* Creates a hex color
|
|
8
|
+
* @param inputs Color hex
|
|
9
|
+
* @returns color string
|
|
10
|
+
* @group create
|
|
11
|
+
* @shortname color
|
|
12
|
+
* @drawable false
|
|
13
|
+
*/
|
|
14
|
+
hexColor(inputs: Inputs.Color.HexDto): Inputs.Base.Color;
|
|
15
|
+
/**
|
|
16
|
+
* Creates rgb color from hex
|
|
17
|
+
* @param inputs Color hex
|
|
18
|
+
* @returns rgb color
|
|
19
|
+
* @group convert
|
|
20
|
+
* @shortname hex to rgb
|
|
21
|
+
* @drawable false
|
|
22
|
+
*/
|
|
23
|
+
hexToRgb(inputs: Inputs.Color.HexDto): Inputs.Base.ColorRGB;
|
|
24
|
+
/**
|
|
25
|
+
* Creates hex color from rgb
|
|
26
|
+
* @param inputs Color hext
|
|
27
|
+
* @returns hex color
|
|
28
|
+
* @group convert
|
|
29
|
+
* @shortname rgb to hex
|
|
30
|
+
* @drawable false
|
|
31
|
+
*/
|
|
32
|
+
rgbToHex(inputs: Inputs.Color.RGBMinMaxDto): Inputs.Base.Color;
|
|
33
|
+
/**
|
|
34
|
+
* Creates hex color from rgb obj that contains {r, g, b} properties in certain range
|
|
35
|
+
* @param inputs Color hext
|
|
36
|
+
* @returns hex color string
|
|
37
|
+
* @group convert
|
|
38
|
+
* @shortname rgb obj to hex
|
|
39
|
+
* @drawable false
|
|
40
|
+
*/
|
|
41
|
+
rgbObjToHex(inputs: Inputs.Color.RGBObjectMaxDto): Inputs.Base.Color;
|
|
42
|
+
/**
|
|
43
|
+
* Creates rgb color from hex and maps to different range if needed
|
|
44
|
+
* @param inputs Color hext
|
|
45
|
+
* @returns rgb color
|
|
46
|
+
* @group convert
|
|
47
|
+
* @shortname hex to rgb mapped
|
|
48
|
+
* @drawable false
|
|
49
|
+
*/
|
|
50
|
+
hexToRgbMapped(inputs: Inputs.Color.HexDtoMapped): Inputs.Base.ColorRGB;
|
|
51
|
+
/**
|
|
52
|
+
* Get red param
|
|
53
|
+
* @param inputs Color hext
|
|
54
|
+
* @returns rgb color
|
|
55
|
+
* @group hex to
|
|
56
|
+
* @shortname red
|
|
57
|
+
* @drawable false
|
|
58
|
+
*/
|
|
59
|
+
getRedParam(inputs: Inputs.Color.HexDtoMapped): number;
|
|
60
|
+
/**
|
|
61
|
+
* Get green param
|
|
62
|
+
* @param inputs Color hext
|
|
63
|
+
* @returns rgb color
|
|
64
|
+
* @group hex to
|
|
65
|
+
* @shortname green
|
|
66
|
+
* @drawable false
|
|
67
|
+
*/
|
|
68
|
+
getGreenParam(inputs: Inputs.Color.HexDtoMapped): number;
|
|
69
|
+
/**
|
|
70
|
+
* Get blue param
|
|
71
|
+
* @param inputs Color hext
|
|
72
|
+
* @returns blue param
|
|
73
|
+
* @group hex to
|
|
74
|
+
* @shortname blue
|
|
75
|
+
* @drawable false
|
|
76
|
+
*/
|
|
77
|
+
getBlueParam(inputs: Inputs.Color.HexDtoMapped): number;
|
|
78
|
+
/**
|
|
79
|
+
* RGB to red
|
|
80
|
+
* @param inputs Color rgb
|
|
81
|
+
* @returns red param
|
|
82
|
+
* @group rgb to
|
|
83
|
+
* @shortname red
|
|
84
|
+
* @drawable false
|
|
85
|
+
*/
|
|
86
|
+
rgbToRed(inputs: Inputs.Color.RGBObjectDto): number;
|
|
87
|
+
/**
|
|
88
|
+
* RGB to green
|
|
89
|
+
* @param inputs Color rgb
|
|
90
|
+
* @returns green param
|
|
91
|
+
* @group rgb to
|
|
92
|
+
* @shortname green
|
|
93
|
+
* @drawable false
|
|
94
|
+
*/
|
|
95
|
+
rgbToGreen(inputs: Inputs.Color.RGBObjectDto): number;
|
|
96
|
+
/**
|
|
97
|
+
* RGB to blue
|
|
98
|
+
* @param inputs Color rgb
|
|
99
|
+
* @returns blue param
|
|
100
|
+
* @group rgb to
|
|
101
|
+
* @shortname blue
|
|
102
|
+
* @drawable false
|
|
103
|
+
*/
|
|
104
|
+
rgbToBlue(inputs: Inputs.Color.RGBObjectDto): number;
|
|
105
|
+
/**
|
|
106
|
+
* Invert color
|
|
107
|
+
* @param inputs hex color and black and white option
|
|
108
|
+
* @returns inverted color
|
|
109
|
+
* @group hex to
|
|
110
|
+
* @shortname invert color
|
|
111
|
+
* @drawable false
|
|
112
|
+
*/
|
|
113
|
+
invert(inputs: Inputs.Color.InvertHexDto): Inputs.Base.Color;
|
|
114
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import * as Inputs from "../inputs";
|
|
2
|
-
import { MathBitByBit } from "./math";
|
|
3
|
-
|
|
4
1
|
export class Color {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
constructor(math) {
|
|
3
|
+
this.math = math;
|
|
4
|
+
}
|
|
9
5
|
/**
|
|
10
6
|
* Creates a hex color
|
|
11
7
|
* @param inputs Color hex
|
|
@@ -14,10 +10,9 @@ export class Color {
|
|
|
14
10
|
* @shortname color
|
|
15
11
|
* @drawable false
|
|
16
12
|
*/
|
|
17
|
-
hexColor(inputs
|
|
13
|
+
hexColor(inputs) {
|
|
18
14
|
return inputs.color;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
/**
|
|
22
17
|
* Creates rgb color from hex
|
|
23
18
|
* @param inputs Color hex
|
|
@@ -26,7 +21,7 @@ export class Color {
|
|
|
26
21
|
* @shortname hex to rgb
|
|
27
22
|
* @drawable false
|
|
28
23
|
*/
|
|
29
|
-
hexToRgb(inputs
|
|
24
|
+
hexToRgb(inputs) {
|
|
30
25
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(inputs.color);
|
|
31
26
|
return result ? {
|
|
32
27
|
r: parseInt(result[1], 16),
|
|
@@ -34,7 +29,6 @@ export class Color {
|
|
|
34
29
|
b: parseInt(result[3], 16)
|
|
35
30
|
} : undefined;
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
/**
|
|
39
33
|
* Creates hex color from rgb
|
|
40
34
|
* @param inputs Color hext
|
|
@@ -43,11 +37,10 @@ export class Color {
|
|
|
43
37
|
* @shortname rgb to hex
|
|
44
38
|
* @drawable false
|
|
45
39
|
*/
|
|
46
|
-
rgbToHex(inputs
|
|
40
|
+
rgbToHex(inputs) {
|
|
47
41
|
let r = inputs.r;
|
|
48
42
|
let g = inputs.g;
|
|
49
43
|
let b = inputs.b;
|
|
50
|
-
|
|
51
44
|
// sometimes rgb values are in 0 - 100 or 0 - 1 ranges
|
|
52
45
|
// so we need to remap them to 0 - 255
|
|
53
46
|
if (inputs.max !== 255) {
|
|
@@ -55,13 +48,9 @@ export class Color {
|
|
|
55
48
|
g = Math.round(this.math.remap({ number: g, fromLow: inputs.min, fromHigh: inputs.max, toLow: 0, toHigh: 255 }));
|
|
56
49
|
b = Math.round(this.math.remap({ number: b, fromLow: inputs.min, fromHigh: inputs.max, toLow: 0, toHigh: 255 }));
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
const s = `#${Number(0x1000000 + r * 0x10000 + g * 0x100 + b).toString(16).substring(1, 7)}`;
|
|
60
|
-
|
|
61
52
|
return s;
|
|
62
53
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
54
|
/**
|
|
66
55
|
* Creates hex color from rgb obj that contains {r, g, b} properties in certain range
|
|
67
56
|
* @param inputs Color hext
|
|
@@ -70,10 +59,9 @@ export class Color {
|
|
|
70
59
|
* @shortname rgb obj to hex
|
|
71
60
|
* @drawable false
|
|
72
61
|
*/
|
|
73
|
-
rgbObjToHex(inputs
|
|
62
|
+
rgbObjToHex(inputs) {
|
|
74
63
|
return this.rgbToHex({ r: inputs.rgb.r, g: inputs.rgb.g, b: inputs.rgb.b, min: inputs.min, max: inputs.max });
|
|
75
64
|
}
|
|
76
|
-
|
|
77
65
|
/**
|
|
78
66
|
* Creates rgb color from hex and maps to different range if needed
|
|
79
67
|
* @param inputs Color hext
|
|
@@ -82,7 +70,7 @@ export class Color {
|
|
|
82
70
|
* @shortname hex to rgb mapped
|
|
83
71
|
* @drawable false
|
|
84
72
|
*/
|
|
85
|
-
hexToRgbMapped(inputs
|
|
73
|
+
hexToRgbMapped(inputs) {
|
|
86
74
|
const rgb = this.hexToRgb(inputs);
|
|
87
75
|
return {
|
|
88
76
|
r: this.math.remap({ number: rgb.r, fromLow: 0, fromHigh: 255, toLow: inputs.from, toHigh: inputs.to }),
|
|
@@ -90,7 +78,6 @@ export class Color {
|
|
|
90
78
|
b: this.math.remap({ number: rgb.b, fromLow: 0, fromHigh: 255, toLow: inputs.from, toHigh: inputs.to }),
|
|
91
79
|
};
|
|
92
80
|
}
|
|
93
|
-
|
|
94
81
|
/**
|
|
95
82
|
* Get red param
|
|
96
83
|
* @param inputs Color hext
|
|
@@ -99,11 +86,10 @@ export class Color {
|
|
|
99
86
|
* @shortname red
|
|
100
87
|
* @drawable false
|
|
101
88
|
*/
|
|
102
|
-
getRedParam(inputs
|
|
89
|
+
getRedParam(inputs) {
|
|
103
90
|
const rgb = this.hexToRgbMapped(inputs);
|
|
104
91
|
return rgb.r;
|
|
105
92
|
}
|
|
106
|
-
|
|
107
93
|
/**
|
|
108
94
|
* Get green param
|
|
109
95
|
* @param inputs Color hext
|
|
@@ -112,11 +98,10 @@ export class Color {
|
|
|
112
98
|
* @shortname green
|
|
113
99
|
* @drawable false
|
|
114
100
|
*/
|
|
115
|
-
getGreenParam(inputs
|
|
101
|
+
getGreenParam(inputs) {
|
|
116
102
|
const rgb = this.hexToRgbMapped(inputs);
|
|
117
103
|
return rgb.g;
|
|
118
104
|
}
|
|
119
|
-
|
|
120
105
|
/**
|
|
121
106
|
* Get blue param
|
|
122
107
|
* @param inputs Color hext
|
|
@@ -125,11 +110,10 @@ export class Color {
|
|
|
125
110
|
* @shortname blue
|
|
126
111
|
* @drawable false
|
|
127
112
|
*/
|
|
128
|
-
getBlueParam(inputs
|
|
113
|
+
getBlueParam(inputs) {
|
|
129
114
|
const rgb = this.hexToRgbMapped(inputs);
|
|
130
115
|
return rgb.b;
|
|
131
116
|
}
|
|
132
|
-
|
|
133
117
|
/**
|
|
134
118
|
* RGB to red
|
|
135
119
|
* @param inputs Color rgb
|
|
@@ -138,10 +122,9 @@ export class Color {
|
|
|
138
122
|
* @shortname red
|
|
139
123
|
* @drawable false
|
|
140
124
|
*/
|
|
141
|
-
rgbToRed(inputs
|
|
125
|
+
rgbToRed(inputs) {
|
|
142
126
|
return inputs.rgb.r;
|
|
143
127
|
}
|
|
144
|
-
|
|
145
128
|
/**
|
|
146
129
|
* RGB to green
|
|
147
130
|
* @param inputs Color rgb
|
|
@@ -150,10 +133,9 @@ export class Color {
|
|
|
150
133
|
* @shortname green
|
|
151
134
|
* @drawable false
|
|
152
135
|
*/
|
|
153
|
-
rgbToGreen(inputs
|
|
136
|
+
rgbToGreen(inputs) {
|
|
154
137
|
return inputs.rgb.g;
|
|
155
138
|
}
|
|
156
|
-
|
|
157
139
|
/**
|
|
158
140
|
* RGB to blue
|
|
159
141
|
* @param inputs Color rgb
|
|
@@ -162,10 +144,9 @@ export class Color {
|
|
|
162
144
|
* @shortname blue
|
|
163
145
|
* @drawable false
|
|
164
146
|
*/
|
|
165
|
-
rgbToBlue(inputs
|
|
147
|
+
rgbToBlue(inputs) {
|
|
166
148
|
return inputs.rgb.b;
|
|
167
149
|
}
|
|
168
|
-
|
|
169
150
|
/**
|
|
170
151
|
* Invert color
|
|
171
152
|
* @param inputs hex color and black and white option
|
|
@@ -174,7 +155,7 @@ export class Color {
|
|
|
174
155
|
* @shortname invert color
|
|
175
156
|
* @drawable false
|
|
176
157
|
*/
|
|
177
|
-
invert(inputs
|
|
158
|
+
invert(inputs) {
|
|
178
159
|
const { r, g, b } = this.hexToRgbMapped({ color: inputs.color, from: 0, to: 255 });
|
|
179
160
|
if (inputs.blackAndWhite) {
|
|
180
161
|
return (r * 0.299 + g * 0.587 + b * 0.114) > 186
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
export declare class GeometryHelper {
|
|
3
|
+
transformControlPoints(transformation: number[][] | number[][][], transformedControlPoints: Inputs.Base.Point3[]): Inputs.Base.Point3[];
|
|
4
|
+
getFlatTransformations(transformation: number[][] | number[][][]): number[][];
|
|
5
|
+
getArrayDepth: (value: any) => number;
|
|
6
|
+
transformPointsByMatrixArray(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[];
|
|
7
|
+
transformPointsCoordinates(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[];
|
|
8
|
+
removeAllDuplicateVectors(vectors: number[][], tolerance?: number): number[][];
|
|
9
|
+
removeConsecutiveVectorDuplicates(vectors: number[][], checkFirstAndLast?: boolean, tolerance?: number): number[][];
|
|
10
|
+
vectorsTheSame(vec1: number[], vec2: number[], tolerance: number): boolean;
|
|
11
|
+
approxEq(num1: number, num2: number, tolerance: number): boolean;
|
|
12
|
+
removeConsecutivePointDuplicates(points: Inputs.Base.Point3[], checkFirstAndLast?: boolean, tolerance?: number): Inputs.Base.Point3[];
|
|
13
|
+
arePointsTheSame(pointA: Inputs.Base.Point3 | Inputs.Base.Point2, pointB: Inputs.Base.Point3 | Inputs.Base.Point2, tolerance: number): boolean;
|
|
14
|
+
private transformCoordinates;
|
|
15
|
+
}
|
|
@@ -1,41 +1,34 @@
|
|
|
1
|
-
import * as Inputs from "../inputs";
|
|
2
|
-
|
|
3
1
|
export class GeometryHelper {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
this.getArrayDepth = (value) => {
|
|
4
|
+
return Array.isArray(value) ?
|
|
5
|
+
1 + Math.max(...value.map(this.getArrayDepth)) :
|
|
6
|
+
0;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
transformControlPoints(transformation, transformedControlPoints) {
|
|
6
10
|
const transformationArrays = this.getFlatTransformations(transformation);
|
|
7
|
-
|
|
8
11
|
transformationArrays.forEach(transform => {
|
|
9
|
-
|
|
10
12
|
transformedControlPoints = this.transformPointsByMatrixArray(transformedControlPoints, transform);
|
|
11
13
|
});
|
|
12
14
|
return transformedControlPoints;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
getFlatTransformations(transformation: number[][] | number[][][]): number[][] {
|
|
16
|
+
getFlatTransformations(transformation) {
|
|
16
17
|
let transformationArrays = [];
|
|
17
|
-
|
|
18
18
|
if (this.getArrayDepth(transformation) === 3) {
|
|
19
19
|
transformation.forEach(transform => {
|
|
20
20
|
transformationArrays.push(...transform);
|
|
21
21
|
});
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
23
24
|
transformationArrays = transformation;
|
|
24
25
|
}
|
|
25
26
|
return transformationArrays;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getArrayDepth = (value): number => {
|
|
29
|
-
return Array.isArray(value) ?
|
|
30
|
-
1 + Math.max(...value.map(this.getArrayDepth)) :
|
|
31
|
-
0;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
transformPointsByMatrixArray(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[] {
|
|
27
|
+
}
|
|
28
|
+
transformPointsByMatrixArray(points, transform) {
|
|
35
29
|
return this.transformPointsCoordinates(points, transform);
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
transformPointsCoordinates(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[] {
|
|
31
|
+
transformPointsCoordinates(points, transform) {
|
|
39
32
|
const transformedPoints = [];
|
|
40
33
|
for (const pt of points) {
|
|
41
34
|
const transformedVector = this.transformCoordinates(pt[0], pt[1], pt[2], transform);
|
|
@@ -43,10 +36,9 @@ export class GeometryHelper {
|
|
|
43
36
|
}
|
|
44
37
|
return transformedPoints;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
// Algorithm works with arbitrary length numeric vectors. This algorithm is more costly for longer arrays of vectors
|
|
48
|
-
removeAllDuplicateVectors(vectors
|
|
49
|
-
const cleanVectors
|
|
40
|
+
removeAllDuplicateVectors(vectors, tolerance = 1e-7) {
|
|
41
|
+
const cleanVectors = [];
|
|
50
42
|
vectors.forEach(vector => {
|
|
51
43
|
// when there are no vectors in cleanVectors array that match the current vector, push it in.
|
|
52
44
|
if (!cleanVectors.some(s => this.vectorsTheSame(vector, s, tolerance))) {
|
|
@@ -55,10 +47,9 @@ export class GeometryHelper {
|
|
|
55
47
|
});
|
|
56
48
|
return cleanVectors;
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
// Algorithm works with arbitrary length numeric vectors.
|
|
60
|
-
removeConsecutiveVectorDuplicates(vectors
|
|
61
|
-
const vectorsRemaining
|
|
51
|
+
removeConsecutiveVectorDuplicates(vectors, checkFirstAndLast = true, tolerance = 1e-7) {
|
|
52
|
+
const vectorsRemaining = [];
|
|
62
53
|
if (vectors.length > 1) {
|
|
63
54
|
for (let i = 1; i < vectors.length; i++) {
|
|
64
55
|
const currentVector = vectors[i];
|
|
@@ -77,17 +68,18 @@ export class GeometryHelper {
|
|
|
77
68
|
vectorsRemaining.pop();
|
|
78
69
|
}
|
|
79
70
|
}
|
|
80
|
-
}
|
|
71
|
+
}
|
|
72
|
+
else if (vectors.length === 1) {
|
|
81
73
|
vectorsRemaining.push(...vectors);
|
|
82
74
|
}
|
|
83
75
|
return vectorsRemaining;
|
|
84
76
|
}
|
|
85
|
-
|
|
86
|
-
vectorsTheSame(vec1: number[], vec2: number[], tolerance: number) {
|
|
77
|
+
vectorsTheSame(vec1, vec2, tolerance) {
|
|
87
78
|
let result = false;
|
|
88
79
|
if (vec1.length !== vec2.length) {
|
|
89
80
|
return result;
|
|
90
|
-
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
91
83
|
result = true;
|
|
92
84
|
for (let i = 0; i < vec1.length; i++) {
|
|
93
85
|
if (!this.approxEq(vec1[i], vec2[i], tolerance)) {
|
|
@@ -98,13 +90,11 @@ export class GeometryHelper {
|
|
|
98
90
|
}
|
|
99
91
|
return result;
|
|
100
92
|
}
|
|
101
|
-
|
|
102
|
-
approxEq(num1: number, num2: number, tolerance: number): boolean {
|
|
93
|
+
approxEq(num1, num2, tolerance) {
|
|
103
94
|
const res = Math.abs(num1 - num2) < tolerance;
|
|
104
95
|
return res;
|
|
105
96
|
}
|
|
106
|
-
|
|
107
|
-
removeConsecutivePointDuplicates(points: Inputs.Base.Point3[], checkFirstAndLast = true, tolerance = 1e-7): Inputs.Base.Point3[] {
|
|
97
|
+
removeConsecutivePointDuplicates(points, checkFirstAndLast = true, tolerance = 1e-7) {
|
|
108
98
|
const pointsRemaining = [];
|
|
109
99
|
if (points.length > 1) {
|
|
110
100
|
for (let i = 1; i < points.length; i++) {
|
|
@@ -124,20 +114,21 @@ export class GeometryHelper {
|
|
|
124
114
|
pointsRemaining.pop();
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
|
-
}
|
|
117
|
+
}
|
|
118
|
+
else if (points.length === 1) {
|
|
128
119
|
pointsRemaining.push(...points);
|
|
129
120
|
}
|
|
130
121
|
return pointsRemaining;
|
|
131
122
|
}
|
|
132
|
-
|
|
133
|
-
arePointsTheSame(pointA: Inputs.Base.Point3 | Inputs.Base.Point2, pointB: Inputs.Base.Point3 | Inputs.Base.Point2, tolerance: number): boolean {
|
|
123
|
+
arePointsTheSame(pointA, pointB, tolerance) {
|
|
134
124
|
let result = false;
|
|
135
125
|
if (pointA.length === 2 && pointB.length === 2) {
|
|
136
126
|
if (this.approxEq(pointA[0], pointB[0], tolerance) &&
|
|
137
127
|
this.approxEq(pointA[1], pointB[1], tolerance)) {
|
|
138
128
|
result = true;
|
|
139
129
|
}
|
|
140
|
-
}
|
|
130
|
+
}
|
|
131
|
+
else if (pointA.length === 3 && pointB.length === 3) {
|
|
141
132
|
if (this.approxEq(pointA[0], pointB[0], tolerance) &&
|
|
142
133
|
this.approxEq(pointA[1], pointB[1], tolerance) &&
|
|
143
134
|
this.approxEq(pointA[2], pointB[2], tolerance)) {
|
|
@@ -146,18 +137,15 @@ export class GeometryHelper {
|
|
|
146
137
|
}
|
|
147
138
|
return result;
|
|
148
139
|
}
|
|
149
|
-
|
|
150
|
-
private transformCoordinates(x: number, y: number, z: number, transformation: number[]): Inputs.Base.Vector3 {
|
|
140
|
+
transformCoordinates(x, y, z, transformation) {
|
|
151
141
|
const m = transformation;
|
|
152
142
|
const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
|
|
153
143
|
const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
|
|
154
144
|
const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
|
|
155
145
|
const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
|
|
156
|
-
|
|
157
146
|
const newx = rx * rw;
|
|
158
147
|
const newy = ry * rw;
|
|
159
148
|
const newz = rz * rw;
|
|
160
149
|
return [newx, newy, newz];
|
|
161
150
|
}
|
|
162
|
-
|
|
163
151
|
}
|