Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FNL::new and FNL::with_seed const #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ pub struct FastNoiseLite {

impl Default for FastNoiseLite {
fn default() -> Self {
Self::new()
}
}

impl FastNoiseLite {
// =====================
// Constructor functions
// =====================

/// # Constructor
///
/// Create new FastNoise object with the default seed of `1337`.
pub const fn new() -> Self {
Self {
seed: 1337,
frequency: 0.01,
Expand All @@ -248,7 +261,7 @@ impl Default for FastNoiseLite {
weighted_strength: 0.,
ping_pong_strength: 2.,

/* private */ fractal_bounding: 1. / 1.75,
/* private */ fractal_bounding: 0.5714285714, // = 1.0 / 1.75

cellular_distance_function: CellularDistanceFunction::EuclideanSq,
cellular_return_type: CellularReturnType::Distance,
Expand All @@ -259,24 +272,11 @@ impl Default for FastNoiseLite {
domain_warp_amp: 1.,
}
}
}

impl FastNoiseLite {
// =====================
// Constructor functions
// =====================

/// # Constructor
///
/// Create new FastNoise object with the default seed of `1337`.
pub fn new() -> Self {
Self::default()
}

/// Create new FastNoise object with a specific seed.
pub fn with_seed(seed: i32) -> Self {
let mut fnl = Self::default();
fnl.set_seed(Some(seed));
pub const fn with_seed(seed: i32) -> Self {
let mut fnl = Self::new();
fnl.seed = seed;
fnl
}

Expand Down