
Show HN: Boxy SVG editor - jarek-foksa
https://boxy-svg.com/app
======
MobiusHorizons
Looks nice!! How do you scale things in an aspect-ratio preserving way?

~~~
jarek-foksa
Thanks!

If I recall correctly, the simplest algorithm was as follows:

1\. When user begins scaling an object, compute the initial bounding box
(bbox) of the object.

2\. On each pointer move determine the scaled bbox into which the object
should fit. If user holds down the shift key, adjust the scaled bbox so that
it has the same aspect ratio as the initial bbox.

3\. Finally, compute the transformation matrix that transforms the initial
bbox into the scaled bbox and apply it as a "transform" attribute on the
object.

The current implementation in Boxy SVG is a bit more complicated because it
has to handle all the edge cases like multiple selected objects that belong to
different groups or objects that have zero width or height (e.g. straight
horizontal or vertical line).

