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