Skip to content

Commit

Permalink
Remove Quadratic Distance Function
Browse files Browse the repository at this point in the history
Getting it working right would need more effort, easier to strip it out for now and maybe re-implement it later (or never)

Closes #175, #176
  • Loading branch information
Razaekel committed Aug 18, 2023
1 parent 2d9fbb8 commit 98d092d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 116 deletions.
20 changes: 0 additions & 20 deletions benches/worley_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ criterion_group!(bench_worley_2d,
bench_worley2d_manhattan_range,
bench_worley2d_chebyshev_value,
bench_worley2d_chebyshev_range,
bench_worley2d_quadratic_value,
bench_worley2d_quadratic_range,
);
criterion_group!(bench_worley_2d_64x64,
bench_worley2d_euclidean_value_64x64,
Expand All @@ -30,8 +28,6 @@ criterion_group!(bench_worley_2d_64x64,
bench_worley2d_manhattan_range_64x64,
bench_worley2d_chebyshev_value_64x64,
bench_worley2d_chebyshev_range_64x64,
bench_worley2d_quadratic_value_64x64,
bench_worley2d_quadratic_range_64x64,
);
criterion_main!(bench_worley_2d, bench_worley_2d_64x64);

Expand Down Expand Up @@ -93,14 +89,6 @@ fn bench_worley2d_chebyshev_range(c: &mut Criterion) {
bench_worley2d(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley2d_quadratic_value(c: &mut Criterion) {
bench_worley2d(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley2d_quadratic_range(c: &mut Criterion) {
bench_worley2d(c, &quadratic, ReturnType::Distance, "quadratic distance");
}

fn bench_worley2d_euclidean_value_64x64(c: &mut Criterion) {
bench_worley2d_64x64(c, &euclidean, ReturnType::Value, "euclidean value");
}
Expand Down Expand Up @@ -132,11 +120,3 @@ fn bench_worley2d_chebyshev_value_64x64(c: &mut Criterion) {
fn bench_worley2d_chebyshev_range_64x64(c: &mut Criterion) {
bench_worley2d_64x64(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley2d_quadratic_value_64x64(c: &mut Criterion) {
bench_worley2d_64x64(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley2d_quadratic_range_64x64(c: &mut Criterion) {
bench_worley2d_64x64(c, &quadratic, ReturnType::Distance, "quadratic distance");
}
20 changes: 0 additions & 20 deletions benches/worley_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ criterion_group!(bench_worley_3d,
bench_worley3d_manhattan_range,
bench_worley3d_chebyshev_value,
bench_worley3d_chebyshev_range,
bench_worley3d_quadratic_value,
bench_worley3d_quadratic_range,
);
criterion_group!(bench_worley_3d_64x64,
bench_worley3d_euclidean_value_64x64,
Expand All @@ -30,8 +28,6 @@ criterion_group!(bench_worley_3d_64x64,
bench_worley3d_manhattan_range_64x64,
bench_worley3d_chebyshev_value_64x64,
bench_worley3d_chebyshev_range_64x64,
bench_worley3d_quadratic_value_64x64,
bench_worley3d_quadratic_range_64x64,
);
criterion_main!(bench_worley_3d, bench_worley_3d_64x64);

Expand Down Expand Up @@ -93,14 +89,6 @@ fn bench_worley3d_chebyshev_range(c: &mut Criterion) {
bench_worley3d(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley3d_quadratic_value(c: &mut Criterion) {
bench_worley3d(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley3d_quadratic_range(c: &mut Criterion) {
bench_worley3d(c, &quadratic, ReturnType::Distance, "quadratic distance");
}

fn bench_worley3d_euclidean_value_64x64(c: &mut Criterion) {
bench_worley3d_64x64(c, &euclidean, ReturnType::Value, "euclidean value");
}
Expand Down Expand Up @@ -132,11 +120,3 @@ fn bench_worley3d_chebyshev_value_64x64(c: &mut Criterion) {
fn bench_worley3d_chebyshev_range_64x64(c: &mut Criterion) {
bench_worley3d_64x64(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley3d_quadratic_value_64x64(c: &mut Criterion) {
bench_worley3d_64x64(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley3d_quadratic_range_64x64(c: &mut Criterion) {
bench_worley3d_64x64(c, &quadratic, ReturnType::Distance, "quadratic distance");
}
66 changes: 37 additions & 29 deletions benches/worley_4d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ extern crate noise;

use criterion::{black_box, Criterion};
use noise::{
core::worley::{distance_functions::*, ReturnType, worley_4d},
core::worley::{distance_functions::*, worley_4d, ReturnType},
math::vectors::Vector4,
permutationtable::PermutationTable,
};

criterion_group!(bench_worley_4d,
criterion_group!(
bench_worley_4d,
bench_worley4d_euclidean_value,
bench_worley4d_euclidean_range,
bench_worley4d_squared_value,
Expand All @@ -18,10 +19,9 @@ criterion_group!(bench_worley_4d,
bench_worley4d_manhattan_range,
bench_worley4d_chebyshev_value,
bench_worley4d_chebyshev_range,
bench_worley4d_quadratic_value,
bench_worley4d_quadratic_range,
);
criterion_group!(bench_worley_4d_64x64,
criterion_group!(
bench_worley_4d_64x64,
bench_worley4d_euclidean_value_64x64,
bench_worley4d_euclidean_range_64x64,
bench_worley4d_squared_value_64x64,
Expand All @@ -30,8 +30,6 @@ criterion_group!(bench_worley_4d_64x64,
bench_worley4d_manhattan_range_64x64,
bench_worley4d_chebyshev_value_64x64,
bench_worley4d_chebyshev_range_64x64,
bench_worley4d_quadratic_value_64x64,
bench_worley4d_quadratic_range_64x64,
);
criterion_main!(bench_worley_4d, bench_worley_4d_64x64);

Expand All @@ -41,20 +39,36 @@ where
{
let hasher = PermutationTable::new(0);
c.bench_function(format!("worley 4d {}", name).as_str(), |b| {
b.iter(|| worley_4d(&hasher, distance_function, return_type, black_box(Vector4::new(42.0f64, 37.0, 26.0, 128.0))))
b.iter(|| {
worley_4d(
&hasher,
distance_function,
return_type,
black_box(Vector4::new(42.0f64, 37.0, 26.0, 128.0)),
)
})
});
}

fn bench_worley4d_64x64<F>(c: &mut Criterion, distance_function: &F, return_type: ReturnType, name: &str)
where
fn bench_worley4d_64x64<F>(
c: &mut Criterion,
distance_function: &F,
return_type: ReturnType,
name: &str,
) where
F: Fn(&[f64], &[f64]) -> f64,
{
let hasher = PermutationTable::new(0);
c.bench_function(format!("worley 4d {} (64x64)", name).as_str(), |b| {
b.iter(|| {
for y in 0i8..64 {
for x in 0i8..64 {
black_box(worley_4d(&hasher, distance_function, return_type, Vector4::new(x as f64, y as f64, x as f64, y as f64)));
black_box(worley_4d(
&hasher,
distance_function,
return_type,
Vector4::new(x as f64, y as f64, x as f64, y as f64),
));
}
}
})
Expand All @@ -74,7 +88,12 @@ fn bench_worley4d_squared_value(c: &mut Criterion) {
}

fn bench_worley4d_squared_range(c: &mut Criterion) {
bench_worley4d(c, &euclidean_squared, ReturnType::Distance, "squared distance");
bench_worley4d(
c,
&euclidean_squared,
ReturnType::Distance,
"squared distance",
);
}

fn bench_worley4d_manhattan_value(c: &mut Criterion) {
Expand All @@ -93,14 +112,6 @@ fn bench_worley4d_chebyshev_range(c: &mut Criterion) {
bench_worley4d(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley4d_quadratic_value(c: &mut Criterion) {
bench_worley4d(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley4d_quadratic_range(c: &mut Criterion) {
bench_worley4d(c, &quadratic, ReturnType::Distance, "quadratic distance");
}

fn bench_worley4d_euclidean_value_64x64(c: &mut Criterion) {
bench_worley4d_64x64(c, &euclidean, ReturnType::Value, "euclidean value");
}
Expand All @@ -114,7 +125,12 @@ fn bench_worley4d_squared_value_64x64(c: &mut Criterion) {
}

fn bench_worley4d_squared_range_64x64(c: &mut Criterion) {
bench_worley4d_64x64(c, &euclidean_squared, ReturnType::Distance, "squared distance");
bench_worley4d_64x64(
c,
&euclidean_squared,
ReturnType::Distance,
"squared distance",
);
}

fn bench_worley4d_manhattan_value_64x64(c: &mut Criterion) {
Expand All @@ -132,11 +148,3 @@ fn bench_worley4d_chebyshev_value_64x64(c: &mut Criterion) {
fn bench_worley4d_chebyshev_range_64x64(c: &mut Criterion) {
bench_worley4d_64x64(c, &chebyshev, ReturnType::Distance, "chebyshev distance");
}

fn bench_worley4d_quadratic_value_64x64(c: &mut Criterion) {
bench_worley4d_64x64(c, &quadratic, ReturnType::Value, "quadratic value");
}

fn bench_worley4d_quadratic_range_64x64(c: &mut Criterion) {
bench_worley4d_64x64(c, &quadratic, ReturnType::Distance, "quadratic distance");
}
30 changes: 0 additions & 30 deletions examples/worley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,4 @@ fn main() {
ReturnType::Distance,
"worley_4d_chebyshev_distance.png",
);
output_2d(
&quadratic,
ReturnType::Value,
"worley_2d_quadratic_value.png",
);
output_3d(
&quadratic,
ReturnType::Value,
"worley_3d_quadratic_value.png",
);
output_4d(
&quadratic,
ReturnType::Value,
"worley_4d_quadratic_value.png",
);
output_2d(
&quadratic,
ReturnType::Distance,
"worley_2d_quadratic_distance.png",
);
output_3d(
&quadratic,
ReturnType::Distance,
"worley_3d_quadratic_distance.png",
);
output_4d(
&quadratic,
ReturnType::Distance,
"worley_4d_quadratic_distance.png",
);
}
17 changes: 0 additions & 17 deletions src/core/worley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ pub mod distance_functions {
.map(|a| a.abs())
.fold(f64::MIN, |a, b| a.max(b))
}

pub fn quadratic(p1: &[f64], p2: &[f64]) -> f64 {
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

let temp: Vec<f64> = p1.iter().zip(p2).map(|(a, b)| *a - *b).collect();

let mut result = 0.0;

for i in &temp {
for j in &temp {
result += *i * *j;
}
}

result
}
}

pub fn worley_2d<F, NH>(
Expand Down

0 comments on commit 98d092d

Please sign in to comment.