Skip to content

Commit d581319

Browse files
authored
Prep gcore splitup 2: Vector extension traits (#2759)
* extension trait for `MergeByDistance::merge_by_distance_*` * extension trait for `VectorData::append_bezpath` * extension trait for `HandleId::set_relative_position` * remove unreferenced rust files
1 parent 2ddae98 commit d581319

File tree

14 files changed

+46
-123
lines changed

14 files changed

+46
-123
lines changed

editor/src/messages/portfolio/document/utility_types/transformation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::messages::tool::common_functionality::shape_editor::ShapeState;
99
use crate::messages::tool::utility_types::ToolType;
1010
use glam::{DAffine2, DMat2, DVec2};
1111
use graphene_std::renderer::Quad;
12-
use graphene_std::vector::ManipulatorPointId;
1312
use graphene_std::vector::VectorModificationType;
13+
use graphene_std::vector::{HandleExt, ManipulatorPointId};
1414
use graphene_std::vector::{HandleId, PointId};
1515
use std::collections::{HashMap, VecDeque};
1616
use std::f64::consts::PI;

editor/src/messages/tool/common_functionality/shape_editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::messages::tool::common_functionality::utility_functions::is_visible_p
1212
use crate::messages::tool::tool_messages::path_tool::{PathOverlayMode, PointSelectState};
1313
use bezier_rs::{Bezier, BezierHandles, Subpath, TValue};
1414
use glam::{DAffine2, DVec2};
15-
use graphene_std::vector::{HandleId, SegmentId};
15+
use graphene_std::vector::{HandleExt, HandleId, SegmentId};
1616
use graphene_std::vector::{ManipulatorPointId, PointId, VectorData, VectorModificationType};
1717

1818
#[derive(Debug, Copy, Clone, PartialEq, Eq)]

editor/src/messages/tool/common_functionality/utility_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bezier_rs::Bezier;
1212
use glam::{DAffine2, DVec2};
1313
use graphene_std::renderer::Quad;
1414
use graphene_std::text::{FontCache, load_face};
15-
use graphene_std::vector::{HandleId, ManipulatorPointId, PointId, SegmentId, VectorData, VectorModificationType};
15+
use graphene_std::vector::{HandleExt, HandleId, ManipulatorPointId, PointId, SegmentId, VectorData, VectorModificationType};
1616

1717
/// Determines if a path should be extended. Goal in viewport space. Returns the path and if it is extending from the start, if applicable.
1818
pub fn should_extend(

editor/src/messages/tool/tool_messages/path_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::messages::tool::common_functionality::snapping::{SnapCache, SnapCandi
1818
use crate::messages::tool::common_functionality::utility_functions::{calculate_segment_angle, find_two_param_best_approximate};
1919
use bezier_rs::{Bezier, TValue};
2020
use graphene_std::renderer::Quad;
21-
use graphene_std::vector::{HandleId, NoHashBuilder, SegmentId, VectorData};
21+
use graphene_std::vector::{HandleExt, HandleId, NoHashBuilder, SegmentId, VectorData};
2222
use graphene_std::vector::{ManipulatorPointId, PointId, VectorModificationType};
2323
use std::vec;
2424

node-graph/gcore/src/raster/image/base64_serde.rs

Whitespace-only changes.

node-graph/gcore/src/vector/algorithms/merge_by_distance.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ use glam::{DAffine2, DVec2};
33
use petgraph::prelude::UnGraphMap;
44
use rustc_hash::FxHashSet;
55

6-
impl VectorData {
6+
pub trait MergeByDistanceExt {
77
/// Collapse all points with edges shorter than the specified distance
8-
pub fn merge_by_distance_topological(&mut self, distance: f64) {
8+
fn merge_by_distance_topological(&mut self, distance: f64);
9+
fn merge_by_distance_spatial(&mut self, transform: DAffine2, distance: f64);
10+
}
11+
12+
impl MergeByDistanceExt for VectorData {
13+
fn merge_by_distance_topological(&mut self, distance: f64) {
914
// Treat self as an undirected graph
1015
let indices = VectorDataIndex::build_from(self);
1116

@@ -95,7 +100,7 @@ impl VectorData {
95100
self.point_domain.retain(&mut self.segment_domain, |id| !points_to_delete.contains(id));
96101
}
97102

98-
pub fn merge_by_distance_spatial(&mut self, transform: DAffine2, distance: f64) {
103+
fn merge_by_distance_spatial(&mut self, transform: DAffine2, distance: f64) {
99104
let point_count = self.point_domain.positions().len();
100105

101106
// Find min x and y for grid cell normalization
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod bezpath_algorithms;
2-
mod instance;
3-
mod merge_by_distance;
2+
pub mod instance;
3+
pub mod merge_by_distance;
44
pub mod offset_subpath;
5-
mod poisson_disk;
5+
pub mod poisson_disk;
66
pub mod spline;

node-graph/gcore/src/vector/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod algorithms;
1+
pub mod algorithms;
22
pub mod brush_stroke;
33
pub mod click_target;
44
pub mod generator_nodes;

node-graph/gcore/src/vector/vector_data.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ impl VectorData {
186186
self.point_domain.push(id, point.position);
187187
}
188188

189-
/// Appends a Kurbo BezPath to the vector data.
190-
pub fn append_bezpath(&mut self, bezpath: kurbo::BezPath) {
191-
AppendBezpath::append_bezpath(self, bezpath);
192-
}
193-
194189
/// Construct some new vector data from a single subpath with an identity transform and black fill.
195190
pub fn from_subpath(subpath: impl Borrow<bezier_rs::Subpath<PointId>>) -> Self {
196191
Self::from_subpaths([subpath], false)
@@ -637,16 +632,6 @@ impl HandleId {
637632
handle_position.map(|pos| (pos - anchor_position).length()).unwrap_or(f64::MAX)
638633
}
639634

640-
/// Set the handle's position relative to the anchor which is the start anchor for the primary handle and end anchor for the end handle.
641-
#[must_use]
642-
pub fn set_relative_position(self, relative_position: DVec2) -> VectorModificationType {
643-
let Self { ty, segment } = self;
644-
match ty {
645-
HandleType::Primary => VectorModificationType::SetPrimaryHandle { segment, relative_position },
646-
HandleType::End => VectorModificationType::SetEndHandle { segment, relative_position },
647-
}
648-
}
649-
650635
/// Convert an end handle to the primary handle and a primary handle to an end handle. Note that the new handle may not exist (e.g. for a quadratic bézier).
651636
#[must_use]
652637
pub fn opposite(self) -> Self {

node-graph/gcore/src/vector/vector_data/modification.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,33 @@ impl<'a> AppendBezpath<'a> {
634634
}
635635
}
636636

637+
pub trait VectorDataExt {
638+
/// Appends a Kurbo BezPath to the vector data.
639+
fn append_bezpath(&mut self, bezpath: BezPath);
640+
}
641+
642+
impl VectorDataExt for VectorData {
643+
fn append_bezpath(&mut self, bezpath: BezPath) {
644+
AppendBezpath::append_bezpath(self, bezpath);
645+
}
646+
}
647+
648+
pub trait HandleExt {
649+
/// Set the handle's position relative to the anchor which is the start anchor for the primary handle and end anchor for the end handle.
650+
#[must_use]
651+
fn set_relative_position(self, relative_position: DVec2) -> VectorModificationType;
652+
}
653+
654+
impl HandleExt for HandleId {
655+
fn set_relative_position(self, relative_position: DVec2) -> VectorModificationType {
656+
let Self { ty, segment } = self;
657+
match ty {
658+
HandleType::Primary => VectorModificationType::SetPrimaryHandle { segment, relative_position },
659+
HandleType::End => VectorModificationType::SetEndHandle { segment, relative_position },
660+
}
661+
}
662+
}
663+
637664
#[cfg(test)]
638665
mod tests {
639666
use super::*;

0 commit comments

Comments
 (0)