@geoblocks/cesium-iso 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/cesium-iso.js +13 -12
  2. package/package.json +2 -2
package/cesium-iso.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {Cartesian2, Cartesian3, Cartographic, FixedFrameTransforms, IntersectionTests, Math as CesiumMath, Matrix4, Plane} from '@cesium/core';
2
+ import {EasingFunction} from '@cesium/engine';
2
3
 
3
4
  // in meters, how far the camera stays from its target by default, out of the scene's way: an orthographic view's
4
5
  // size does not depend on it, its depth's precision does (32-bit floats: half a millimeter at 5 km)
@@ -17,7 +18,7 @@ const TWIST = CesiumMath.toRadians(15);
17
18
  const DAMPING = 0.95;
18
19
  const LET_GO = 60;
19
20
 
20
- const easeInOut = (/** @type {number} */ t) => t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
21
+ const easeInOut = EasingFunction.QUADRATIC_IN_OUT;
21
22
  const positionScratch = new Cartesian2();
22
23
  const planeScratch = new Plane(Cartesian3.UNIT_Z, 0);
23
24
  const normalScratch = new Cartesian3();
@@ -55,7 +56,7 @@ export default class CesiumIso {
55
56
  /** @type {Cartesian3} */
56
57
  this.target_ = new Cartesian3();
57
58
  this.heading_ = 0;
58
- /** @type {Map<number, {x: number, y: number}>} */
59
+ /** @type {Map<number, Cartesian2>} */
59
60
  this.pointers_ = new Map();
60
61
  /** @type {{grab?: Cartesian3 | undefined, turn?: boolean, last?: {x: number, y: number}, distance?: number, angle?: number, twist?: number} | undefined} */
61
62
  this.drag_ = undefined;
@@ -192,7 +193,7 @@ export default class CesiumIso {
192
193
  this.drift_ = this.drifted_ = undefined;
193
194
  this.anchor_();
194
195
  const to = CesiumMath.toRadians(heading);
195
- const delta = Math.atan2(Math.sin(to - this.heading_), Math.cos(to - this.heading_));
196
+ const delta = CesiumMath.negativePiToPi(to - this.heading_);
196
197
  this.turning_ = {from: this.heading_, to: this.heading_ + delta, start: performance.now()};
197
198
  this.animate_();
198
199
  }
@@ -278,7 +279,7 @@ export default class CesiumIso {
278
279
  * @param {number} sign
279
280
  */
280
281
  cornerAfter_(heading, sign) {
281
- const quarter = Math.PI / 2;
282
+ const quarter = CesiumMath.PI_OVER_TWO;
282
283
  return this.corner_ + (Math.round((heading - this.corner_) / quarter) + sign) * quarter;
283
284
  }
284
285
 
@@ -365,8 +366,8 @@ export default class CesiumIso {
365
366
  const points = [...this.pointers_.values()];
366
367
  if (points.length === 2) {
367
368
  const [a, b] = points;
368
- const middle = new Cartesian2((a.x + b.x) / 2, (a.y + b.y) / 2);
369
- return {grab: this.ground_(middle, this.target_), distance: Math.hypot(b.x - a.x, b.y - a.y), angle: Math.atan2(b.y - a.y, b.x - a.x), twist: 0};
369
+ const middle = Cartesian2.lerp(a, b, 0.5, new Cartesian2());
370
+ return {grab: this.ground_(middle, this.target_), distance: Cartesian2.distance(a, b), angle: Math.atan2(b.y - a.y, b.x - a.x), twist: 0};
370
371
  }
371
372
  const slide = e.pointerType === 'touch' || e.button === 2 || e.ctrlKey || e.shiftKey;
372
373
  const point = /** @type {{x: number, y: number}} */ (points[0]);
@@ -384,15 +385,15 @@ export default class CesiumIso {
384
385
  const drag = this.drag_;
385
386
  const points = [...this.pointers_.values()];
386
387
  if (points.length === 2 && drag.distance !== undefined) {
387
- const [a, b] = /** @type {[{x: number, y: number}, {x: number, y: number}]} */ (points);
388
- const middle = new Cartesian2((a.x + b.x) / 2, (a.y + b.y) / 2);
389
- const [distance, angle] = [Math.hypot(b.x - a.x, b.y - a.y), Math.atan2(b.y - a.y, b.x - a.x)];
388
+ const [a, b] = /** @type {[Cartesian2, Cartesian2]} */ (points);
389
+ const middle = Cartesian2.lerp(a, b, 0.5, new Cartesian2());
390
+ const [distance, angle] = [Cartesian2.distance(a, b), Math.atan2(b.y - a.y, b.x - a.x)];
390
391
  this.size_ = CesiumMath.clamp(this.size_ * drag.distance / distance, this.minSize_, this.maxSize_);
391
392
  this.place_();
392
393
  if (drag.grab) {
393
394
  this.keep_(drag.grab, middle);
394
395
  }
395
- const turned = Math.atan2(Math.sin(angle - /** @type {number} */ (drag.angle)), Math.cos(angle - /** @type {number} */ (drag.angle)));
396
+ const turned = CesiumMath.negativePiToPi(angle - /** @type {number} */ (drag.angle));
396
397
  drag.twist = /** @type {number} */ (drag.twist) + turned;
397
398
  if (Math.abs(drag.twist) >= TWIST) {
398
399
  // the screen's y down: the fingers turning clockwise on it turn the ground clockwise under them
@@ -405,7 +406,7 @@ export default class CesiumIso {
405
406
  return;
406
407
  } else if (drag.turn && drag.last) {
407
408
  const point = /** @type {{x: number, y: number}} */ (points[0]);
408
- this.heading_ -= 2 * Math.PI * (point.x - drag.last.x) / this.viewer.scene.canvas.clientHeight;
409
+ this.heading_ -= CesiumMath.TWO_PI * (point.x - drag.last.x) / this.viewer.scene.canvas.clientHeight;
409
410
  drag.last = point;
410
411
  this.place_();
411
412
  } else if (drag.grab) {
@@ -539,7 +540,7 @@ export default class CesiumIso {
539
540
  }
540
541
  if (this.turning_) {
541
542
  const t = Math.min(1, (now - this.turning_.start) / TURN_TIME);
542
- this.heading_ = this.turning_.from + (this.turning_.to - this.turning_.from) * easeInOut(t);
543
+ this.heading_ = CesiumMath.lerp(this.turning_.from, this.turning_.to, easeInOut(t));
543
544
  this.place_();
544
545
  if (t === 1) {
545
546
  this.turning_ = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoblocks/cesium-iso",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "type": "module",
6
6
  "repository": {
@@ -21,5 +21,5 @@
21
21
  "@cesium/core": ">=0.1.0",
22
22
  "@cesium/engine": ">=10"
23
23
  },
24
- "gitHead": "430bbbb63bf3d60221d670f65d5e51fdb6d5b944"
24
+ "gitHead": "0abb7f3381fdf13b15d50047a46d3789f5f95a9e"
25
25
  }