pub mod colours;
pub mod crpix;
pub mod trace;
#[cfg(feature = "bake")]
pub mod bake;
#[cfg(feature = "load")]
pub mod load;
use core::fmt;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Rect {
pub x: u32,
pub y: u32,
pub w: u32,
pub h: u32,
}
impl Rect {
#[must_use]
pub const fn new(x: u32, y: u32, w: u32, h: u32) -> Self {
Self { x, y, w, h }
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.w == 0 || self.h == 0
}
#[must_use]
pub const fn fits_in(&self, width: u32, height: u32) -> bool {
match (self.x.checked_add(self.w), self.y.checked_add(self.h)) {
(Some(right), Some(bottom)) => right <= width && bottom <= height,
_ => false,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Frame {
pub name: String,
pub rect: Rect,
pub hold: u32,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Direction {
#[default]
Forward,
Reverse,
PingPong,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Clip {
pub name: String,
pub frames: Vec<usize>,
pub direction: Direction,
pub looping: bool,
}
impl Clip {
#[must_use]
pub fn steps(&self) -> usize {
let n = self.frames.len();
match self.direction {
_ if n <= 1 => n,
Direction::Forward | Direction::Reverse => n,
Direction::PingPong if self.looping => 2 * n - 2,
Direction::PingPong => 2 * n - 1,
}
}
#[must_use]
pub fn step(&self, step: usize) -> Option<usize> {
let n = self.frames.len();
if step >= self.steps() {
return None;
}
let position = match self.direction {
_ if n <= 1 => step,
Direction::Forward => step,
Direction::Reverse => n - 1 - step,
Direction::PingPong if step < n => step,
Direction::PingPong => 2 * n - 2 - step,
};
self.frames.get(position).copied()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Playback {
elapsed: u64,
}
impl Playback {
#[must_use]
pub const fn new() -> Self {
Self { elapsed: 0 }
}
#[must_use]
pub const fn elapsed(&self) -> u64 {
self.elapsed
}
pub const fn advance(&mut self, ticks: u64) {
self.elapsed = self.elapsed.saturating_add(ticks);
}
pub const fn restart(&mut self) {
self.elapsed = 0;
}
pub const fn seek(&mut self, tick: u64) {
self.elapsed = tick;
}
#[must_use]
pub fn frame_index(&self, sheet: &Sheet, clip: &Clip) -> Option<usize> {
let steps = clip.steps();
let total = sheet.clip_duration(clip)?;
if total == 0 {
return None;
}
let tick = if clip.looping {
self.elapsed % total
} else {
self.elapsed.min(total - 1)
};
let mut end = 0;
for step in 0..steps {
let frame = clip.step(step)?;
end += u64::from(sheet.frames.get(frame)?.hold);
if tick < end {
return Some(frame);
}
}
clip.step(steps - 1)
}
#[must_use]
pub fn finished(&self, sheet: &Sheet, clip: &Clip) -> bool {
!clip.looping
&& sheet
.clip_duration(clip)
.is_none_or(|total| self.elapsed >= total)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NineSlice {
pub left: u32,
pub right: u32,
pub top: u32,
pub bottom: u32,
}
impl NineSlice {
#[must_use]
pub const fn new(left: u32, right: u32, top: u32, bottom: u32) -> Self {
Self {
left,
right,
top,
bottom,
}
}
#[must_use]
pub fn from_center(frame: Rect, center: Rect) -> Option<Self> {
let right_edge = center.x.checked_add(center.w)?;
let bottom_edge = center.y.checked_add(center.h)?;
if right_edge > frame.w || bottom_edge > frame.h {
return None;
}
Some(Self {
left: center.x,
right: frame.w - right_edge,
top: center.y,
bottom: frame.h - bottom_edge,
})
}
#[must_use]
pub fn fits_in(&self, frame: Rect) -> bool {
self.left.saturating_add(self.right) <= frame.w
&& self.top.saturating_add(self.bottom) <= frame.h
}
#[must_use]
pub const fn minimum_size(&self) -> (u32, u32) {
(self.left + self.right, self.top + self.bottom)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SampleMode {
#[default]
Pixel,
Smooth,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Sheet {
pub width: u32,
pub height: u32,
pub frames: Vec<Frame>,
pub clips: Vec<Clip>,
pub nine: Option<NineSlice>,
pub sample: SampleMode,
}
impl Sheet {
#[must_use]
pub fn frame(&self, name: &str) -> Option<&Frame> {
self.frames.iter().find(|frame| frame.name == name)
}
#[must_use]
pub fn frame_index(&self, name: &str) -> Option<usize> {
self.frames.iter().position(|frame| frame.name == name)
}
#[must_use]
pub fn clip(&self, name: &str) -> Option<&Clip> {
self.clips.iter().find(|clip| clip.name == name)
}
#[must_use]
pub fn uv(&self, index: usize) -> Option<[f32; 4]> {
if self.width == 0 || self.height == 0 {
return None;
}
let rect = self.frames.get(index)?.rect;
let width = self.width as f32;
let height = self.height as f32;
let right = u64::from(rect.x) + u64::from(rect.w);
let bottom = u64::from(rect.y) + u64::from(rect.h);
Some([
rect.x as f32 / width,
rect.y as f32 / height,
right as f32 / width,
bottom as f32 / height,
])
}
#[must_use]
pub fn clip_duration(&self, clip: &Clip) -> Option<u64> {
let steps = clip.steps();
if steps == 0 {
return None;
}
let mut total = 0u64;
for step in 0..steps {
let frame = self.frames.get(clip.step(step)?)?;
total = total.saturating_add(u64::from(frame.hold));
}
Some(total)
}
pub fn validate(&self) -> Result<(), SheetError> {
if self.frames.is_empty() {
return Err(SheetError::NoFrames);
}
for frame in &self.frames {
if frame.rect.is_empty() {
return Err(SheetError::EmptyFrame {
frame: frame.name.clone(),
});
}
if !frame.rect.fits_in(self.width, self.height) {
return Err(SheetError::FrameOutsideSheet {
frame: frame.name.clone(),
rect: frame.rect,
width: self.width,
height: self.height,
});
}
if frame.hold == 0 {
return Err(SheetError::ZeroHold {
frame: frame.name.clone(),
});
}
}
for (index, frame) in self.frames.iter().enumerate() {
if self.frames[..index]
.iter()
.any(|other| other.name == frame.name)
{
return Err(SheetError::DuplicateFrame {
frame: frame.name.clone(),
});
}
}
for clip in &self.clips {
if clip.frames.is_empty() {
return Err(SheetError::EmptyClip {
clip: clip.name.clone(),
});
}
if let Some(&bad) = clip.frames.iter().find(|&&i| i >= self.frames.len()) {
return Err(SheetError::ClipFrameOutOfRange {
clip: clip.name.clone(),
index: bad,
frames: self.frames.len(),
});
}
}
if let Some(nine) = self.nine {
let frame = &self.frames[0];
if !nine.fits_in(frame.rect) {
return Err(SheetError::NineTooBig {
nine,
frame: frame.rect,
});
}
}
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SheetError {
NoFrames,
EmptyFrame {
frame: String,
},
FrameOutsideSheet {
frame: String,
rect: Rect,
width: u32,
height: u32,
},
ZeroHold {
frame: String,
},
DuplicateFrame {
frame: String,
},
EmptyClip {
clip: String,
},
ClipFrameOutOfRange {
clip: String,
index: usize,
frames: usize,
},
NineTooBig {
nine: NineSlice,
frame: Rect,
},
}
impl fmt::Display for SheetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoFrames => write!(f, "a sheet with no frames draws nothing"),
Self::EmptyFrame { frame } => {
write!(f, "frame `{frame}` has no area")
}
Self::FrameOutsideSheet {
frame,
rect,
width,
height,
} => write!(
f,
"frame `{frame}` at {}x{}+{}+{} runs outside a {width}x{height} sheet; \
it would sample whatever is next to it",
rect.w, rect.h, rect.x, rect.y
),
Self::ZeroHold { frame } => write!(
f,
"frame `{frame}` is held for zero ticks, so a clip containing it \
would advance forever without drawing"
),
Self::DuplicateFrame { frame } => {
write!(f, "two frames are both called `{frame}`")
}
Self::EmptyClip { clip } => write!(f, "clip `{clip}` names no frames"),
Self::ClipFrameOutOfRange {
clip,
index,
frames,
} => write!(
f,
"clip `{clip}` names frame {index}, but the sheet has {frames}"
),
Self::NineTooBig { nine, frame } => write!(
f,
"nine-slice insets {}+{} wide and {}+{} tall do not fit a {}x{} frame",
nine.left, nine.right, nine.top, nine.bottom, frame.w, frame.h
),
}
}
}
impl core::error::Error for SheetError {}
#[cfg(test)]
mod tests {
use super::*;
fn sheet() -> Sheet {
Sheet {
width: 32,
height: 16,
frames: vec![
Frame {
name: "a".into(),
rect: Rect::new(0, 0, 16, 16),
hold: 4,
},
Frame {
name: "b".into(),
rect: Rect::new(16, 0, 16, 16),
hold: 4,
},
],
clips: vec![Clip {
name: "walk".into(),
frames: vec![0, 1],
direction: Direction::Forward,
looping: true,
}],
nine: None,
sample: SampleMode::Pixel,
}
}
#[test]
fn a_well_formed_sheet_validates_and_can_be_looked_up_by_name() {
let sheet = sheet();
sheet.validate().expect("this sheet is well formed");
assert_eq!(
sheet.frame("b").map(|f| f.rect),
Some(Rect::new(16, 0, 16, 16))
);
assert_eq!(sheet.frame_index("b"), Some(1));
assert_eq!(sheet.frame("nope"), None);
assert_eq!(sheet.clip("walk").map(|c| c.frames.len()), Some(2));
}
#[test]
fn a_frame_that_runs_off_the_sheet_is_refused() {
let mut sheet = sheet();
sheet.frames[1].rect = Rect::new(20, 0, 16, 16);
let error = sheet.validate().expect_err("this frame runs off the right");
assert!(matches!(error, SheetError::FrameOutsideSheet { .. }));
assert!(error.to_string().contains("outside"), "{error}");
}
#[test]
fn a_frame_rect_cannot_wrap_its_way_inside_the_sheet() {
assert!(!Rect::new(u32::MAX - 1, 0, 4, 4).fits_in(64, 64));
assert!(!Rect::new(0, u32::MAX, 4, 4).fits_in(64, 64));
assert!(!Rect::new(0, 0, 128, 4).fits_in(64, 64));
assert!(!Rect::new(0, 0, 4, 128).fits_in(64, 64));
assert!(
Rect::new(60, 60, 4, 4).fits_in(64, 64),
"flush to the edge fits"
);
}
#[test]
fn the_other_rules_each_have_a_message() {
let mut empty = sheet();
empty.frames.clear();
assert_eq!(empty.validate(), Err(SheetError::NoFrames));
let mut zero = sheet();
zero.frames[0].hold = 0;
assert!(matches!(zero.validate(), Err(SheetError::ZeroHold { .. })));
let mut duplicate = sheet();
duplicate.frames[1].name = "a".into();
assert!(matches!(
duplicate.validate(),
Err(SheetError::DuplicateFrame { .. })
));
let mut dangling = sheet();
dangling.clips[0].frames = vec![0, 7];
assert!(matches!(
dangling.validate(),
Err(SheetError::ClipFrameOutOfRange { .. })
));
let mut hollow = sheet();
hollow.clips[0].frames.clear();
assert!(matches!(
hollow.validate(),
Err(SheetError::EmptyClip { .. })
));
let mut flat = sheet();
flat.frames[0].rect = Rect::new(0, 0, 0, 16);
assert!(matches!(
flat.validate(),
Err(SheetError::EmptyFrame { .. })
));
}
#[test]
fn nine_slice_insets_that_overlap_are_refused() {
let frame = Rect::new(0, 0, 16, 16);
assert!(
NineSlice::new(8, 8, 8, 8).fits_in(frame),
"exactly touching is fine"
);
assert!(!NineSlice::new(9, 8, 0, 0).fits_in(frame));
assert!(!NineSlice::new(0, 0, 12, 12).fits_in(frame));
assert!(
!NineSlice::new(u32::MAX, 1, 0, 0).fits_in(frame),
"and must not wrap"
);
let mut sheet = sheet();
sheet.nine = Some(NineSlice::new(9, 9, 0, 0));
assert!(matches!(
sheet.validate(),
Err(SheetError::NineTooBig { .. })
));
}
#[test]
fn asepite_centre_rects_convert_to_the_insets_they_describe() {
let frame = Rect::new(0, 0, 32, 16);
let nine = NineSlice::from_center(frame, Rect::new(4, 6, 20, 4))
.expect("the centre is inside the frame");
assert_eq!(nine, NineSlice::new(4, 8, 6, 6));
assert_eq!(nine.minimum_size(), (12, 12));
assert_eq!(NineSlice::from_center(frame, Rect::new(30, 0, 8, 4)), None);
assert_eq!(NineSlice::from_center(frame, Rect::new(0, 14, 4, 8)), None);
}
fn strip(holds: [u32; 4]) -> Sheet {
let frame = |name: &str, x: u32, hold: u32| Frame {
name: name.into(),
rect: Rect::new(x, 0, 16, 16),
hold,
};
Sheet {
width: 64,
height: 16,
frames: vec![
frame("a", 0, holds[0]),
frame("b", 16, holds[1]),
frame("c", 32, holds[2]),
frame("d", 48, holds[3]),
],
..Sheet::default()
}
}
fn clip(frames: Vec<usize>, direction: Direction, looping: bool) -> Clip {
Clip {
name: "clip".into(),
frames,
direction,
looping,
}
}
fn drawn(sheet: &Sheet, clip: &Clip, ticks: u64) -> Vec<usize> {
let mut play = Playback::new();
(0..ticks)
.map(|_| {
let frame = play.frame_index(sheet, clip).expect("the clip draws");
play.advance(1);
frame
})
.collect()
}
fn showings(clip: &Clip) -> Vec<usize> {
(0..clip.steps())
.map(|step| clip.step(step).expect("inside the pass"))
.collect()
}
fn naive(sheet: &Sheet, clip: &Clip, ticks: u64) -> usize {
let steps = clip.steps();
let mut step = 0;
let mut held = 0;
for _ in 0..ticks {
let frame = clip.step(step).expect("inside the pass");
let hold = sheet.frames[frame].hold;
held += 1;
if held < hold {
continue;
}
held = 0;
if step + 1 < steps {
step += 1;
} else if clip.looping {
step = 0;
} else {
held = hold; }
}
clip.step(step).expect("inside the pass")
}
fn cases() -> Vec<(Sheet, Clip)> {
let uneven = strip([2, 1, 3, 1]);
let flat = strip([1, 1, 1, 1]);
let mut out = Vec::new();
for direction in [Direction::Forward, Direction::Reverse, Direction::PingPong] {
for looping in [true, false] {
for sheet in [uneven.clone(), flat.clone()] {
out.push((sheet.clone(), clip(vec![0, 1, 2, 3], direction, looping)));
out.push((sheet.clone(), clip(vec![2], direction, looping)));
out.push((sheet.clone(), clip(vec![1, 3], direction, looping)));
out.push((sheet, clip(vec![0, 2, 0, 3], direction, looping)));
}
}
}
out
}
#[test]
fn forward_holds_each_frame_for_its_own_ticks_and_wraps() {
let sheet = strip([2, 1, 3, 1]);
let walk = clip(vec![0, 1, 2, 3], Direction::Forward, true);
assert_eq!(showings(&walk), vec![0, 1, 2, 3]);
assert_eq!(sheet.clip_duration(&walk), Some(7), "2 + 1 + 3 + 1");
assert_eq!(
drawn(&sheet, &walk, 16),
vec![0, 0, 1, 2, 2, 2, 3, 0, 0, 1, 2, 2, 2, 3, 0, 0],
"two whole cycles and a bit"
);
let flat = strip([1, 1, 1, 1]);
assert_eq!(flat.clip_duration(&walk), Some(4));
assert_eq!(drawn(&flat, &walk, 9), vec![0, 1, 2, 3, 0, 1, 2, 3, 0]);
}
#[test]
fn reverse_runs_the_frames_backwards_and_takes_their_holds_with_them() {
let sheet = strip([2, 1, 3, 1]);
let back = clip(vec![0, 1, 2, 3], Direction::Reverse, true);
assert_eq!(showings(&back), vec![3, 2, 1, 0]);
assert_eq!(
sheet.clip_duration(&back),
Some(7),
"the same holds, so the same total"
);
assert_eq!(
drawn(&sheet, &back, 14),
vec![3, 2, 2, 2, 1, 0, 0, 3, 2, 2, 2, 1, 0, 0],
"`d` is held 1 tick and `c` 3, exactly as forward holds them"
);
let forward = clip(vec![0, 1, 2, 3], Direction::Forward, true);
let mut mirrored = drawn(&sheet, &forward, 7);
mirrored.reverse();
assert_eq!(drawn(&sheet, &back, 7), mirrored);
}
#[test]
fn ping_pong_shows_each_end_once_so_its_period_is_two_n_minus_two() {
let sheet = strip([2, 1, 3, 1]);
let flap = clip(vec![0, 1, 2, 3], Direction::PingPong, true);
assert_eq!(flap.steps(), 6, "2n - 2 for n = 4, not 2n");
assert_eq!(showings(&flap), vec![0, 1, 2, 3, 2, 1]);
assert_eq!(
sheet.clip_duration(&flap),
Some(11),
"2 + 1 + 3 + 1 + 3 + 1; repeating the ends would be 14"
);
let cycle = vec![0, 0, 1, 2, 2, 2, 3, 2, 2, 2, 1];
let mut twice = cycle.clone();
twice.extend_from_slice(&cycle);
assert_eq!(drawn(&sheet, &flap, 22), twice);
let mut here = Playback::new();
let mut later = Playback::new();
later.advance(11 * 9);
for _ in 0..40 {
assert_eq!(
here.frame_index(&sheet, &flap),
later.frame_index(&sheet, &flap),
"at tick {}",
here.elapsed()
);
here.advance(1);
later.advance(1);
}
assert!(
cycle.windows(2).any(|pair| pair[0] != pair[1]),
"a playback that never advances would satisfy a weaker assertion"
);
}
#[test]
fn a_one_shot_ping_pong_returns_to_its_first_frame_and_parks() {
let sheet = strip([2, 1, 3, 1]);
let once = clip(vec![0, 1, 2, 3], Direction::PingPong, false);
assert_eq!(once.steps(), 7, "2n - 1: the walk home is not a repeat");
assert_eq!(showings(&once), vec![0, 1, 2, 3, 2, 1, 0]);
assert_eq!(sheet.clip_duration(&once), Some(13), "11 + `a`'s two ticks");
assert_eq!(
drawn(&sheet, &once, 17),
vec![0, 0, 1, 2, 2, 2, 3, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0]
);
}
#[test]
fn a_one_shot_holds_its_last_frame_and_reports_finished_after_it() {
let sheet = strip([2, 1, 3, 1]);
let once = clip(vec![0, 1, 2, 3], Direction::Forward, false);
assert_eq!(sheet.clip_duration(&once), Some(7));
assert_eq!(
drawn(&sheet, &once, 12),
vec![0, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3],
"and then `d` forever"
);
let mut play = Playback::new();
play.advance(6);
assert_eq!(
play.frame_index(&sheet, &once),
Some(3),
"the last frame, on the first tick it is drawn"
);
assert!(
!play.finished(&sheet, &once),
"on the last frame is not the same as done with it"
);
play.advance(1);
assert_eq!(play.frame_index(&sheet, &once), Some(3));
assert!(play.finished(&sheet, &once), "after its hold, it is over");
play.advance(1_000);
assert!(play.finished(&sheet, &once));
assert_eq!(
play.frame_index(&sheet, &once),
Some(3),
"a caller ignoring `finished` still draws something"
);
let forever = clip(vec![0, 1, 2, 3], Direction::Forward, true);
assert!(!play.finished(&sheet, &forever));
}
#[test]
fn a_single_frame_clip_is_one_showing_in_every_direction() {
let sheet = strip([2, 1, 3, 1]);
for direction in [Direction::Forward, Direction::Reverse, Direction::PingPong] {
for looping in [true, false] {
let lone = clip(vec![2], direction, looping);
assert_eq!(lone.steps(), 1, "{direction:?} looping={looping}");
assert_eq!(showings(&lone), vec![2]);
assert_eq!(lone.step(1), None);
assert_eq!(
sheet.clip_duration(&lone),
Some(3),
"`c`'s hold, counted once: {direction:?}"
);
assert_eq!(
drawn(&sheet, &lone, 8),
vec![2; 8],
"{direction:?} looping={looping}"
);
let mut play = Playback::new();
play.advance(3);
assert_eq!(play.finished(&sheet, &lone), !looping);
}
}
}
#[test]
fn the_closed_form_agrees_with_a_tick_by_tick_walk() {
for (sheet, clip) in cases() {
for ticks in 0..200 {
let mut play = Playback::new();
play.advance(ticks);
assert_eq!(
play.frame_index(&sheet, &clip),
Some(naive(&sheet, &clip, ticks)),
"{:?} looping={} frames={:?} at tick {ticks}",
clip.direction,
clip.looping,
clip.frames,
);
}
}
}
#[test]
fn advancing_many_ticks_at_once_lands_where_one_at_a_time_does() {
for (sheet, clip) in cases() {
let mut stepped = Playback::new();
for ticks in 0..300u64 {
let mut jumped = Playback::new();
jumped.advance(ticks);
assert_eq!(
jumped.frame_index(&sheet, &clip),
stepped.frame_index(&sheet, &clip),
"{:?} looping={} frames={:?} at tick {ticks}",
clip.direction,
clip.looping,
clip.frames,
);
assert_eq!(jumped.elapsed(), stepped.elapsed());
let mut split = Playback::new();
split.advance(ticks / 3);
split.advance(ticks - ticks / 3);
assert_eq!(
split.frame_index(&sheet, &clip),
stepped.frame_index(&sheet, &clip)
);
stepped.advance(1);
}
}
}
#[test]
fn restarting_and_seeking_put_playback_where_asked() {
let sheet = strip([2, 1, 3, 1]);
let walk = clip(vec![0, 1, 2, 3], Direction::Forward, false);
let mut play = Playback::new();
play.advance(5);
assert_eq!(play.elapsed(), 5);
assert_eq!(play.frame_index(&sheet, &walk), Some(2));
play.restart();
assert_eq!(play.elapsed(), 0);
assert_eq!(play.frame_index(&sheet, &walk), Some(0));
play.seek(6);
assert_eq!(play.frame_index(&sheet, &walk), Some(3));
assert!(!play.finished(&sheet, &walk));
play.seek(u64::MAX);
play.advance(9);
assert_eq!(play.elapsed(), u64::MAX, "saturates rather than wrapping");
assert!(play.finished(&sheet, &walk));
}
#[test]
fn a_clip_that_cannot_draw_answers_none() {
let sheet = strip([2, 1, 3, 1]);
let empty = clip(vec![], Direction::PingPong, true);
assert_eq!(empty.steps(), 0);
assert_eq!(empty.step(0), None);
assert_eq!(sheet.clip_duration(&empty), None);
assert_eq!(Playback::new().frame_index(&sheet, &empty), None);
let dangling = clip(vec![0, 9], Direction::Forward, true);
assert_eq!(Playback::new().frame_index(&sheet, &dangling), None);
}
#[test]
fn frame_uvs_are_normalised_with_the_top_left_corner_first() {
let sheet = Sheet {
width: 64,
height: 32,
frames: vec![
Frame {
name: "left".into(),
rect: Rect::new(0, 0, 16, 8),
hold: 1,
},
Frame {
name: "far".into(),
rect: Rect::new(48, 24, 16, 8),
hold: 1,
},
],
..Sheet::default()
};
sheet.validate().expect("well formed");
assert_eq!(sheet.uv(0), Some([0.0, 0.0, 0.25, 0.25]));
assert_eq!(sheet.uv(1), Some([0.75, 0.75, 1.0, 1.0]));
assert_eq!(sheet.uv(2), None, "no such frame");
let sizeless = Sheet {
width: 0,
..sheet.clone()
};
assert_eq!(sizeless.uv(0), None);
}
}