mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 21:18:12 +08:00
Snapping improvements (#1567)
This commit is contained in:
@@ -98,7 +98,28 @@ impl ShapeState {
|
||||
SnapSource::Geometry(GeometrySnapSource::Sharp)
|
||||
};
|
||||
let Some(position) = handle.get_position(&group) else { continue };
|
||||
let point = SnapCandidatePoint::new_source(to_document.transform_point2(position) + mouse_delta, source);
|
||||
let mut point = SnapCandidatePoint::new_source(to_document.transform_point2(position) + mouse_delta, source);
|
||||
|
||||
let mut push_neighbour = |group: ManipulatorGroup<ManipulatorGroupId>| {
|
||||
if !state.is_selected(ManipulatorPointId::new(group.id, SelectedType::Anchor)) {
|
||||
point.neighbors.push(group.anchor)
|
||||
}
|
||||
};
|
||||
if handle == SelectedType::Anchor {
|
||||
// Previous anchor (looping if closed)
|
||||
if index > 0 {
|
||||
push_neighbour(subpath.manipulator_groups()[index - 1]);
|
||||
} else if subpath.closed() {
|
||||
push_neighbour(subpath.manipulator_groups()[subpath.len() - 1]);
|
||||
}
|
||||
// Next anchor (looping if closed)
|
||||
if index + 1 < subpath.len() {
|
||||
push_neighbour(subpath.manipulator_groups()[index + 1]);
|
||||
} else if subpath.closed() {
|
||||
push_neighbour(subpath.manipulator_groups()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
let snapped = snap_manager.free_snap(&snap_data, &point, None, false);
|
||||
if best_snapped.other_snap_better(&snapped) {
|
||||
offset = snapped.snapped_point_document - point.document_point + mouse_delta;
|
||||
|
||||
@@ -64,9 +64,9 @@ pub fn snap_tolerance(document: &DocumentMessageHandler) -> f64 {
|
||||
}
|
||||
|
||||
fn compare_points(a: &&SnappedPoint, b: &&SnappedPoint) -> Ordering {
|
||||
if (a.target.bounding_box() && !b.target.bounding_box()) || (a.at_intersection && !b.at_intersection) {
|
||||
if (a.target.bounding_box() && !b.target.bounding_box()) || (a.at_intersection && !b.at_intersection) || (a.source.bounding_box() && !b.source.bounding_box()) {
|
||||
Ordering::Greater
|
||||
} else if (!a.target.bounding_box() && b.target.bounding_box()) || (!a.at_intersection && b.at_intersection) {
|
||||
} else if (!a.target.bounding_box() && b.target.bounding_box()) || (!a.at_intersection && b.at_intersection) || (!a.source.bounding_box() && b.source.bounding_box()) {
|
||||
Ordering::Less
|
||||
} else {
|
||||
a.distance.partial_cmp(&b.distance).unwrap()
|
||||
|
||||
@@ -330,7 +330,7 @@ impl SnapCandidatePoint {
|
||||
}
|
||||
}
|
||||
#[derive(Default)]
|
||||
struct BBoxSnapValues {
|
||||
pub struct BBoxSnapValues {
|
||||
corner_source: SnapSource,
|
||||
corner_target: SnapTarget,
|
||||
edge_source: SnapSource,
|
||||
@@ -348,7 +348,7 @@ impl BBoxSnapValues {
|
||||
centre_target: SnapTarget::BoundingBox(BoundingBoxSnapTarget::Centre),
|
||||
};
|
||||
}
|
||||
fn get_bbox_points(quad: Quad, points: &mut Vec<SnapCandidatePoint>, values: BBoxSnapValues, document: &DocumentMessageHandler) {
|
||||
pub fn get_bbox_points(quad: Quad, points: &mut Vec<SnapCandidatePoint>, values: BBoxSnapValues, document: &DocumentMessageHandler) {
|
||||
for index in 0..4 {
|
||||
let start = quad.0[index];
|
||||
let end = quad.0[(index + 1) % 4];
|
||||
|
||||
Reference in New Issue
Block a user