@tspro/ts-utils-lib 1.20.0 → 1.21.0

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.20.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.21.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __export = (target, all) => {
@@ -1611,8 +1611,179 @@ var Vec = class _Vec extends BaseContainer {
1611
1611
  }
1612
1612
  };
1613
1613
 
1614
- // src/core/div-rect.ts
1615
- var DivRect = class _DivRect {
1614
+ // src/core/rect.ts
1615
+ var Rect = class _Rect {
1616
+ constructor(...args) {
1617
+ __publicField(this, "x");
1618
+ __publicField(this, "y");
1619
+ __publicField(this, "width");
1620
+ __publicField(this, "height");
1621
+ if (args.length === 0) {
1622
+ this.x = this.y = this.width = this.height = 0;
1623
+ } else if (args.length === 2) {
1624
+ this.x = this.y = 0;
1625
+ this.width = args[0];
1626
+ this.height = args[1];
1627
+ } else {
1628
+ this.x = args[0];
1629
+ this.y = args[1];
1630
+ this.width = args[2];
1631
+ this.height = args[3];
1632
+ }
1633
+ if (this.width < 0 || this.height < 0)
1634
+ throw new Error("Rect width and height must be non-negative.");
1635
+ }
1636
+ set(...args) {
1637
+ if (args.length === 0) {
1638
+ this.x = this.y = this.width = this.height = 0;
1639
+ } else if (args.length === 2) {
1640
+ this.x = this.y = 0;
1641
+ this.width = args[0];
1642
+ this.height = args[1];
1643
+ } else {
1644
+ this.x = args[0];
1645
+ this.y = args[1];
1646
+ this.width = args[2];
1647
+ this.height = args[3];
1648
+ }
1649
+ if (this.width < 0 || this.height < 0)
1650
+ throw new Error("Rect width and height must be non-negative.");
1651
+ return this;
1652
+ }
1653
+ // --- Static Constructors ---
1654
+ static fromPoints(p1, p2) {
1655
+ const x = Math.min(p1.x, p2.x);
1656
+ const y = Math.min(p1.y, p2.y);
1657
+ const w = Math.abs(p1.x - p2.x);
1658
+ const h = Math.abs(p1.y - p2.y);
1659
+ return new _Rect(x, y, w, h);
1660
+ }
1661
+ static fromCenter(cx, cy, width, height) {
1662
+ return new _Rect(cx - width / 2, cy - height / 2, width, height);
1663
+ }
1664
+ // --- Derived Properties ---
1665
+ get left() {
1666
+ return this.x;
1667
+ }
1668
+ get top() {
1669
+ return this.y;
1670
+ }
1671
+ get right() {
1672
+ return this.x + this.width;
1673
+ }
1674
+ get bottom() {
1675
+ return this.y + this.height;
1676
+ }
1677
+ get centerX() {
1678
+ return this.x + this.width / 2;
1679
+ }
1680
+ get centerY() {
1681
+ return this.y + this.height / 2;
1682
+ }
1683
+ get center() {
1684
+ return { x: this.centerX, y: this.centerY };
1685
+ }
1686
+ get area() {
1687
+ return this.width * this.height;
1688
+ }
1689
+ get isEmpty() {
1690
+ return this.width <= 0 || this.height <= 0;
1691
+ }
1692
+ // --- Geometric Tests ---
1693
+ containsPoint(px, py) {
1694
+ return px >= this.left && px <= this.right && py >= this.top && py <= this.bottom;
1695
+ }
1696
+ containsRect(other) {
1697
+ return other.left >= this.left && other.right <= this.right && other.top >= this.top && other.bottom <= this.bottom;
1698
+ }
1699
+ intersects(other) {
1700
+ return !(other.right < this.left || other.left > this.right || other.bottom < this.top || other.top > this.bottom);
1701
+ }
1702
+ // --- Operations ---
1703
+ intersectionCopy(other) {
1704
+ const x1 = Math.max(this.left, other.left);
1705
+ const y1 = Math.max(this.top, other.top);
1706
+ const x2 = Math.min(this.right, other.right);
1707
+ const y2 = Math.min(this.bottom, other.bottom);
1708
+ if (x2 <= x1 || y2 <= y1) return new _Rect();
1709
+ return new _Rect(x1, y1, x2 - x1, y2 - y1);
1710
+ }
1711
+ unionCopy(other) {
1712
+ const x1 = Math.min(this.left, other.left);
1713
+ const y1 = Math.min(this.top, other.top);
1714
+ const x2 = Math.max(this.right, other.right);
1715
+ const y2 = Math.max(this.bottom, other.bottom);
1716
+ return new _Rect(x1, y1, x2 - x1, y2 - y1);
1717
+ }
1718
+ insetCopy(dx, dy) {
1719
+ return new _Rect(this.x + dx, this.y + dy, this.width - 2 * dx, this.height - 2 * dy);
1720
+ }
1721
+ inflateCopy(dx, dy) {
1722
+ return new _Rect(this.x - dx, this.y - dy, this.width + 2 * dx, this.height + 2 * dy);
1723
+ }
1724
+ offsetInPlace(dx, dy) {
1725
+ this.x += dx;
1726
+ this.y += dy;
1727
+ return this;
1728
+ }
1729
+ offsetCopy(dx, dy) {
1730
+ return new _Rect(this.x + dx, this.y + dy, this.width, this.height);
1731
+ }
1732
+ scaleInPlace(scaleX, scaleY = scaleX) {
1733
+ this.x = this.centerX - this.width * scaleX / 2;
1734
+ this.width *= scaleX;
1735
+ this.y = this.centerY - this.height * scaleY / 2;
1736
+ this.height *= scaleY;
1737
+ return this;
1738
+ }
1739
+ scaleCopy(scaleX, scaleY = scaleX) {
1740
+ return this.clone().scaleInPlace(scaleX, scaleY);
1741
+ }
1742
+ roundCopy() {
1743
+ const left = Math.round(this.left);
1744
+ const top = Math.round(this.top);
1745
+ const right = Math.round(this.right);
1746
+ const bottom = Math.round(this.bottom);
1747
+ return new _Rect(left, top, right - left, bottom - top);
1748
+ }
1749
+ floorCopy() {
1750
+ const left = Math.floor(this.left);
1751
+ const top = Math.floor(this.top);
1752
+ const right = Math.floor(this.right);
1753
+ const bottom = Math.floor(this.bottom);
1754
+ return new _Rect(left, top, right - left, bottom - top);
1755
+ }
1756
+ ceilCopy() {
1757
+ const left = Math.ceil(this.left);
1758
+ const top = Math.ceil(this.top);
1759
+ const right = Math.ceil(this.right);
1760
+ const bottom = Math.ceil(this.bottom);
1761
+ return new _Rect(left, top, right - left, bottom - top);
1762
+ }
1763
+ expandCopy(px, py) {
1764
+ const left = Math.min(this.left, px);
1765
+ const top = Math.min(this.top, py);
1766
+ const right = Math.max(this.right, px);
1767
+ const bottom = Math.max(this.bottom, py);
1768
+ return new _Rect(left, top, right - left, bottom - top);
1769
+ }
1770
+ // --- Utilities ---
1771
+ equals(other) {
1772
+ return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
1773
+ }
1774
+ clone() {
1775
+ return new _Rect(this.x, this.y, this.width, this.height);
1776
+ }
1777
+ toString() {
1778
+ return `Rect(x=${this.x}, y=${this.y}, w=${this.width}, h=${this.height})`;
1779
+ }
1780
+ toAnchoredRect() {
1781
+ return new AnchoredRect(this.left, this.right, this.top, this.bottom);
1782
+ }
1783
+ };
1784
+
1785
+ // src/core/anchor-rect.ts
1786
+ var AnchoredRect = class _AnchoredRect {
1616
1787
  constructor(...args) {
1617
1788
  __publicField(this, "left");
1618
1789
  __publicField(this, "anchorX");
@@ -1638,8 +1809,31 @@ var DivRect = class _DivRect {
1638
1809
  this.left = this.anchorX = this.right = 0;
1639
1810
  this.top = this.anchorY = this.bottom = 0;
1640
1811
  } else {
1641
- throw new TypeError(`Invalid DivRect args: ${args}`);
1812
+ throw new TypeError(`Invalid AnchoredRect args: ${args}`);
1813
+ }
1814
+ }
1815
+ set(...args) {
1816
+ if (args.length === 6) {
1817
+ this.left = args[0];
1818
+ this.anchorX = args[1];
1819
+ this.right = args[2];
1820
+ this.top = args[3];
1821
+ this.anchorY = args[4];
1822
+ this.bottom = args[5];
1823
+ } else if (args.length === 4) {
1824
+ this.left = args[0];
1825
+ this.right = args[1];
1826
+ this.anchorX = (this.left + this.right) / 2;
1827
+ this.top = args[2];
1828
+ this.bottom = args[3];
1829
+ this.anchorY = (this.top + this.bottom) / 2;
1830
+ } else if (args.length === 0) {
1831
+ this.left = this.anchorX = this.right = 0;
1832
+ this.top = this.anchorY = this.bottom = 0;
1833
+ } else {
1834
+ throw new TypeError(`Invalid AnchoredRect args: ${args}`);
1642
1835
  }
1836
+ return this;
1643
1837
  }
1644
1838
  /**
1645
1839
  * Create rect from basic left, top, width and height arguments.
@@ -1648,10 +1842,10 @@ var DivRect = class _DivRect {
1648
1842
  * @param top - Top coordinate.
1649
1843
  * @param width - Width.
1650
1844
  * @param height - Height.
1651
- * @returns - DivRect.
1845
+ * @returns - AnchoredRect.
1652
1846
  */
1653
1847
  static create(left, top, width, height) {
1654
- return new _DivRect(left, left + width, top, top + height);
1848
+ return new _AnchoredRect(left, left + width, top, top + height);
1655
1849
  }
1656
1850
  /**
1657
1851
  * Create rect from anchorX, anchorY, width, height arguments.
@@ -1660,10 +1854,10 @@ var DivRect = class _DivRect {
1660
1854
  * @param centerY - Center y-coordinate.
1661
1855
  * @param width - Width.
1662
1856
  * @param height - Height.
1663
- * @returns - DivRect.
1857
+ * @returns - AnchoredRect.
1664
1858
  */
1665
1859
  static createCentered(centerX, centerY, width, height) {
1666
- return new _DivRect(
1860
+ return new _AnchoredRect(
1667
1861
  centerX - width / 2,
1668
1862
  centerX,
1669
1863
  centerX + width / 2,
@@ -1679,38 +1873,22 @@ var DivRect = class _DivRect {
1679
1873
  * @param rightw - Right section width.
1680
1874
  * @param toph - Top section height.
1681
1875
  * @param bottomh - Bottomsection height.
1682
- * @returns - DivRect.
1876
+ * @returns - AnchoredRect.
1683
1877
  */
1684
1878
  static createSections(leftw, rightw, toph, bottomh) {
1685
- return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
1879
+ return new _AnchoredRect(-leftw, 0, rightw, -toph, 0, bottomh);
1686
1880
  }
1687
1881
  /**
1688
- * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1689
- * @private
1690
- * */
1882
+ * Get center x-coordinate.
1883
+ */
1691
1884
  get centerX() {
1692
- return this.anchorX;
1693
- }
1694
- /**
1695
- * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1696
- * @private
1697
- * */
1698
- set centerX(x) {
1699
- this.anchorX = x;
1885
+ return this.left + this.width / 2;
1700
1886
  }
1701
1887
  /**
1702
- * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1703
- * @private
1704
- * */
1888
+ * Get center ycoordinate.
1889
+ */
1705
1890
  get centerY() {
1706
- return this.anchorY;
1707
- }
1708
- /**
1709
- * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1710
- * @private
1711
- * */
1712
- set centerY(y) {
1713
- this.anchorY = y;
1891
+ return this.top + this.height / 2;
1714
1892
  }
1715
1893
  /**
1716
1894
  * Width getter.
@@ -1761,8 +1939,8 @@ var DivRect = class _DivRect {
1761
1939
  /**
1762
1940
  * Do a and b rects overlap?
1763
1941
  *
1764
- * @param a - DivRect a.
1765
- * @param b - DivRect b.
1942
+ * @param a - AnchoredRect a.
1943
+ * @param b - AnchoredRect b.
1766
1944
  * @returns - True/false.
1767
1945
  */
1768
1946
  static overlap(a, b) {
@@ -1771,8 +1949,8 @@ var DivRect = class _DivRect {
1771
1949
  /**
1772
1950
  * Do horizontal measures of a and b rects overlap?
1773
1951
  *
1774
- * @param a - DivRect a.
1775
- * @param b - DivRect b.
1952
+ * @param a - AnchoredRect a.
1953
+ * @param b - AnchoredRect b.
1776
1954
  * @returns - True/false.
1777
1955
  */
1778
1956
  static overlapX(a, b) {
@@ -1780,8 +1958,8 @@ var DivRect = class _DivRect {
1780
1958
  }
1781
1959
  /**
1782
1960
  * Check if given rects are equal.
1783
- * @param a - DivRect a.
1784
- * @param b - DivRect b.
1961
+ * @param a - AnchoredRect a.
1962
+ * @param b - AnchoredRect b.
1785
1963
  * @returns - True/false.
1786
1964
  */
1787
1965
  static equals(a, b) {
@@ -1799,13 +1977,13 @@ var DivRect = class _DivRect {
1799
1977
  * @returns - True/false.
1800
1978
  */
1801
1979
  equals(other) {
1802
- return _DivRect.equals(this, other);
1980
+ return _AnchoredRect.equals(this, other);
1803
1981
  }
1804
1982
  /**
1805
1983
  * Check if edges of given rects are equal, ignoring anchorX and anchorY.
1806
1984
  *
1807
- * @param a - DivRect a.
1808
- * @param b - DivRect b.
1985
+ * @param a - AnchoredRect a.
1986
+ * @param b - AnchoredRect b.
1809
1987
  * @returns - True/false.
1810
1988
  */
1811
1989
  static equalsEdges(a, b) {
@@ -1820,33 +1998,25 @@ var DivRect = class _DivRect {
1820
1998
  /**
1821
1999
  * Check if edges of this Rect equals with given Rect, ignoring anchorX and anchorY.
1822
2000
  *
1823
- * @param other - The other DivRect.
2001
+ * @param other - The other AnchoredRect.
1824
2002
  * @returns - True/false.
1825
2003
  */
1826
2004
  equalsEdges(other) {
1827
- return _DivRect.equalsEdges(this, other);
1828
- }
1829
- /**
1830
- * @deprecated - Use `DivRect.equalsEdges()` instead. Will be removed in v2.0.0.
1831
- * @private
1832
- */
1833
- static equalsFrame(a, b) {
1834
- return _DivRect.equalsEdges(a, b);
2005
+ return _AnchoredRect.equalsEdges(this, other);
1835
2006
  }
1836
2007
  /**
1837
2008
  * Created duplicate of this Rect.
1838
- *
1839
2009
  * @returns - Duplicate.
1840
2010
  */
1841
- copy() {
1842
- return new _DivRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
2011
+ clone() {
2012
+ return new _AnchoredRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
1843
2013
  }
1844
2014
  /**
1845
2015
  * Move this rect by (dx, dy). Modifies this Rect.
1846
2016
  *
1847
2017
  * @param dx - Offset amount in x-direction.
1848
2018
  * @param dy - Offset amount in y-direction.
1849
- * @returns - This DivRect instance.
2019
+ * @returns - This AnchoredRect instance.
1850
2020
  */
1851
2021
  offsetInPlace(dx, dy) {
1852
2022
  this.left += dx;
@@ -1862,16 +2032,16 @@ var DivRect = class _DivRect {
1862
2032
  *
1863
2033
  * @param dx - Offset amount in x-direction.
1864
2034
  * @param dy - Offset amount in y-direction.
1865
- * @returns - DivRect copy with applied offset.
2035
+ * @returns - AnchoredRect copy with applied offset.
1866
2036
  */
1867
2037
  offsetCopy(dx, dy) {
1868
- return this.copy().offsetInPlace(dx, dy);
2038
+ return this.clone().offsetInPlace(dx, dy);
1869
2039
  }
1870
2040
  /**
1871
2041
  * Expand this Rect by given Rect. Modifies this Rect.
1872
2042
  *
1873
- * @param rect - DivRect to expand this instance with.
1874
- * @returns - This DivRect instance.
2043
+ * @param rect - AnchoredRect to expand this instance with.
2044
+ * @returns - This AnchoredRect instance.
1875
2045
  */
1876
2046
  expandInPlace(rect) {
1877
2047
  this.left = Math.min(this.left, rect.left);
@@ -1883,17 +2053,17 @@ var DivRect = class _DivRect {
1883
2053
  /**
1884
2054
  * Expand this Rect by given Rect. Immutable, returns modified copy.
1885
2055
  *
1886
- * @param rect - DivRect to expand this instance with.
1887
- * @returns - Expanded copy of this DivRect.
2056
+ * @param rect - AnchoredRect to expand this instance with.
2057
+ * @returns - Expanded copy of this AnchoredRect.
1888
2058
  */
1889
2059
  expandCopy(rect) {
1890
- return this.copy().expandInPlace(rect);
2060
+ return this.clone().expandInPlace(rect);
1891
2061
  }
1892
2062
  /**
1893
2063
  * Clip this Rect by given Rect. Mmodifies this Rect.
1894
2064
  *
1895
- * @param clipRect - DivRect to clip this instance with.
1896
- * @returns - This DivRect instance.
2065
+ * @param clipRect - AnchoredRect to clip this instance with.
2066
+ * @returns - This AnchoredRect instance.
1897
2067
  */
1898
2068
  clipInPlace(clipRect) {
1899
2069
  this.left = Math.max(this.left, clipRect.left);
@@ -1907,21 +2077,20 @@ var DivRect = class _DivRect {
1907
2077
  /**
1908
2078
  * Clip this Rect by given Rect. Immutable, return modified copy.
1909
2079
  *
1910
- * @param clipRect - DivRecto to clip this instance with.
1911
- * @returns - Clipped DivRect copy.
2080
+ * @param clipRect - AnchoredRecto to clip this instance with.
2081
+ * @returns - Clipped AnchoredRect copy.
1912
2082
  */
1913
2083
  clipCopy(clipRect) {
1914
- return this.copy().clipInPlace(clipRect);
2084
+ return this.clone().clipInPlace(clipRect);
1915
2085
  }
1916
2086
  /**
1917
2087
  * Scale Rect. Anchor pos is (anchorX, anchorY). Modifies this Rect.
1918
2088
  *
1919
2089
  * @param scaleX - Scale x-amount.
1920
2090
  * @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
1921
- * @returns This DivRect instance.
2091
+ * @returns This AnchoredRect instance.
1922
2092
  */
1923
- scaleInPlace(scaleX, scaleY) {
1924
- scaleY = scaleY ?? scaleX;
2093
+ scaleInPlace(scaleX, scaleY = scaleX) {
1925
2094
  this.left = this.anchorX - this.leftw * scaleX;
1926
2095
  this.right = this.anchorX + this.rightw * scaleX;
1927
2096
  this.top = this.anchorY - this.toph * scaleY;
@@ -1933,18 +2102,21 @@ var DivRect = class _DivRect {
1933
2102
  *
1934
2103
  * @param scaleX - Scale x-amount.
1935
2104
  * @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
1936
- * @returns Scaled copy of this DivRect.
2105
+ * @returns Scaled copy of this AnchoredRect.
1937
2106
  */
1938
- scaleCopy(scaleX, scaleY) {
1939
- return this.copy().scaleInPlace(scaleX, scaleY);
2107
+ scaleCopy(scaleX, scaleY = scaleX) {
2108
+ return this.clone().scaleInPlace(scaleX, scaleY);
1940
2109
  }
1941
2110
  /**
1942
- * Get this DivRect instance.
1943
- * @returns - This DivRect instance.
2111
+ * Get this AnchoredRect instance.
2112
+ * @returns - This AnchoredRect instance.
1944
2113
  */
1945
2114
  getRect() {
1946
2115
  return this;
1947
2116
  }
2117
+ toRect() {
2118
+ return new Rect(this.left, this.right, this.width, this.height);
2119
+ }
1948
2120
  };
1949
2121
 
1950
2122
  // src/core/LRU-cache.ts
@@ -4853,7 +5025,375 @@ var DeepSet = class _DeepSet extends SetBase {
4853
5025
  return isDeepEqual2(a, b);
4854
5026
  }
4855
5027
  };
5028
+
5029
+ // src/deprecated/div-rect.ts
5030
+ var DivRect = class _DivRect {
5031
+ constructor(...args) {
5032
+ __publicField(this, "left");
5033
+ __publicField(this, "anchorX");
5034
+ __publicField(this, "right");
5035
+ __publicField(this, "top");
5036
+ __publicField(this, "anchorY");
5037
+ __publicField(this, "bottom");
5038
+ if (args.length === 6) {
5039
+ this.left = args[0];
5040
+ this.anchorX = args[1];
5041
+ this.right = args[2];
5042
+ this.top = args[3];
5043
+ this.anchorY = args[4];
5044
+ this.bottom = args[5];
5045
+ } else if (args.length === 4) {
5046
+ this.left = args[0];
5047
+ this.right = args[1];
5048
+ this.anchorX = (this.left + this.right) / 2;
5049
+ this.top = args[2];
5050
+ this.bottom = args[3];
5051
+ this.anchorY = (this.top + this.bottom) / 2;
5052
+ } else if (args.length === 0) {
5053
+ this.left = this.anchorX = this.right = 0;
5054
+ this.top = this.anchorY = this.bottom = 0;
5055
+ } else {
5056
+ throw new TypeError(`Invalid DivRect args: ${args}`);
5057
+ }
5058
+ }
5059
+ set(...args) {
5060
+ if (args.length === 6) {
5061
+ this.left = args[0];
5062
+ this.anchorX = args[1];
5063
+ this.right = args[2];
5064
+ this.top = args[3];
5065
+ this.anchorY = args[4];
5066
+ this.bottom = args[5];
5067
+ } else if (args.length === 4) {
5068
+ this.left = args[0];
5069
+ this.right = args[1];
5070
+ this.anchorX = (this.left + this.right) / 2;
5071
+ this.top = args[2];
5072
+ this.bottom = args[3];
5073
+ this.anchorY = (this.top + this.bottom) / 2;
5074
+ } else if (args.length === 0) {
5075
+ this.left = this.anchorX = this.right = 0;
5076
+ this.top = this.anchorY = this.bottom = 0;
5077
+ } else {
5078
+ throw new TypeError(`Invalid DivRect args: ${args}`);
5079
+ }
5080
+ return this;
5081
+ }
5082
+ /**
5083
+ * Create rect from basic left, top, width and height arguments.
5084
+ *
5085
+ * @param left - Left coordinate.
5086
+ * @param top - Top coordinate.
5087
+ * @param width - Width.
5088
+ * @param height - Height.
5089
+ * @returns - DivRect.
5090
+ */
5091
+ static create(left, top, width, height) {
5092
+ return new _DivRect(left, left + width, top, top + height);
5093
+ }
5094
+ /**
5095
+ * Create rect from anchorX, anchorY, width, height arguments.
5096
+ *
5097
+ * @param centerX - Center x-coordinate.
5098
+ * @param centerY - Center y-coordinate.
5099
+ * @param width - Width.
5100
+ * @param height - Height.
5101
+ * @returns - DivRect.
5102
+ */
5103
+ static createCentered(centerX, centerY, width, height) {
5104
+ return new _DivRect(
5105
+ centerX - width / 2,
5106
+ centerX,
5107
+ centerX + width / 2,
5108
+ centerY - height / 2,
5109
+ centerY,
5110
+ centerY + height / 2
5111
+ );
5112
+ }
5113
+ /**
5114
+ * Create rect from sections.
5115
+ *
5116
+ * @param leftw - Left section width.
5117
+ * @param rightw - Right section width.
5118
+ * @param toph - Top section height.
5119
+ * @param bottomh - Bottomsection height.
5120
+ * @returns - DivRect.
5121
+ */
5122
+ static createSections(leftw, rightw, toph, bottomh) {
5123
+ return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
5124
+ }
5125
+ /**
5126
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
5127
+ * @private
5128
+ * */
5129
+ get centerX() {
5130
+ return this.anchorX;
5131
+ }
5132
+ /**
5133
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
5134
+ * @private
5135
+ * */
5136
+ set centerX(x) {
5137
+ this.anchorX = x;
5138
+ }
5139
+ /**
5140
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
5141
+ * @private
5142
+ * */
5143
+ get centerY() {
5144
+ return this.anchorY;
5145
+ }
5146
+ /**
5147
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
5148
+ * @private
5149
+ * */
5150
+ set centerY(y) {
5151
+ this.anchorY = y;
5152
+ }
5153
+ /**
5154
+ * Width getter.
5155
+ */
5156
+ get width() {
5157
+ return this.right - this.left;
5158
+ }
5159
+ /**
5160
+ * Height getter.
5161
+ */
5162
+ get height() {
5163
+ return this.bottom - this.top;
5164
+ }
5165
+ /**
5166
+ * Left section width getter.
5167
+ */
5168
+ get leftw() {
5169
+ return this.anchorX - this.left;
5170
+ }
5171
+ /**
5172
+ * Right section width getter.
5173
+ */
5174
+ get rightw() {
5175
+ return this.right - this.anchorX;
5176
+ }
5177
+ /**
5178
+ * Top section height getter.
5179
+ */
5180
+ get toph() {
5181
+ return this.anchorY - this.top;
5182
+ }
5183
+ /**
5184
+ * Bottom section height getter.
5185
+ */
5186
+ get bottomh() {
5187
+ return this.bottom - this.anchorY;
5188
+ }
5189
+ /**
5190
+ * Does this Rect contain given (x, y)-point?
5191
+ *
5192
+ * @param x - X-coordinate.
5193
+ * @param y - Y-coordinate.
5194
+ * @returns - True/false.
5195
+ */
5196
+ contains(x, y) {
5197
+ return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
5198
+ }
5199
+ /**
5200
+ * Do a and b rects overlap?
5201
+ *
5202
+ * @param a - DivRect a.
5203
+ * @param b - DivRect b.
5204
+ * @returns - True/false.
5205
+ */
5206
+ static overlap(a, b) {
5207
+ return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
5208
+ }
5209
+ /**
5210
+ * Do horizontal measures of a and b rects overlap?
5211
+ *
5212
+ * @param a - DivRect a.
5213
+ * @param b - DivRect b.
5214
+ * @returns - True/false.
5215
+ */
5216
+ static overlapX(a, b) {
5217
+ return a.right > b.left && a.left < b.right;
5218
+ }
5219
+ /**
5220
+ * Check if given rects are equal.
5221
+ * @param a - DivRect a.
5222
+ * @param b - DivRect b.
5223
+ * @returns - True/false.
5224
+ */
5225
+ static equals(a, b) {
5226
+ if (a == null && b == null) {
5227
+ return true;
5228
+ } else if (a == null || b == null) {
5229
+ return false;
5230
+ } else {
5231
+ return a === b || a.left === b.left && a.anchorX === b.anchorX && a.right === b.right && a.top === b.top && a.anchorY === b.anchorY && a.bottom === b.bottom;
5232
+ }
5233
+ }
5234
+ /**
5235
+ * Check if this rect equals with another rect.
5236
+ * @param other - The other rect.
5237
+ * @returns - True/false.
5238
+ */
5239
+ equals(other) {
5240
+ return _DivRect.equals(this, other);
5241
+ }
5242
+ /**
5243
+ * Check if edges of given rects are equal, ignoring anchorX and anchorY.
5244
+ *
5245
+ * @param a - DivRect a.
5246
+ * @param b - DivRect b.
5247
+ * @returns - True/false.
5248
+ */
5249
+ static equalsEdges(a, b) {
5250
+ if (a == null && b == null) {
5251
+ return true;
5252
+ } else if (a == null || b == null) {
5253
+ return false;
5254
+ } else {
5255
+ return a === b || a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom;
5256
+ }
5257
+ }
5258
+ /**
5259
+ * Check if edges of this Rect equals with given Rect, ignoring anchorX and anchorY.
5260
+ *
5261
+ * @param other - The other DivRect.
5262
+ * @returns - True/false.
5263
+ */
5264
+ equalsEdges(other) {
5265
+ return _DivRect.equalsEdges(this, other);
5266
+ }
5267
+ /**
5268
+ * @deprecated - Use {@link equalsEdges()} instead. Will be removed in v2.0.0.
5269
+ * @private
5270
+ */
5271
+ static equalsFrame(a, b) {
5272
+ return _DivRect.equalsEdges(a, b);
5273
+ }
5274
+ /**
5275
+ * @deprecated - Use {@link clone()} instead. Will be removed in v2.0.0.
5276
+ * @private
5277
+ */
5278
+ copy() {
5279
+ return new _DivRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
5280
+ }
5281
+ /**
5282
+ * Created duplicate of this Rect.
5283
+ * @returns - Duplicate.
5284
+ */
5285
+ clone() {
5286
+ return new _DivRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
5287
+ }
5288
+ /**
5289
+ * Move this rect by (dx, dy). Modifies this Rect.
5290
+ *
5291
+ * @param dx - Offset amount in x-direction.
5292
+ * @param dy - Offset amount in y-direction.
5293
+ * @returns - This DivRect instance.
5294
+ */
5295
+ offsetInPlace(dx, dy) {
5296
+ this.left += dx;
5297
+ this.anchorX += dx;
5298
+ this.right += dx;
5299
+ this.top += dy;
5300
+ this.anchorY += dy;
5301
+ this.bottom += dy;
5302
+ return this;
5303
+ }
5304
+ /**
5305
+ * Move this rect by (dx, dy). Immutable, returns modified copy.
5306
+ *
5307
+ * @param dx - Offset amount in x-direction.
5308
+ * @param dy - Offset amount in y-direction.
5309
+ * @returns - DivRect copy with applied offset.
5310
+ */
5311
+ offsetCopy(dx, dy) {
5312
+ return this.clone().offsetInPlace(dx, dy);
5313
+ }
5314
+ /**
5315
+ * Expand this Rect by given Rect. Modifies this Rect.
5316
+ *
5317
+ * @param rect - DivRect to expand this instance with.
5318
+ * @returns - This DivRect instance.
5319
+ */
5320
+ expandInPlace(rect) {
5321
+ this.left = Math.min(this.left, rect.left);
5322
+ this.right = Math.max(this.right, rect.right);
5323
+ this.top = Math.min(this.top, rect.top);
5324
+ this.bottom = Math.max(this.bottom, rect.bottom);
5325
+ return this;
5326
+ }
5327
+ /**
5328
+ * Expand this Rect by given Rect. Immutable, returns modified copy.
5329
+ *
5330
+ * @param rect - DivRect to expand this instance with.
5331
+ * @returns - Expanded copy of this DivRect.
5332
+ */
5333
+ expandCopy(rect) {
5334
+ return this.clone().expandInPlace(rect);
5335
+ }
5336
+ /**
5337
+ * Clip this Rect by given Rect. Mmodifies this Rect.
5338
+ *
5339
+ * @param clipRect - DivRect to clip this instance with.
5340
+ * @returns - This DivRect instance.
5341
+ */
5342
+ clipInPlace(clipRect) {
5343
+ this.left = Math.max(this.left, clipRect.left);
5344
+ this.right = Math.min(this.right, clipRect.right);
5345
+ this.anchorX = clamp(this.anchorX, this.left, this.right);
5346
+ this.top = Math.max(this.top, clipRect.top);
5347
+ this.bottom = Math.min(this.bottom, clipRect.bottom);
5348
+ this.anchorY = clamp(this.anchorY, this.top, this.bottom);
5349
+ return this;
5350
+ }
5351
+ /**
5352
+ * Clip this Rect by given Rect. Immutable, return modified copy.
5353
+ *
5354
+ * @param clipRect - DivRecto to clip this instance with.
5355
+ * @returns - Clipped DivRect copy.
5356
+ */
5357
+ clipCopy(clipRect) {
5358
+ return this.clone().clipInPlace(clipRect);
5359
+ }
5360
+ /**
5361
+ * Scale Rect. Anchor pos is (anchorX, anchorY). Modifies this Rect.
5362
+ *
5363
+ * @param scaleX - Scale x-amount.
5364
+ * @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
5365
+ * @returns This DivRect instance.
5366
+ */
5367
+ scaleInPlace(scaleX, scaleY = scaleX) {
5368
+ this.left = this.anchorX - this.leftw * scaleX;
5369
+ this.right = this.anchorX + this.rightw * scaleX;
5370
+ this.top = this.anchorY - this.toph * scaleY;
5371
+ this.bottom = this.anchorY + this.bottomh * scaleY;
5372
+ return this;
5373
+ }
5374
+ /**
5375
+ * Scale Rect. Anchor pos is (anchorX, anchorY). Immutable, returns modified copy.
5376
+ *
5377
+ * @param scaleX - Scale x-amount.
5378
+ * @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
5379
+ * @returns Scaled copy of this DivRect.
5380
+ */
5381
+ scaleCopy(scaleX, scaleY = scaleX) {
5382
+ return this.clone().scaleInPlace(scaleX, scaleY);
5383
+ }
5384
+ /**
5385
+ * Get this DivRect instance.
5386
+ * @returns - This DivRect instance.
5387
+ */
5388
+ getRect() {
5389
+ return this;
5390
+ }
5391
+ toRect() {
5392
+ return new Rect(this.left, this.right, this.width, this.height);
5393
+ }
5394
+ };
4856
5395
  export {
5396
+ AnchoredRect,
4857
5397
  assert_exports as Assert,
4858
5398
  BaseContainer,
4859
5399
  BiMap,
@@ -4871,6 +5411,7 @@ export {
4871
5411
  Map2,
4872
5412
  Map3,
4873
5413
  MultiContainer,
5414
+ Rect,
4874
5415
  Set1,
4875
5416
  SetBase,
4876
5417
  SignedIndexArray,