noise/core/
checkerboard.rs1use crate::math::vectors::{Vector2, Vector3, Vector4};
2
3#[inline(always)]
4pub fn checkerboard_2d(point: Vector2<f64>, grid_size: f64) -> f64 {
5 let floor = (point / grid_size).floor_to_isize();
6 if (floor.x & 1) ^ (floor.y & 1) == 0 {
7 -1.0
8 } else {
9 1.0
10 }
11}
12
13#[inline(always)]
14pub fn checkerboard_3d(point: Vector3<f64>, grid_size: f64) -> f64 {
15 let floor = (point / grid_size).floor_to_isize();
16 if (floor.x & 1) ^ (floor.y & 1) ^ (floor.z & 1) == 0 {
17 -1.0
18 } else {
19 1.0
20 }
21}
22
23#[inline(always)]
24pub fn checkerboard_4d(point: Vector4<f64>, grid_size: f64) -> f64 {
25 let floor = (point / grid_size).floor_to_isize();
26 if (floor.x & 1) ^ (floor.y & 1) ^ (floor.z & 1) ^ (floor.w & 1) == 0 {
27 -1.0
28 } else {
29 1.0
30 }
31}