use std::mem::swap;
use kurbo::{Affine, Point, Vec2};
pub type Transform = kurbo::Affine;
pub type Color = peniko::Color;
pub type ColorStops = peniko::ColorStops;
pub type Brush = peniko::Brush;
pub type Stroke = kurbo::Stroke;
#[derive(Clone, Debug)]
pub struct Repeater {
pub copies: usize,
pub offset: f64,
pub anchor_point: Point,
pub position: Point,
pub rotation: f64,
pub scale: Vec2,
pub start_opacity: f64,
pub end_opacity: f64,
}
impl Repeater {
pub fn transform(&self, index: usize) -> Affine {
let t = self.offset + index as f64;
Affine::translate((
t * self.position.x + self.anchor_point.x,
t * self.position.y + self.anchor_point.y,
)) * Affine::rotate((t * self.rotation).to_radians())
* Affine::scale_non_uniform(
(self.scale.x / 100.0).powf(t),
(self.scale.y / 100.0).powf(t),
)
* Affine::translate((-self.anchor_point.x, -self.anchor_point.y))
}
}
#[derive(Clone, Debug)]
pub struct Trim {
pub start: f64,
pub end: f64,
pub offset: f64,
}
type NormalizedTrim = ((f64, f64), Option<(f64, f64)>);
impl Trim {
pub fn normalized(&self) -> Option<NormalizedTrim> {
let (start_pct, end_pct) = if self.start <= self.end {
(self.start, self.end)
} else {
(self.end, self.start)
};
let range_pct = end_pct - start_pct;
if range_pct < 1e-9 {
return None;
}
if range_pct >= 100.0 - 1e-9 {
return Some(((0.0, 1.0), None));
}
let offset_pct = self.offset * (100.0 / 360.0);
let start_pct = (start_pct + offset_pct).rem_euclid(100.0);
let end_pct = start_pct + range_pct;
if end_pct <= 100.0 {
Some(((start_pct / 100.0, end_pct / 100.0), None))
} else {
Some((
(start_pct / 100.0, 1.0),
Some((0.0, (end_pct - 100.0) / 100.0)),
))
}
}
}