1use vek::*;
2
3use crate::util::{RandomField, Sampler};
4
5#[derive(Copy, Clone, Debug, Default)]
6pub struct Way {
7 pub offset: Vec2<i8>,
9 pub neighbors: u8,
11}
12
13impl Way {
14 pub fn is_way(&self) -> bool { self.neighbors != 0 }
15
16 pub fn clear(&mut self) { self.neighbors = 0; }
17}
18
19#[derive(Copy, Clone, Debug, PartialEq)]
20pub struct Path {
21 pub width: f32, }
23
24impl Default for Path {
25 fn default() -> Self { Self { width: 5.0 } }
26}
27
28impl Lerp for Path {
29 type Output = Self;
30
31 fn lerp_unclamped(from: Self, to: Self, factor: f32) -> Self::Output {
32 Self {
33 width: Lerp::lerp(from.width, to.width, factor),
34 }
35 }
36}
37pub fn noisy_color(color: Rgb<u8>, factor: u32, wpos: Vec3<i32>) -> Rgb<u8> {
38 let nz = RandomField::new(0).get(wpos);
39 color.map(|e| {
40 (e as u32 + nz % (factor * 2))
41 .saturating_sub(factor)
42 .min(255) as u8
43 })
44}
45
46impl Path {
47 pub fn head_space(&self, dist: f32) -> i32 { (8 - (dist * 0.25).powi(6).round() as i32).max(1) }
51
52 pub fn surface_color(&self, col: Rgb<u8>, wpos: Vec3<i32>) -> Rgb<u8> {
54 noisy_color(col.map(|e| (e as f32 * 0.7) as u8), 8, wpos)
55 }
56}