Skip to content

Commit

Permalink
bug fix + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
juliapaci committed Aug 3, 2024
1 parent 0062a9c commit bb5f80c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ fn render_shapes(mut commands: Commands) {
Fill::new().with_color(css::YELLOW_GREEN.into()),
Stroke::new(5.0).with_color(css::DARK_GREEN.into()),
Transform::from_xyz(100.0, 0.0, 0.0),
HeadBundle{
HeadBundle {
vector: HeadVector(VelloRect::new(20.0, 20.0)),
head: Head::default().with_offset(DVec2::new(0.0, -50.0)),
transform: HeadTransform::default()
});
transform: HeadTransform::default(),
},
);

let mut bez_path = kurbo::BezPath::new();
bez_path.move_to((300.0, 100.0));
Expand Down
5 changes: 3 additions & 2 deletions src/bezpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ impl VelloBezPath {
self
}

// TODO: need a constant interpolation time `t` thats even accross all `PathEl`s
/// Gets the progress of/and [`kurbo::PathEl`] which the [`VelloBezPath`] is inbetween at `t`
fn inbetween(&self, t: f64) -> (&[PathEl], f64) {
let elements = self.path.elements();
let index_f = (t * elements.len() as f64 - 1.0).max(0.0);
let index_f = t * (elements.len() - 1) as f64;
let index = index_f as usize;

(
&elements[index..=index - (t == 1.0) as usize + 1],
&elements[index..=index + 1 - (t == 1.0) as usize],
index_f % 1.0,
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ pub(super) fn prepare_heads<V: Vector + Component>(
mut q_vectors: Query<(&V, &Head, &mut HeadTransform), Or<(Changed<V>, Changed<Head>)>>,
) {
for (vector, head, mut head_transform) in q_vectors.iter_mut() {
let translation = vector.border_translation(head.time) + DVec2::ZERO.lerp(head.translation_offset, head.time);
let rotation = vector.border_rotation(head.time) + 0.0_f64.lerp(head.rotation_offset, head.time);
let translation = vector.border_translation(head.time)
+ DVec2::ZERO.lerp(head.translation_offset, head.time);
let rotation =
vector.border_rotation(head.time) + 0.0_f64.lerp(head.rotation_offset, head.time);
let scale = head.scale;

head_transform.0 = kurbo::Affine::rotate(rotation)
Expand Down

0 comments on commit bb5f80c

Please sign in to comment.