use crate::noise_fns::NoiseFn;
pub struct TranslatePoint<Source> {
pub source: Source,
pub x_translation: f64,
pub y_translation: f64,
pub z_translation: f64,
pub u_translation: f64,
}
impl<Source> TranslatePoint<Source> {
pub fn new(source: Source) -> Self {
Self {
source,
x_translation: 0.0,
y_translation: 0.0,
z_translation: 0.0,
u_translation: 0.0,
}
}
pub fn set_x_translation(self, x_translation: f64) -> Self {
Self {
x_translation,
..self
}
}
pub fn set_y_translation(self, y_translation: f64) -> Self {
Self {
y_translation,
..self
}
}
pub fn set_z_translation(self, z_translation: f64) -> Self {
Self {
z_translation,
..self
}
}
pub fn set_u_translation(self, u_translation: f64) -> Self {
Self {
u_translation,
..self
}
}
pub fn set_translation(self, scale: f64) -> Self {
Self {
x_translation: scale,
y_translation: scale,
z_translation: scale,
u_translation: scale,
..self
}
}
pub fn set_all_translations(
self,
x_translation: f64,
y_translation: f64,
z_translation: f64,
u_translation: f64,
) -> Self {
Self {
x_translation,
y_translation,
z_translation,
u_translation,
..self
}
}
}
impl<Source> NoiseFn<f64, 2> for TranslatePoint<Source>
where
Source: NoiseFn<f64, 2>,
{
fn get(&self, point: [f64; 2]) -> f64 {
self.source
.get([point[0] + self.x_translation, point[1] + self.y_translation])
}
}
impl<Source> NoiseFn<f64, 3> for TranslatePoint<Source>
where
Source: NoiseFn<f64, 3>,
{
fn get(&self, point: [f64; 3]) -> f64 {
self.source.get([
point[0] + self.x_translation,
point[1] + self.y_translation,
point[2] + self.z_translation,
])
}
}
impl<Source> NoiseFn<f64, 4> for TranslatePoint<Source>
where
Source: NoiseFn<f64, 4>,
{
fn get(&self, point: [f64; 4]) -> f64 {
self.source.get([
point[0] + self.x_translation,
point[1] + self.y_translation,
point[2] + self.z_translation,
point[3] + self.u_translation,
])
}
}