extra-math 1.3.1 → 1.3.2
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 +7 -13
- package/index.js +10 -4
- package/index.mjs +10 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -112,24 +112,18 @@ declare function degrees(x: number): number;
|
|
|
112
112
|
*/
|
|
113
113
|
declare function radians(x: number): number;
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param x
|
|
117
|
-
* @param y length on y-axis
|
|
118
|
-
* @param z length on x-axis
|
|
115
|
+
* Calculate the magnitude (length) of a vector.
|
|
116
|
+
* @param xs vector ([x, y, z, ...])
|
|
119
117
|
* @returns √(x² + y² + z²)
|
|
120
118
|
*/
|
|
121
|
-
declare function mag(
|
|
119
|
+
declare function mag(xs: number[]): number;
|
|
122
120
|
/**
|
|
123
|
-
*
|
|
124
|
-
* @param
|
|
125
|
-
* @param
|
|
126
|
-
* @param z1 z-coordinate of first point
|
|
127
|
-
* @param x2 x-coordinate of second point
|
|
128
|
-
* @param y2 y-coordinate of second point
|
|
129
|
-
* @param z2 z-coordinate of second point
|
|
121
|
+
* Calculate the distance between two points.
|
|
122
|
+
* @param xs first point ([x, y, z, ...])
|
|
123
|
+
* @param ys second point ([x, y, z, ...])
|
|
130
124
|
* @returns √(Δx² + Δy² + Δz²)
|
|
131
125
|
*/
|
|
132
|
-
declare function dist(
|
|
126
|
+
declare function dist(xs: number[], ys: number[]): number;
|
|
133
127
|
/**
|
|
134
128
|
* Find the sum of numbers (Σ).
|
|
135
129
|
* @param xs a list of numbers
|
package/index.js
CHANGED
|
@@ -79,11 +79,17 @@ function degrees(x) {
|
|
|
79
79
|
function radians(x) {
|
|
80
80
|
return x * (Math.PI / 180);
|
|
81
81
|
}
|
|
82
|
-
function mag(
|
|
83
|
-
|
|
82
|
+
function mag(xs) {
|
|
83
|
+
var a = 0;
|
|
84
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
85
|
+
a += xs[i] ** 2;
|
|
86
|
+
return Math.sqrt(a);
|
|
84
87
|
}
|
|
85
|
-
function dist(
|
|
86
|
-
|
|
88
|
+
function dist(xs, ys) {
|
|
89
|
+
var a = 0;
|
|
90
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
91
|
+
a += (xs[i] - ys[i]) ** 2;
|
|
92
|
+
return Math.sqrt(a);
|
|
87
93
|
}
|
|
88
94
|
function sum(...xs) {
|
|
89
95
|
var a = 0;
|
package/index.mjs
CHANGED
|
@@ -75,11 +75,17 @@ function degrees(x) {
|
|
|
75
75
|
function radians(x) {
|
|
76
76
|
return x * (Math.PI / 180);
|
|
77
77
|
}
|
|
78
|
-
function mag(
|
|
79
|
-
|
|
78
|
+
function mag(xs) {
|
|
79
|
+
var a = 0;
|
|
80
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
81
|
+
a += xs[i] ** 2;
|
|
82
|
+
return Math.sqrt(a);
|
|
80
83
|
}
|
|
81
|
-
function dist(
|
|
82
|
-
|
|
84
|
+
function dist(xs, ys) {
|
|
85
|
+
var a = 0;
|
|
86
|
+
for (var i = 0, I = xs.length; i < I; i++)
|
|
87
|
+
a += (xs[i] - ys[i]) ** 2;
|
|
88
|
+
return Math.sqrt(a);
|
|
83
89
|
}
|
|
84
90
|
function sum(...xs) {
|
|
85
91
|
var a = 0;
|