mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 02:58:11 +08:00
Tidy up path handling in document_file (#464)
* Tidy up path handling in document_file + Improve #455 * Cargo Clippy lints * Rename to_vec to map_to_vec Co-authored-by: Oliver Davies <oliver@psyfer.io>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Oliver Davies
parent
8b3edb0c6e
commit
aa9770092f
@@ -5,26 +5,21 @@ use crate::consts::SNAP_TOLERANCE;
|
||||
|
||||
use super::DocumentMessageHandler;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct SnapHandler {
|
||||
snap_targets: Option<(Vec<f64>, Vec<f64>)>,
|
||||
}
|
||||
impl Default for SnapHandler {
|
||||
fn default() -> Self {
|
||||
Self { snap_targets: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapHandler {
|
||||
/// Gets a list of snap targets for the X and Y axes in Viewport coords for the target layers (usually all layers or all non-selected layers.)
|
||||
/// This should be called at the start of a drag.
|
||||
pub fn start_snap(&mut self, document_message_handler: &DocumentMessageHandler, target_layers: Vec<Vec<LayerId>>, ignore_layers: &[Vec<LayerId>]) {
|
||||
pub fn start_snap(&mut self, document_message_handler: &DocumentMessageHandler, target_layers: Vec<&[LayerId]>, ignore_layers: &[Vec<LayerId>]) {
|
||||
if document_message_handler.snapping_enabled {
|
||||
// Could be made into sorted Vec or a HashSet for more performant lookups.
|
||||
self.snap_targets = Some(
|
||||
target_layers
|
||||
.iter()
|
||||
.filter(|path| !ignore_layers.contains(path))
|
||||
.filter(|path| !ignore_layers.iter().any(|layer| layer.as_slice() == **path))
|
||||
.filter_map(|path| document_message_handler.graphene_document.viewport_bounding_box(path).ok()?)
|
||||
.flat_map(|[bound1, bound2]| [bound1, bound2, ((bound1 + bound2) / 2.)])
|
||||
.map(|vec| vec.into())
|
||||
|
||||
Reference in New Issue
Block a user