@andrew_l/toolkit 0.2.12 → 0.2.13

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/index.cjs CHANGED
@@ -198,6 +198,22 @@ const avg = (values) => {
198
198
  return sum / amount;
199
199
  };
200
200
 
201
+ const avgCircular = (values, max) => {
202
+ const len = values.length;
203
+ if (!len) return 0;
204
+ let sumX = 0;
205
+ let sumY = 0;
206
+ let angle;
207
+ let value;
208
+ for (value of values) {
209
+ angle = value / max * 2 * Math.PI;
210
+ sumX += Math.cos(angle);
211
+ sumY += Math.sin(angle);
212
+ }
213
+ angle = Math.atan2(sumY / len, sumX / len);
214
+ return (angle / (2 * Math.PI) * max + max) % max;
215
+ };
216
+
201
217
  function chunk(list, size = 1) {
202
218
  return list.reduce((res, item, index) => {
203
219
  if (index % size === 0) {
@@ -4587,6 +4603,7 @@ exports.asyncFind = asyncFind;
4587
4603
  exports.asyncForEach = asyncForEach;
4588
4604
  exports.asyncMap = asyncMap;
4589
4605
  exports.avg = avg;
4606
+ exports.avgCircular = avgCircular;
4590
4607
  exports.base64ToBytes = base64ToBytes;
4591
4608
  exports.bigIntBytes = bigIntBytes;
4592
4609
  exports.bigIntFromBytes = bigIntFromBytes;