use core::ops::Range;
use vello_common::geometry::RectU16;
use vello_common::paint::Paint;
use vello_common::record::Drawable;
use vello_common::strip::Strip;
use vello_common::util::strip_bbox;
#[derive(Debug, Clone)]
pub struct EngineDraw {
pub paint: Paint,
pub depth: u32,
pub strip_range: Range<usize>,
}
impl EngineDraw {
pub fn new(paint: Paint, depth: u32, strip_range: Range<usize>) -> Self {
Self {
paint,
depth,
strip_range,
}
}
}
impl Drawable for EngineDraw {
fn bbox(&self, strips: &[Strip]) -> Option<RectU16> {
strip_bbox(strips)
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct DepthCounter {
next: u32,
}
impl DepthCounter {
pub fn new() -> Self {
Self::default()
}
pub fn advance(&mut self) -> u32 {
let depth = self.next;
self.next = self.next.saturating_add(1);
depth
}
pub fn count(&self) -> u32 {
self.next
}
}
#[cfg(test)]
mod tests {
use super::*;
use vello_common::color::palette::css::RED;
#[test]
fn depths_start_at_zero_and_increase() {
let mut counter = DepthCounter::new();
assert_eq!(counter.advance(), 0);
assert_eq!(counter.advance(), 1);
assert_eq!(counter.advance(), 2);
assert_eq!(counter.count(), 3);
}
#[test]
fn depth_saturates_instead_of_wrapping() {
let mut counter = DepthCounter { next: u32::MAX };
assert_eq!(counter.advance(), u32::MAX);
assert_eq!(counter.advance(), u32::MAX);
}
#[test]
fn a_draw_with_no_strips_has_no_bbox() {
let draw = EngineDraw::new(Paint::from(RED), 0, 0..0);
assert!(draw.bbox(&[]).is_none());
}
}