@jangaba/qube 1.0.0 → 1.0.1
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/index.d.ts +14 -14
- package/index.js +28 -28
- package/package.json +4 -1
package/index.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export interface CubeResult {
|
|
2
|
-
/**
|
|
2
|
+
/** Edge length */
|
|
3
3
|
edge: number;
|
|
4
|
-
/**
|
|
4
|
+
/** Face diagonal: a√2 */
|
|
5
5
|
faceDiagonal: number;
|
|
6
|
-
/**
|
|
6
|
+
/** Space diagonal: a√3 */
|
|
7
7
|
spaceDiagonal: number;
|
|
8
|
-
/**
|
|
8
|
+
/** Surface area: 6a² */
|
|
9
9
|
surfaceArea: number;
|
|
10
|
-
/**
|
|
10
|
+
/** Volume: a³ */
|
|
11
11
|
volume: number;
|
|
12
|
-
/**
|
|
12
|
+
/** Face area: a² */
|
|
13
13
|
faceArea: number;
|
|
14
|
-
/**
|
|
14
|
+
/** Face perimeter: 4a */
|
|
15
15
|
perimeter: number;
|
|
16
|
-
/**
|
|
16
|
+
/** Total edge length: 12a */
|
|
17
17
|
totalEdgeLength: number;
|
|
18
|
-
/**
|
|
18
|
+
/** Circumscribed sphere radius: (a√3)/2 */
|
|
19
19
|
circumRadius: number;
|
|
20
|
-
/**
|
|
20
|
+
/** Inscribed sphere radius: a/2 */
|
|
21
21
|
inRadius: number;
|
|
22
|
-
/**
|
|
22
|
+
/** Midsphere radius (touches edges): (a√2)/2 */
|
|
23
23
|
midRadius: number;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ export type CubeInput = { [K in keyof CubeResult]?: number } & {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Compute all cube parameters from any single one.
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* cube({ edge: 5 })
|
|
@@ -38,11 +38,11 @@ export type CubeInput = { [K in keyof CubeResult]?: number } & {
|
|
|
38
38
|
export function cube(input: Partial<CubeResult>): CubeResult;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Print all cube parameters to the console and return the result.
|
|
42
42
|
*/
|
|
43
43
|
export function printCube(input: Partial<CubeResult>): CubeResult;
|
|
44
44
|
|
|
45
|
-
/**
|
|
45
|
+
/** Human-readable parameter descriptions. */
|
|
46
46
|
export const descriptions: Record<keyof CubeResult, string>;
|
|
47
47
|
|
|
48
48
|
export default cube;
|
package/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cube Calculator
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Compute all cube parameters from any single one.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* faceDiagonal
|
|
9
|
-
* spaceDiagonal
|
|
10
|
-
* surfaceArea
|
|
11
|
-
* volume
|
|
12
|
-
* faceArea
|
|
13
|
-
* perimeter
|
|
14
|
-
* totalEdgeLength -
|
|
15
|
-
* circumRadius
|
|
16
|
-
* inRadius
|
|
17
|
-
* midRadius
|
|
6
|
+
* Parameters:
|
|
7
|
+
* edge - edge length
|
|
8
|
+
* faceDiagonal - face diagonal: a√2
|
|
9
|
+
* spaceDiagonal - space diagonal: a√3
|
|
10
|
+
* surfaceArea - surface area: 6a²
|
|
11
|
+
* volume - volume: a³
|
|
12
|
+
* faceArea - face area: a²
|
|
13
|
+
* perimeter - face perimeter: 4a
|
|
14
|
+
* totalEdgeLength - total edge length: 12a
|
|
15
|
+
* circumRadius - circumscribed sphere radius: (a√3)/2
|
|
16
|
+
* inRadius - inscribed sphere radius: a/2
|
|
17
|
+
* midRadius - midsphere radius (touches edges): (a√2)/2
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const SQRT2 = Math.sqrt(2);
|
|
@@ -51,17 +51,17 @@ const paramToEdge = {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const descriptions = {
|
|
54
|
-
edge: "
|
|
55
|
-
faceDiagonal: "
|
|
56
|
-
spaceDiagonal: "
|
|
57
|
-
surfaceArea: "
|
|
58
|
-
volume: "
|
|
59
|
-
faceArea: "
|
|
60
|
-
perimeter: "
|
|
61
|
-
totalEdgeLength: "
|
|
62
|
-
circumRadius: "
|
|
63
|
-
inRadius: "
|
|
64
|
-
midRadius: "
|
|
54
|
+
edge: "Edge length",
|
|
55
|
+
faceDiagonal: "Face diagonal",
|
|
56
|
+
spaceDiagonal: "Space diagonal",
|
|
57
|
+
surfaceArea: "Surface area",
|
|
58
|
+
volume: "Volume",
|
|
59
|
+
faceArea: "Face area",
|
|
60
|
+
perimeter: "Face perimeter",
|
|
61
|
+
totalEdgeLength: "Total edge length",
|
|
62
|
+
circumRadius: "Circumscribed sphere radius",
|
|
63
|
+
inRadius: "Inscribed sphere radius",
|
|
64
|
+
midRadius: "Midsphere radius",
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
function cube(input) {
|
|
@@ -69,18 +69,18 @@ function cube(input) {
|
|
|
69
69
|
|
|
70
70
|
if (keys.length === 0) {
|
|
71
71
|
throw new Error(
|
|
72
|
-
`
|
|
72
|
+
`Unknown parameter. Allowed: ${Object.keys(paramToEdge).join(", ")}`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
if (keys.length > 1) {
|
|
76
|
-
throw new Error("
|
|
76
|
+
throw new Error("Provide exactly one parameter.");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const key = keys[0];
|
|
80
80
|
const value = input[key];
|
|
81
81
|
|
|
82
82
|
if (typeof value !== "number" || value <= 0 || !isFinite(value)) {
|
|
83
|
-
throw new Error("
|
|
83
|
+
throw new Error("Value must be a positive finite number.");
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const a = paramToEdge[key](value);
|
|
@@ -89,7 +89,7 @@ function cube(input) {
|
|
|
89
89
|
|
|
90
90
|
function printCube(input) {
|
|
91
91
|
const result = cube(input);
|
|
92
|
-
console.log("===
|
|
92
|
+
console.log("=== Cube parameters ===");
|
|
93
93
|
for (const [key, value] of Object.entries(result)) {
|
|
94
94
|
const desc = descriptions[key] || key;
|
|
95
95
|
console.log(` ${desc}: ${value}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jangaba/qube",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Cube calculator – compute all cube parameters from any single one (edge, diagonal, volume, surface area, radius...)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": ""
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
37
40
|
}
|
|
38
41
|
}
|