1#![no_std]
51#![cfg_attr(
52 feature = "document-features",
53 cfg_attr(doc, doc = ::document_features::document_features!())
54)]
55#![cfg_attr(feature = "nightly-simd", feature(portable_simd))]
56#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg_hide), doc(cfg_hide(no_global_oom_handling, feature = "nightly-const-fn-float")))]
57#![allow(clippy::excessive_precision, clippy::needless_late_init, clippy::too_many_arguments, clippy::approx_constant)]
58
59#[cfg(any(feature = "std", test))]
60extern crate std;
61
62#[cfg(feature = "alloc")]
63extern crate alloc;
64
65#[cfg(all(not(feature = "std"), not(feature = "libm")))]
66compile_error!(r#"`noise-functions` crate: either the "std" or "libm" feature must be enabled"#);
67
68mod base;
69mod cellular;
70mod constant;
71mod from_fast_noise_2;
72mod from_fast_noise_lite;
73mod from_open_simplex_2;
74mod lookup_table;
75mod math;
76pub mod modifiers;
78mod noise;
79mod noise_fn;
80mod open_simplex_2;
81mod sample;
82#[cfg(test)]
83mod tests;
84mod value_or_noise;
85
86pub use base::{CellDistance, CellDistanceSq, CellValue, OpenSimplex2, OpenSimplex2s, Perlin, Simplex, Value, ValueCubic};
87pub use constant::Constant;
88pub use noise::Noise;
89pub use noise_fn::NoiseFn;
90pub use open_simplex_2::OpenSimplexNoise;
91pub use sample::Sample;
92pub use value_or_noise::ValueOrNoise;
93
94#[inline(always)]
95#[cfg(feature = "nightly-simd")]
96fn array_4_take_3<T>(array: &[T; 4]) -> &[T; 3] {
97 array[..3].try_into().unwrap()
98}
99
100macro_rules! simple_enum {
101 (
102 enum $name:ident {
103 $(
104 $(#[$variant_attr:meta])*
105 $variant:ident $(= $variant_expr:expr)?
106 ),* $(,)?
107 }
108 ) => {
109 #[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
110 pub enum $name {
111 $(
112 $(#[$variant_attr])*
113 $variant $(= $variant_expr)?,
114 )*
115 }
116
117 impl core::str::FromStr for $name {
118 type Err = $crate::errors::EnumFromStrError;
119
120 fn from_str(s: &str) -> Result<Self, Self::Err> {
121 Ok(match s {
122 $(stringify!($variant) => Self::$variant,)*
123 _ => return Err($crate::errors::EnumFromStrError),
124 })
125 }
126 }
127
128 impl $name {
129 #[expect(dead_code)]
130 pub const VARIANTS: &'static [Self] = &[
131 $(Self::$variant,)*
132 ];
133
134 pub fn to_str(self) -> &'static str {
135 [$(stringify!($variant)),*][self as usize]
136 }
137 }
138
139 impl core::fmt::Debug for $name {
140 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
141 f.write_str(self.to_str())
142 }
143 }
144
145 impl core::fmt::Display for $name {
146 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
147 f.write_str(self.to_str())
148 }
149 }
150 };
151}
152
153pub(crate) use simple_enum;
154
155pub mod errors {
157 #[derive(Debug, Clone, Copy)]
158 pub struct EnumFromStrError;
159
160 impl core::fmt::Display for EnumFromStrError {
161 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
162 f.write_str("can't convert string to enum")
163 }
164 }
165}