diff --git a/benches/perlin.rs b/benches/perlin.rs index 942890f3..522f4125 100644 --- a/benches/perlin.rs +++ b/benches/perlin.rs @@ -3,7 +3,11 @@ extern crate criterion; extern crate noise; use criterion::{black_box, Criterion}; -use noise::{NoiseFn, Perlin}; +use noise::{ + core::perlin::{perlin_2d, perlin_3d, perlin_4d}, + permutationtable::PermutationTable, + Vector2, Vector3, Vector4, +}; criterion_group!(perlin, bench_perlin2, bench_perlin3, bench_perlin4); criterion_group!( @@ -15,33 +19,38 @@ criterion_group!( criterion_main!(perlin, perlin_64x64); fn bench_perlin2(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 2d", |b| { - b.iter(|| perlin.get(black_box([42.0_f64, 37.0]))) + b.iter(|| perlin_2d(black_box(Vector2::new(42.0_f64, 37.0)), &hasher)) }); } fn bench_perlin3(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 3d", |b| { - b.iter(|| perlin.get(black_box([42.0_f64, 37.0, 26.0]))) + b.iter(|| perlin_3d(black_box(Vector3::new(42.0_f64, 37.0, 26.0)), &hasher)) }); } fn bench_perlin4(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 4d", |b| { - b.iter(|| perlin.get(black_box([42.0_f64, 37.0, 26.0, 128.0]))) + b.iter(|| { + perlin_4d( + black_box(Vector4::new(42.0_f64, 37.0, 26.0, 128.0)), + &hasher, + ) + }) }); } fn bench_perlin2_64x64(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 2d (64x64)", |b| { b.iter(|| { for y in 0i8..64 { for x in 0i8..64 { - black_box(perlin.get([x as f64, y as f64])); + perlin_2d(black_box(Vector2::new(x as f64, y as f64)), &hasher); } } }) @@ -49,12 +58,15 @@ fn bench_perlin2_64x64(c: &mut Criterion) { } fn bench_perlin3_64x64(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 3d (64x64)", |b| { b.iter(|| { for y in 0i8..64 { for x in 0i8..64 { - black_box(perlin.get([x as f64, y as f64, x as f64])); + perlin_3d( + black_box(Vector3::new(x as f64, y as f64, x as f64)), + &hasher, + ); } } }) @@ -62,12 +74,15 @@ fn bench_perlin3_64x64(c: &mut Criterion) { } fn bench_perlin4_64x64(c: &mut Criterion) { - let perlin = Perlin::default(); + let hasher = PermutationTable::new(0); c.bench_function("perlin 4d (64x64)", |b| { b.iter(|| { for y in 0i8..64 { for x in 0i8..64 { - black_box(perlin.get([x as f64, y as f64, x as f64, y as f64])); + perlin_4d( + black_box(Vector4::new(x as f64, y as f64, x as f64, y as f64)), + &hasher, + ); } } }) diff --git a/src/lib.rs b/src/lib.rs index e9e9de8e..ffc9deef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,11 +15,12 @@ #[macro_use] extern crate alloc; +pub use crate::math::vectors::*; pub use crate::noise_fns::*; pub mod core; mod gradient; -mod math; +pub mod math; mod noise_fns; pub mod permutationtable; pub mod utils; diff --git a/src/math.rs b/src/math.rs index c8ecffee..5bf8c66e 100644 --- a/src/math.rs +++ b/src/math.rs @@ -3,7 +3,7 @@ pub(crate) mod interpolate; pub(crate) mod s_curve; -pub(crate) mod vectors; +pub mod vectors; #[cfg(not(target_os = "emscripten"))] #[inline]