Skip to content

Commit

Permalink
fixed camera bounded bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Mar 3, 2024
1 parent f422146 commit d620408
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ class Camera {
// Do not let transform offet go beyond this limit.
// if (scaled-image-size < screen) it remains fully contained
// else the scaled-image boundary closest to the screen cannot enter the screen.
const dx = Math.abs(bw - sw) / 2 + this.boundingBox.center()[0] - tbox.center()[0];
const dx = Math.abs(bw - sw) / 2;// + this.boundingBox.center().x- tbox.center().x;
x = Math.min(Math.max(-dx, x), dx);

const dy = Math.abs(bh - sh) / 2 + this.boundingBox.center()[1] - tbox.center()[1];
const dy = Math.abs(bh - sh) / 2;// + this.boundingBox.center().y - tbox.center().y;
y = Math.min(Math.max(-dy, y), dy);
}

Expand All @@ -165,6 +165,7 @@ class Camera {
if (a - this.source.a > 180) this.source.a += 360;
if (this.source.a - a > 180) this.source.a -= 360;
Object.assign(this.target, { x: x, y: y, z: z, a: a, t: now + dt });
console.assert(!isNaN(this.target.x));
this.emit('update');
}

Expand Down Expand Up @@ -290,7 +291,7 @@ class Camera {
let c = box.center();
let z = Math.min(w / bw, h / bh);

this.setPosition(dt, -c[0]*z, -c[1]*z, z, 0);
this.setPosition(dt, -c.x*z, -c.y*z, z, 0);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class Transform { //FIXME Add translation to P?
* @returns {Transform} The interpolated transform.
*/
static interpolate(source, target, time, easing) { //FIXME STATIC
console.assert(!isNaN(source.x));
console.assert(!isNaN(target.x));
const pos = new Transform();
let dt = (target.t - source.t);
if (time < source.t) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let lime = new Viewer('.openlime', { background: 'black', canvas: { preserveDraw
//imageTest('google'); // image google deepzoom deepzoom1px zoomify iiif tarzoon itarzoom
//flipTest();
//brdfTest();
//rtiTest('rbf');
rtiTest('rbf');
//tomeTest();
//testUIBasic();

Expand All @@ -32,7 +32,7 @@ let lime = new Viewer('.openlime', { background: 'black', canvas: { preserveDraw

//testMedicalAnnotations();

testAnnotationEditor();
//testAnnotationEditor();

//testNeural();

Expand Down

0 comments on commit d620408

Please sign in to comment.