@itowns/geographic 2.46.1-next.51 → 2.46.1-next.53

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/lib/Extent.d.ts CHANGED
@@ -127,12 +127,38 @@ declare class Extent {
127
127
  * @param extent - the provided extent
128
128
  */
129
129
  intersectsExtent(extent: Extent): boolean;
130
+ /**
131
+ * Tests whether two extents intersect.
132
+ *
133
+ * This method checks if the geographic extents `extentA` and `extentB`
134
+ * overlap. If their coordinate reference systems (CRS) differ, `extentB`
135
+ * is reprojected into the CRS of `extentA` before performing the test.
136
+ *
137
+ * Extents that touch at an edge or a corner aren't treated as intersecting.
138
+ *
139
+ * @param extentA - The reference extent.
140
+ * @param extentB - The extent to test against.
141
+ *
142
+ * @returns `true` if the extents intersect, `false` otherwise.
143
+ */
130
144
  static intersectsExtent(extentA: Extent, extentB: Extent): boolean;
131
145
  /**
132
146
  * Returns the intersection of this extent with another one.
133
- * @param extent - extent to intersect
147
+ *
148
+ * This method computes the overlapping region between this extent and
149
+ * another extent. If their coordinate reference systems (CRS) differ,
150
+ * the other extent is reprojected into the CRS of this extent before
151
+ * performing the intersection.
152
+ *
153
+ *
154
+ * @param extent - The extent to intersect with this one.
155
+ * @param target - The target extent to store the result. If not provided,
156
+ * a new extent will be created.
157
+ *
158
+ * @returns The intersection extent
159
+ * (may be empty if extents do not intersect).
134
160
  */
135
- intersect(extent: Extent): Extent;
161
+ intersect(extent: Extent, target?: Extent): Extent;
136
162
  /**
137
163
  * Set west, east, south and north values.
138
164
  *
@@ -165,7 +191,7 @@ declare class Extent {
165
191
  * Union this extent with the input extent.
166
192
  * @param extent - the extent to union.
167
193
  */
168
- union(extent: Extent): void;
194
+ union(extent: Extent): this;
169
195
  /**
170
196
  * expandByCoordinates perfoms the minimal extension
171
197
  * for the coordinates to belong to this Extent object
package/lib/Extent.js CHANGED
@@ -243,24 +243,50 @@ class Extent {
243
243
  intersectsExtent(extent) {
244
244
  return Extent.intersectsExtent(this, extent);
245
245
  }
246
+
247
+ /**
248
+ * Tests whether two extents intersect.
249
+ *
250
+ * This method checks if the geographic extents `extentA` and `extentB`
251
+ * overlap. If their coordinate reference systems (CRS) differ, `extentB`
252
+ * is reprojected into the CRS of `extentA` before performing the test.
253
+ *
254
+ * Extents that touch at an edge or a corner aren't treated as intersecting.
255
+ *
256
+ * @param extentA - The reference extent.
257
+ * @param extentB - The extent to test against.
258
+ *
259
+ * @returns `true` if the extents intersect, `false` otherwise.
260
+ */
246
261
  static intersectsExtent(extentA, extentB) {
247
- // TODO don't work when is on limit
248
262
  const other = extentB.crs == extentA.crs ? extentB : extentB.as(extentA.crs, _extent);
249
263
  return !(extentA.west >= other.east || extentA.east <= other.west || extentA.south >= other.north || extentA.north <= other.south);
250
264
  }
251
265
 
252
266
  /**
253
267
  * Returns the intersection of this extent with another one.
254
- * @param extent - extent to intersect
268
+ *
269
+ * This method computes the overlapping region between this extent and
270
+ * another extent. If their coordinate reference systems (CRS) differ,
271
+ * the other extent is reprojected into the CRS of this extent before
272
+ * performing the intersection.
273
+ *
274
+ *
275
+ * @param extent - The extent to intersect with this one.
276
+ * @param target - The target extent to store the result. If not provided,
277
+ * a new extent will be created.
278
+ *
279
+ * @returns The intersection extent
280
+ * (may be empty if extents do not intersect).
255
281
  */
256
- intersect(extent) {
282
+ intersect(extent, target = new Extent(this.crs)) {
257
283
  if (!this.intersectsExtent(extent)) {
258
- return new Extent(this.crs);
284
+ return target;
259
285
  }
260
286
  if (extent.crs != this.crs) {
261
287
  extent = extent.as(this.crs, _extent);
262
288
  }
263
- return new Extent(this.crs, Math.max(this.west, extent.west), Math.min(this.east, extent.east), Math.max(this.south, extent.south), Math.min(this.north, extent.north));
289
+ return target.set(Math.max(this.west, extent.west), Math.min(this.east, extent.east), Math.max(this.south, extent.south), Math.min(this.north, extent.north));
264
290
  }
265
291
 
266
292
  /**
@@ -360,6 +386,7 @@ class Extent {
360
386
  this.north = north;
361
387
  }
362
388
  }
389
+ return this;
363
390
  }
364
391
 
365
392
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itowns/geographic",
3
- "version": "2.46.1-next.51",
3
+ "version": "2.46.1-next.53",
4
4
  "description": "Proj4-based three.js geodesy toolkit",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
package/src/Extent.ts CHANGED
@@ -299,8 +299,21 @@ class Extent {
299
299
  return Extent.intersectsExtent(this, extent);
300
300
  }
301
301
 
302
+ /**
303
+ * Tests whether two extents intersect.
304
+ *
305
+ * This method checks if the geographic extents `extentA` and `extentB`
306
+ * overlap. If their coordinate reference systems (CRS) differ, `extentB`
307
+ * is reprojected into the CRS of `extentA` before performing the test.
308
+ *
309
+ * Extents that touch at an edge or a corner aren't treated as intersecting.
310
+ *
311
+ * @param extentA - The reference extent.
312
+ * @param extentB - The extent to test against.
313
+ *
314
+ * @returns `true` if the extents intersect, `false` otherwise.
315
+ */
302
316
  static intersectsExtent(extentA: Extent, extentB: Extent) {
303
- // TODO don't work when is on limit
304
317
  const other = extentB.crs == extentA.crs ? extentB : extentB.as(extentA.crs, _extent);
305
318
  return !(extentA.west >= other.east ||
306
319
  extentA.east <= other.west ||
@@ -310,16 +323,29 @@ class Extent {
310
323
 
311
324
  /**
312
325
  * Returns the intersection of this extent with another one.
313
- * @param extent - extent to intersect
326
+ *
327
+ * This method computes the overlapping region between this extent and
328
+ * another extent. If their coordinate reference systems (CRS) differ,
329
+ * the other extent is reprojected into the CRS of this extent before
330
+ * performing the intersection.
331
+ *
332
+ *
333
+ * @param extent - The extent to intersect with this one.
334
+ * @param target - The target extent to store the result. If not provided,
335
+ * a new extent will be created.
336
+ *
337
+ * @returns The intersection extent
338
+ * (may be empty if extents do not intersect).
314
339
  */
315
- intersect(extent: Extent) {
340
+ intersect(extent: Extent, target = new Extent(this.crs)) {
316
341
  if (!this.intersectsExtent(extent)) {
317
- return new Extent(this.crs);
342
+ return target;
318
343
  }
319
344
  if (extent.crs != this.crs) {
320
345
  extent = extent.as(this.crs, _extent);
321
346
  }
322
- return new Extent(this.crs,
347
+
348
+ return target.set(
323
349
  Math.max(this.west, extent.west),
324
350
  Math.min(this.east, extent.east),
325
351
  Math.max(this.south, extent.south),
@@ -432,6 +458,8 @@ class Extent {
432
458
  this.north = north;
433
459
  }
434
460
  }
461
+
462
+ return this;
435
463
  }
436
464
 
437
465
  /**