Skip to content

Commit 86c07b2

Browse files
committed
Remove floating point operations for is_inside_primitive.
1 parent 8ca8130 commit 86c07b2

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/geometrify.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,9 @@ impl Triangle {
6262

6363
impl Primitive for Triangle {
6464
fn is_inside_primitive(&self, p: Point) -> bool {
65-
let span_a = Point {
66-
x: self.b.x - self.a.x,
67-
y: self.b.y - self.a.y,
68-
};
69-
let span_b = Point {
70-
x: self.c.x - self.a.x,
71-
y: self.c.y - self.a.y,
72-
};
73-
74-
let q = Point {
75-
x: p.x - self.a.x,
76-
y: p.y - self.a.y,
77-
};
78-
79-
let s = q.cross_product(span_b) as f32 * self.span_div();
80-
let t = span_a.cross_product(q) as f32 * self.span_div();
81-
82-
(s >= 0.0) && (t >= 0.0) && ((s + t) <= 1.0)
65+
return (self.a.x - self.b.x) * (p.y - self.a.y) - (self.a.y - self.b.y) * (p.x - self.a.x) > 0 &&
66+
(self.b.x - self.c.x) * (p.y - self.b.y) - (self.b.y - self.c.y) * (p.x - self.b.x) > 0 &&
67+
(self.c.x - self.a.x) * (p.y - self.c.y) - (self.c.y - self.a.y) * (p.x - self.c.x) > 0;
8368
}
8469

8570
fn bounding_box(&self) -> BoundingBox {

0 commit comments

Comments
 (0)