Skip to content

Commit ce3706a

Browse files
committed
bold logic
1 parent 72200ff commit ce3706a

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

iOverlay/src/mesh/outline/builder_join.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@ impl BevelJoinBuilder {
3232
adapter: &FloatPointAdapter<P, T>,
3333
segments: &mut Vec<Segment<ShapeCountOffset>>,
3434
) {
35-
Self::add_weak_segment(&s0.b_top, &s1.a_top, adapter, segments);
36-
}
37-
38-
#[inline]
39-
fn add_weak_segment<T: FloatNumber, P: FloatPointCompatible<T>>(
40-
a: &P,
41-
b: &P,
42-
adapter: &FloatPointAdapter<P, T>,
43-
segments: &mut Vec<Segment<ShapeCountOffset>>,
44-
) {
45-
let ia = adapter.float_to_int(a);
46-
let ib = adapter.float_to_int(b);
47-
if ia != ib {
48-
segments.push(Segment::weak_subject_ab(ia, ib));
35+
let b0 = adapter.float_to_int(&s0.b_top);
36+
let a1 = adapter.float_to_int(&s1.a_top);
37+
if b0 == a1 {
38+
return;
4939
}
40+
let a0 = adapter.float_to_int(&s0.a_top);
41+
let b1 = adapter.float_to_int(&s1.b_top);
42+
43+
let a0b0 = b0 - a0;
44+
let a1b1 = b1 - a1;
45+
let b0a1 = a1 - b0;
46+
47+
let a0b0_x_a1b1 = a0b0.cross_product(a1b1);
48+
let a0b0_x_b0a1 = a0b0.cross_product(b0a1);
49+
let bold = (a0b0_x_a1b1 >= 0) == (a0b0_x_b0a1 >= 0);
50+
51+
segments.push(Segment::subject_ab(b0, a1, bold));
5052
}
5153
}
5254

iOverlay/src/mesh/subject.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ impl Segment<ShapeCountOffset> {
1818
}
1919
}
2020
}
21-
21+
2222
#[inline]
23-
pub(crate) fn weak_subject_ab(p0: IntPoint, p1: IntPoint) -> Self {
23+
pub(crate) fn subject_ab(p0: IntPoint, p1: IntPoint, bold: bool) -> Self {
2424
if p0 < p1 {
2525
Self {
2626
x_segment: XSegment { a: p0, b: p1 },
27-
count: ShapeCountOffset { subj: 1, bold: false },
27+
count: ShapeCountOffset { subj: 1, bold },
2828
}
2929
} else {
3030
Self {
3131
x_segment: XSegment { a: p1, b: p0 },
32-
count: ShapeCountOffset {
33-
subj: -1,
34-
bold: false,
35-
},
32+
count: ShapeCountOffset { subj: -1, bold },
3633
}
3734
}
3835
}

0 commit comments

Comments
 (0)