question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Properly calculate bounds of rotated elements

See original GitHub issue

From: https://github.com/excalidraw/excalidraw/pull/1273#issuecomment-610385649

This is more like request for comment.

I’m not sure if it’s correct wording, but let’s call Coords and Bounds.

For unrotated diamonds: image

For rotated diamonds: image

Now, Coords is used for resizing and rotating, and Bounds is used for selection detection and calculating canvas size. Bounds are also currently used for multiple element resizing.

Issue 1: https://github.com/excalidraw/excalidraw/pull/1273#issuecomment-610345053 The selection doesn’t detect the diamond because it’s smaller than the Bounds.

image

Issue 2: When exporting, there is an extra margin compared to unrotated elements.

image

What would be an ideal solution and maybe a practical workaround?

(edit) We go with this https://github.com/excalidraw/excalidraw/issues/1303#issuecomment-610462010 and revisit the UI issue later.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
dwellecommented, Apr 7, 2020

Anyway, you don’t need to convince me, I trust your judgement. As long as it fixes export and selection, it’s fine, and we can tweak it as we go along.

(Also, the selection issue I mentioned in the PR elsewhere isn’t really related to multiselection.)

0reactions
dai-shicommented, Apr 7, 2020

(Yeah, I know.)

My original issue title was misleading. Basically we need to properly calculate bounds of rotated elements. (In code, improve getElementBounds.) What I would like to have discussed was the UI issue that may only happen with multiselection. I actually wondered if there could be any totally different solution.

Now, I think the multiselection UI issue is trivial (just make the coords lighter, or we will come up with better ideas later). This issue is all about calculating bounds properly.

Could there be anybody here (or in the internet) who might be interested in tackling this???

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get the bounds of a rotated SVG element in screen pixels?
After some research, here are the best options I've found: getBoundingClientRect() seems to work well for SVG elements in modern browsers, and is...
Read more >
Calculate bounds of a box including rotation - Unity Answers
Probably easier to go through all the vertices instead and find the topmost, leftmost, bottommost and rightmost of them. That way you can...
Read more >
Finding the minimum bounding box of a rotated rectangle
Example · This is a good answer. · @RyanPeschel Objects are normally rotated around an origin, in this case the origin is given...
Read more >
Get bounding rectangle of rotated object - MSDN - Microsoft
I'm trying to get the bounding rectangle of a rotated object on a canvas. I tried this code: public Rect CalculateDragElementRect().
Read more >
Scripting API: GeometryUtility.CalculateBounds - Unity - Manual
positions, An array that stores the location of 3d positions. transform, A matrix that changes the position, rotation and size of the bounds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found