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 CHANGED
@@ -112,24 +112,18 @@ declare function degrees(x: number): number;
112
112
  */
113
113
  declare function radians(x: number): number;
114
114
  /**
115
- * TODO: (use array?) Calculate the magnitude (length) of a vector.
116
- * @param x length on x-axis
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(x: number, y: number, z: number): number;
119
+ declare function mag(xs: number[]): number;
122
120
  /**
123
- * TODO: (use array?) Calculate the distance between points.
124
- * @param x1 x-coordinate of first point
125
- * @param y1 y-coordinate of first point
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(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): number;
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(x, y, z) {
83
- return Math.sqrt(x * x + y * y + z * z);
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(x1, y1, z1, x2, y2, z2) {
86
- return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2);
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(x, y, z) {
79
- return Math.sqrt(x * x + y * y + z * z);
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(x1, y1, z1, x2, y2, z2) {
82
- return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-math",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Mathematics is the classification and study of all possible patterns.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",