Advertisement
YorKnEz

Untitled

Jan 17th, 2024
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.72 KB | None | 0 0
  1. pub fn inside(&self, x: u32, y: u32) -> bool {
  2.         let p = Vector2f::new(x as f32, y as f32);
  3.  
  4.         !self.under_slope(p, self.points[5], self.points[0])
  5.             && !self.under_slope(p, self.points[0], self.points[1])
  6.             && self.under_slope(p, self.points[2], self.points[3])
  7.             && self.under_slope(p, self.points[3], self.points[4])
  8.             && self.points[5].x <= p.x
  9.             && p.x <= self.points[1].x
  10.     }
  11.  
  12.     fn under_slope(&self, p: Vector2f, a: Vector2f, b: Vector2f) -> bool {
  13.         // ignore verticals
  14.         if a.x == b.x {
  15.             return false;
  16.         }
  17.  
  18.         let g = (a.y - b.y) / (a.x - b.x);
  19.         let y = g * (p.x - a.x) + a.y;
  20.  
  21.         p.y < y
  22.     }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement