@tspro/ts-utils-lib 3.3.0 → 3.4.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/CHANGELOG.md +12 -1
- package/README.md +30 -30
- package/dist/index.d.ts +304 -113
- package/dist/index.es5.iife.js +1 -1
- package/dist/index.es5.polyfilled.iife.js +1 -1
- package/dist/index.js +250 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -113
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* TsUtilsLib v3.
|
|
2
|
+
* TsUtilsLib v3.4.0 (esm)
|
|
3
3
|
* (c) 2023-2025 PahkaSoft
|
|
4
4
|
* Licensed under the MIT License
|
|
5
5
|
*/
|
|
@@ -2026,6 +2026,24 @@ var Vec = class _Vec extends BaseContainer {
|
|
|
2026
2026
|
};
|
|
2027
2027
|
|
|
2028
2028
|
// src/core/rect.ts
|
|
2029
|
+
function getRectProps(arg) {
|
|
2030
|
+
let left = NaN;
|
|
2031
|
+
let right = NaN;
|
|
2032
|
+
let top = NaN;
|
|
2033
|
+
let bottom = NaN;
|
|
2034
|
+
if (hasProperties(arg, ["left", "top"])) {
|
|
2035
|
+
left = Number(arg.left);
|
|
2036
|
+
top = Number(arg.top);
|
|
2037
|
+
} else if (hasProperties(arg, ["x", "y"])) {
|
|
2038
|
+
left = Number(arg.x);
|
|
2039
|
+
top = Number(arg.y);
|
|
2040
|
+
}
|
|
2041
|
+
if (hasProperties(arg, ["width", "height"])) {
|
|
2042
|
+
right = left + Number(arg.width);
|
|
2043
|
+
bottom = top + Number(arg.height);
|
|
2044
|
+
}
|
|
2045
|
+
return { left, top, right, bottom };
|
|
2046
|
+
}
|
|
2029
2047
|
var Rect = class _Rect {
|
|
2030
2048
|
constructor(...args) {
|
|
2031
2049
|
__publicField(this, "x");
|
|
@@ -2034,15 +2052,21 @@ var Rect = class _Rect {
|
|
|
2034
2052
|
__publicField(this, "height");
|
|
2035
2053
|
if (args.length === 0) {
|
|
2036
2054
|
this.x = this.y = this.width = this.height = 0;
|
|
2055
|
+
} else if (args.length === 1) {
|
|
2056
|
+
const _args = getRectProps(args[0]);
|
|
2057
|
+
this.x = _args.left;
|
|
2058
|
+
this.y = _args.top;
|
|
2059
|
+
this.width = _args.right - _args.left;
|
|
2060
|
+
this.height = _args.bottom - _args.top;
|
|
2037
2061
|
} else if (args.length === 2) {
|
|
2038
2062
|
this.x = this.y = 0;
|
|
2039
|
-
this.width = args[0];
|
|
2040
|
-
this.height = args[1];
|
|
2063
|
+
this.width = Number(args[0]);
|
|
2064
|
+
this.height = Number(args[1]);
|
|
2041
2065
|
} else {
|
|
2042
|
-
this.x = args[0];
|
|
2043
|
-
this.y = args[1];
|
|
2044
|
-
this.width = args[2];
|
|
2045
|
-
this.height = args[3];
|
|
2066
|
+
this.x = Number(args[0]);
|
|
2067
|
+
this.y = Number(args[1]);
|
|
2068
|
+
this.width = Number(args[2]);
|
|
2069
|
+
this.height = Number(args[3]);
|
|
2046
2070
|
}
|
|
2047
2071
|
if (this.width < 0 || this.height < 0)
|
|
2048
2072
|
throw new Error("Rect width and height must be non-negative.");
|
|
@@ -2064,7 +2088,9 @@ var Rect = class _Rect {
|
|
|
2064
2088
|
throw new Error("Rect width and height must be non-negative.");
|
|
2065
2089
|
return this;
|
|
2066
2090
|
}
|
|
2067
|
-
|
|
2091
|
+
/**
|
|
2092
|
+
* Create the smallest rectangle enclosing two points.
|
|
2093
|
+
*/
|
|
2068
2094
|
static fromPoints(p1, p2) {
|
|
2069
2095
|
const x = Math.min(p1.x, p2.x);
|
|
2070
2096
|
const y = Math.min(p1.y, p2.y);
|
|
@@ -2072,77 +2098,129 @@ var Rect = class _Rect {
|
|
|
2072
2098
|
const h = Math.abs(p1.y - p2.y);
|
|
2073
2099
|
return new _Rect(x, y, w, h);
|
|
2074
2100
|
}
|
|
2101
|
+
/**
|
|
2102
|
+
* Create a rectangle centered at the given point.
|
|
2103
|
+
*
|
|
2104
|
+
* @param cx - Center x-coordinate
|
|
2105
|
+
* @param cy - Center y-coordinate
|
|
2106
|
+
* @param width - Rectangle width
|
|
2107
|
+
* @param height - Rectangle height
|
|
2108
|
+
*/
|
|
2075
2109
|
static fromCenter(cx, cy, width, height) {
|
|
2076
2110
|
return new _Rect(cx - width / 2, cy - height / 2, width, height);
|
|
2077
2111
|
}
|
|
2078
|
-
|
|
2112
|
+
/** Left edge coordinate. */
|
|
2079
2113
|
get left() {
|
|
2080
2114
|
return this.x;
|
|
2081
2115
|
}
|
|
2116
|
+
/** Top edge coordinate. */
|
|
2082
2117
|
get top() {
|
|
2083
2118
|
return this.y;
|
|
2084
2119
|
}
|
|
2120
|
+
/** Right edge coordinate. */
|
|
2085
2121
|
get right() {
|
|
2086
2122
|
return this.x + this.width;
|
|
2087
2123
|
}
|
|
2124
|
+
/** Bottom edge coordinate. */
|
|
2088
2125
|
get bottom() {
|
|
2089
2126
|
return this.y + this.height;
|
|
2090
2127
|
}
|
|
2128
|
+
/** Geometric center x-coordinate. */
|
|
2091
2129
|
get centerX() {
|
|
2092
2130
|
return this.x + this.width / 2;
|
|
2093
2131
|
}
|
|
2132
|
+
/** Geometric center y-coordinate. */
|
|
2094
2133
|
get centerY() {
|
|
2095
2134
|
return this.y + this.height / 2;
|
|
2096
2135
|
}
|
|
2136
|
+
/** Geometric center point. */
|
|
2097
2137
|
get center() {
|
|
2098
2138
|
return { x: this.centerX, y: this.centerY };
|
|
2099
2139
|
}
|
|
2140
|
+
/** Rectangle area (`width * height`). */
|
|
2100
2141
|
get area() {
|
|
2101
2142
|
return this.width * this.height;
|
|
2102
2143
|
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Whether this rectangle has zero or negative area.
|
|
2146
|
+
* Note: width and height are guaranteed non-negative.
|
|
2147
|
+
*/
|
|
2103
2148
|
get isEmpty() {
|
|
2104
2149
|
return this.width <= 0 || this.height <= 0;
|
|
2105
2150
|
}
|
|
2106
|
-
|
|
2151
|
+
/**
|
|
2152
|
+
* Test whether a point lies inside or on the edges of this rectangle.
|
|
2153
|
+
*/
|
|
2107
2154
|
containsPoint(px, py) {
|
|
2108
2155
|
return px >= this.left && px <= this.right && py >= this.top && py <= this.bottom;
|
|
2109
2156
|
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Test whether another rectangle is fully contained within this rectangle.
|
|
2159
|
+
*/
|
|
2110
2160
|
containsRect(other) {
|
|
2111
2161
|
return other.left >= this.left && other.right <= this.right && other.top >= this.top && other.bottom <= this.bottom;
|
|
2112
2162
|
}
|
|
2113
2163
|
intersects(other) {
|
|
2114
|
-
|
|
2164
|
+
const _args = getRectProps(other);
|
|
2165
|
+
return !(_args.right < this.left || _args.left > this.right || _args.bottom < this.top || _args.top > this.bottom);
|
|
2115
2166
|
}
|
|
2116
|
-
// --- Operations ---
|
|
2117
2167
|
intersectionCopy(other) {
|
|
2118
|
-
const
|
|
2119
|
-
const
|
|
2120
|
-
const
|
|
2121
|
-
const
|
|
2168
|
+
const _args = getRectProps(other);
|
|
2169
|
+
const x1 = Math.max(this.left, _args.left);
|
|
2170
|
+
const y1 = Math.max(this.top, _args.top);
|
|
2171
|
+
const x2 = Math.min(this.right, _args.right);
|
|
2172
|
+
const y2 = Math.min(this.bottom, _args.bottom);
|
|
2122
2173
|
if (x2 <= x1 || y2 <= y1) return new _Rect();
|
|
2123
2174
|
return new _Rect(x1, y1, x2 - x1, y2 - y1);
|
|
2124
2175
|
}
|
|
2125
2176
|
unionCopy(other) {
|
|
2126
|
-
const
|
|
2127
|
-
const
|
|
2128
|
-
const
|
|
2129
|
-
const
|
|
2177
|
+
const _args = getRectProps(other);
|
|
2178
|
+
const x1 = Math.min(this.left, _args.left);
|
|
2179
|
+
const y1 = Math.min(this.top, _args.top);
|
|
2180
|
+
const x2 = Math.max(this.right, _args.right);
|
|
2181
|
+
const y2 = Math.max(this.bottom, _args.bottom);
|
|
2130
2182
|
return new _Rect(x1, y1, x2 - x1, y2 - y1);
|
|
2131
2183
|
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Create an inset (shrunken) copy of this rectangle.
|
|
2186
|
+
*
|
|
2187
|
+
* @param dx - Horizontal inset
|
|
2188
|
+
* @param dy - Vertical inset
|
|
2189
|
+
*/
|
|
2132
2190
|
insetCopy(dx, dy) {
|
|
2133
2191
|
return new _Rect(this.x + dx, this.y + dy, this.width - 2 * dx, this.height - 2 * dy);
|
|
2134
2192
|
}
|
|
2193
|
+
/**
|
|
2194
|
+
* Create an inflated (expanded) copy of this rectangle.
|
|
2195
|
+
*
|
|
2196
|
+
* @param dx - Horizontal expansion
|
|
2197
|
+
* @param dy - Vertical expansion
|
|
2198
|
+
*/
|
|
2135
2199
|
inflateCopy(dx, dy) {
|
|
2136
2200
|
return new _Rect(this.x - dx, this.y - dy, this.width + 2 * dx, this.height + 2 * dy);
|
|
2137
2201
|
}
|
|
2202
|
+
/**
|
|
2203
|
+
* Move this rectangle by the given offset.
|
|
2204
|
+
* Modifies this instance.
|
|
2205
|
+
*/
|
|
2138
2206
|
offsetInPlace(dx, dy) {
|
|
2139
2207
|
this.x += dx;
|
|
2140
2208
|
this.y += dy;
|
|
2141
2209
|
return this;
|
|
2142
2210
|
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Create a translated copy of this rectangle.
|
|
2213
|
+
*/
|
|
2143
2214
|
offsetCopy(dx, dy) {
|
|
2144
2215
|
return new _Rect(this.x + dx, this.y + dy, this.width, this.height);
|
|
2145
2216
|
}
|
|
2217
|
+
/**
|
|
2218
|
+
* Scale this rectangle around its geometric center.
|
|
2219
|
+
* Modifies this instance.
|
|
2220
|
+
*
|
|
2221
|
+
* @param scaleX - Horizontal scale factor
|
|
2222
|
+
* @param scaleY - Vertical scale factor (defaults to scaleX)
|
|
2223
|
+
*/
|
|
2146
2224
|
scaleInPlace(scaleX, scaleY = scaleX) {
|
|
2147
2225
|
this.x = this.centerX - this.width * scaleX / 2;
|
|
2148
2226
|
this.width *= scaleX;
|
|
@@ -2150,9 +2228,16 @@ var Rect = class _Rect {
|
|
|
2150
2228
|
this.height *= scaleY;
|
|
2151
2229
|
return this;
|
|
2152
2230
|
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Create a scaled copy of this rectangle.
|
|
2233
|
+
* Scaling is performed around the geometric center.
|
|
2234
|
+
*/
|
|
2153
2235
|
scaleCopy(scaleX, scaleY = scaleX) {
|
|
2154
2236
|
return this.clone().scaleInPlace(scaleX, scaleY);
|
|
2155
2237
|
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Create a copy with all edges rounded to the nearest integer.
|
|
2240
|
+
*/
|
|
2156
2241
|
roundCopy() {
|
|
2157
2242
|
const left = Math.round(this.left);
|
|
2158
2243
|
const top = Math.round(this.top);
|
|
@@ -2160,6 +2245,9 @@ var Rect = class _Rect {
|
|
|
2160
2245
|
const bottom = Math.round(this.bottom);
|
|
2161
2246
|
return new _Rect(left, top, right - left, bottom - top);
|
|
2162
2247
|
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Create a copy with all edges rounded down.
|
|
2250
|
+
*/
|
|
2163
2251
|
floorCopy() {
|
|
2164
2252
|
const left = Math.floor(this.left);
|
|
2165
2253
|
const top = Math.floor(this.top);
|
|
@@ -2167,6 +2255,9 @@ var Rect = class _Rect {
|
|
|
2167
2255
|
const bottom = Math.floor(this.bottom);
|
|
2168
2256
|
return new _Rect(left, top, right - left, bottom - top);
|
|
2169
2257
|
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Create a copy with all edges rounded up.
|
|
2260
|
+
*/
|
|
2170
2261
|
ceilCopy() {
|
|
2171
2262
|
const left = Math.ceil(this.left);
|
|
2172
2263
|
const top = Math.ceil(this.top);
|
|
@@ -2174,6 +2265,9 @@ var Rect = class _Rect {
|
|
|
2174
2265
|
const bottom = Math.ceil(this.bottom);
|
|
2175
2266
|
return new _Rect(left, top, right - left, bottom - top);
|
|
2176
2267
|
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Expand this rectangle to include a point.
|
|
2270
|
+
*/
|
|
2177
2271
|
expandCopy(px, py) {
|
|
2178
2272
|
const left = Math.min(this.left, px);
|
|
2179
2273
|
const top = Math.min(this.top, py);
|
|
@@ -2181,22 +2275,55 @@ var Rect = class _Rect {
|
|
|
2181
2275
|
const bottom = Math.max(this.bottom, py);
|
|
2182
2276
|
return new _Rect(left, top, right - left, bottom - top);
|
|
2183
2277
|
}
|
|
2184
|
-
|
|
2278
|
+
/**
|
|
2279
|
+
* Test for exact equality with another rectangle.
|
|
2280
|
+
*/
|
|
2185
2281
|
equals(other) {
|
|
2186
2282
|
return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
|
|
2187
2283
|
}
|
|
2284
|
+
/**
|
|
2285
|
+
* Create a deep copy of this rectangle.
|
|
2286
|
+
*/
|
|
2188
2287
|
clone() {
|
|
2189
2288
|
return new _Rect(this.x, this.y, this.width, this.height);
|
|
2190
2289
|
}
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2290
|
+
/**
|
|
2291
|
+
* Convert this rectangle to an AnchoredRect.
|
|
2292
|
+
* The anchor is placed at the geometric center.
|
|
2293
|
+
*/
|
|
2194
2294
|
toAnchoredRect() {
|
|
2195
2295
|
return new AnchoredRect(this.left, this.right, this.top, this.bottom);
|
|
2196
2296
|
}
|
|
2297
|
+
toString() {
|
|
2298
|
+
return `Rect(x=${this.x}, y=${this.y}, w=${this.width}, h=${this.height})`;
|
|
2299
|
+
}
|
|
2197
2300
|
};
|
|
2198
2301
|
|
|
2199
2302
|
// src/core/anchor-rect.ts
|
|
2303
|
+
function getRectProps2(arg) {
|
|
2304
|
+
let left = NaN;
|
|
2305
|
+
let anchorX;
|
|
2306
|
+
let right = NaN;
|
|
2307
|
+
let top = NaN;
|
|
2308
|
+
let anchorY;
|
|
2309
|
+
let bottom = NaN;
|
|
2310
|
+
if (hasProperties(arg, ["left", "top"])) {
|
|
2311
|
+
left = Number(arg.left);
|
|
2312
|
+
top = Number(arg.top);
|
|
2313
|
+
} else if (hasProperties(arg, ["x", "y"])) {
|
|
2314
|
+
left = Number(arg.x);
|
|
2315
|
+
top = Number(arg.y);
|
|
2316
|
+
}
|
|
2317
|
+
if (hasProperties(arg, ["width", "height"])) {
|
|
2318
|
+
right = left + Number(arg.width);
|
|
2319
|
+
bottom = top + Number(arg.height);
|
|
2320
|
+
}
|
|
2321
|
+
if (hasProperties(arg, ["anchorX", "anchorY"])) {
|
|
2322
|
+
anchorX = Number(arg.anchorX);
|
|
2323
|
+
anchorY = Number(arg.anchorY);
|
|
2324
|
+
}
|
|
2325
|
+
return { left, anchorX, right, top, anchorY, bottom };
|
|
2326
|
+
}
|
|
2200
2327
|
var AnchoredRect = class _AnchoredRect {
|
|
2201
2328
|
constructor(...args) {
|
|
2202
2329
|
__publicField(this, "left");
|
|
@@ -2219,6 +2346,14 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2219
2346
|
this.top = args[2];
|
|
2220
2347
|
this.bottom = args[3];
|
|
2221
2348
|
this.anchorY = (this.top + this.bottom) / 2;
|
|
2349
|
+
} else if (args.length === 1) {
|
|
2350
|
+
const _args = getRectProps2(args[0]);
|
|
2351
|
+
this.left = _args.left;
|
|
2352
|
+
this.right = _args.right;
|
|
2353
|
+
this.anchorX = _args.anchorX ?? (this.left + this.right) / 2;
|
|
2354
|
+
this.top = _args.top;
|
|
2355
|
+
this.bottom = _args.bottom;
|
|
2356
|
+
this.anchorY = _args.anchorY ?? (this.top + this.bottom) / 2;
|
|
2222
2357
|
} else if (args.length === 0) {
|
|
2223
2358
|
this.left = this.anchorX = this.right = 0;
|
|
2224
2359
|
this.top = this.anchorY = this.bottom = 0;
|
|
@@ -2292,89 +2427,90 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2292
2427
|
static createSections(leftw, rightw, toph, bottomh) {
|
|
2293
2428
|
return new _AnchoredRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
2294
2429
|
}
|
|
2295
|
-
/**
|
|
2296
|
-
* Get center x-coordinate.
|
|
2297
|
-
*/
|
|
2430
|
+
/** Geometric center x-coordinate (ignores anchor). */
|
|
2298
2431
|
get centerX() {
|
|
2299
2432
|
return this.left + this.width / 2;
|
|
2300
2433
|
}
|
|
2301
|
-
/**
|
|
2302
|
-
* Get center ycoordinate.
|
|
2303
|
-
*/
|
|
2434
|
+
/** Geometric center y-coordinate (ignores anchor). */
|
|
2304
2435
|
get centerY() {
|
|
2305
2436
|
return this.top + this.height / 2;
|
|
2306
2437
|
}
|
|
2307
|
-
/**
|
|
2308
|
-
* Width getter.
|
|
2309
|
-
*/
|
|
2438
|
+
/** Rectangle width (`right - left`). */
|
|
2310
2439
|
get width() {
|
|
2311
2440
|
return this.right - this.left;
|
|
2312
2441
|
}
|
|
2313
|
-
/**
|
|
2314
|
-
* Height getter.
|
|
2315
|
-
*/
|
|
2442
|
+
/** Rectangle height (`bottom - top`). */
|
|
2316
2443
|
get height() {
|
|
2317
2444
|
return this.bottom - this.top;
|
|
2318
2445
|
}
|
|
2319
|
-
/**
|
|
2320
|
-
* Left section width getter.
|
|
2321
|
-
*/
|
|
2446
|
+
/** Distance from left edge to anchor. */
|
|
2322
2447
|
get leftw() {
|
|
2323
2448
|
return this.anchorX - this.left;
|
|
2324
2449
|
}
|
|
2325
|
-
/**
|
|
2326
|
-
* Right section width getter.
|
|
2327
|
-
*/
|
|
2450
|
+
/** Distance from anchor to right edge. */
|
|
2328
2451
|
get rightw() {
|
|
2329
2452
|
return this.right - this.anchorX;
|
|
2330
2453
|
}
|
|
2331
|
-
/**
|
|
2332
|
-
* Top section height getter.
|
|
2333
|
-
*/
|
|
2454
|
+
/** Distance from top edge to anchor. */
|
|
2334
2455
|
get toph() {
|
|
2335
2456
|
return this.anchorY - this.top;
|
|
2336
2457
|
}
|
|
2337
|
-
/**
|
|
2338
|
-
* Bottom section height getter.
|
|
2339
|
-
*/
|
|
2458
|
+
/** Distance from anchor to bottom edge. */
|
|
2340
2459
|
get bottomh() {
|
|
2341
2460
|
return this.bottom - this.anchorY;
|
|
2342
2461
|
}
|
|
2343
2462
|
/**
|
|
2344
|
-
*
|
|
2345
|
-
*
|
|
2346
|
-
* @param x - X-coordinate.
|
|
2347
|
-
* @param y - Y-coordinate.
|
|
2348
|
-
* @returns - True/false.
|
|
2463
|
+
* Test whether a point lies inside or on the edges of this rectangle.
|
|
2349
2464
|
*/
|
|
2350
2465
|
contains(x, y) {
|
|
2351
2466
|
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
|
|
2352
2467
|
}
|
|
2353
2468
|
/**
|
|
2354
|
-
*
|
|
2355
|
-
*
|
|
2356
|
-
*
|
|
2357
|
-
*
|
|
2358
|
-
*
|
|
2469
|
+
* Create an inset (shrunken) copy of this rectangle.
|
|
2470
|
+
*
|
|
2471
|
+
* The rectangle edges are moved inward by the given amounts.
|
|
2472
|
+
* The anchor position is preserved.
|
|
2473
|
+
*
|
|
2474
|
+
* @param dx - Horizontal inset applied to left and right edges.
|
|
2475
|
+
* @param dy - Vertical inset applied to top and bottom edges.
|
|
2476
|
+
* Defaults to `dx`.
|
|
2477
|
+
* @returns A new AnchoredRect inset from all sides.
|
|
2478
|
+
*/
|
|
2479
|
+
insetCopy(dx, dy = dx) {
|
|
2480
|
+
return new _AnchoredRect(this.left + dx, this.anchorX, this.right - dx, this.top + dy, this.anchorY, this.bottom - dy);
|
|
2481
|
+
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Create an inflated (expanded) copy of this rectangle.
|
|
2484
|
+
*
|
|
2485
|
+
* The rectangle edges are moved outward by the given amounts.
|
|
2486
|
+
* The anchor position is preserved.
|
|
2487
|
+
*
|
|
2488
|
+
* @param dx - Horizontal expansion applied to left and right edges.
|
|
2489
|
+
* @param dy - Vertical expansion applied to top and bottom edges.
|
|
2490
|
+
* Defaults to `dx`.
|
|
2491
|
+
* @returns A new AnchoredRect expanded on all sides.
|
|
2492
|
+
*/
|
|
2493
|
+
inflateCopy(dx, dy = dx) {
|
|
2494
|
+
return new _AnchoredRect(this.left - dx, this.anchorX, this.right + dx, this.top - dy, this.anchorY, this.bottom + dy);
|
|
2495
|
+
}
|
|
2496
|
+
intersects(other) {
|
|
2497
|
+
const _args = getRectProps2(other);
|
|
2498
|
+
return !(_args.right < this.left || _args.left > this.right || _args.bottom < this.top || _args.top > this.bottom);
|
|
2499
|
+
}
|
|
2500
|
+
/**
|
|
2501
|
+
* This method requires strict overlap (edge-touching does NOT count).
|
|
2359
2502
|
*/
|
|
2360
2503
|
static overlap(a, b) {
|
|
2361
2504
|
return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
2362
2505
|
}
|
|
2363
2506
|
/**
|
|
2364
|
-
*
|
|
2365
|
-
*
|
|
2366
|
-
* @param a - AnchoredRect a.
|
|
2367
|
-
* @param b - AnchoredRect b.
|
|
2368
|
-
* @returns - True/false.
|
|
2507
|
+
* This method requires strict (horizontal) overlap (edge-touching does NOT count).
|
|
2369
2508
|
*/
|
|
2370
2509
|
static overlapX(a, b) {
|
|
2371
2510
|
return a.right > b.left && a.left < b.right;
|
|
2372
2511
|
}
|
|
2373
2512
|
/**
|
|
2374
|
-
*
|
|
2375
|
-
* @param a - AnchoredRect a.
|
|
2376
|
-
* @param b - AnchoredRect b.
|
|
2377
|
-
* @returns - True/false.
|
|
2513
|
+
* Test if rects are equal.
|
|
2378
2514
|
*/
|
|
2379
2515
|
static equals(a, b) {
|
|
2380
2516
|
if (a == null && b == null) {
|
|
@@ -2386,19 +2522,13 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2386
2522
|
}
|
|
2387
2523
|
}
|
|
2388
2524
|
/**
|
|
2389
|
-
*
|
|
2390
|
-
* @param other - The other rect.
|
|
2391
|
-
* @returns - True/false.
|
|
2525
|
+
* Test if this rect equals with given rect.
|
|
2392
2526
|
*/
|
|
2393
2527
|
equals(other) {
|
|
2394
2528
|
return _AnchoredRect.equals(this, other);
|
|
2395
2529
|
}
|
|
2396
2530
|
/**
|
|
2397
|
-
*
|
|
2398
|
-
*
|
|
2399
|
-
* @param a - AnchoredRect a.
|
|
2400
|
-
* @param b - AnchoredRect b.
|
|
2401
|
-
* @returns - True/false.
|
|
2531
|
+
* Test if edges of given rects are equal, ignoring anchorX and anchorY.
|
|
2402
2532
|
*/
|
|
2403
2533
|
static equalsEdges(a, b) {
|
|
2404
2534
|
if (a == null && b == null) {
|
|
@@ -2410,27 +2540,23 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2410
2540
|
}
|
|
2411
2541
|
}
|
|
2412
2542
|
/**
|
|
2413
|
-
*
|
|
2414
|
-
*
|
|
2415
|
-
* @param other - The other AnchoredRect.
|
|
2416
|
-
* @returns - True/false.
|
|
2543
|
+
* Test if edges of this equal with given Rect, ignoring anchorX and anchorY.
|
|
2417
2544
|
*/
|
|
2418
2545
|
equalsEdges(other) {
|
|
2419
2546
|
return _AnchoredRect.equalsEdges(this, other);
|
|
2420
2547
|
}
|
|
2421
2548
|
/**
|
|
2422
|
-
*
|
|
2423
|
-
* @returns - Duplicate.
|
|
2549
|
+
* Create copy.
|
|
2424
2550
|
*/
|
|
2425
2551
|
clone() {
|
|
2426
2552
|
return new _AnchoredRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
|
|
2427
2553
|
}
|
|
2428
2554
|
/**
|
|
2429
|
-
* Move this rect by (dx, dy).
|
|
2555
|
+
* Move this rect by (dx, dy).
|
|
2430
2556
|
*
|
|
2431
2557
|
* @param dx - Offset amount in x-direction.
|
|
2432
2558
|
* @param dy - Offset amount in y-direction.
|
|
2433
|
-
* @returns -
|
|
2559
|
+
* @returns - Modified this.
|
|
2434
2560
|
*/
|
|
2435
2561
|
offsetInPlace(dx, dy) {
|
|
2436
2562
|
this.left += dx;
|
|
@@ -2442,42 +2568,52 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2442
2568
|
return this;
|
|
2443
2569
|
}
|
|
2444
2570
|
/**
|
|
2445
|
-
* Move this rect by (dx, dy).
|
|
2571
|
+
* Move this rect by (dx, dy).
|
|
2446
2572
|
*
|
|
2447
2573
|
* @param dx - Offset amount in x-direction.
|
|
2448
2574
|
* @param dy - Offset amount in y-direction.
|
|
2449
|
-
* @returns -
|
|
2575
|
+
* @returns - Copy with applied offset.
|
|
2450
2576
|
*/
|
|
2451
2577
|
offsetCopy(dx, dy) {
|
|
2452
2578
|
return this.clone().offsetInPlace(dx, dy);
|
|
2453
2579
|
}
|
|
2454
2580
|
/**
|
|
2455
|
-
* Expand this
|
|
2456
|
-
*
|
|
2457
|
-
* @param rect - AnchoredRect to expand this instance with.
|
|
2458
|
-
* @returns - This AnchoredRect instance.
|
|
2581
|
+
* Expand this rectangle to include another rectangle.
|
|
2582
|
+
* The anchor is preserved.
|
|
2459
2583
|
*/
|
|
2460
|
-
|
|
2461
|
-
this.left = Math.min(this.left,
|
|
2462
|
-
this.right = Math.max(this.right,
|
|
2463
|
-
this.top = Math.min(this.top,
|
|
2464
|
-
this.bottom = Math.max(this.bottom,
|
|
2584
|
+
unionInPlace(other) {
|
|
2585
|
+
this.left = Math.min(this.left, other.left);
|
|
2586
|
+
this.right = Math.max(this.right, other.right);
|
|
2587
|
+
this.top = Math.min(this.top, other.top);
|
|
2588
|
+
this.bottom = Math.max(this.bottom, other.bottom);
|
|
2465
2589
|
return this;
|
|
2466
2590
|
}
|
|
2591
|
+
/** @deprecated - Use unionInPlace(). */
|
|
2592
|
+
expandInPlace(other) {
|
|
2593
|
+
return this.unionInPlace(other);
|
|
2594
|
+
}
|
|
2467
2595
|
/**
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
* @
|
|
2471
|
-
* @returns - Expanded copy of this AnchoredRect.
|
|
2596
|
+
* Union this rect with given Rect.
|
|
2597
|
+
* @param other - Union with.
|
|
2598
|
+
* @returns - Modified copy.
|
|
2472
2599
|
*/
|
|
2473
|
-
|
|
2474
|
-
return
|
|
2600
|
+
unionCopy(other) {
|
|
2601
|
+
return new _AnchoredRect(
|
|
2602
|
+
Math.min(this.left, other.left),
|
|
2603
|
+
this.anchorX,
|
|
2604
|
+
Math.max(this.right, other.right),
|
|
2605
|
+
Math.min(this.top, other.top),
|
|
2606
|
+
this.anchorY,
|
|
2607
|
+
Math.max(this.bottom, other.bottom)
|
|
2608
|
+
);
|
|
2609
|
+
}
|
|
2610
|
+
/** @deprecated - Use unionCopy(). */
|
|
2611
|
+
expandCopy(other) {
|
|
2612
|
+
return this.unionCopy(other);
|
|
2475
2613
|
}
|
|
2476
2614
|
/**
|
|
2477
|
-
* Clip this
|
|
2478
|
-
*
|
|
2479
|
-
* @param clipRect - AnchoredRect to clip this instance with.
|
|
2480
|
-
* @returns - This AnchoredRect instance.
|
|
2615
|
+
* Clip this rectangle to the bounds of another rectangle.
|
|
2616
|
+
* The anchor is clamped to remain inside the clipped region.
|
|
2481
2617
|
*/
|
|
2482
2618
|
clipInPlace(clipRect) {
|
|
2483
2619
|
this.left = Math.max(this.left, clipRect.left);
|
|
@@ -2498,11 +2634,8 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2498
2634
|
return this.clone().clipInPlace(clipRect);
|
|
2499
2635
|
}
|
|
2500
2636
|
/**
|
|
2501
|
-
* Scale
|
|
2502
|
-
*
|
|
2503
|
-
* @param scaleX - Scale x-amount.
|
|
2504
|
-
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
2505
|
-
* @returns This AnchoredRect instance.
|
|
2637
|
+
* Scale this rectangle around its anchor point.
|
|
2638
|
+
* Edges are moved relative to the anchor.
|
|
2506
2639
|
*/
|
|
2507
2640
|
scaleInPlace(scaleX, scaleY = scaleX) {
|
|
2508
2641
|
this.left = this.anchorX - this.leftw * scaleX;
|
|
@@ -2522,15 +2655,19 @@ var AnchoredRect = class _AnchoredRect {
|
|
|
2522
2655
|
return this.clone().scaleInPlace(scaleX, scaleY);
|
|
2523
2656
|
}
|
|
2524
2657
|
/**
|
|
2525
|
-
*
|
|
2526
|
-
* @returns - This AnchoredRect instance.
|
|
2658
|
+
* Return this rect.
|
|
2527
2659
|
*/
|
|
2528
2660
|
getRect() {
|
|
2529
2661
|
return this;
|
|
2530
2662
|
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Convert to a basic Rect using geometric edges.
|
|
2665
|
+
* Anchor information is discarded.
|
|
2666
|
+
*/
|
|
2531
2667
|
toRect() {
|
|
2532
|
-
return new Rect(this.left, this.
|
|
2668
|
+
return new Rect(this.left, this.top, this.width, this.height);
|
|
2533
2669
|
}
|
|
2670
|
+
/** String of this rect. */
|
|
2534
2671
|
toString() {
|
|
2535
2672
|
return `Rect(left=${this.left}, anchorX=${this.anchorX}, right=${this.right}, top=${this.top}, anchorY=${this.anchorY}, bottom=${this.bottom})`;
|
|
2536
2673
|
}
|
|
@@ -4464,7 +4601,7 @@ var CallTracker = _CallTracker;
|
|
|
4464
4601
|
|
|
4465
4602
|
// src/index.ts
|
|
4466
4603
|
function getLibInfo() {
|
|
4467
|
-
return "TsUtilsLib v3.
|
|
4604
|
+
return "TsUtilsLib v3.4.0 (esm)";
|
|
4468
4605
|
}
|
|
4469
4606
|
|
|
4470
4607
|
export { AnchoredRect, assert_exports as Assert, BaseContainer, BiMap, CallTracker, cookies_exports as Cookies, DefaultArray, DefaultEqualityFn, device_exports as Device, guard_exports as Guard, IndexArray, LRUCache, LinkedList, MultiContainer, Rect, SignedIndexArray, Stack, TriMap, UniMap, utils_exports as Utils, ValueSet, Vec, asMulti, getLibInfo };
|