Skip to content

Commit

Permalink
Change Checkerboard to take a size with ::new()
Browse files Browse the repository at this point in the history
::default() keeps the original size.
  • Loading branch information
Razaekel committed Jul 21, 2020
1 parent 9cff996 commit 8744b15
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate noise;
use noise::{utils::*, Cache, Checkerboard};

fn main() {
let cboard = Checkerboard::new();
let cboard = Checkerboard::default();
let cache = Cache::new(&cboard);

PlaneMapBuilder::new(&cache)
Expand Down
2 changes: 1 addition & 1 deletion examples/checkerboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate noise;
use noise::{utils::*, Checkerboard};

fn main() {
let checker = Checkerboard::new();
let checker = Checkerboard::default();

PlaneMapBuilder::new(&checker)
.build()
Expand Down
2 changes: 1 addition & 1 deletion examples/displace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate noise;
use noise::{utils::*, Checkerboard, Constant, Cylinders, Displace, Perlin};

fn main() {
let cboard = Checkerboard::new();
let cboard = Checkerboard::default();
let constant = Constant::new(0.0);
let cylinders = Cylinders::new();
let perlin = Perlin::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/scale_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate noise;
use noise::{utils::*, Checkerboard, ScalePoint};

fn main() {
let cboard = Checkerboard::new();
let cboard = Checkerboard::default();
let scale_point = ScalePoint::new(cboard).set_all_scales(1.0, 2.0, 3.0, 1.0);

PlaneMapBuilder::new(&scale_point)
Expand Down
2 changes: 1 addition & 1 deletion examples/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate noise;
use noise::{utils::*, Checkerboard, Constant, Cylinders, Perlin, Select};

fn main() {
let checkerboard = &Checkerboard::new();
let checkerboard = &Checkerboard::default();
let cylinders = &Cylinders::new();
let perlin = &Perlin::new();
let constant = &Constant::new(0.5);
Expand Down
2 changes: 1 addition & 1 deletion examples/translate_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate noise;
use noise::{utils::*, Checkerboard, TranslatePoint};

fn main() {
let cboard = Checkerboard::new();
let cboard = Checkerboard::default();
let translate_point = TranslatePoint::new(cboard).set_all_translations(0.5, 0.5, 0.0, 0.0);

PlaneMapBuilder::new(&translate_point)
Expand Down
18 changes: 10 additions & 8 deletions src/noise_fns/generators/checkerboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ pub struct Checkerboard {
impl Checkerboard {
const DEFAULT_SIZE: usize = 0;

pub fn new() -> Self {
Self {
size: 1 << Self::DEFAULT_SIZE,
}
pub fn new(size: usize) -> Self {
Self { size: 1 << size }
}

pub fn set_size(self, size: usize) -> Self {
Self {
size: 1 << size,
}
Self { size: 1 << size }
}

pub fn size(&self) -> usize {
self.size
}
}

impl Default for Checkerboard {
fn default() -> Self {
Self::new()
Self {
size: 1 << Checkerboard::DEFAULT_SIZE,
}
}
}

Expand Down

0 comments on commit 8744b15

Please sign in to comment.