@woosh/meep-engine 2.109.21 → 2.109.22

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/build/meep.cjs CHANGED
@@ -76728,9 +76728,10 @@ function planesEqual(a, b) {
76728
76728
  * @param {T[]} a
76729
76729
  * @param {T[]} b
76730
76730
  * @param {function(T,T):boolean} elements_equal
76731
+ * @param {*} [element_equal_context]
76731
76732
  * @returns {boolean}
76732
76733
  */
76733
- function isArraysEqualWithComparator(a, b, elements_equal) {
76734
+ function isArraysEqualWithComparator(a, b, elements_equal, element_equal_context) {
76734
76735
  if (a === b) {
76735
76736
  // same object
76736
76737
  return true;
@@ -76751,7 +76752,7 @@ function isArraysEqualWithComparator(a, b, elements_equal) {
76751
76752
  const aE = a[i];
76752
76753
  const bE = b[i];
76753
76754
 
76754
- if (!elements_equal(aE, bE)) {
76755
+ if (!elements_equal.call(element_equal_context, aE, bE)) {
76755
76756
  return false;
76756
76757
  }
76757
76758
  }
@@ -102537,9 +102538,16 @@ function easeInOutQuad(t) {
102537
102538
  * @template A,B
102538
102539
  * @param {A} a
102539
102540
  * @param {B} b
102541
+ * @param {function(a:A, b:B):boolean} [value_equality_function] allows you to insert custom element comparison function
102542
+ * @param {*} [value_equality_function_context]
102540
102543
  * @returns {boolean}
102541
102544
  */
102542
- function objectDeepEquals(a, b) {
102545
+ function objectDeepEquals(
102546
+ a, b,
102547
+ value_equality_function = objectDeepEquals,
102548
+ value_equality_function_context = null
102549
+ ) {
102550
+
102543
102551
  if (a === b) {
102544
102552
  // identity shortcut
102545
102553
  return true;
@@ -102555,43 +102563,64 @@ function objectDeepEquals(a, b) {
102555
102563
  if (tA !== "object") {
102556
102564
  // primitive types, identity equality already checked
102557
102565
  return false;
102558
- } else {
102566
+ }
102559
102567
 
102560
- if (a === null || b === null) {
102561
- // we know that A and B are not the same, so if one of them is a null - there is no possible equality
102568
+ if (a === null || b === null) {
102569
+ // we know that A and B are not the same, so if one of them is a null - there is no possible equality
102570
+ return false;
102571
+ }
102572
+
102573
+ if (Array.isArray(a)) {
102574
+ // special fast path for arrays
102575
+ if (!Array.isArray(b)) {
102576
+ // one is an array, the other is not
102562
102577
  return false;
102563
102578
  }
102579
+ return isArraysEqualWithComparator(a, b, value_equality_function, value_equality_function_context);
102580
+ }
102564
102581
 
102565
- if (Array.isArray(a)) {
102566
- // special fast path for arrays
102567
- if (!Array.isArray(b)) {
102568
- // one is an array, the other is not
102569
- return false;
102570
- }
102571
- return isArraysEqualWithComparator(a, b, objectDeepEquals);
102572
- }
102582
+ // try equals function
102583
+ if (
102584
+ typeof a.equals === "function"
102585
+ && typeof b.equals === "function"
102586
+ ) {
102587
+ return a.equals(b);
102588
+ }
102573
102589
 
102574
- const keys_a = Object.keys(a);
102575
- const keys_b = Object.keys(b);
102590
+ const keys_a = Object.keys(a);
102591
+ const keys_b = Object.keys(b);
102576
102592
 
102577
- if (!isArrayEqualStrict(keys_a, keys_b)) {
102578
- // different fields
102579
- return false;
102580
- }
102593
+ // sort keys to eliminate ordering concerns
102594
+ keys_a.sort();
102595
+ keys_b.sort();
102581
102596
 
102582
- const key_count = keys_a.length;
102597
+ if (!isArrayEqualStrict(keys_a, keys_b)) {
102598
+ // different fields
102599
+ return false;
102600
+ }
102583
102601
 
102584
- for (let i = 0; i < key_count; i++) {
102585
- const key = keys_a[i];
102602
+ const key_count = keys_a.length;
102586
102603
 
102587
- if (!objectDeepEquals(a[key], b[key])) {
102588
- return false;
102589
- }
102590
- }
102604
+ for (let i = 0; i < key_count; i++) {
102605
+ const key = keys_a[i];
102591
102606
 
102592
- return true;
102607
+ const a_value = a[key];
102608
+ const b_value = b[key];
102593
102609
 
102610
+ const values_are_equal = value_equality_function.call(
102611
+ value_equality_function_context,
102612
+ a_value,
102613
+ b_value
102614
+ );
102615
+
102616
+ if (!values_are_equal) {
102617
+ return false;
102618
+ }
102594
102619
  }
102620
+
102621
+ // looks like we have equality
102622
+ return true;
102623
+
102595
102624
  }
102596
102625
 
102597
102626
  /**