Skip to content

Commit

Permalink
Fixed incorrect Object.isOnScreen functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptspry committed Feb 24, 2018
1 parent 71b2801 commit 0bcd7cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/mixins/object_geometry.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@
}
}
// no points on screen, check intersection with absolute coordinates
if (this.intersectsWithRect(pointTL, pointBR, true)) {
if (this.intersectsWithRect(pointTL, pointBR, true, calculate)) {
return true;
}
// worst case scenario the object is so big that contains the screen
var centerPoint = { x: (pointTL.x + pointBR.x) / 2, y: (pointTL.y + pointBR.y) / 2 };
if (this.containsPoint(centerPoint, null, true)) {
if (this.containsPoint(centerPoint, null, true, calculate)) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@
if (this.isNotVisible()) {
return;
}
if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen()) {
if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen(true)) {
return;
}
ctx.save();
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@
if (!this.visible) {
return;
}
if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen()) {
if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen(true)) {
return;
}
if (this._shouldClearDimensionCache()) {
Expand Down
18 changes: 12 additions & 6 deletions test/unit/object_geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,20 @@
var cObj = new fabric.Object({ left: 50, top: 50, width: 100, height: 100, strokeWidth: 0});
canvas.viewportTransform = [1, 0, 0, 1, 0, 0];
cObj.canvas = canvas;
cObj.setCoords();
assert.ok(cObj.isOnScreen(), 'object is onScreen');
assert.ok(cObj.isOnScreen(true), 'object is onScreen');

cObj.top = 1000;
cObj.setCoords();
assert.ok(!cObj.isOnScreen(), 'object is not onScreen with top 1000');
assert.ok(cObj.isOnScreen(), 'isOnScreen should return true when top is 1000 and coords not being calculated');
assert.ok(!cObj.isOnScreen(true), 'isOnScreen should return false when top is 1000 and coords are calculated');

canvas.setZoom(0.1);
cObj.setCoords();
assert.ok(cObj.isOnScreen(), 'zooming out the object is again on screen');
assert.ok(cObj.isOnScreen(true), 'isOnScreen should return true, zooming out and the object is again on screen');

cObj.top = 50;
canvas.zoomToPoint({ x: 60, y: 60 }, 10);
assert.ok(cObj.isOnScreen(true), 'isOnScreen should return true when object fills the viewport completely');

canvas.zoomToPoint({ x: 0, y: 0 }, 1);
});

QUnit.test('transformMatrixKey depends from properties', function(assert) {
Expand Down

0 comments on commit 0bcd7cb

Please sign in to comment.