mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
New nodes: Resample Points, Spline from Points (#1226)
* Create node (no implementation) * Resampling - WIP * use bezier::from_linear_dvec2 * Use from anchors instead of Bezier * Tidy up anchor collection & subpath creation * Add Spline from Points node (not implemented) * Add spline from points node implementation * Update resampling * Update minimum density 0.01 -> 1.0 * Add a way to create a custom vector network * Add spline from points node to spline tool * Fix crash when no points * Add anchor method to subpath * Exact start and end point * Fix compile errors from rebase * Fix spline tool * Rename 'Density' to 'Spacing' * Fix transforms * Only close subpaths with >1 anchor * Fix compile * Fix compile error * Fix from points with many subpaths * Fix new_cubic_spline crash with one point * Rename to resample as polyline * Fix div zero * Fix missing file * Fix resample * Rename to resample points --------- Co-authored-by: hypercube <0hypercube@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -6,6 +6,13 @@ use super::*;
|
||||
impl Bezier {
|
||||
/// Convert a euclidean distance ratio along the `Bezier` curve to a parametric `t`-value.
|
||||
pub fn euclidean_to_parametric(&self, ratio: f64, error: f64) -> f64 {
|
||||
if ratio < error {
|
||||
return 0.;
|
||||
}
|
||||
if 1. - ratio < error {
|
||||
return 1.;
|
||||
}
|
||||
|
||||
let mut low = 0.;
|
||||
let mut mid = 0.;
|
||||
let mut high = 1.;
|
||||
|
||||
@@ -112,6 +112,11 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
|
||||
&self.manipulator_groups
|
||||
}
|
||||
|
||||
/// Returns a vector of all the anchors (DVec2) for this `Subpath`.
|
||||
pub fn anchors(&self) -> Vec<DVec2> {
|
||||
self.manipulator_groups().iter().map(|group| group.anchor).collect()
|
||||
}
|
||||
|
||||
/// Returns if the Subpath is equivalent to a single point.
|
||||
pub fn is_point(&self) -> bool {
|
||||
if self.is_empty() {
|
||||
@@ -254,7 +259,7 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
|
||||
/// Construct a cubic spline from a list of points.
|
||||
/// Based on <https://mathworld.wolfram.com/CubicSpline.html>.
|
||||
pub fn new_cubic_spline(points: Vec<DVec2>) -> Self {
|
||||
if points.is_empty() {
|
||||
if points.len() < 2 {
|
||||
return Self::new(Vec::new(), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,4 +252,16 @@ mod tests {
|
||||
assert_eq!(closed_subpath.t_value_to_parametric(SubpathTValue::GlobalParametric(0.)), (0, 0.));
|
||||
assert_eq!(closed_subpath.t_value_to_parametric(SubpathTValue::GlobalParametric(1.)), (4, 1.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_start_end() {
|
||||
let start = DVec2::new(20., 30.);
|
||||
let end = DVec2::new(60., 45.);
|
||||
let handle = DVec2::new(75., 85.);
|
||||
|
||||
let subpath: Subpath<EmptyId> = Subpath::from_bezier(&Bezier::from_quadratic_dvec2(start, handle, end));
|
||||
|
||||
assert_eq!(subpath.evaluate(SubpathTValue::GlobalEuclidean(0.0)), start);
|
||||
assert_eq!(subpath.evaluate(SubpathTValue::GlobalEuclidean(1.0)), end);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user