Fix inability to drag axis-aligned lines (#2561)

* Fix 1 and 3

* Fix 2

* Shape tools refactor

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
mTvare
2025-04-13 03:51:40 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent fdff5d4e5e
commit 3e6021fb8f
4 changed files with 9 additions and 6 deletions
@@ -142,14 +142,17 @@ impl DocumentMetadata {
///
/// If the layer bounds are `0` in either axis then they are changed to be `1`.
pub fn nonzero_bounding_box(&self, layer: LayerNodeIdentifier) -> [DVec2; 2] {
let [bounds_min, mut bounds_max] = self.bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default();
let [mut bounds_min, mut bounds_max] = self.bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default();
let bounds_size = bounds_max - bounds_min;
let bounds_midpoint = bounds_min.midpoint(bounds_max);
if bounds_size.x < 1e-10 {
bounds_max.x = bounds_min.x + 1.;
bounds_max.x = bounds_midpoint.x + 0.5;
bounds_min.x = bounds_midpoint.x - 0.5;
}
if bounds_size.y < 1e-10 {
bounds_max.y = bounds_min.y + 1.;
bounds_max.y = bounds_midpoint.y + 0.5;
bounds_min.y = bounds_midpoint.y - 0.5;
}
[bounds_min, bounds_max]