14 lines
394 B
Rust
14 lines
394 B
Rust
use std::hash::{Hash, Hasher};
|
|
use crate::core::pbrt::Float;
|
|
use std::collections::hash_map::DefaultHasher;
|
|
|
|
const U32_TO_F32_SCALE: f32 = 1.0 / 4294967296.0;
|
|
|
|
pub fn hash_float<T: Hash>(args: T) -> Float {
|
|
let mut hasher = DefaultHasher::new();
|
|
args.hash(&mut hasher);
|
|
let hash_u64 = hasher.finish();
|
|
let hash_u32 = hash_u64 as u32;
|
|
(hash_u32 as f32) * U32_TO_F32_SCALE
|
|
}
|
|
|