@guillaume-docquier/tools-ts 6.5.0 → 6.7.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 +14 -10
- package/dist/Scalar.d.ts +7 -0
- package/dist/Scalar.js +10 -0
- package/dist/Scalar.js.map +1 -0
- package/dist/entry.tools-ts.d.ts +4 -1
- package/dist/entry.tools-ts.js +3 -0
- package/dist/entry.tools-ts.js.map +1 -1
- package/dist/measurements/Angle.d.ts +30 -0
- package/dist/measurements/Angle.js +43 -0
- package/dist/measurements/Angle.js.map +1 -0
- package/dist/measurements/Point2D.d.ts +34 -0
- package/dist/measurements/Point2D.js +51 -0
- package/dist/measurements/Point2D.js.map +1 -0
- package/dist/measurements/Point3D.d.ts +2 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,14 +35,15 @@ external APIs, CLI input, local storage, or other unknown data.
|
|
|
35
35
|
| `getEnumKey` | Looks up the enum key associated with a value. | You have an enum value and need the more descriptive key for display, logs, or diagnostics. |
|
|
36
36
|
| `asArray` | Normalizes a single value or array into an array. | An API accepts both `T` and `T[]`, but downstream logic should iterate uniformly. |
|
|
37
37
|
|
|
38
|
-
### Numeric
|
|
38
|
+
### Numeric Utilities
|
|
39
39
|
|
|
40
|
-
Use
|
|
41
|
-
|
|
40
|
+
Use these tools when code needs reusable numeric operations or validated
|
|
41
|
+
intervals.
|
|
42
42
|
|
|
43
|
-
| Export
|
|
44
|
-
|
|
|
45
|
-
| `
|
|
43
|
+
| Export | What it is | Use it when |
|
|
44
|
+
| -------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
45
|
+
| `Scalar` | Helpers for scalar number operations. | You need to constrain a number to an inclusive minimum and maximum. |
|
|
46
|
+
| `Range` | Helpers for creating, validating, comparing, and testing ranges. | You need finite integer or float intervals with inclusive minimums and configurable maximums. |
|
|
46
47
|
|
|
47
48
|
### Sorting
|
|
48
49
|
|
|
@@ -122,10 +123,13 @@ Use these helpers for quick profiling.
|
|
|
122
123
|
|
|
123
124
|
### Measurements
|
|
124
125
|
|
|
125
|
-
| Export
|
|
126
|
-
|
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
126
|
+
| Export | What it is | Use it when |
|
|
127
|
+
| ---------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
128
|
+
| `Angle`, `UnitOfAngle` | An angle measurement and its supported degree and radian units. | You need to represent angles and convert between degrees and radians. |
|
|
129
|
+
| `Time`, `UnitOfTime` | A time measurement and its supported units, with conversion and arithmetic tools. | You need unit-aware durations or calculations across different time units. |
|
|
130
|
+
| `Distance`, `UnitOfDistance` | A distance measurement and its supported units, with conversion and comparison. | You need unit-aware lengths, spatial comparisons, or distances between points. |
|
|
131
|
+
| `Point2D`, `XY` | A two-dimensional position and its plain coordinate-value shape. | You need 2D positions whose axes can use and convert between distance units. |
|
|
132
|
+
| `Point3D`, `XYZ` | A three-dimensional position and its plain coordinate-value shape. | You need 3D positions whose axes can use and convert between distance units. |
|
|
129
133
|
|
|
130
134
|
### Date manipulations
|
|
131
135
|
|
package/dist/Scalar.d.ts
ADDED
package/dist/Scalar.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const Scalar = {
|
|
2
|
+
/**
|
|
3
|
+
* Restricts a number to the inclusive range between min and max.
|
|
4
|
+
* It will not validate that min < max.
|
|
5
|
+
*/
|
|
6
|
+
clamp: (value, min, max) => {
|
|
7
|
+
return Math.min(Math.max(value, min), max);
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=Scalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scalar.js","sourceRoot":"","sources":["../src/Scalar.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;OAGG;IACH,KAAK,EAAE,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAU,EAAE;QACzD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5C,CAAC;CACF,CAAA"}
|
package/dist/entry.tools-ts.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { Assert } from "./Assert.js";
|
|
|
11
11
|
export { Result, type Success, type Failure } from "./Result.js";
|
|
12
12
|
export { Profile } from "./Profile.js";
|
|
13
13
|
export { Range } from "./Range.js";
|
|
14
|
+
export { Scalar } from "./Scalar.js";
|
|
14
15
|
export { TypeGuard } from "./TypeGuard.js";
|
|
15
16
|
export { setTimeoutAsync } from "./setTimeoutAsync.js";
|
|
16
17
|
export { noop, asyncNoop } from "./noop.js";
|
|
@@ -28,8 +29,10 @@ export { Sort } from "./Sort.js";
|
|
|
28
29
|
export { createRng, type Rng, type Generator } from "./rng/rng.js";
|
|
29
30
|
export { mulberry32Prng } from "./rng/mulberry32prng.js";
|
|
30
31
|
export { Datetime } from "./Datetime.js";
|
|
32
|
+
export { Angle, UnitOfAngle } from "./measurements/Angle.js";
|
|
31
33
|
export { Time, UnitOfTime } from "./measurements/Time.js";
|
|
32
34
|
export { Distance, UnitOfDistance } from "./measurements/Distance.js";
|
|
33
|
-
export {
|
|
35
|
+
export { Point2D, type XY } from "./measurements/Point2D.js";
|
|
36
|
+
export { Point3D, type XYZ } from "./measurements/Point3D.js";
|
|
34
37
|
export { Timer } from "./Timer.js";
|
|
35
38
|
export { type Branded, branded } from "./Brand.js";
|
package/dist/entry.tools-ts.js
CHANGED
|
@@ -10,6 +10,7 @@ export { Assert } from "./Assert.js";
|
|
|
10
10
|
export { Result } from "./Result.js";
|
|
11
11
|
export { Profile } from "./Profile.js";
|
|
12
12
|
export { Range } from "./Range.js";
|
|
13
|
+
export { Scalar } from "./Scalar.js";
|
|
13
14
|
export { TypeGuard } from "./TypeGuard.js";
|
|
14
15
|
export { setTimeoutAsync } from "./setTimeoutAsync.js";
|
|
15
16
|
export { noop, asyncNoop } from "./noop.js";
|
|
@@ -23,8 +24,10 @@ export { Sort } from "./Sort.js";
|
|
|
23
24
|
export { createRng } from "./rng/rng.js";
|
|
24
25
|
export { mulberry32Prng } from "./rng/mulberry32prng.js";
|
|
25
26
|
export { Datetime } from "./Datetime.js";
|
|
27
|
+
export { Angle, UnitOfAngle } from "./measurements/Angle.js";
|
|
26
28
|
export { Time, UnitOfTime } from "./measurements/Time.js";
|
|
27
29
|
export { Distance, UnitOfDistance } from "./measurements/Distance.js";
|
|
30
|
+
export { Point2D } from "./measurements/Point2D.js";
|
|
28
31
|
export { Point3D } from "./measurements/Point3D.js";
|
|
29
32
|
export { Timer } from "./Timer.js";
|
|
30
33
|
export { branded } from "./Brand.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.tools-ts.js","sourceRoot":"","sources":["../src/entry.tools-ts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAA8B,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe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AAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAgB,OAAO,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Measurement } from "./Measurement.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the possible units to define an angle.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum UnitOfAngle {
|
|
6
|
+
DEGREES = "degrees",
|
|
7
|
+
RADIANS = "radians"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents an angle with its unit.
|
|
11
|
+
*/
|
|
12
|
+
export type Angle = Measurement<UnitOfAngle>;
|
|
13
|
+
/**
|
|
14
|
+
* A set of functions to work with angles.
|
|
15
|
+
*/
|
|
16
|
+
export declare const Angle: {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an angle.
|
|
19
|
+
*/
|
|
20
|
+
create(value: number, unit: UnitOfAngle): Angle;
|
|
21
|
+
/**
|
|
22
|
+
* Converts an angle to another unit.
|
|
23
|
+
* The provided angle is left untouched.
|
|
24
|
+
*/
|
|
25
|
+
convert(angle: Readonly<Angle>, newUnit: UnitOfAngle): Angle;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the value of the angle in the given unit.
|
|
28
|
+
*/
|
|
29
|
+
in({ value, unit }: Readonly<Angle>, newUnit: UnitOfAngle): number;
|
|
30
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the possible units to define an angle.
|
|
3
|
+
*/
|
|
4
|
+
export var UnitOfAngle;
|
|
5
|
+
(function (UnitOfAngle) {
|
|
6
|
+
UnitOfAngle["DEGREES"] = "degrees";
|
|
7
|
+
UnitOfAngle["RADIANS"] = "radians";
|
|
8
|
+
})(UnitOfAngle || (UnitOfAngle = {}));
|
|
9
|
+
const RADIANS_PER_ANGLE = {
|
|
10
|
+
[UnitOfAngle.DEGREES]: Math.PI / 180,
|
|
11
|
+
[UnitOfAngle.RADIANS]: 1,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A set of functions to work with angles.
|
|
15
|
+
*/
|
|
16
|
+
export const Angle = {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an angle.
|
|
19
|
+
*/
|
|
20
|
+
create(value, unit) {
|
|
21
|
+
return { value, unit };
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Converts an angle to another unit.
|
|
25
|
+
* The provided angle is left untouched.
|
|
26
|
+
*/
|
|
27
|
+
convert(angle, newUnit) {
|
|
28
|
+
return {
|
|
29
|
+
value: Angle.in(angle, newUnit),
|
|
30
|
+
unit: newUnit,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Returns the value of the angle in the given unit.
|
|
35
|
+
*/
|
|
36
|
+
in({ value, unit }, newUnit) {
|
|
37
|
+
if (unit === newUnit) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
return (value * RADIANS_PER_ANGLE[unit]) / RADIANS_PER_ANGLE[newUnit];
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=Angle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Angle.js","sourceRoot":"","sources":["../../src/measurements/Angle.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAED,MAAM,iBAAiB,GAAgC;IACrD,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG;IACpC,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;CACzB,CAAA;AAOD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,MAAM,CAAC,KAAa,EAAE,IAAiB;QACrC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAsB,EAAE,OAAoB;QAClD,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;YAC/B,IAAI,EAAE,OAAO;SACd,CAAA;IACH,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAmB,EAAE,OAAoB;QACvD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,CAAC,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACvE,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Distance, UnitOfDistance } from "./Distance.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a position in 2D space.
|
|
4
|
+
*/
|
|
5
|
+
export type Point2D = {
|
|
6
|
+
x: Distance;
|
|
7
|
+
y: Distance;
|
|
8
|
+
};
|
|
9
|
+
export type XY = {
|
|
10
|
+
x: Distance["value"];
|
|
11
|
+
y: Distance["value"];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A set of functions to work with 2D positions.
|
|
15
|
+
*/
|
|
16
|
+
export declare const Point2D: {
|
|
17
|
+
/**
|
|
18
|
+
* Builds a position from XY values with the same unit.
|
|
19
|
+
*/
|
|
20
|
+
create({ x, y }: Readonly<XY>, unit: UnitOfDistance): Point2D;
|
|
21
|
+
/**
|
|
22
|
+
* Converts x and y to one unit or to the matching units of another position.
|
|
23
|
+
* The provided position is left untouched.
|
|
24
|
+
*/
|
|
25
|
+
convert({ x, y }: Readonly<Point2D>, unit: Readonly<Point2D> | UnitOfDistance): Point2D;
|
|
26
|
+
/**
|
|
27
|
+
* Converts x and y to the given unit and returns their values.
|
|
28
|
+
*/
|
|
29
|
+
in({ x, y }: Readonly<Point2D>, newUnit: UnitOfDistance): XY;
|
|
30
|
+
/**
|
|
31
|
+
* Determines if two positions are within an inclusive distance tolerance.
|
|
32
|
+
*/
|
|
33
|
+
areEqual(position1: Readonly<Point2D>, position2: Readonly<Point2D>, tolerance: Readonly<Distance>): boolean;
|
|
34
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TypeGuard } from "../TypeGuard.js";
|
|
2
|
+
import { Distance, UnitOfDistance } from "./Distance.js";
|
|
3
|
+
/**
|
|
4
|
+
* A set of functions to work with 2D positions.
|
|
5
|
+
*/
|
|
6
|
+
export const Point2D = {
|
|
7
|
+
/**
|
|
8
|
+
* Builds a position from XY values with the same unit.
|
|
9
|
+
*/
|
|
10
|
+
create({ x, y }, unit) {
|
|
11
|
+
return {
|
|
12
|
+
x: Distance.create(x, unit),
|
|
13
|
+
y: Distance.create(y, unit),
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Converts x and y to one unit or to the matching units of another position.
|
|
18
|
+
* The provided position is left untouched.
|
|
19
|
+
*/
|
|
20
|
+
convert({ x, y }, unit) {
|
|
21
|
+
if (TypeGuard.isEnumMember(UnitOfDistance, unit)) {
|
|
22
|
+
return {
|
|
23
|
+
x: Distance.convert(x, unit),
|
|
24
|
+
y: Distance.convert(y, unit),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
x: Distance.convert(x, unit.x.unit),
|
|
29
|
+
y: Distance.convert(y, unit.y.unit),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Converts x and y to the given unit and returns their values.
|
|
34
|
+
*/
|
|
35
|
+
in({ x, y }, newUnit) {
|
|
36
|
+
return {
|
|
37
|
+
x: Distance.in(x, newUnit),
|
|
38
|
+
y: Distance.in(y, newUnit),
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Determines if two positions are within an inclusive distance tolerance.
|
|
43
|
+
*/
|
|
44
|
+
areEqual(position1, position2, tolerance) {
|
|
45
|
+
const xy1 = Point2D.in(position1, tolerance.unit);
|
|
46
|
+
const xy2 = Point2D.in(position2, tolerance.unit);
|
|
47
|
+
const distance = Math.hypot(xy1.x - xy2.x, xy1.y - xy2.y);
|
|
48
|
+
return distance <= tolerance.value;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=Point2D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Point2D.js","sourceRoot":"","sources":["../../src/measurements/Point2D.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAexD;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAgB,EAAE,IAAoB;QACjD,OAAO;YACL,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;YAC3B,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;SAC5B,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAqB,EAAE,IAAwC;QAC3E,IAAI,SAAS,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC;YACjD,OAAO;gBACL,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;gBAC5B,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;aAC7B,CAAA;QACH,CAAC;QAED,OAAO;YACL,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACnC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;SACpC,CAAA;IACH,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAqB,EAAE,OAAuB;QACrD,OAAO;YACL,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC;YAC1B,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC;SAC3B,CAAA;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,SAA4B,EAAE,SAA4B,EAAE,SAA6B;QAChG,MAAM,GAAG,GAAG,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QACjD,MAAM,GAAG,GAAG,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAEzD,OAAO,QAAQ,IAAI,SAAS,CAAC,KAAK,CAAA;IACpC,CAAC;CACF,CAAA"}
|
|
@@ -7,11 +7,11 @@ export type Point3D = {
|
|
|
7
7
|
y: Distance;
|
|
8
8
|
z: Distance;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
export type XYZ = {
|
|
11
11
|
x: Distance["value"];
|
|
12
12
|
y: Distance["value"];
|
|
13
13
|
z: Distance["value"];
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
/**
|
|
16
16
|
* A set of functions to work with Positions.
|
|
17
17
|
*/
|
|
@@ -47,4 +47,3 @@ export declare const Point3D: {
|
|
|
47
47
|
*/
|
|
48
48
|
areEqual(position1: Readonly<Point3D>, position2: Readonly<Point3D>, tolerance: Readonly<Distance>): boolean;
|
|
49
49
|
};
|
|
50
|
-
export {};
|