Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn inside(&self, x: u32, y: u32) -> bool {
- let p = Vector2f::new(x as f32, y as f32);
- !self.under_slope(p, self.points[5], self.points[0])
- && !self.under_slope(p, self.points[0], self.points[1])
- && self.under_slope(p, self.points[2], self.points[3])
- && self.under_slope(p, self.points[3], self.points[4])
- && self.points[5].x <= p.x
- && p.x <= self.points[1].x
- }
- fn under_slope(&self, p: Vector2f, a: Vector2f, b: Vector2f) -> bool {
- // ignore verticals
- if a.x == b.x {
- return false;
- }
- let g = (a.y - b.y) / (a.x - b.x);
- let y = g * (p.x - a.x) + a.y;
- p.y < y
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement