Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn scale<U>(&self, target_min: U, target_max: U) -> HeightMap<U>
- where
- U: Num + std::cmp::PartialOrd + Copy + ToPrimitive + NumCast + std::fmt::Display,
- {
- let mut map = HeightMap::<U>::with_edge_size(self.edge_size());
- let (current_min, current_max) = self.min_max();
- let current_range = current_max - current_min;
- let target_range = target_max - target_min;
- for (i, height) in self.buffer.iter().enumerate() {
- map.buffer[i] = target_min
- + U::from((*height - current_min) / current_range * T::from(target_range).unwrap())
- .unwrap();
- }
- map
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement