Add rem_euclid_*_px for pixel calculations

This commit is contained in:
Gwilym Kuiper 2022-05-03 23:00:31 +01:00
parent 4d3d2acd3b
commit 817e1e305e
2 changed files with 10 additions and 2 deletions

View file

@ -190,8 +190,8 @@ impl<'a> InfiniteScrolledMap<'a> {
let current_scroll = self.map.scroll_pos();
let new_scroll = (
size.rem_euclid_width(current_scroll.x as i32 + difference.x) as u16,
size.rem_euclid_height(current_scroll.y as i32 + difference.y) as u16,
size.rem_euclid_width_px(current_scroll.x as i32 + difference.x) as u16,
size.rem_euclid_height_px(current_scroll.y as i32 + difference.y) as u16,
)
.into();

View file

@ -55,6 +55,14 @@ impl RegularBackgroundSize {
pub(crate) fn rem_euclid_height(&self, y: i32) -> u32 {
(y as u32) & (self.height() - 1)
}
pub(crate) fn rem_euclid_width_px(&self, x: i32) -> u32 {
(x as u32) & (self.width() * 8 - 1)
}
pub(crate) fn rem_euclid_height_px(&self, y: i32) -> u32 {
(y as u32) & (self.height() * 8 - 1)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]