@interstellar-tools/types 0.6.0 → 0.8.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/dist/numeric.d.ts +74 -4
- package/dist/numeric.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/numeric.d.ts
CHANGED
|
@@ -17,15 +17,85 @@ export interface ValueInterface {
|
|
|
17
17
|
value: number;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* **Angle in radians** (branded nominal type).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
22
|
+
* **Relations**
|
|
23
|
+
*
|
|
24
|
+
* $$
|
|
25
|
+
* \pi\ \mathrm{rad}=180^\circ,\qquad
|
|
26
|
+
* 1\ \mathrm{rad}=\frac{\text{arc length}}{\text{radius}}
|
|
27
|
+
* $$
|
|
28
|
+
*
|
|
29
|
+
* **Why branded?**
|
|
30
|
+
* This type brands a `number` to prevent accidentally mixing **degrees** and **radians**
|
|
31
|
+
* at compile time. You must construct it explicitly (e.g., via a small factory or cast).
|
|
32
|
+
*
|
|
33
|
+
* **Units**
|
|
34
|
+
* - Stored as a JavaScript `number` whose unit is **radians** (dimensionless).
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* // Construct with an explicit cast or small factory
|
|
39
|
+
* const halfTurn: Radians = Math.PI as Radians;
|
|
40
|
+
*
|
|
41
|
+
* // Function expecting radians
|
|
42
|
+
* function usesRadians(nu: Radians) { …}
|
|
43
|
+
* usesRadians(halfTurn);
|
|
44
|
+
* // usesRadians(180 as number); // avoid passing degrees as a plain number
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Optional helper factory (recommended pattern)
|
|
50
|
+
* const rad = (x: number): Radians => x as Radians;
|
|
51
|
+
* const quarter: Radians = rad(Math.PI / 2);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @see flightPathAngleFromTrueAnomaly - accepts `nu: Radians`
|
|
55
|
+
* @group Numeric
|
|
56
|
+
*/
|
|
57
|
+
export type Radians = number & {
|
|
58
|
+
readonly __unit: 'radians';
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* **Angle in degrees** (branded nominal type).
|
|
62
|
+
*
|
|
63
|
+
* **Relations**
|
|
64
|
+
*
|
|
65
|
+
* $$
|
|
66
|
+
* 180^\circ=\pi\ \mathrm{rad},\qquad
|
|
67
|
+
* \text{deg}\to\text{rad}:~\theta_\mathrm{rad}=\theta_\mathrm{deg}\,\frac{\pi}{180},\qquad
|
|
68
|
+
* \text{rad}\to\text{deg}:~\theta_\mathrm{deg}=\theta_\mathrm{rad}\,\frac{180}{\pi}
|
|
69
|
+
* $$
|
|
70
|
+
*
|
|
71
|
+
* **Why branded?**
|
|
72
|
+
* Brands a `number` to prevent accidentally mixing **degrees** and **radians**
|
|
73
|
+
* at compile time. Construct explicitly (via a helper or cast).
|
|
74
|
+
*
|
|
75
|
+
* **Units**
|
|
76
|
+
* - Stored as a JavaScript `number` whose unit is **degrees** (dimensionless).
|
|
23
77
|
*
|
|
24
78
|
* @example
|
|
25
79
|
* ```ts
|
|
26
|
-
*
|
|
80
|
+
* // Simple factory (recommended)
|
|
81
|
+
* const deg = (x: number): DegreesType => x as DegreesType;
|
|
82
|
+
* const rightAngle: DegreesType = deg(90);
|
|
27
83
|
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* // Converting to radians (using your own helper)
|
|
88
|
+
* type Radians = number & { readonly __unit: 'radians' };
|
|
89
|
+
* const toRadians = (d: DegreesType): Radians => ((d as number) * Math.PI / 180) as Radians;
|
|
90
|
+
*
|
|
91
|
+
* const heading: DegreesType = (45 as DegreesType);
|
|
92
|
+
* const headingRad: Radians = toRadians(heading);
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @see Radians - branded type for angles in radians
|
|
28
96
|
* @group Numeric
|
|
29
97
|
*/
|
|
30
|
-
export type
|
|
98
|
+
export type DegreesType = number & {
|
|
99
|
+
readonly __unit: 'degrees';
|
|
100
|
+
};
|
|
31
101
|
//# sourceMappingURL=numeric.d.ts.map
|
package/dist/numeric.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numeric.d.ts","sourceRoot":"","sources":["../src/numeric.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;AAED
|
|
1
|
+
{"version":3,"file":"numeric.d.ts","sourceRoot":"","sources":["../src/numeric.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC"}
|
package/package.json
CHANGED