@@ -189,6 +189,7 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
189
189
} ;
190
190
let size = self . size . in_pixels ( & ps) . max ( 0 ) as f32 ;
191
191
let spacing = self . spacing . in_pixels ( & ps) . max ( 0 ) as f32 ;
192
+ let mut is_previous_solid = false ;
192
193
for curr in points {
193
194
let curr_f = to_f ( curr) ;
194
195
let ( dx, dy) = ( curr_f. 0 - start. 0 , curr_f. 1 - start. 1 ) ;
@@ -199,6 +200,11 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
199
200
// 1) o-- -- o (need to patch last one)
200
201
// 2) o-- -- o (ignore the last one)
201
202
// 3) o o (points are too dense)
203
+ if is_previous_solid {
204
+ start. 0 += dx * gap_scale;
205
+ start. 1 += dy * gap_scale;
206
+ d -= spacing;
207
+ }
202
208
while d >= size {
203
209
// Solid line
204
210
let end = ( start. 0 + dx * scale, start. 1 + dy * scale) ;
@@ -210,8 +216,10 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
210
216
// Finish the last segment
211
217
// 1) o-- -- -o (patched)
212
218
// 2) o-o (become solid line)
213
- if d > 0. {
214
- backend. draw_path ( [ to_i ( start) , curr] , & self . style ) ?;
219
+ let line = [ to_i ( start) , curr] ;
220
+ is_previous_solid = d > 0. && line[ 0 ] != line[ 1 ] ;
221
+ if is_previous_solid {
222
+ backend. draw_path ( line, & self . style ) ?;
215
223
}
216
224
// Move to the current point
217
225
start = curr_f;
@@ -226,14 +234,15 @@ fn test_dashed_path_element() {
226
234
use crate :: prelude:: * ;
227
235
let check_list = std:: cell:: RefCell :: new ( vec ! [
228
236
[ ( 100 , 100 ) , ( 100 , 103 ) ] ,
229
- [ ( 100 , 103 ) , ( 100 , 108 ) ] ,
230
- [ ( 100 , 110 ) , ( 100 , 115 ) ] ,
231
- [ ( 100 , 117 ) , ( 100 , 120 ) ] ,
237
+ [ ( 100 , 105 ) , ( 100 , 110 ) ] ,
238
+ [ ( 100 , 112 ) , ( 100 , 117 ) ] ,
239
+ [ ( 100 , 119 ) , ( 100 , 120 ) ] ,
232
240
] ) ;
233
241
let da = crate :: create_mocked_drawing_area ( 300 , 300 , |m| {
234
242
m. check_draw_path ( move |c, s, path| {
235
243
assert_eq ! ( c, BLUE . to_rgba( ) ) ;
236
244
assert_eq ! ( s, 7 ) ;
245
+ dbg ! ( & path) ;
237
246
assert_eq ! ( path, check_list. borrow_mut( ) . remove( 0 ) ) ;
238
247
} ) ;
239
248
m. drop_check ( |b| {
0 commit comments