@itowns/geographic 2.46.1-next.37 → 2.46.1-next.39

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.
@@ -334,6 +334,7 @@ export function quaternionFromCRSToEnu(crsOrProj, coordinates, target = new Quat
334
334
  return quaternionUnimplemented(proj);
335
335
  }
336
336
  }
337
+ const quaternionCrs2CrsCache = {};
337
338
  /**
338
339
  * Return the function that computes the quaternion that represents a
339
340
  * rotation of coordinates between two CRS frames.
@@ -352,9 +353,18 @@ export function quaternionFromCRSToCRS(crsIn, crsOut, coordinates, target = new
352
353
  if (crsIn == crsOut) {
353
354
  return (origin, target = new Quaternion()) => target.set(0, 0, 0, 1);
354
355
  }
356
+ if (quaternionCrs2CrsCache[crsIn] && quaternionCrs2CrsCache[crsIn][crsOut]) {
357
+ return quaternionCrs2CrsCache[crsIn][crsOut];
358
+ }
355
359
 
356
360
  // get rotations from the local East/North/Up (ENU) frame to both CRS.
357
361
  const fromCrs = quaternionFromCRSToEnu(crsIn);
358
362
  const toCrs = quaternionFromEnuToCRS(crsOut);
359
- return (origin, target = new Quaternion()) => toCrs(origin, target).multiply(fromCrs(origin, quat));
363
+ if (!quaternionCrs2CrsCache[crsIn]) {
364
+ quaternionCrs2CrsCache[crsIn] = {};
365
+ }
366
+ if (!quaternionCrs2CrsCache[crsIn][crsOut]) {
367
+ quaternionCrs2CrsCache[crsIn][crsOut] = (origin, target = new Quaternion()) => toCrs(origin, target).multiply(fromCrs(origin, quat));
368
+ }
369
+ return quaternionCrs2CrsCache[crsIn][crsOut];
360
370
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itowns/geographic",
3
- "version": "2.46.1-next.37",
3
+ "version": "2.46.1-next.39",
4
4
  "description": "Proj4-based three.js geodesy toolkit",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -462,13 +462,14 @@ export function quaternionFromCRSToEnu(
462
462
  }
463
463
  }
464
464
 
465
+ const quaternionCrs2CrsCache: Record<string, Record<string, QuaternionFunction>> = {};
465
466
  export function quaternionFromCRSToCRS(
466
- crsIn: ProjectionLike,
467
- crsOut: ProjectionLike,
467
+ crsIn: string,
468
+ crsOut: string,
468
469
  ): QuaternionFunction;
469
470
  export function quaternionFromCRSToCRS(
470
- crsIn: ProjectionLike,
471
- crsOut: ProjectionLike,
471
+ crsIn: string,
472
+ crsOut: string,
472
473
  coords: Coordinates,
473
474
  target?: Quaternion,
474
475
  ): Quaternion;
@@ -484,8 +485,8 @@ export function quaternionFromCRSToCRS(
484
485
  * function to compute it from coordinates.
485
486
  */
486
487
  export function quaternionFromCRSToCRS(
487
- crsIn: ProjectionLike,
488
- crsOut: ProjectionLike,
488
+ crsIn: string,
489
+ crsOut: string,
489
490
  coordinates?: Coordinates,
490
491
  target = new Quaternion(),
491
492
  ) {
@@ -494,9 +495,23 @@ export function quaternionFromCRSToCRS(
494
495
  return (origin: Coordinates, target = new Quaternion()) => target.set(0, 0, 0, 1);
495
496
  }
496
497
 
498
+ if (quaternionCrs2CrsCache[crsIn] && quaternionCrs2CrsCache[crsIn][crsOut]) {
499
+ return quaternionCrs2CrsCache[crsIn][crsOut];
500
+ }
501
+
497
502
  // get rotations from the local East/North/Up (ENU) frame to both CRS.
498
503
  const fromCrs = quaternionFromCRSToEnu(crsIn);
499
504
  const toCrs = quaternionFromEnuToCRS(crsOut);
500
- return (origin: Coordinates, target = new Quaternion()) =>
501
- toCrs(origin, target).multiply(fromCrs(origin, quat));
505
+
506
+ if (!quaternionCrs2CrsCache[crsIn]) {
507
+ quaternionCrs2CrsCache[crsIn] = {};
508
+ }
509
+
510
+ if (!quaternionCrs2CrsCache[crsIn][crsOut]) {
511
+ quaternionCrs2CrsCache[crsIn][crsOut] =
512
+ (origin: Coordinates, target = new Quaternion()) =>
513
+ toCrs(origin, target).multiply(fromCrs(origin, quat));
514
+ }
515
+
516
+ return quaternionCrs2CrsCache[crsIn][crsOut];
502
517
  }