Skip to content

Commit 1ed13fe

Browse files
Merge pull request #43 from iShape-Rust/fix/zero_length_segment
buffer segment zero length fix
2 parents d8dd433 + 102de24 commit 1ed13fe

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

iOverlay/src/mesh/outline/offset.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,44 @@ mod tests {
444444
assert!(path.outline_fixed_scale(&style, f64::NAN).is_err());
445445
assert!(path.outline_fixed_scale(&style, f64::INFINITY).is_err());
446446
}
447+
448+
#[test]
449+
fn test_zero_length_segment_0() {
450+
let path = [
451+
[2681.39599938213, 5892784.488998892],
452+
[5419.06964821636, 5891947.742386343],
453+
[5419.1446127397, 5891949.316633703],
454+
[5422.8669123155, 5892027.484991552],
455+
[5034.8682417375, 5892817.151239874],
456+
[4804.8188261491, 5892876.799252035],
457+
[4804.81882805645, 5892876.799253942],
458+
[4551.3436274034, 5892942.5211854],
459+
[2681.39599938213, 5892784.488998892],
460+
];
461+
462+
let angle = 10.0f64 / (core::f64::consts::PI / 2.0f64);
463+
let style = OutlineStyle::new(150.0).line_join(LineJoin::Round(angle));
464+
465+
if let Some(shape) = path.outline(&style).first() {
466+
assert!(shape[0].len() < 1_000);
467+
};
468+
}
469+
470+
#[test]
471+
fn test_zero_length_segment_1() {
472+
let path = [
473+
[2681.39599938213, 5892876.0],
474+
[5400.0, 5891947.742386343],
475+
[5400.0, 5892817.151239874],
476+
[4804.8188261491, 5892876.799252035],
477+
[4804.81882805645, 5892876.799253942]
478+
];
479+
480+
let angle = 10.0f64 / (core::f64::consts::PI / 2.0f64);
481+
let style = OutlineStyle::new(150.0).line_join(LineJoin::Round(angle));
482+
483+
if let Some(shape) = path.outline(&style).first() {
484+
assert!(shape[0].len() < 1_000);
485+
};
486+
}
447487
}

iOverlay/src/mesh/outline/section.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl<T: FloatNumber, P: FloatPointCompatible<T>> SectionToSegment<T, P> for Vec<
4343
fn add_section(&mut self, section: &Section<P, T>, adapter: &FloatPointAdapter<P, T>) {
4444
let a_top = adapter.float_to_int(&section.a_top);
4545
let b_top = adapter.float_to_int(&section.b_top);
46-
self.push(Segment::bold_subject_ab(a_top, b_top));
46+
if a_top != b_top {
47+
self.push(Segment::bold_subject_ab(a_top, b_top));
48+
}
4749
}
4850
}

iOverlay/src/mesh/stroke/section.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ impl<T: FloatNumber, P: FloatPointCompatible<T>> SectionToSegment<T, P> for Vec<
5555
let a_bot = adapter.float_to_int(&section.a_bot);
5656
let b_bot = adapter.float_to_int(&section.b_bot);
5757

58-
self.push(Segment::bold_subject_ab(b_top, a_top));
59-
self.push(Segment::bold_subject_ab(a_bot, b_bot));
58+
if a_top != b_top {
59+
self.push(Segment::bold_subject_ab(b_top, a_top));
60+
}
61+
if a_bot != b_bot {
62+
self.push(Segment::bold_subject_ab(a_bot, b_bot));
63+
}
6064
}
6165
}

0 commit comments

Comments
 (0)