pub mod curves;
pub mod geometry;
pub mod time_curves;
use alpha2_geometry::CanvasSize;
use alpha2_time::MediaTime;
pub(crate) fn canvas(width: u32, height: u32) -> Result<CanvasSize, String> {
if width == 0 || height == 0 || width > 16_384 || height > 16_384 {
return Err(format!(
"a picture is 1 to 16384 pixels on each side, not {width}x{height}"
));
}
Ok(CanvasSize::new(width, height))
}
pub(crate) fn aspect(size: CanvasSize) -> f64 {
f64::from(size.width) / f64::from(size.height)
}
#[allow(clippy::cast_possible_truncation)]
pub fn time(ticks: f64) -> Result<MediaTime, String> {
if !ticks.is_finite() || ticks.fract() != 0.0 || ticks.abs() > 9.007_199_254_740_991e15 {
return Err(format!("a time is a whole number of ticks, not {ticks}"));
}
Ok(MediaTime(ticks as i64))
}
pub(crate) fn to_text(value: &impl serde::Serialize) -> Result<String, String> {
serde_json::to_string(value).map_err(|error| error.to_string())
}