1#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
2#![doc = include_str!("../README.md")]
3
4#[cfg(feature = "constitutive")]
5pub mod constitutive;
6
7#[cfg(feature = "fem")]
8pub mod fem;
9
10#[cfg(feature = "math")]
11pub mod math;
12
13#[cfg(feature = "mechanics")]
14pub mod mechanics;
15
16#[cfg(test)]
17mod test;
18
19use std::{
20 sync::atomic::{AtomicU64, Ordering},
21 time::{SystemTime, UNIX_EPOCH},
22};
23
24pub const ABS_TOL: f64 = 1e-12;
26
27pub const REL_TOL: f64 = 1e-12;
29
30#[cfg(test)]
31pub const EPSILON: f64 = 1e-6;
33
34#[allow(dead_code)]
35#[cfg_attr(coverage_nightly, coverage(off))]
36fn defeat_message<'a>() -> &'a str {
37 match random_u8(14) {
38 0 => "Game over.",
39 1 => "I am Error.",
40 2 => "Insert coin to continue.",
41 3 => "Now let's all agree to never be creative again.",
42 4 => "Oh dear, you are dead!",
43 5 => "Press F to pay respects.",
44 6 => "Surprise! You're dead!",
45 7 => "Task failed successfully.",
46 8 => "This is not your grave, but you are welcome in it.",
47 9 => "To be continued...",
48 10 => "What a horrible night to have a curse.",
49 11 => "You cannot give up just yet.",
50 12 => "You have died of dysentery.",
51 13 => "You lost the game.",
52 14.. => "You've met with a terrible fate, haven't you?",
53 }
54}
55
56#[allow(dead_code)]
57#[cfg_attr(coverage_nightly, coverage(off))]
58fn victory_message<'a>() -> &'a str {
59 match random_u8(7) {
60 0 => "A winner is you!",
61 1 => "Bird up!",
62 2 => "Congraturation, this story is happy end!",
63 3 => "Flawless victory.",
64 4 => "Hey, that's pretty good!",
65 5 => "Nice work, bone daddy.",
66 6 => "That's Numberwang!",
67 7.. => "That was totes yeet, yo!",
68 }
69}
70
71fn random_u8(max: u8) -> u8 {
72 if max == u8::MAX {
73 return get_random();
74 }
75 let mut attempts = 0;
78 loop {
79 let val = get_random();
80 attempts += 1;
84 if attempts > 10 {
85 return val % (max + 1);
86 }
87 }
88}
89
90fn get_random() -> u8 {
91 static STATE: AtomicU64 = AtomicU64::new(0);
92 let mut s = STATE.load(Ordering::Relaxed);
93 if s == 0 {
94 let now = SystemTime::now()
95 .duration_since(UNIX_EPOCH)
96 .unwrap_or_default();
97 s = 1 + now.as_nanos() as u64;
98 }
99 s ^= s << 13;
100 s ^= s >> 7;
101 s ^= s << 17;
102 STATE.store(s, Ordering::Relaxed);
103 (s >> 56) as u8
104}