1use qualia_core_db::q42::m64_matter::{Q42ConstituentLutEntry, BANK_1_PAGED_COUNT};
7
8#[derive(Debug, Clone, PartialEq)]
10pub struct GeologicUnitRecord {
11 pub unit_code: String,
13 pub lithology: String,
15 pub stratigraphic_age_ma: f64,
17 pub lut_index: u8,
19}
20
21#[derive(Debug, Clone)]
23pub struct GeologicVectorLayer {
24 pub units: Vec<GeologicUnitRecord>,
25}
26
27impl Default for GeologicVectorLayer {
28 fn default() -> Self {
29 Self::new_snowy_monaro_baseline()
30 }
31}
32
33impl GeologicVectorLayer {
34 pub fn new_snowy_monaro_baseline() -> Self {
36 let units = vec![
37 GeologicUnitRecord {
38 unit_code: "Jmb".to_string(), lithology: "Basalt".to_string(),
40 stratigraphic_age_ma: 45.0,
41 lut_index: 128,
42 },
43 GeologicUnitRecord {
44 unit_code: "Gda".to_string(), lithology: "Granite".to_string(),
46 stratigraphic_age_ma: 410.0,
47 lut_index: 129,
48 },
49 GeologicUnitRecord {
50 unit_code: "Skt".to_string(), lithology: "Siltstone".to_string(),
52 stratigraphic_age_ma: 425.0,
53 lut_index: 130,
54 },
55 GeologicUnitRecord {
56 unit_code: "Qa".to_string(), lithology: "Gravel".to_string(),
58 stratigraphic_age_ma: 0.1,
59 lut_index: 131,
60 },
61 ];
62 Self { units }
63 }
64
65 pub fn resolve_unit_to_lut_index(&self, unit_code: &str) -> Option<u8> {
67 self.units
68 .iter()
69 .find(|u| u.unit_code.eq_ignore_ascii_case(unit_code))
70 .map(|u| u.lut_index)
71 }
72
73 pub fn compile_bank_1_recipes(&self) -> [Q42ConstituentLutEntry; BANK_1_PAGED_COUNT] {
75 let mut recipes = [Q42ConstituentLutEntry::default(); BANK_1_PAGED_COUNT];
76
77 for unit in &self.units {
78 let offset = (unit.lut_index as usize).saturating_sub(128);
79 if offset < BANK_1_PAGED_COUNT {
80 match unit.lithology.as_str() {
81 "Basalt" => {
82 recipes[offset].bulk_density_kg_m3 = 2850;
83 recipes[offset].friction_angle_deg = 44;
84 recipes[offset].cohesion_kpa = 1100;
85 recipes[offset].refractive_index_x100 = 164;
86 }
87 "Granite" => {
88 recipes[offset].bulk_density_kg_m3 = 2680;
89 recipes[offset].friction_angle_deg = 50;
90 recipes[offset].cohesion_kpa = 4500;
91 recipes[offset].refractive_index_x100 = 155;
92 }
93 "Siltstone" => {
94 recipes[offset].bulk_density_kg_m3 = 2400;
95 recipes[offset].friction_angle_deg = 30;
96 recipes[offset].cohesion_kpa = 180;
97 recipes[offset].refractive_index_x100 = 158;
98 }
99 _ => {}
100 }
101 }
102 }
103
104 for recipe in recipes.iter_mut() {
105 recipe.update_crc();
106 }
107
108 recipes
109 }
110}