@whitesev/utils 2.11.3 → 2.11.4

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.umd.js CHANGED
@@ -243,7 +243,7 @@
243
243
  const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
244
244
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
245
245
 
246
- const version = "2.11.3";
246
+ const version = "2.11.4";
247
247
 
248
248
  /* eslint-disable */
249
249
  // ==UserScript==
@@ -8486,6 +8486,58 @@
8486
8486
  }
8487
8487
  });
8488
8488
  }
8489
+ calcPositionDistance(...args) {
8490
+ let position = {
8491
+ x: 0,
8492
+ y: 0,
8493
+ };
8494
+ let otherPosition = {
8495
+ x: 0,
8496
+ y: 0,
8497
+ };
8498
+ if (typeof args[0] === "object" && args[0] != null && typeof args[1] === "object" && args[1] != null) {
8499
+ position = args[0];
8500
+ otherPosition = args[1];
8501
+ }
8502
+ else if (args.length === 4) {
8503
+ position = {
8504
+ x: args[0],
8505
+ y: args[1],
8506
+ };
8507
+ otherPosition = {
8508
+ x: args[2],
8509
+ y: args[3],
8510
+ };
8511
+ }
8512
+ else {
8513
+ throw new Error("Invalid arguments");
8514
+ }
8515
+ if (typeof position.x === "string") {
8516
+ position.x = Number(position.x);
8517
+ }
8518
+ if (isNaN(position.x)) {
8519
+ throw new Error(`Invalid x: ${position.x}`);
8520
+ }
8521
+ if (typeof position.y === "string") {
8522
+ position.y = Number(position.y);
8523
+ }
8524
+ if (isNaN(position.y)) {
8525
+ throw new Error(`Invalid y: ${position.y}`);
8526
+ }
8527
+ if (typeof otherPosition.x === "string") {
8528
+ otherPosition.x = Number(otherPosition.x);
8529
+ }
8530
+ if (isNaN(otherPosition.x)) {
8531
+ throw new Error(`Invalid x: ${otherPosition.x}`);
8532
+ }
8533
+ if (typeof otherPosition.y === "string") {
8534
+ otherPosition.y = Number(otherPosition.y);
8535
+ }
8536
+ if (isNaN(otherPosition.y)) {
8537
+ throw new Error(`Invalid y: ${otherPosition.y}`);
8538
+ }
8539
+ return Math.sqrt(Math.pow(otherPosition.x - position.x, 2) + Math.pow(otherPosition.y - position.y, 2));
8540
+ }
8489
8541
  }
8490
8542
  const utils = new Utils();
8491
8543