replace common index code

This commit is contained in:
2025-03-27 14:37:36 -04:00
parent d1f515b17d
commit a8fc644d6c
3 changed files with 12 additions and 9 deletions

View File

@@ -16,10 +16,7 @@ impl Buf {
// Truncate x and y and return a corresponding index into the data slice.
const fn index(&self, x: f32, y: f32) -> usize {
// x/y can come in negative, hence we shift them by width/height.
let i = (x + self.width as f32) as usize & (self.width - 1);
let j = (y + self.height as f32) as usize & (self.height - 1);
j * self.width + i
crate::util::index(self.width, self.height, x, y)
}
// Get the buffer value at a given position. The implementation effectively treats data as periodic, hence any finite position will produce a value.