@flighthq/math 0.5.1-next.658.9cb44d7 → 0.5.1-next.685.f72fc7f

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 CHANGED
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/math`. The `@flighth
13
13
  This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
14
14
 
15
15
  - [Flight project](https://github.com/flighthq/flight)
16
- - [Source for @flighthq/math@0.5.1-next.658.9cb44d7](https://github.com/flighthq/flight/tree/9cb44d76b981adad2503d5e62207be99adb35c55/packages/math)
17
- - [License](https://github.com/flighthq/flight/blob/9cb44d76b981adad2503d5e62207be99adb35c55/LICENSE.md)
16
+ - [Source for @flighthq/math@0.5.1-next.685.f72fc7f](https://github.com/flighthq/flight/tree/f72fc7feaa9653d950f39c7d2fe6365f48e82e51/packages/math)
17
+ - [License](https://github.com/flighthq/flight/blob/f72fc7feaa9653d950f39c7d2fe6365f48e82e51/LICENSE.md)
@@ -26,7 +26,7 @@ export declare function floorTo(value: number, step: number): number;
26
26
  * the sign is preserved (e.g. `fract(-1.3)` → `-0.3`), mirroring GLSL `fract`.
27
27
  */
28
28
  export declare function fract(value: number): number;
29
- /** Round `value` to the nearest multiple of `step`.
29
+ /** Round `value` to the nearest multiple of `step`, with halfway ties away from zero.
30
30
  *
31
31
  * `roundTo(7, 5)` → `5`; `roundTo(8, 5)` → `10`. When `step <= 0` the
32
32
  * result is `value`. Also useful as a snap / quantize primitive.
@@ -1 +1 @@
1
- {"version":3,"file":"rounding.d.ts","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3D"}
1
+ {"version":3,"file":"rounding.d.ts","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3D"}
package/dist/rounding.js CHANGED
@@ -40,7 +40,7 @@ export function floorTo(value, step) {
40
40
  export function fract(value) {
41
41
  return value - Math.trunc(value);
42
42
  }
43
- /** Round `value` to the nearest multiple of `step`.
43
+ /** Round `value` to the nearest multiple of `step`, with halfway ties away from zero.
44
44
  *
45
45
  * `roundTo(7, 5)` → `5`; `roundTo(8, 5)` → `10`. When `step <= 0` the
46
46
  * result is `value`. Also useful as a snap / quantize primitive.
@@ -48,6 +48,9 @@ export function fract(value) {
48
48
  export function roundTo(value, step) {
49
49
  if (step <= 0)
50
50
  return value;
51
- return Math.round(value / step) * step;
51
+ const magnitude = Math.round(Math.abs(value) / step) * step;
52
+ if (magnitude === 0)
53
+ return 0;
54
+ return value < 0 ? -magnitude : magnitude;
52
55
  }
53
56
  //# sourceMappingURL=rounding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rounding.js","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa,EAAE,IAAY;IAChD,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACxC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,OAAe;IACzD,IAAI,OAAO,KAAK,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;IAC/E,OAAO,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAY;IACjD,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAY;IACjD,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACzC,CAAC"}
1
+ {"version":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C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/math",
3
- "version": "0.5.1-next.658.9cb44d7",
3
+ "version": "0.5.1-next.685.f72fc7f",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/types": "0.5.1-next.658.9cb44d7"
41
+ "@flighthq/types": "0.5.1-next.685.f72fc7f"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "^5.3.0"
@@ -62,6 +62,11 @@ describe('fract', () => {
62
62
  });
63
63
 
64
64
  describe('roundTo', () => {
65
+ it('rounds halfway ties away from zero symmetrically', () => {
66
+ expect(roundTo(5, 10)).toBe(10);
67
+ expect(roundTo(-5, 10)).toBe(-10);
68
+ expect(Object.is(roundTo(-4, 10), -0)).toBe(false);
69
+ });
65
70
  it('rounds to the nearest step', () => {
66
71
  expect(roundTo(7, 5)).toBe(5);
67
72
  expect(roundTo(8, 5)).toBe(10);