File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -62,9 +62,24 @@ impl Triangle {
62
62
63
63
impl Primitive for Triangle {
64
64
fn is_inside_primitive ( & self , p : Point ) -> bool {
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 ;
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 )
68
83
}
69
84
70
85
fn bounding_box ( & self ) -> BoundingBox {
You can’t perform that action at this time.
0 commit comments