Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect Object.isOnScreen functionality. #4763

Merged
merged 2 commits into from
Mar 1, 2018

Conversation

scriptspry
Copy link
Contributor

I have not found any usages of Object.isOnScreen being called with calculate = false. I thought about removing it but, was not sure. Hence, left it as it is, added a couple more tests, removed setCoords calls that were kind of bypassing the functionality being tested.

@asturur
Copy link
Member

asturur commented Feb 24, 2018

We do not want to use calculate true during rendering, that will add unnecessary calculations.

@scriptspry
Copy link
Contributor Author

The travis build... it is running same tests as npm test ? I am seeing all tests pass in my system. Is there another test system for me to check before pushing?

As for the calculations during rendering, you're absolutely right, but these coords calculations, they are everywhere, can't we do something about these, performance wise?

I mean, something on lines of when canvas/object's properties that affect the coords are changed, calculate the coords. Probably by having setter's to object properties might help. But this is all another different issue I think.

Going back to thread, I really thought that this isOnScreen not calculating coords is a big problem. It is returning wrong results because of this reason. I think it should calculate and performance issue should be fixed in a different manner, immediately.

@asturur
Copy link
Member

asturur commented Feb 24, 2018

So Fabricjs offers an api and some built in interactions.

The built in interactions, are used by user of a product, and are probably outside dev complete control, and in that case fabricjs takes care of updating the coordinates.

For all other situations, to move an object, you have to write some code, in that code you will call setCoords.
You can also override the _set method and for one of the many prop that influences coords, you can call setCoords automatically.

But should not be a default behaviours. If you can make setCoords faster, even by just removing some add and multiply, please do it.

All the usage of trigonometric functions like sin cos atan and atan2, have been minimized recently because often they give back weird float results.

Also isOnScreen needs just the 4 main corners, while setCoords i think updates everything.

asturur
asturur previously requested changes Mar 1, 2018
@@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not change. can you provide any insight for the reason behind this change?

The same apply to object.js

@@ -324,6 +324,7 @@
cObj.setCoords();
assert.ok(cObj.isOnScreen(), 'object is onScreen');
cObj.top = 1000;
assert.ok(!cObj.isOnScreen(true), 'object is not onScreen with top 1000 with calculate true and no setCoords call');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add over this line one that says:

assert.ok(cObj.isOnScreen(), 'object is still wrongly on screen since setCoords is not called and calculate is not set, even when top is already at 1000');

@asturur
Copy link
Member

asturur commented Mar 1, 2018

I added the extra line so i can merge it, i wrote that comment but probably forgot to submit review

@asturur asturur dismissed their stale review March 1, 2018 00:33

added test

@asturur asturur merged commit 38f2d5c into fabricjs:master Mar 1, 2018
@asturur asturur mentioned this pull request Mar 6, 2018
thiagocunha pushed a commit to thiagocunha/fabric.js that referenced this pull request Nov 18, 2019
* Added missing calculate parameter in Object.isOnScreen.

* Update object_geometry.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants