rust/land2d/src/lib.rs
changeset 13936 78c798d655ad
parent 13934 9c112f2ae02d
child 13938 1fa905aa4cdb
equal deleted inserted replaced
13935:75eaf7c71789 13936:78c798d655ad
       
     1 extern crate integral_geometry;
     1 extern crate vec2d;
     2 extern crate vec2d;
     2 
     3 
     3 use std::cmp;
     4 use std::cmp;
     4 use std::ops;
     5 use std::ops;
     5 
     6 
   144 
   145 
   145         result
   146         result
   146     }
   147     }
   147 
   148 
   148     pub fn draw_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, value: T) -> usize {
   149     pub fn draw_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, value: T) -> usize {
   149         <Land2D<T>>::apply_along_line(x1, y1, x2, y2, &mut |x, y| {
   150         integral_geometry::LinePoints::new(x1, y1, x2, y2)
   150             self.map(y, x, |p| *p = value);
   151             .filter_map(|(x, y)| {
   151             1
   152                 self.map(y, x, |p| {
   152         })
   153                     *p = value;
       
   154                     Some(1)
       
   155                 })
       
   156             }).count()
   153     }
   157     }
   154 
   158 
   155     pub fn fill(&mut self, start_x: i32, start_y: i32, border_value: T, fill_value: T) {
   159     pub fn fill(&mut self, start_x: i32, start_y: i32, border_value: T, fill_value: T) {
   156         debug_assert!(self.is_valid_coordinate(start_x - 1, start_y));
   160         debug_assert!(self.is_valid_coordinate(start_x - 1, start_y));
   157         debug_assert!(self.is_valid_coordinate(start_x, start_y));
   161         debug_assert!(self.is_valid_coordinate(start_x, start_y));