let s = (-s1.y * (p1.x - p3.x) + s1.x * (p1.y - p3.y)) / denomimator;
let t = ( s2.x * (p1.y - p3.y) - s2.y * (p1.x - p3.x)) / denomimator;
- if s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0 {
+ if (0.0..=1.0).contains(&s) && (0.0..=1.0).contains(&t) {
return Intersection::Point(p1 + (s1 * t))
}
}
if d.y > 0 { 1 } else { -1 }
);
- let mut p = p1.clone();
+ let mut p = p1;
let mut points = vec!(point!(p.x as isize, p.y as isize));
let mut i = point!(0, 0);
while i.x < n.x || i.y < n.y {
// if let Some(s) = self.states.last_mut() {
// s.pause();
// }
- state.enter(&mut self.ctrl_man);
+ state.enter(&self.ctrl_man);
self.states.push(state);
}
StateChange::Pop => {
fn render(&mut self) {
self.renderer.clear();
- self.states.last_mut().unwrap().render(&mut self.renderer, &mut self.sprites);
+ self.states.last_mut().unwrap().render(&mut self.renderer, &self.sprites);
self.renderer.present();
}
}
println!(" {} iterations needed", count);
}
- fn neighbours(&self, grid: &Vec<Vec<bool>>, px: usize, py: usize, distance: usize) -> u8 {
+ fn neighbours(&self, grid: &[Vec<bool>], px: usize, py: usize, distance: usize) -> u8 {
let mut count = 0;
for x in (px - distance)..=(px + distance) {
for y in (py - distance)..=(py + distance) {
}
#[allow(dead_code)]
- fn print_grid(&self, grid: &Vec<Vec<bool>>) {
+ fn print_grid(&self, grid: &[Vec<bool>]) {
let w = grid.len();
let h = grid[0].len();
let mut g = vec!(vec!(false; w); h);
grid
}
- fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &Vec<Vec<bool>>) -> Point<isize> {
+ fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &[Vec<bool>]) -> Point<isize> {
let (ox, oy, w, h) = rect;
let is_outer_wall = (ox, oy) == (&0, &0); // we know this is always the outer wall of the level
for x in 0..*w {
panic!("no wall found!");
}
- fn find_next_point_of_outline(&self, grid: &Vec<Vec<bool>>, p: &mut Point<isize>, directions: &mut Vec<(isize, isize)>) {
+ fn find_next_point_of_outline(&self, grid: &[Vec<bool>], p: &mut Point<isize>, directions: &mut Vec<(isize, isize)>) {
directions.rotate_left(2);
loop {
let d = directions[0];
}
}
- fn check(&self, p: Point<isize>, grid: &Vec<Vec<bool>>) -> bool {
+ fn check(&self, p: Point<isize>, grid: &[Vec<bool>]) -> bool {
if p.x < 0 || p.x >= grid.len() as isize || p.y < 0 || p.y >= grid[0].len() as isize {
false
} else {
fn leave(&mut self) {
}
- fn handle_event(&mut self, _event: Event) -> Option<StateChange> {
- match _event {
- Event::MouseMotion { x, y, .. } => self.mouse = point!(x, y),
- _ => {}
+ fn handle_event(&mut self, event: Event) -> Option<StateChange> {
+ if let Event::MouseMotion { x, y, .. } = event {
+ self.mouse = point!(x, y);
}
None
}