27 lines
728 B
Rust
27 lines
728 B
Rust
#[derive(Debug, Clone)]
|
|
pub struct Buf {
|
|
width: usize,
|
|
height: usize,
|
|
pub buf: Vec<f32>,
|
|
}
|
|
|
|
impl Buf {
|
|
pub fn new(width: usize, height: usize) -> Self {
|
|
Buf {
|
|
width,
|
|
height,
|
|
buf: vec![0.0; height * width],
|
|
}
|
|
}
|
|
|
|
/// Truncate x and y and return a corresponding index into the data slice.
|
|
const fn index(&self, x: f32, y: f32) -> usize {
|
|
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.
|
|
pub fn get_buf(&self, x: f32, y: f32) -> f32 {
|
|
self.buf[self.index(x, y)]
|
|
}
|
|
}
|