@@ -14,13 +14,23 @@ fn get_dir_vector(from: BackendCoord, to: BackendCoord, flag: bool) -> ((f64, f6
14
14
}
15
15
}
16
16
17
- // Compute the polygonized vertex of the given angle
18
- // d is the distance between the polygon edge and the actual line.
19
- // d can be negative, this will emit a vertex on the other side of the line.
17
+ /// Consider two line segments between three points: t1-t2-t3
18
+ /// Imagine the line bends to the right, and we run along the line on the right hand side.
19
+ /// In that case, we make an "inside corner" at t2.
20
+ /// This function would compute the point close to t2 that makes the line have thickness `d`
21
+ ///
22
+ /// For "outside corners" (the line bends to the left), we sometimes get too pointy corners
23
+ /// if there is just one new point. In that case, we add a cap to make the corner look better.
24
+ /// In that case, the function emits two points.
25
+ ///
26
+ /// The function will return values via the `buf` parameter, after clearing it.
27
+ ///
28
+ /// d can be negative, this will emit a vertex on the other side of the line.
29
+ ///
20
30
fn compute_polygon_vertex ( triple : & [ BackendCoord ; 3 ] , d : f64 , buf : & mut Vec < BackendCoord > ) {
21
31
buf. clear ( ) ;
22
32
23
- // Compute the tanginal and normal vectors of the given straight line.
33
+ // Compute the tangential and normal vectors of the given straight line.
24
34
let ( a_t, a_n) = get_dir_vector ( triple[ 0 ] , triple[ 1 ] , false ) ;
25
35
let ( b_t, b_n) = get_dir_vector ( triple[ 2 ] , triple[ 1 ] , true ) ;
26
36
@@ -55,24 +65,25 @@ fn compute_polygon_vertex(triple: &[BackendCoord; 3], d: f64, buf: &mut Vec<Back
55
65
let b1 = -b_t. 1 ;
56
66
let c1 = b_p. 1 - a_p. 1 ;
57
67
58
- // If the determinant is 0, then we cannot actually 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 {
68
+ // If the determinant is 0, then we cannot actually get an intersection point.
69
+ // In that case, the two lines are parallel and we just emit the point a_p, which is
70
+ // approximately equal to b_p
71
+ if ( a0 * b1 - a1 * b0) . abs ( ) <= f64:: EPSILON {
61
72
buf. push ( ( a_p. 0 as i32 , a_p. 1 as i32 ) ) ;
62
73
return ;
63
- }
64
- else {
74
+ } else {
65
75
let u = ( c0 * b1 - c1 * b0) / ( a0 * b1 - a1 * b0) ;
66
76
let x = a_p. 0 + u * a_t. 0 ;
67
77
let y = a_p. 1 + u * a_t. 1 ;
68
-
78
+
69
79
let cross_product = a_t. 0 * b_t. 1 - a_t. 1 * b_t. 0 ;
70
- let is_outside_the_angle = ( cross_product < 0.0 && d < 0.0 ) || ( cross_product > 0.0 && d > 0.0 ) ;
80
+ let is_outside_the_angle =
81
+ ( cross_product < 0.0 && d < 0.0 ) || ( cross_product > 0.0 && d > 0.0 ) ;
71
82
if is_outside_the_angle {
72
- // Then we are at the outter side of the angle, so we need to consider a cap.
83
+ // We are at the outer side of the angle, so we need to consider a cap.
73
84
let dist_square = ( x - triple[ 1 ] . 0 as f64 ) . powi ( 2 ) + ( y - triple[ 1 ] . 1 as f64 ) . powi ( 2 ) ;
74
85
let needs_capping = dist_square > d * d * 16.0 ;
75
- if needs_capping {
86
+ if needs_capping {
76
87
// If the point is too far away from the line, we need to cap it to make it look okay
77
88
buf. push ( ( a_p. 0 . round ( ) as i32 , a_p. 1 . round ( ) as i32 ) ) ;
78
89
buf. push ( ( b_p. 0 . round ( ) as i32 , b_p. 1 . round ( ) as i32 ) ) ;
@@ -86,8 +97,6 @@ fn compute_polygon_vertex(triple: &[BackendCoord; 3], d: f64, buf: &mut Vec<Back
86
97
buf. push ( ( x. round ( ) as i32 , y. round ( ) as i32 ) ) ;
87
98
}
88
99
}
89
-
90
-
91
100
}
92
101
93
102
fn traverse_vertices < ' a > (
0 commit comments