rust/landgen/src/outline_template_based/outline.rs
branchtransitional_engine
changeset 16032 31cc1e450273
parent 16029 9cbd18220eb7
child 16035 0caa3dfb3ba2
equal deleted inserted replaced
16031:1b1d5729ff3e 16032:31cc1e450273
     9 pub struct OutlinePoints {
     9 pub struct OutlinePoints {
    10     pub islands: Vec<Polygon>,
    10     pub islands: Vec<Polygon>,
    11     pub fill_points: Vec<Point>,
    11     pub fill_points: Vec<Point>,
    12     pub size: Size,
    12     pub size: Size,
    13     pub play_box: Rect,
    13     pub play_box: Rect,
    14     intersections_box: Rect,
    14     pub intersections_box: Rect,
    15 }
    15 }
    16 
    16 
    17 impl OutlinePoints {
    17 impl OutlinePoints {
    18     pub fn from_outline_template<I: Iterator<Item = u32>>(
    18     pub fn from_outline_template<I: Iterator<Item = u32>>(
    19         outline_template: &OutlineTemplate,
    19         outline_template: &OutlineTemplate,
    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         distortion_limiting_factor: u32,
    69         random_numbers: &mut I,
    69         random_numbers: &mut I,
    70     ) -> Option<Point> {
    70     ) -> Option<Point> {
    71         #[inline]
    71         #[inline]
    72         fn intersects(ray: &Ray, edge: &Line) -> bool {
    72         fn intersects(ray: &Ray, edge: &Line) -> bool {
    73             ray.orientation(edge.start) != ray.orientation(edge.end)
    73             ray.orientation(edge.start) != ray.orientation(edge.end)
   224                     }
   224                     }
   225                 }
   225                 }
   226             }
   226             }
   227         }
   227         }
   228 
   228 
   229         let max_dist = normal_len * 128 / distance_limiting_factor;
   229         let max_dist = normal_len * 128 / distortion_limiting_factor;
   230         dist_left = min(dist_left, max_dist);
   230         dist_left = min(dist_left, max_dist);
   231         dist_right = min(dist_right, max_dist);
   231         dist_right = min(dist_right, max_dist);
   232 
   232 
   233         if dist_right + dist_left < min_distance as u32 * 2 + 10 {
   233         if dist_right + dist_left < min_distance as u32 * 2 + 10 {
   234             // limits are too narrow, just divide
   234             // limits are too narrow, just divide
   245     }
   245     }
   246 
   246 
   247     fn divide_edges<I: Iterator<Item = u32>>(
   247     fn divide_edges<I: Iterator<Item = u32>>(
   248         &mut self,
   248         &mut self,
   249         distance_divisor: u32,
   249         distance_divisor: u32,
   250         distance_limiting_factor: u32,
   250         distortion_limiting_factor: u32,
   251         random_numbers: &mut I,
   251         random_numbers: &mut I,
   252     ) {
   252     ) {
   253         for is in 0..self.islands.len() {
   253         for is in 0..self.islands.len() {
   254             let mut i = 0;
   254             let mut i = 0;
   255             while i < self.islands[is].edges_count() {
   255             while i < self.islands[is].edges_count() {
   256                 let segment = self.islands[is].get_edge(i);
   256                 let segment = self.islands[is].get_edge(i);
   257                 if let Some(new_point) = self.divide_edge(
   257                 if let Some(new_point) = self.divide_edge(
   258                     segment,
   258                     segment,
   259                     distance_divisor,
   259                     distance_divisor,
   260                     distance_limiting_factor,
   260                     distortion_limiting_factor,
   261                     random_numbers,
   261                     random_numbers,
   262                 ) {
   262                 ) {
   263                     self.islands[is].split_edge(i, new_point);
   263                     self.islands[is].split_edge(i, new_point);
   264                     i += 2;
   264                     i += 2;
   265                 } else {
   265                 } else {
   278     pub fn distort<I: Iterator<Item = u32>>(
   278     pub fn distort<I: Iterator<Item = u32>>(
   279         &mut self,
   279         &mut self,
   280         distance_divisor: u32,
   280         distance_divisor: u32,
   281         random_numbers: &mut I,
   281         random_numbers: &mut I,
   282     ) {
   282     ) {
   283         let distance_limiting_factor = 100 + random_numbers.next().unwrap() as u32 % 8 * 10;
   283         let distortion_limiting_factor = 100 + random_numbers.next().unwrap() as u32 % 8 * 10;
   284 
   284 
   285         loop {
   285         loop {
   286             let old_len = self.total_len();
   286             let old_len = self.total_len();
   287             self.divide_edges(distance_divisor, distance_limiting_factor, random_numbers);
   287             self.divide_edges(distance_divisor, distortion_limiting_factor, random_numbers);
   288 
   288 
   289             if self.total_len() == old_len {
   289             if self.total_len() == old_len {
   290                 break;
   290                 break;
   291             }
   291             }
   292         }
   292         }