Advertisement
kacejot

Untitled

Dec 28th, 2019
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.68 KB | None | 0 0
  1.     pub fn scale<U>(&self, target_min: U, target_max: U) -> HeightMap<U>
  2.     where
  3.         U: Num + std::cmp::PartialOrd + Copy + ToPrimitive + NumCast + std::fmt::Display,
  4.     {
  5.         let mut map = HeightMap::<U>::with_edge_size(self.edge_size());
  6.  
  7.         let (current_min, current_max) = self.min_max();
  8.  
  9.         let current_range = current_max - current_min;
  10.         let target_range = target_max - target_min;
  11.  
  12.         for (i, height) in self.buffer.iter().enumerate() {
  13.             map.buffer[i] = target_min
  14.                 + U::from((*height - current_min) / current_range * T::from(target_range).unwrap())
  15.                     .unwrap();
  16.         }
  17.  
  18.         map
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement