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

Rotating group fabricjs objects with snapangle property set, produces incorrect individual object angles #3857

Closed
OutrageousSoftware opened this issue Apr 20, 2017 · 3 comments · Fixed by #3872

Comments

@OutrageousSoftware
Copy link

Version

1.7.8

Test Case

http://jsfiddle.net/Outrageous/a50nrcv0/

Steps to reproduce

  1. Run this jsfiddle... http://jsfiddle.net/Outrageous/a50nrcv0/
  2. Click the "Show Angle" button. (it should read 0 degrees, and it does)
  3. Select both text objects ("text1" and "text2") with your mouse.
  4. Rotate the selected group 90 degrees to the right.
  5. Click on the canvas to Un-Select the text box group.
  6. Click the "Show Angle" button. (it should read 90 degrees, and it does)
  7. Select both text objects ("text1" and "text2") with your mouse.
  8. Rotate the selected group 90 degrees to the left (to return the text boxes back to a 0 degree angle).
  9. Click on the canvas to Un-Select the text box group.
  10. Click the "Show Angle" button. (it should read 0 degrees and instead reads -1.4033418597069752e-14 degrees)

From here on out all of the angles are off when rotating via a group - The angle of the objects show -1.4033418597069752e-14 degrees instead of 0 degrees when rotating objects as a group. Note: this code uses a snapThreshold: 45, and a snapAngle: 90 so I wouldn't think this would happen. When I rotate the objects individually the angles correct themselves. I have tried using the setCoords() with no luck. This issue doesn't happen when only rotating in a positive direction, only in a negative direction. Also, I have noticed that the object.left and object.top values change slightly as well after performing the steps above.

Expected Behavior

The angle of the objects should be 0 degrees.

Actual Behavior

The angle of the objects show -1.4033418597069752e-14 degrees instead of 0 degrees.

@asturur
Copy link
Member

asturur commented Apr 22, 2017

may be some snap angle problem or a calculation error of ungrouping.
There is a missing precision inherited from how floats are done.

-1.4 x 10 ^ -14 is basically 0: 0.000000000000014033.

If is not a snapping bug, i cannot fix it.

@asturur
Copy link
Member

asturur commented Apr 23, 2017

so the error is that Math.cos never gives 0 for 90 deg or 270 degrees...

@OutrageousSoftware
Copy link
Author

Thank you Andrea for the quick turn around on that. Fabric.js is amazing!

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

Successfully merging a pull request may close this issue.

2 participants