replace common index code
This commit is contained in:
@@ -2,3 +2,12 @@
|
||||
pub fn wrap(x: f32, max: f32) -> f32 {
|
||||
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
||||
}
|
||||
|
||||
// Truncate x and y and return a corresponding index into the data slice.
|
||||
#[inline]
|
||||
pub const fn index(width: usize, height: usize, x: f32, y: f32) -> usize {
|
||||
// x/y can come in negative, hence we shift them by width/height.
|
||||
let i = (x + width as f32) as usize & (width - 1);
|
||||
let j = (y + height as f32) as usize & (height - 1);
|
||||
j * width + i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user