@reekon-tools/boldr-utils 1.6.2 → 1.6.3
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DecimalTolerance, FractionalTolerance, Units } from '../types/firestore.js';
|
|
2
|
+
export declare const roundToT1Values: (value: number, u: Units) => number;
|
|
2
3
|
export declare const convertMicrometers: (micrometers: number | null | undefined, unit: Units, fractionalTolerance: FractionalTolerance, decimalTolerance: DecimalTolerance) => {
|
|
3
4
|
value: string;
|
|
4
5
|
unit: string;
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { Units, convertUnitsToReadable, } from '../types/firestore.js';
|
|
2
2
|
import { create, all } from 'mathjs';
|
|
3
3
|
const math = create(all);
|
|
4
|
+
// The T1 rounds differently depending on the selected measurement unit.
|
|
5
|
+
// This function mirrors the rounding behavior implemented on the firmware.
|
|
6
|
+
// The value being rounded is in microns.
|
|
7
|
+
export const roundToT1Values = (value, u) => {
|
|
8
|
+
switch (u) {
|
|
9
|
+
case Units.Millimeters:
|
|
10
|
+
case Units.Centimeters:
|
|
11
|
+
return Math.round(value / 500) * 500;
|
|
12
|
+
case Units.Meters:
|
|
13
|
+
return Math.round(value / 1000) * 1000;
|
|
14
|
+
case Units.Inches:
|
|
15
|
+
return Math.round(value / 508) * 508;
|
|
16
|
+
case Units.Feet:
|
|
17
|
+
return Math.round(value / 304.8) * 304.8;
|
|
18
|
+
case Units.FeetInchesDecimal:
|
|
19
|
+
return Math.round(value / 508) * 508;
|
|
20
|
+
case Units.FractionalInches:
|
|
21
|
+
case Units.FeetInchesFractional:
|
|
22
|
+
return value;
|
|
23
|
+
default:
|
|
24
|
+
return Math.round(value / 500) * 500;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
4
27
|
export const convertMicrometers = (micrometers, unit, fractionalTolerance, decimalTolerance) => {
|
|
5
28
|
if (micrometers == null || isNaN(micrometers)) {
|
|
6
29
|
return { value: 'NaN', unit: '' };
|
|
7
30
|
}
|
|
8
31
|
try {
|
|
9
|
-
const converted = math.unit(micrometers, 'um');
|
|
32
|
+
const converted = math.unit(roundToT1Values(micrometers, unit), 'um');
|
|
10
33
|
let value = 0;
|
|
11
34
|
let displayUnit = '';
|
|
12
35
|
switch (unit) {
|