Rename rem_euclid functions

This commit is contained in:
Gwilym Kuiper 2022-05-03 23:23:55 +01:00
parent be650779e6
commit 5211781429

View file

@ -52,19 +52,19 @@ impl RegularBackgroundSize {
self.num_tiles() / (32 * 32)
}
pub(crate) fn rem_euclid_width(&self, x: i32) -> u16 {
pub(crate) fn tile_pos_x(&self, x: i32) -> u16 {
((x as u32) & (self.width() - 1)) as u16
}
pub(crate) fn rem_euclid_height(&self, y: i32) -> u16 {
pub(crate) fn tile_pos_y(&self, y: i32) -> u16 {
((y as u32) & (self.height() - 1)) as u16
}
pub(crate) fn rem_euclid_width_px(&self, x: i32) -> u16 {
pub(crate) fn px_offset_x(&self, x: i32) -> u16 {
((x as u32) & (self.width() * 8 - 1)) as u16
}
pub(crate) fn rem_euclid_height_px(&self, y: i32) -> u16 {
pub(crate) fn px_offset_y(&self, y: i32) -> u16 {
((y as u32) & (self.height() * 8 - 1)) as u16
}
}
@ -127,15 +127,12 @@ mod test {
for size in sizes.iter() {
let width = size.width() as i32;
assert_eq!(size.rem_euclid_width(8), 8);
assert_eq!(size.rem_euclid_width(3 + width), 3);
assert_eq!(size.rem_euclid_width(7 + width * 9), 7);
assert_eq!(size.tile_pos_x(8), 8);
assert_eq!(size.tile_pos_x(3 + width), 3);
assert_eq!(size.tile_pos_x(7 + width * 9), 7);
assert_eq!(size.rem_euclid_width(-8), (size.width() - 8) as u16);
assert_eq!(
size.rem_euclid_width(-17 - width * 8),
(size.width() - 17) as u16
);
assert_eq!(size.tile_pos_x(-8), (size.width() - 8) as u16);
assert_eq!(size.tile_pos_x(-17 - width * 8), (size.width() - 17) as u16);
}
}
}