use rand::Rng;
use crate::materials::MatProps;
pub struct PropRange {
pub density: (f32, f32),
pub elastic_modulus: (f32, f32),
pub tensile_strength: (f32, f32),
pub compressive_strength: (f32, f32),
pub hardness: (f32, f32),
pub fracture_toughness: (f32, f32),
pub fatigue_resistance: (f32, f32),
pub thermal_conductivity: (f32, f32),
pub thermal_expansion: (f32, f32),
pub melting_point: (f32, f32),
pub corrosion_resistance: (f32, f32),
pub solubility: (f32, f32),
pub permeability: (f32, f32),
pub flammability: (f32, f32),
pub electrical_conductivity: (f32, f32),
pub magnetic_permeability: (f32, f32),
}
pub enum MatCategory {
Metal = 0x01,
SoftMetal = 0x02,
Alloy = 0x03,
Plastic = 0x04,
Rubber = 0x05,
Foam = 0x06,
Wood = 0x07,
Stone = 0x08,
Concrete = 0x09,
Ceramic = 0x0A,
Glass = 0x0B,
Liquid = 0x0C,
Gas = 0x0D,
Composite = 0x0E,
Fabric = 0x0F,
Paper = 0x10,
Organic = 0x11,
Ice = 0x12,
Soil = 0x13,
Nanomaterial = 0x14,
}
pub fn get_category_ranges(cat: u8) -> Option<PropRange> {
match cat {
0x01 => Some(PropRange { density: (2700.0, 8900.0),
elastic_modulus: (7e10, 2.1e11),
tensile_strength: (200.0, 2000.0),
compressive_strength: (300.0, 3000.0),
hardness: (3.0, 9.0),
fracture_toughness: (10.0, 150.0),
fatigue_resistance: (0.6, 1.0),
thermal_conductivity: (15.0, 400.0),
thermal_expansion: (1e-6, 2.5e-5),
melting_point: (600.0, 3400.0),
corrosion_resistance: (0.1, 0.9),
solubility: (0.0, 0.01),
permeability: (0.0, 0.1),
flammability: (0.0, 0.1),
electrical_conductivity: (1e6, 1e7),
magnetic_permeability: (1.0, 1000.0),
}),
0x02 => Some(PropRange { density: (5000.0, 15000.0),
elastic_modulus: (1e11, 2.5e11),
tensile_strength: (300.0, 2200.0),
compressive_strength: (500.0, 3500.0),
hardness: (4.0, 9.0),
fracture_toughness: (15.0, 200.0),
fatigue_resistance: (0.7, 1.0),
thermal_conductivity: (10.0, 250.0),
thermal_expansion: (5e-6, 2.0e-5),
melting_point: (800.0, 3200.0),
corrosion_resistance: (0.2, 0.95),
solubility: (0.0, 0.02),
permeability: (0.0, 0.2),
flammability: (0.0, 0.1),
electrical_conductivity: (1e5, 8e6),
magnetic_permeability: (1.0, 2000.0),
}),
0x03 => Some(PropRange { density: (2000.0, 6500.0),
elastic_modulus: (1e10, 4e11),
tensile_strength: (50.0, 500.0),
compressive_strength: (500.0, 5000.0),
hardness: (6.0, 9.0),
fracture_toughness: (2.0, 15.0),
fatigue_resistance: (0.1, 0.4),
thermal_conductivity: (1.0, 60.0),
thermal_expansion: (2e-6, 1.0e-5),
melting_point: (1000.0, 3000.0),
corrosion_resistance: (0.7, 1.0),
solubility: (0.0, 0.05),
permeability: (0.0, 0.1),
flammability: (0.0, 0.1),
electrical_conductivity: (0.0, 10.0),
magnetic_permeability: (0.0, 2.0),
}),
0x04 => Some(PropRange { density: (800.0, 2200.0),
elastic_modulus: (1e8, 1e10),
tensile_strength: (20.0, 100.0),
compressive_strength: (40.0, 300.0),
hardness: (1.0, 3.0),
fracture_toughness: (0.5, 5.0),
fatigue_resistance: (0.4, 0.8),
thermal_conductivity: (0.1, 0.5),
thermal_expansion: (5e-5, 2e-4),
melting_point: (100.0, 400.0),
corrosion_resistance: (0.7, 1.0),
solubility: (0.0, 0.5),
permeability: (0.1, 0.9),
flammability: (0.5, 1.0),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x05 => Some(PropRange { density: (10.0, 500.0),
elastic_modulus: (1e5, 1e8),
tensile_strength: (1.0, 20.0),
compressive_strength: (2.0, 50.0),
hardness: (0.1, 1.0),
fracture_toughness: (0.1, 2.0),
fatigue_resistance: (0.2, 0.6),
thermal_conductivity: (0.01, 0.2),
thermal_expansion: (2e-5, 2e-4),
melting_point: (50.0, 300.0),
corrosion_resistance: (0.5, 0.9),
solubility: (0.0, 0.8),
permeability: (0.5, 1.0),
flammability: (0.6, 1.0),
electrical_conductivity: (0.0, 0.1),
magnetic_permeability: (0.0, 1.0),
}),
0x06 => Some(PropRange { density: (2000.0, 6000.0),
elastic_modulus: (5e10, 9e10),
tensile_strength: (20.0, 300.0),
compressive_strength: (200.0, 1000.0),
hardness: (5.0, 7.0),
fracture_toughness: (0.5, 2.0),
fatigue_resistance: (0.1, 0.3),
thermal_conductivity: (0.8, 2.0),
thermal_expansion: (3e-6, 1e-5),
melting_point: (1000.0, 1600.0),
corrosion_resistance: (0.9, 1.0),
solubility: (0.0, 0.1),
permeability: (0.0, 0.1),
flammability: (0.0, 0.1),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x07 => Some(PropRange { density: (200.0, 1200.0),
elastic_modulus: (1e9, 2e10),
tensile_strength: (40.0, 150.0),
compressive_strength: (10.0, 80.0),
hardness: (2.0, 5.0),
fracture_toughness: (0.5, 5.0),
fatigue_resistance: (0.3, 0.7),
thermal_conductivity: (0.05, 0.3),
thermal_expansion: (1e-5, 5e-5),
melting_point: (200.0, 600.0),
corrosion_resistance: (0.2, 0.6),
solubility: (0.1, 0.5),
permeability: (0.3, 0.9),
flammability: (0.7, 1.0),
electrical_conductivity: (0.0, 0.5),
magnetic_permeability: (0.0, 1.0),
}),
0x08 => Some(PropRange { density: (2200.0, 3000.0),
elastic_modulus: (3e10, 7e10),
tensile_strength: (5.0, 25.0),
compressive_strength: (30.0, 300.0),
hardness: (4.0, 8.0),
fracture_toughness: (1.0, 5.0),
fatigue_resistance: (0.1, 0.4),
thermal_conductivity: (1.5, 5.0),
thermal_expansion: (4e-6, 1.2e-5),
melting_point: (800.0, 1800.0),
corrosion_resistance: (0.8, 1.0),
solubility: (0.0, 0.01),
permeability: (0.0, 0.2),
flammability: (0.0, 0.1),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x09 => Some(PropRange { density: (2200.0, 2600.0),
elastic_modulus: (2e10, 5e10),
tensile_strength: (2.0, 10.0),
compressive_strength: (20.0, 80.0),
hardness: (3.0, 6.0),
fracture_toughness: (0.2, 2.0),
fatigue_resistance: (0.2, 0.5),
thermal_conductivity: (0.8, 2.0),
thermal_expansion: (6e-6, 1.2e-5),
melting_point: (1000.0, 1600.0),
corrosion_resistance: (0.7, 0.95),
solubility: (0.0, 0.05),
permeability: (0.1, 0.5),
flammability: (0.0, 0.1),
electrical_conductivity: (0.0, 0.5),
magnetic_permeability: (0.0, 1.0),
}),
0x0A => Some(PropRange { density: (1200.0, 2000.0),
elastic_modulus: (5e9, 2e11),
tensile_strength: (200.0, 2500.0),
compressive_strength: (100.0, 1500.0),
hardness: (3.0, 7.0),
fracture_toughness: (5.0, 40.0),
fatigue_resistance: (0.5, 0.9),
thermal_conductivity: (0.1, 20.0),
thermal_expansion: (1e-6, 3e-5),
melting_point: (200.0, 1200.0),
corrosion_resistance: (0.5, 0.95),
solubility: (0.0, 0.1),
permeability: (0.0, 0.2),
flammability: (0.2, 0.8),
electrical_conductivity: (0.0, 1e6),
magnetic_permeability: (0.0, 10.0),
}),
0x0B => Some(PropRange { density: (900.0, 1300.0),
elastic_modulus: (1e6, 1e8),
tensile_strength: (5.0, 50.0),
compressive_strength: (2.0, 30.0),
hardness: (0.5, 3.0),
fracture_toughness: (1.0, 10.0),
fatigue_resistance: (0.6, 0.95),
thermal_conductivity: (0.1, 0.5),
thermal_expansion: (1e-4, 6e-4),
melting_point: (200.0, 600.0),
corrosion_resistance: (0.4, 0.8),
solubility: (0.1, 0.9),
permeability: (0.4, 1.0),
flammability: (0.6, 1.0),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x0C => Some(PropRange { density: (500.0, 2000.0),
elastic_modulus: (1e3, 1e6), tensile_strength: (0.0, 0.1),
compressive_strength: (0.0, 0.1),
hardness: (0.0, 0.1),
fracture_toughness: (0.0, 0.1),
fatigue_resistance: (0.0, 0.1),
thermal_conductivity: (0.05, 1.0),
thermal_expansion: (1e-4, 1e-3),
melting_point: (-200.0, 500.0),
corrosion_resistance: (0.0, 1.0),
solubility: (0.5, 1.0),
permeability: (1.0, 1.1),
flammability: (0.0, 1.0),
electrical_conductivity: (0.0, 1e4),
magnetic_permeability: (0.0, 1.0),
}),
0x0D => Some(PropRange { density: (0.1, 10.0),
elastic_modulus: (1e2, 1e6), tensile_strength: (0.0, 0.1),
compressive_strength: (0.0, 0.1),
hardness: (0.0, 0.1),
fracture_toughness: (0.0, 0.1),
fatigue_resistance: (0.0, 0.1),
thermal_conductivity: (0.01, 0.5),
thermal_expansion: (1e-3, 1e-2),
melting_point: (-270.0, 0.0),
corrosion_resistance: (0.0, 1.0),
solubility: (0.0, 1.0),
permeability: (1.0, 1.1),
flammability: (0.0, 1.0),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x0E => Some(PropRange { density: (1200.0, 2200.0),
elastic_modulus: (1e7, 1e9),
tensile_strength: (0.1, 5.0),
compressive_strength: (0.5, 50.0),
hardness: (0.5, 3.0),
fracture_toughness: (0.1, 2.0),
fatigue_resistance: (0.1, 0.3),
thermal_conductivity: (0.2, 2.0),
thermal_expansion: (1e-5, 5e-5),
melting_point: (0.0, 1200.0),
corrosion_resistance: (0.3, 0.8),
solubility: (0.0, 0.3),
permeability: (0.2, 0.9),
flammability: (0.0, 0.2),
electrical_conductivity: (0.0, 100.0),
magnetic_permeability: (0.0, 10.0),
}),
0x0F => Some(PropRange { density: (100.0, 1500.0),
elastic_modulus: (1e6, 1e9),
tensile_strength: (5.0, 100.0),
compressive_strength: (0.5, 20.0),
hardness: (0.5, 2.0),
fracture_toughness: (0.5, 5.0),
fatigue_resistance: (0.3, 0.8),
thermal_conductivity: (0.01, 0.2),
thermal_expansion: (5e-5, 5e-4),
melting_point: (100.0, 600.0),
corrosion_resistance: (0.4, 0.8),
solubility: (0.0, 0.6),
permeability: (0.5, 1.0),
flammability: (0.6, 1.0),
electrical_conductivity: (0.0, 1.0),
magnetic_permeability: (0.0, 1.0),
}),
0x10 => Some(PropRange { density: (900.0, 1200.0),
elastic_modulus: (1e5, 1e7),
tensile_strength: (1.0, 50.0),
compressive_strength: (0.5, 20.0),
hardness: (0.1, 2.0),
fracture_toughness: (0.2, 2.0),
fatigue_resistance: (0.3, 0.7),
thermal_conductivity: (0.2, 0.6),
thermal_expansion: (5e-5, 5e-4),
melting_point: (0.0, 100.0),
corrosion_resistance: (0.2, 0.7),
solubility: (0.5, 1.0),
permeability: (0.5, 1.0),
flammability: (0.5, 0.9),
electrical_conductivity: (0.0, 10.0),
magnetic_permeability: (0.0, 1.0),
}),
0x11 => Some(PropRange { density: (900.0, 1000.0),
elastic_modulus: (1e9, 1e10),
tensile_strength: (0.5, 3.0),
compressive_strength: (5.0, 25.0),
hardness: (1.0, 3.0),
fracture_toughness: (0.2, 1.5),
fatigue_resistance: (0.2, 0.5),
thermal_conductivity: (2.0, 5.0),
thermal_expansion: (5e-5, 1e-4),
melting_point: (-10.0, 0.0),
corrosion_resistance: (0.8, 1.0),
solubility: (0.0, 0.1),
permeability: (0.0, 0.2),
flammability: (0.0, 0.1),
electrical_conductivity: (0.0, 0.5),
magnetic_permeability: (0.0, 1.0),
}),
0x12 => Some(PropRange { density: (3000.0, 12000.0),
elastic_modulus: (1e11, 5e11),
tensile_strength: (500.0, 5000.0),
compressive_strength: (500.0, 8000.0),
hardness: (7.0, 10.0),
fracture_toughness: (20.0, 200.0),
fatigue_resistance: (0.7, 1.0),
thermal_conductivity: (10.0, 1000.0),
thermal_expansion: (0.0, 5e-6),
melting_point: (1000.0, 5000.0),
corrosion_resistance: (0.5, 1.0),
solubility: (0.0, 0.01),
permeability: (0.0, 0.1),
flammability: (0.0, 0.1),
electrical_conductivity: (1e6, 1e8),
magnetic_permeability: (0.0, 10000.0),
}),
_ => None,
}
}
pub fn generate_props_from_category(cat: u8, rng: &mut impl Rng) -> Option<MatProps> {
get_category_ranges(cat).map(|r| MatProps {
density: rng.random_range(r.density.0..r.density.1),
elastic_modulus: rng.random_range(r.elastic_modulus.0..r.elastic_modulus.1),
tensile_strength: rng.random_range(r.tensile_strength.0..r.tensile_strength.1),
compressive_strength: rng.random_range(r.compressive_strength.0..r.compressive_strength.1),
hardness: rng.random_range(r.hardness.0..r.hardness.1),
fracture_toughness: rng.random_range(r.fracture_toughness.0..r.fracture_toughness.1),
fatigue_resistance: rng.random_range(r.fatigue_resistance.0..r.fatigue_resistance.1),
thermal_conductivity: rng.random_range(r.thermal_conductivity.0..r.thermal_conductivity.1),
thermal_expansion: rng.random_range(r.thermal_expansion.0..r.thermal_expansion.1),
melting_point: rng.random_range(r.melting_point.0..r.melting_point.1),
corrosion_resistance: rng.random_range(r.corrosion_resistance.0..r.corrosion_resistance.1),
solubility: rng.random_range(r.solubility.0..r.solubility.1),
permeability: rng.random_range(r.permeability.0..r.permeability.1),
flammability: rng.random_range(r.flammability.0..r.flammability.1),
electrical_conductivity: rng.random_range(r.electrical_conductivity.0..r.electrical_conductivity.1),
magnetic_permeability: rng.random_range(r.magnetic_permeability.0..r.magnetic_permeability.1),
})
}