@@ -34,13 +34,7 @@ fn compute_polygon_vertex(triple: &[BackendCoord; 3], d: f64, buf: &mut Vec<Back
34
34
f64:: from ( triple[ 1 ] . 1 ) + d * b_n. 1 ,
35
35
) ;
36
36
37
- // Check if 3 points are colinear. If so, just emit the point.
38
- if a_t. 1 * b_t. 0 == a_t. 0 * b_t. 1 {
39
- buf. push ( ( a_p. 0 as i32 , a_p. 1 as i32 ) ) ;
40
- return ;
41
- }
42
-
43
- // So we are actually computing the intersection of two lines:
37
+ // We want to compute the intersection of two lines:
44
38
// a_p + u * a_t and b_p + v * b_t.
45
39
// We can solve the following vector equation:
46
40
// u * a_t + a_p = v * b_t + b_p
@@ -61,30 +55,34 @@ fn compute_polygon_vertex(triple: &[BackendCoord; 3], d: f64, buf: &mut Vec<Back
61
55
let b1 = -b_t. 1 ;
62
56
let c1 = b_p. 1 - a_p. 1 ;
63
57
64
- let mut x = f64:: INFINITY ;
65
- let mut y = f64:: INFINITY ;
66
-
67
- // Well if the determinant is not 0, then we can actually get a intersection point.
68
- if ( a0 * b1 - a1 * b0) . abs ( ) > f64:: EPSILON {
69
- let u = ( c0 * b1 - c1 * b0) / ( a0 * b1 - a1 * b0) ;
70
-
71
- x = a_p. 0 + u * a_t. 0 ;
72
- y = a_p. 1 + u * a_t. 1 ;
58
+ // If the determinant is 0, then we cannot actuall get a intersection point.
59
+ // n that case, the two lines are parallel and we just emit the point a_p \approx b_p
60
+ if ( a0 * b1 - a1 * b0) . abs ( ) <= f64:: EPSILON {
61
+ buf. push ( ( a_p. 0 as i32 , a_p. 1 as i32 ) ) ;
62
+ return ;
73
63
}
74
-
75
- let cross_product = a_t. 0 * b_t. 1 - a_t. 1 * b_t. 0 ;
76
- if ( cross_product < 0.0 && d < 0.0 ) || ( cross_product > 0.0 && d > 0.0 ) {
77
- // Then we are at the outer side of the angle, so we need to consider a cap.
78
- let dist_square = ( x - triple[ 1 ] . 0 as f64 ) . powi ( 2 ) + ( y - triple[ 1 ] . 1 as f64 ) . powi ( 2 ) ;
79
- // If the point is too far away from the line, we need to cap it.
80
- if dist_square > d * d * 16.0 {
81
- buf. push ( ( a_p. 0 . round ( ) as i32 , a_p. 1 . round ( ) as i32 ) ) ;
82
- buf. push ( ( b_p. 0 . round ( ) as i32 , b_p. 1 . round ( ) as i32 ) ) ;
83
- return ;
64
+ else {
65
+ let u = ( c0 * b1 - c1 * b0) / ( a0 * b1 - a1 * b0) ;
66
+ let x = a_p. 0 + u * a_t. 0 ;
67
+ let y = a_p. 1 + u * a_t. 1 ;
68
+
69
+ let cross_product = a_t. 0 * b_t. 1 - a_t. 1 * b_t. 0 ;
70
+ if ( cross_product < 0.0 && d < 0.0 ) || ( cross_product > 0.0 && d > 0.0 ) {
71
+ // Then we are at the outter side of the angle, so we need to consider a cap.
72
+ let dist_square = ( x - triple[ 1 ] . 0 as f64 ) . powi ( 2 ) + ( y - triple[ 1 ] . 1 as f64 ) . powi ( 2 ) ;
73
+ // If the point is too far away from the line, we need to cap it.
74
+ if dist_square > d * d * 16.0 {
75
+ buf. push ( ( a_p. 0 . round ( ) as i32 , a_p. 1 . round ( ) as i32 ) ) ;
76
+ buf. push ( ( b_p. 0 . round ( ) as i32 , b_p. 1 . round ( ) as i32 ) ) ;
77
+ return ;
78
+ }
79
+ } else {
80
+ // We are at the inner side of the angle, so we just emit the point.
81
+ buf. push ( ( x. round ( ) as i32 , y. round ( ) as i32 ) ) ;
84
82
}
85
83
}
86
84
87
- buf . push ( ( x . round ( ) as i32 , y . round ( ) as i32 ) ) ;
85
+
88
86
}
89
87
90
88
fn traverse_vertices < ' a > (
0 commit comments