1
- use super :: line_intersection:: FalseIntersectionPointType :: AfterEnd ;
1
+ use super :: line_intersection:: FalseIntersectionPointType :: {
2
+ BeforeStart ,
3
+ AfterEnd ,
4
+ } ;
2
5
use super :: line_intersection:: LineSegmentIntersectionType :: {
3
6
FalseIntersectionPoint , TrueIntersectionPoint ,
4
7
} ;
51
54
/// negative.
52
55
///
53
56
/// Negative `distance` values will offset the edges of the geometry to the
54
- /// left, when facing the direction of increasing coordinate index.
57
+ /// left, when facing the direction of increasing coordinate index. For a
58
+ /// polygon with clockwise winding order, a positive 'offset' corresponds with
59
+ /// an 'inset'.
55
60
///
56
61
/// ```
57
62
/// #use crate::{line_string, Coord};
86
91
}
87
92
}
88
93
94
+
95
+ /// # Offset for LineString
96
+ /// ## Algorithm
97
+ /// Loosely follows the algorithm described by
98
+ /// [Xu-Zheng Liu, Jun-Hai Yong, Guo-Qin Zheng, Jia-Guang Sun. An offset algorithm for polyline curves. Computers in Industry, Elsevier, 2007, 15p. inria-00518005]
99
+ /// (https://hal.inria.fr/inria-00518005/document)
100
+ /// This was the first google result for 'line offset algorithm'
89
101
impl < T > Offset < T > for LineString < T >
90
102
where
91
103
T : CoordFloat ,
@@ -102,6 +114,7 @@ where
102
114
if offset_segments. len ( ) == 1 {
103
115
return offset_segments[ 0 ] . into ( ) ;
104
116
}
117
+ // First and last will always work:
105
118
let first_point = offset_segments. first ( ) . unwrap ( ) . start ;
106
119
let last_point = offset_segments. last ( ) . unwrap ( ) . end ;
107
120
@@ -127,13 +140,23 @@ where
127
140
//println!("CASE 1 - extend");
128
141
vec ! [ intersection]
129
142
} ,
130
- ( FalseIntersectionPoint ( AfterEnd ) , FalseIntersectionPoint ( _) ) => {
143
+
144
+ ( TrueIntersectionPoint , FalseIntersectionPoint ( _) ) => {
145
+ //println!("CASE 1 - extend");
146
+ vec ! [ intersection]
147
+ } ,
148
+ ( FalseIntersectionPoint ( _) , TrueIntersectionPoint ) => {
149
+ //println!("CASE 1 - extend");
150
+ vec ! [ intersection]
151
+ } ,
152
+ ( FalseIntersectionPoint ( BeforeStart ) , FalseIntersectionPoint ( _) ) => {
131
153
// TODO: Mitre limit logic goes here
132
154
//println!("CASE 2 - extend");
133
155
vec ! [ intersection]
134
- }
156
+ } ,
135
157
_ => {
136
- println ! ( "CASE 3 - bridge" ) ;
158
+ //println!("CASE 3 - bridge");
159
+ //vec![intersection]
137
160
vec ! [ * b, * c]
138
161
} ,
139
162
0 commit comments