Fix snapping bug where snapped-together shapes couldn't be moved (#1818)

* Fixup dragging snap

* Reenable snapping by default on some demo art files

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
James Lindsay 2024-07-12 23:04:14 +01:00 committed by GitHub
parent 3657b37574
commit dba0433100
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -72,7 +72,7 @@ pub struct SnappingState {
impl Default for SnappingState {
fn default() -> Self {
Self {
snapping_enabled: false, // TODO: Reenable this by default once <https://github.com/GraphiteEditor/Graphite/issues/1817> is fixed
snapping_enabled: true,
grid_snapping: false,
bounds: Default::default(),
nodes: Default::default(),

View File

@ -226,24 +226,25 @@ pub fn snap_drag(start: DVec2, current: DVec2, axis_align: bool, snap_data: Snap
let mut best_snap = SnappedPoint::infinite_snap(document.metadata.document_to_viewport.inverse().transform_point2(mouse_position));
for point in candidates {
let origin = point.document_point + total_mouse_delta_document;
let mut point = point.clone();
point.document_point += total_mouse_delta_document;
let snapped = if axis_align {
snap_manager.constrained_snap(
&snap_data,
point,
&point,
SnapConstraint::Line {
origin,
origin: point.document_point,
direction: total_mouse_delta_document.try_normalize().unwrap_or(DVec2::X),
},
None,
)
} else {
snap_manager.free_snap(&snap_data, point, None, false)
snap_manager.free_snap(&snap_data, &point, None, false)
};
if best_snap.other_snap_better(&snapped) {
offset = snapped.snapped_point_document - origin + mouse_delta_document;
offset = snapped.snapped_point_document - point.document_point + mouse_delta_document;
best_snap = snapped;
}
}

View File

@ -1,5 +1,4 @@
[target.wasm32-unknown-unknown]
rustflags = [
# Currently disabled because of https://github.com/GraphiteEditor/Graphite/issues/1262
# The current simd implementation leads to undefined behavior