rust/landgen/src/outline_template_based/outline.rs
branchtransitional_engine
changeset 16028 509ecce37522
parent 15926 c273908218f3
child 16029 9cbd18220eb7
equal deleted inserted replaced
16027:d4675c190fa5 16028:509ecce37522
    63 
    63 
    64     fn divide_edge<I: Iterator<Item = u32>>(
    64     fn divide_edge<I: Iterator<Item = u32>>(
    65         &self,
    65         &self,
    66         segment: Line,
    66         segment: Line,
    67         distance_divisor: u32,
    67         distance_divisor: u32,
       
    68         distance_limiting_factor: u32,
    68         random_numbers: &mut I,
    69         random_numbers: &mut I,
    69     ) -> Option<Point> {
    70     ) -> Option<Point> {
    70         #[inline]
    71         #[inline]
    71         fn intersects(ray: &Ray, edge: &Line) -> bool {
    72         fn intersects(ray: &Ray, edge: &Line) -> bool {
    72             ray.orientation(edge.start) != ray.orientation(edge.end)
    73             ray.orientation(edge.start) != ray.orientation(edge.end)
   115             } else {
   116             } else {
   116                 None
   117                 None
   117             }
   118             }
   118         }
   119         }
   119 
   120 
   120         let min_distance = 40;
   121         let min_distance = distance_divisor as i32;
   121         // new point should fall inside this box
   122         // new point should fall inside this box
   122         let map_box = self.play_box.with_margin(min_distance);
   123         let map_box = self.play_box.with_margin(min_distance);
   123 
   124 
   124         let normal = segment.scaled_normal();
   125         let normal = segment.scaled_normal();
   125         let normal_len = normal.integral_norm();
   126         let normal_len = normal.integral_norm();
   223                     }
   224                     }
   224                 }
   225                 }
   225             }
   226             }
   226         }
   227         }
   227 
   228 
   228         let max_dist = normal_len * 100 / distance_divisor;
   229         let max_dist = normal_len * 128 / distance_limiting_factor;
   229         dist_left = min(dist_left, max_dist);
   230         dist_left = min(dist_left, max_dist);
   230         dist_right = min(dist_right, max_dist);
   231         dist_right = min(dist_right, max_dist);
   231 
   232 
   232         if dist_right + dist_left < min_distance as u32 * 2 + 10 {
   233         if dist_right + dist_left < min_distance as u32 * 2 + 10 {
   233             // limits are too narrow, just divide
   234             // limits are too narrow, just divide
   244     }
   245     }
   245 
   246 
   246     fn divide_edges<I: Iterator<Item = u32>>(
   247     fn divide_edges<I: Iterator<Item = u32>>(
   247         &mut self,
   248         &mut self,
   248         distance_divisor: u32,
   249         distance_divisor: u32,
       
   250         distance_limiting_factor: u32,
   249         random_numbers: &mut I,
   251         random_numbers: &mut I,
   250     ) {
   252     ) {
   251         for is in 0..self.islands.len() {
   253         for is in 0..self.islands.len() {
   252             let mut i = 0;
   254             let mut i = 0;
   253             while i < self.islands[is].edges_count() {
   255             while i < self.islands[is].edges_count() {
   254                 let segment = self.islands[is].get_edge(i);
   256                 let segment = self.islands[is].get_edge(i);
   255                 if let Some(new_point) = self.divide_edge(segment, distance_divisor, random_numbers)
   257                 if let Some(new_point) = self.divide_edge(segment, distance_divisor, distance_limiting_factor, random_numbers)
   256                 {
   258                 {
   257                     self.islands[is].split_edge(i, new_point);
   259                     self.islands[is].split_edge(i, new_point);
   258                     i += 2;
   260                     i += 2;
   259                 } else {
   261                 } else {
   260                     i += 1;
   262                     i += 1;
   272     pub fn distort<I: Iterator<Item = u32>>(
   274     pub fn distort<I: Iterator<Item = u32>>(
   273         &mut self,
   275         &mut self,
   274         distance_divisor: u32,
   276         distance_divisor: u32,
   275         random_numbers: &mut I,
   277         random_numbers: &mut I,
   276     ) {
   278     ) {
       
   279         let distance_limiting_factor = 100 + random_numbers.next().unwrap() as u32 % 8 * 10;
       
   280 
   277         loop {
   281         loop {
   278             let old_len = self.total_len();
   282             let old_len = self.total_len();
   279             self.divide_edges(distance_divisor, random_numbers);
   283             self.divide_edges(distance_divisor, distance_limiting_factor, random_numbers);
   280 
   284 
   281             if self.total_len() == old_len {
   285             if self.total_len() == old_len {
   282                 break;
   286                 break;
   283             }
   287             }
   284         }
   288         }