From eed2db4528752490cb65aab27dd757afe78590c5 Mon Sep 17 00:00:00 2001 From: julia Date: Thu, 20 Jun 2024 18:44:24 +1000 Subject: [PATCH] apply suggestions --- src/bezpath.rs | 23 +++++++++++++++++------ src/circle.rs | 8 ++++---- src/head.rs | 11 ++++++----- src/lib.rs | 22 +++++++--------------- src/line.rs | 6 +++--- src/rect.rs | 12 +++++++++--- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/bezpath.rs b/src/bezpath.rs index 18c8c2c..6b95ee1 100644 --- a/src/bezpath.rs +++ b/src/bezpath.rs @@ -141,14 +141,25 @@ fn interp_pathel(p0: kurbo::Point, pathel: kurbo::PathEl, t: f32) -> kurbo::Path } impl VectorBorder for VelloBezPath { - fn border_translation(&self, _time: f32) -> DVec2 { + fn border_translation(&self, time: f64) -> DVec2 { // TODO: def should not unwrap here - let p = self.path.iter().last().unwrap().end_point().unwrap_or_default().to_vec2(); - - DVec2::new(p.x, p.y) + let first = self.path.elements()[0] + .end_point() + .unwrap_or_default() + .to_vec2(); + let last = self + .path + .iter() + .last() + .unwrap() + .end_point() + .unwrap_or_default() + .to_vec2(); + + DVec2::new(first.x, first.y).lerp(DVec2::new(last.x, last.y), time) } - fn border_tangent(&self, _time: f32) -> f64 { - self.border_translation(f32::default()).to_angle() + fn border_tangent(&self, time: f64) -> f64 { + self.border_translation(time).to_angle() } } diff --git a/src/circle.rs b/src/circle.rs index 5742255..597a804 100644 --- a/src/circle.rs +++ b/src/circle.rs @@ -28,11 +28,11 @@ impl VelloVector for VelloCircle { } impl VectorBorder for VelloCircle { - fn border_translation(&self, _time: f32) -> DVec2 { - DVec2::new(0.0, self.radius) + fn border_translation(&self, time: f64) -> DVec2 { + DVec2::new(0.0, self.radius).lerp(DVec2::new(0.0, 0.0), time) } - fn border_tangent(&self, _time: f32) -> f64 { - 0.0 + fn border_tangent(&self, time: f64) -> f64 { + self.border_translation(time).to_angle() } } diff --git a/src/head.rs b/src/head.rs index be12e0a..9575ad1 100644 --- a/src/head.rs +++ b/src/head.rs @@ -8,8 +8,9 @@ pub struct ShapeId(Uuid); #[derive(Component, Default, Copy, Clone)] pub struct Head { pub shape_id: ShapeId, + pub time: f64, - pub scale: f32, + pub scale: f64, pub offset: f32, pub rotation_offset: f32, } @@ -20,8 +21,8 @@ pub struct Shapes { } pub trait VectorBorder { - /// translation of the chosen "apex" - fn border_translation(&self, time: f32) -> DVec2; - /// gradient of the tangent to the border - fn border_tangent(&self, time: f32) -> f64; + /// Translation of the of the border at a specific `time` value. + fn border_translation(&self, time: f64) -> DVec2; + /// The gradient of the tangent to the border at a specific `time` value. + fn border_tangent(&self, time: f64) -> f64; } diff --git a/src/lib.rs b/src/lib.rs index 651915f..c45341c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,10 +39,6 @@ impl Plugin for VelloGraphicsPlugin { build_vector::(), build_vector::(), build_vector::(), - build_head::(), - build_head::(), - build_head::(), - build_head::(), ), ); } @@ -74,19 +70,18 @@ pub trait VelloVector { } } -pub(crate) fn build_vector() -> SystemConfigs { +pub(crate) fn build_vector() -> SystemConfigs { ( + // vector build_fill_only_vector::, build_stroke_only_vector::, build_fill_and_stroke_vector::, + // head + append_heads::, ) .into_configs() } -pub(crate) fn build_head() -> SystemConfigs { - append_heads::.into_configs() -} - #[allow(clippy::type_complexity)] fn append_heads( mut q_vectors: Query< @@ -94,20 +89,17 @@ fn append_heads( (Without, Or<(Changed, Changed)>), >, shapes: Res, - time: Res