@itwin/core-quantity 4.9.0-dev.21 → 4.9.0-dev.23

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/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log - @itwin/core-quantity
2
2
 
3
- This log was last generated on Wed, 28 Aug 2024 17:28:58 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 06 Sep 2024 05:08:18 GMT and should not be manually modified.
4
+
5
+ ## 4.8.6
6
+ Fri, 06 Sep 2024 05:06:49 GMT
7
+
8
+ _Version update only_
4
9
 
5
10
  ## 4.8.5
6
11
  Wed, 28 Aug 2024 17:27:23 GMT
@@ -2,6 +2,15 @@
2
2
  * @module Quantity
3
3
  */
4
4
  import { QuantityProps, UnitConversionProps, UnitProps } from "./Interfaces";
5
+ /**
6
+ * Checks if two numbers are approximately equal within given relative tolerance.
7
+ * @param a - The first number to compare.
8
+ * @param b - The second number to compare.
9
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
10
+ * @returns True if the numbers are approximately equal, false otherwise.
11
+ * @internal
12
+ */
13
+ export declare function almostEqual(a: number, b: number, tolerance?: number): boolean;
5
14
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
6
15
  * returned as the result of parsing a string that represents a quantity.
7
16
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
1
+ {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,MAA+B,GAAG,OAAO,CAIrG;AAED;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
@@ -7,7 +7,21 @@
7
7
  * @module Quantity
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Quantity = void 0;
10
+ exports.Quantity = exports.almostEqual = void 0;
11
+ /**
12
+ * Checks if two numbers are approximately equal within given relative tolerance.
13
+ * @param a - The first number to compare.
14
+ * @param b - The second number to compare.
15
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
16
+ * @returns True if the numbers are approximately equal, false otherwise.
17
+ * @internal
18
+ */
19
+ function almostEqual(a, b, tolerance = 2.2204460492503131e-16) {
20
+ const absDiff = Math.abs(a - b);
21
+ const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;
22
+ return absDiff <= scaledTolerance;
23
+ }
24
+ exports.almostEqual = almostEqual;
11
25
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
12
26
  * returned as the result of parsing a string that represents a quantity.
13
27
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;GAGG;AACH,MAAa,QAAQ;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;CACF;AAlCD,4BAkCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityProps, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\r\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,eAAe,CAAC;AACpC,CAAC;AAJD,kCAIC;AAED;;;GAGG;AACH,MAAa,QAAQ;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;CACF;AAlCD,4BAkCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityProps, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within given relative tolerance.\r\n * @param a - The first number to compare.\r\n * @param b - The second number to compare.\r\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\r\n * @returns True if the numbers are approximately equal, false otherwise.\r\n * @internal\r\n */\r\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\r\n const absDiff = Math.abs(a - b);\r\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\r\n return absDiff <= scaledTolerance;\r\n}\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\r\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n"]}
@@ -2,6 +2,15 @@
2
2
  * @module Quantity
3
3
  */
4
4
  import { QuantityProps, UnitConversionProps, UnitProps } from "./Interfaces";
5
+ /**
6
+ * Checks if two numbers are approximately equal within given relative tolerance.
7
+ * @param a - The first number to compare.
8
+ * @param b - The second number to compare.
9
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
10
+ * @returns True if the numbers are approximately equal, false otherwise.
11
+ * @internal
12
+ */
13
+ export declare function almostEqual(a: number, b: number, tolerance?: number): boolean;
5
14
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
6
15
  * returned as the result of parsing a string that represents a quantity.
7
16
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
1
+ {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,MAA+B,GAAG,OAAO,CAIrG;AAED;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
@@ -5,6 +5,19 @@
5
5
  /** @packageDocumentation
6
6
  * @module Quantity
7
7
  */
8
+ /**
9
+ * Checks if two numbers are approximately equal within given relative tolerance.
10
+ * @param a - The first number to compare.
11
+ * @param b - The second number to compare.
12
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
13
+ * @returns True if the numbers are approximately equal, false otherwise.
14
+ * @internal
15
+ */
16
+ export function almostEqual(a, b, tolerance = 2.2204460492503131e-16) {
17
+ const absDiff = Math.abs(a - b);
18
+ const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;
19
+ return absDiff <= scaledTolerance;
20
+ }
8
21
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
9
22
  * returned as the result of parsing a string that represents a quantity.
10
23
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityProps, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\r\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,eAAe,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityProps, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within given relative tolerance.\r\n * @param a - The first number to compare.\r\n * @param b - The second number to compare.\r\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\r\n * @returns True if the numbers are approximately equal, false otherwise.\r\n * @internal\r\n */\r\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\r\n const absDiff = Math.abs(a - b);\r\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\r\n return absDiff <= scaledTolerance;\r\n}\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\r\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-quantity",
3
- "version": "4.9.0-dev.21",
3
+ "version": "4.9.0-dev.23",
4
4
  "description": "Quantity parsing, formatting and conversions for iModel.js",
5
5
  "main": "lib/cjs/core-quantity.js",
6
6
  "module": "lib/esm/core-quantity.js",
@@ -33,13 +33,13 @@
33
33
  "mocha": "^10.2.0",
34
34
  "nyc": "^15.1.0",
35
35
  "rimraf": "^3.0.2",
36
- "sinon": "^17.0.1",
36
+ "sinon": "^17.0.2",
37
37
  "typescript": "~5.3.3",
38
- "@itwin/build-tools": "4.9.0-dev.21",
39
- "@itwin/core-bentley": "4.9.0-dev.21"
38
+ "@itwin/build-tools": "4.9.0-dev.23",
39
+ "@itwin/core-bentley": "4.9.0-dev.23"
40
40
  },
41
41
  "peerDependencies": {
42
- "@itwin/core-bentley": "^4.9.0-dev.21"
42
+ "@itwin/core-bentley": "^4.9.0-dev.23"
43
43
  },
44
44
  "nyc": {
45
45
  "extends": "./node_modules/@itwin/build-tools/.nycrc"