Commit e97b05c4 authored by Romain Vimont's avatar Romain Vimont Committed by Romain Vimont

Add EdgedPlaneSlice

For tiling, we want subslices to never exceed their parent slice.

However, several functions need to read few pixels on top and on the
left of a given PlaneSlice.

For that purpose, introduce EdgedPlaneSlice, containing a PlaneSlice
which includes edges and the edges size.
parent 0a35174f
......@@ -189,6 +189,19 @@ impl<T: Pixel> Plane<T> {
self.mut_slice(&PlaneOffset { x: 0, y: 0 })
}
#[inline]
pub fn edged_slice(&self, po: &PlaneOffset, left_edge: usize, top_edge: usize) -> EdgedPlaneSlice<'_, T> {
debug_assert!(po.x >= 0);
debug_assert!(po.y >= 0);
let left_edge = left_edge.min(po.x as usize);
let top_edge = top_edge.min(po.y as usize);
let edged_po = PlaneOffset {
x: po.x - left_edge as isize,
y: po.y - top_edge as isize,
};
EdgedPlaneSlice { ps: self.slice(&edged_po), left_edge, top_edge }
}
#[inline]
fn index(&self, x: usize, y: usize) -> usize {
(y + self.cfg.yorigin) * self.cfg.stride + (x + self.cfg.xorigin)
......@@ -576,6 +589,18 @@ impl<'a, T: Pixel> IndexMut<usize> for PlaneMutSlice<'a, T> {
}
}
pub struct EdgedPlaneSlice<'a, T: Pixel> {
pub ps: PlaneSlice<'a, T>,
pub left_edge: usize,
pub top_edge: usize,
}
impl<T: Pixel> EdgedPlaneSlice<'_, T> {
pub fn without_edges(&self) -> PlaneSlice<'_, T> {
self.ps.subslice(self.left_edge, self.top_edge)
}
}
#[cfg(test)]
pub mod test {
use super::*;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment