Rename to `new_clamped`
diff --git a/sparse_strips/vello_common/src/strip.rs b/sparse_strips/vello_common/src/strip.rs index 7af904f..469d0b2 100644 --- a/sparse_strips/vello_common/src/strip.rs +++ b/sparse_strips/vello_common/src/strip.rs
@@ -133,7 +133,7 @@ let mut accumulated_winding = f32x4::splat(s, 0.0); /// A special tile to keep the logic below simple. - const SENTINEL: Tile = Tile::new_const(u16::MAX, u16::MAX, 0, false); + const SENTINEL: Tile = Tile::new(u16::MAX, u16::MAX, 0, false); // The strip we're building. let mut strip = Strip::new(
diff --git a/sparse_strips/vello_common/src/tile.rs b/sparse_strips/vello_common/src/tile.rs index e24df66..f688f6c 100644 --- a/sparse_strips/vello_common/src/tile.rs +++ b/sparse_strips/vello_common/src/tile.rs
@@ -68,11 +68,12 @@ pub const HEIGHT: u16 = 4; /// Create a new tile. + /// `x` and `y` will be clamped to the largest possible coordinate if they are too large. /// /// `line_idx` must be smaller than [`MAX_LINES_PER_PATH`]. #[inline] - pub fn new(x: u16, y: u16, line_idx: u32, winding: bool) -> Self { - Self::new_const( + pub fn new_clamped(x: u16, y: u16, line_idx: u32, winding: bool) -> Self { + Self::new( // Make sure that x and y stay in range when multiplying // with the tile width and height during strips generation. x.min(u16::MAX / Self::WIDTH), @@ -83,7 +84,7 @@ } #[inline] - pub(crate) const fn new_const(x: u16, y: u16, line_idx: u32, winding: bool) -> Self { + pub(crate) const fn new(x: u16, y: u16, line_idx: u32, winding: bool) -> Self { #[cfg(debug_assertions)] if line_idx >= MAX_LINES_PER_PATH { panic!("Max. number of lines per path exceeded."); @@ -289,7 +290,7 @@ for y_idx in y_top_tiles..y_bottom_tiles { let y = f32::from(y_idx); - let tile = Tile::new(x, y_idx, line_idx, y >= line_top_y); + let tile = Tile::new_clamped(x, y_idx, line_idx, y >= line_top_y); self.tile_buf.push(tile); } } else { @@ -327,7 +328,7 @@ for x_idx in line_row_left_x as u16..=(line_row_right_x as u16).min(tile_columns - 1) { - let tile = Tile::new( + let tile = Tile::new_clamped( x_idx, y_idx, line_idx, @@ -398,7 +399,7 @@ let mut tiles = Tiles::new(Level::try_detect().unwrap_or(Level::fallback())); tiles.make_tiles(&[line], 100, 100); - assert_eq!(tiles.tile_buf, [Tile::new(0, 0, 0, true)]); + assert_eq!(tiles.tile_buf, [Tile::new_clamped(0, 0, 0, true)]); } #[test] @@ -415,9 +416,9 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(0, 0, 0, false), - Tile::new(1, 0, 0, false), - Tile::new(2, 0, 0, false), + Tile::new_clamped(0, 0, 0, false), + Tile::new_clamped(1, 0, 0, false), + Tile::new_clamped(2, 0, 0, false), ] ); } @@ -436,9 +437,9 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(0, 0, 0, false), - Tile::new(0, 1, 0, true), - Tile::new(0, 2, 0, true), + Tile::new_clamped(0, 0, 0, false), + Tile::new_clamped(0, 1, 0, true), + Tile::new_clamped(0, 2, 0, true), ] ); } @@ -457,11 +458,11 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(0, 0, 0, false), - Tile::new(1, 0, 0, false), - Tile::new(1, 1, 0, true), - Tile::new(2, 1, 0, false), - Tile::new(2, 2, 0, true), + Tile::new_clamped(0, 0, 0, false), + Tile::new_clamped(1, 0, 0, false), + Tile::new_clamped(1, 1, 0, true), + Tile::new_clamped(2, 1, 0, false), + Tile::new_clamped(2, 2, 0, true), ] ); } @@ -480,11 +481,11 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(0, 0, 0, false), - Tile::new(1, 0, 0, false), - Tile::new(1, 1, 0, true), - Tile::new(2, 1, 0, false), - Tile::new(2, 2, 0, true), + Tile::new_clamped(0, 0, 0, false), + Tile::new_clamped(1, 0, 0, false), + Tile::new_clamped(1, 1, 0, true), + Tile::new_clamped(2, 1, 0, false), + Tile::new_clamped(2, 2, 0, true), ] ); } @@ -503,11 +504,11 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(2, 1, 0, false), - Tile::new(3, 1, 0, false), - Tile::new(0, 2, 0, false), - Tile::new(1, 2, 0, false), - Tile::new(2, 2, 0, true), + Tile::new_clamped(2, 1, 0, false), + Tile::new_clamped(3, 1, 0, false), + Tile::new_clamped(0, 2, 0, false), + Tile::new_clamped(1, 2, 0, false), + Tile::new_clamped(2, 2, 0, true), ] ); } @@ -526,11 +527,11 @@ assert_eq!( tiles.tile_buf, [ - Tile::new(2, 1, 0, false), - Tile::new(3, 1, 0, false), - Tile::new(0, 2, 0, false), - Tile::new(1, 2, 0, false), - Tile::new(2, 2, 0, true), + Tile::new_clamped(2, 1, 0, false), + Tile::new_clamped(3, 1, 0, false), + Tile::new_clamped(0, 2, 0, false), + Tile::new_clamped(1, 2, 0, false), + Tile::new_clamped(2, 2, 0, true), ] ); } @@ -552,7 +553,10 @@ assert_eq!( tiles.tile_buf, - [Tile::new(0, 0, 0, false), Tile::new(0, 0, 1, false),] + [ + Tile::new_clamped(0, 0, 0, false), + Tile::new_clamped(0, 0, 1, false), + ] ); }