Skip to content

Commit 29b96c1

Browse files
Merge pull request #54 from iShape-Rust/fix/rust_fmt
Fix/rust fmt
2 parents fe4480b + 2a3a045 commit 29b96c1

104 files changed

Lines changed: 1368 additions & 1394 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- uses: dtolnay/rust-toolchain@stable
16+
with:
17+
components: rustfmt
18+
- name: Run fmt check
19+
working-directory: iOverlay
20+
run: cargo fmt --all -- --check
1621
- name: Run tests
1722
working-directory: iOverlay
1823
run: cargo test

iOverlay/rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
edition = "2024"
2+
max_width = 110

iOverlay/src/bind/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
pub(crate) mod segment;
12
pub(crate) mod solver;
2-
pub(crate) mod segment;

iOverlay/src/bind/segment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use alloc::vec::Vec;
21
use crate::geom::v_segment::VSegment;
32
use crate::vector::edge::{VectorEdge, VectorPath};
3+
use alloc::vec::Vec;
44
use i_float::int::point::IntPoint;
55
use i_shape::int::path::IntPath;
66

@@ -139,4 +139,4 @@ impl IdSegments for VectorPath {
139139
inner(self.iter().rev().copied(), buffer, id_data, x_min, x_max);
140140
}
141141
}
142-
}
142+
}

iOverlay/src/bind/solver.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ impl ShapeBinder {
8383
j += 1
8484
}
8585

86-
let target_id =
87-
scan_list.first_less(anchor.v_segment.a.x, ContourIndex::EMPTY, anchor.v_segment);
86+
let target_id = scan_list.first_less(anchor.v_segment.a.x, ContourIndex::EMPTY, anchor.v_segment);
8887
let parent_index = if target_id.is_hole() {
8988
// index is a hole index
9089
// at this moment this hole parent is known
@@ -108,12 +107,7 @@ impl ShapeBinder {
108107

109108
pub(crate) trait JoinHoles {
110109
fn join_unsorted_holes(&mut self, holes: Vec<IntContour>, clockwise: bool);
111-
fn join_sorted_holes(
112-
&mut self,
113-
holes: Vec<IntContour>,
114-
anchors: Vec<IdSegment>,
115-
clockwise: bool,
116-
);
110+
fn join_sorted_holes(&mut self, holes: Vec<IntContour>, anchors: Vec<IdSegment>, clockwise: bool);
117111
fn scan_join(&mut self, holes: Vec<IntPath>, hole_segments: Vec<IdSegment>, clockwise: bool);
118112
}
119113

@@ -146,12 +140,7 @@ impl JoinHoles for Vec<IntShape> {
146140
}
147141

148142
#[inline]
149-
fn join_sorted_holes(
150-
&mut self,
151-
holes: Vec<IntContour>,
152-
anchors: Vec<IdSegment>,
153-
clockwise: bool,
154-
) {
143+
fn join_sorted_holes(&mut self, holes: Vec<IntContour>, anchors: Vec<IdSegment>, clockwise: bool) {
155144
if self.is_empty() || holes.is_empty() {
156145
return;
157146
}
@@ -175,23 +164,11 @@ impl JoinHoles for Vec<IntShape> {
175164
let capacity = self.iter().fold(0, |s, it| s + it[0].len()) / 2;
176165
let mut segments = Vec::with_capacity(capacity);
177166
for (i, shape) in self.iter().enumerate() {
178-
shape[0].append_id_segments(
179-
&mut segments,
180-
ContourIndex::new_shape(i),
181-
x_min,
182-
x_max,
183-
clockwise,
184-
);
167+
shape[0].append_id_segments(&mut segments, ContourIndex::new_shape(i), x_min, x_max, clockwise);
185168
}
186169

187170
for (i, hole) in holes.iter().enumerate() {
188-
hole.append_id_segments(
189-
&mut segments,
190-
ContourIndex::new_hole(i),
191-
x_min,
192-
x_max,
193-
clockwise,
194-
);
171+
hole.append_id_segments(&mut segments, ContourIndex::new_hole(i), x_min, x_max, clockwise);
195172
}
196173

197174
segments.sort_by_a_then_by_angle();
@@ -322,16 +299,8 @@ mod tests {
322299
];
323300

324301
let holes = vec![
325-
vec![
326-
IntPoint::new(2, 3),
327-
IntPoint::new(4, 4),
328-
IntPoint::new(4, 3),
329-
],
330-
vec![
331-
IntPoint::new(2, 3),
332-
IntPoint::new(4, 2),
333-
IntPoint::new(3, 1),
334-
],
302+
vec![IntPoint::new(2, 3), IntPoint::new(4, 4), IntPoint::new(4, 3)],
303+
vec![IntPoint::new(2, 3), IntPoint::new(4, 2), IntPoint::new(3, 1)],
335304
];
336305

337306
shapes.join_unsorted_holes(holes, false);

iOverlay/src/build/boolean.rs

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
use alloc::vec::Vec;
2-
use i_shape::util::reserve::Reserve;
3-
use crate::segm::boolean::ShapeCountBoolean;
4-
use crate::core::link::OverlayLinkFilter;
5-
use crate::core::graph::OverlayNode;
6-
use crate::core::fill_rule::FillRule;
7-
use crate::core::solver::Solver;
81
use crate::build::builder::{FillStrategy, GraphBuilder, InclusionFilterStrategy};
92
use crate::core::extract::VisitState;
3+
use crate::core::fill_rule::FillRule;
104
use crate::core::graph::OverlayGraph;
5+
use crate::core::graph::OverlayNode;
116
use crate::core::link::OverlayLink;
7+
use crate::core::link::OverlayLinkFilter;
128
use crate::core::overlay::IntOverlayOptions;
139
use crate::core::overlay_rule::OverlayRule;
14-
use crate::segm::segment::{Segment, SegmentFill, ALL, BOTH_BOTTOM, BOTH_TOP, CLIP_BOTH, CLIP_BOTTOM, CLIP_TOP, SUBJ_BOTH, SUBJ_BOTTOM, SUBJ_TOP};
10+
use crate::core::solver::Solver;
11+
use crate::segm::boolean::ShapeCountBoolean;
12+
use crate::segm::segment::{
13+
ALL, BOTH_BOTTOM, BOTH_TOP, CLIP_BOTH, CLIP_BOTTOM, CLIP_TOP, SUBJ_BOTH, SUBJ_BOTTOM, SUBJ_TOP, Segment,
14+
SegmentFill,
15+
};
1516
use crate::segm::winding::WindingCount;
17+
use alloc::vec::Vec;
18+
use i_shape::util::reserve::Reserve;
1619

1720
impl GraphBuilder<ShapeCountBoolean, OverlayNode> {
1821
#[inline]
19-
pub(crate) fn build_boolean_all(&mut self,
20-
fill_rule: FillRule,
21-
options: IntOverlayOptions,
22-
solver: &Solver,
23-
segments: &[Segment<ShapeCountBoolean>],
22+
pub(crate) fn build_boolean_all(
23+
&mut self,
24+
fill_rule: FillRule,
25+
options: IntOverlayOptions,
26+
solver: &Solver,
27+
segments: &[Segment<ShapeCountBoolean>],
2428
) -> OverlayGraph<'_> {
2529
self.build_boolean_fills(fill_rule, solver, segments);
2630
self.build_links_all(segments);
2731
self.boolean_graph(options, solver)
2832
}
2933

3034
#[inline]
31-
pub(crate) fn build_boolean_overlay(&mut self,
32-
fill_rule: FillRule,
33-
overlay_rule: OverlayRule,
34-
options: IntOverlayOptions,
35-
solver: &Solver,
36-
segments: &[Segment<ShapeCountBoolean>],
35+
pub(crate) fn build_boolean_overlay(
36+
&mut self,
37+
fill_rule: FillRule,
38+
overlay_rule: OverlayRule,
39+
options: IntOverlayOptions,
40+
solver: &Solver,
41+
segments: &[Segment<ShapeCountBoolean>],
3742
) -> OverlayGraph<'_> {
3843
self.build_boolean_fills(fill_rule, solver, segments);
3944
match overlay_rule {
@@ -49,7 +54,12 @@ impl GraphBuilder<ShapeCountBoolean, OverlayNode> {
4954
}
5055

5156
#[inline]
52-
fn build_boolean_fills(&mut self, fill_rule: FillRule, solver: &Solver, segments: &[Segment<ShapeCountBoolean>]) {
57+
fn build_boolean_fills(
58+
&mut self,
59+
fill_rule: FillRule,
60+
solver: &Solver,
61+
segments: &[Segment<ShapeCountBoolean>],
62+
) {
5363
match fill_rule {
5464
FillRule::EvenOdd => self.build_fills_with_strategy::<EvenOddStrategy>(solver, segments),
5565
FillRule::NonZero => self.build_fills_with_strategy::<NonZeroStrategy>(solver, segments),
@@ -64,7 +74,7 @@ impl GraphBuilder<ShapeCountBoolean, OverlayNode> {
6474
OverlayGraph {
6575
nodes: &self.nodes,
6676
links: &self.links,
67-
options
77+
options,
6878
}
6979
}
7080
}
@@ -76,10 +86,7 @@ struct NegativeStrategy;
7686

7787
impl FillStrategy<ShapeCountBoolean> for EvenOddStrategy {
7888
#[inline(always)]
79-
fn add_and_fill(
80-
this: ShapeCountBoolean,
81-
bot: ShapeCountBoolean,
82-
) -> (ShapeCountBoolean, SegmentFill) {
89+
fn add_and_fill(this: ShapeCountBoolean, bot: ShapeCountBoolean) -> (ShapeCountBoolean, SegmentFill) {
8390
let top = bot.add(this);
8491
let subj_top = 1 & top.subj as SegmentFill;
8592
let subj_bot = 1 & bot.subj as SegmentFill;
@@ -94,10 +101,7 @@ impl FillStrategy<ShapeCountBoolean> for EvenOddStrategy {
94101

95102
impl FillStrategy<ShapeCountBoolean> for NonZeroStrategy {
96103
#[inline(always)]
97-
fn add_and_fill(
98-
this: ShapeCountBoolean,
99-
bot: ShapeCountBoolean,
100-
) -> (ShapeCountBoolean, SegmentFill) {
104+
fn add_and_fill(this: ShapeCountBoolean, bot: ShapeCountBoolean) -> (ShapeCountBoolean, SegmentFill) {
101105
let top = bot.add(this);
102106
let subj_top = (top.subj != 0) as SegmentFill;
103107
let subj_bot = (bot.subj != 0) as SegmentFill;
@@ -112,10 +116,7 @@ impl FillStrategy<ShapeCountBoolean> for NonZeroStrategy {
112116

113117
impl FillStrategy<ShapeCountBoolean> for PositiveStrategy {
114118
#[inline(always)]
115-
fn add_and_fill(
116-
this: ShapeCountBoolean,
117-
bot: ShapeCountBoolean,
118-
) -> (ShapeCountBoolean, SegmentFill) {
119+
fn add_and_fill(this: ShapeCountBoolean, bot: ShapeCountBoolean) -> (ShapeCountBoolean, SegmentFill) {
119120
let top = bot.add(this);
120121
let subj_top = (top.subj > 0) as SegmentFill;
121122
let subj_bot = (bot.subj > 0) as SegmentFill;
@@ -130,10 +131,7 @@ impl FillStrategy<ShapeCountBoolean> for PositiveStrategy {
130131

131132
impl FillStrategy<ShapeCountBoolean> for NegativeStrategy {
132133
#[inline(always)]
133-
fn add_and_fill(
134-
this: ShapeCountBoolean,
135-
bot: ShapeCountBoolean,
136-
) -> (ShapeCountBoolean, SegmentFill) {
134+
fn add_and_fill(this: ShapeCountBoolean, bot: ShapeCountBoolean) -> (ShapeCountBoolean, SegmentFill) {
137135
let top = bot.add(this);
138136
let subj_top = (top.subj < 0) as SegmentFill;
139137
let subj_bot = (bot.subj < 0) as SegmentFill;
@@ -307,37 +305,58 @@ impl OverlayLinkFilter for [OverlayLink] {
307305

308306
#[inline]
309307
fn filter_subject(links: &[OverlayLink]) -> Vec<VisitState> {
310-
links.iter().map(|link| VisitState::new(!link.fill.is_subject())).collect()
308+
links
309+
.iter()
310+
.map(|link| VisitState::new(!link.fill.is_subject()))
311+
.collect()
311312
}
312313

313314
#[inline]
314315
fn filter_clip(links: &[OverlayLink]) -> Vec<VisitState> {
315-
links.iter().map(|link| VisitState::new(!link.fill.is_clip())).collect()
316+
links
317+
.iter()
318+
.map(|link| VisitState::new(!link.fill.is_clip()))
319+
.collect()
316320
}
317321

318322
#[inline]
319323
fn filter_intersect(links: &[OverlayLink]) -> Vec<VisitState> {
320-
links.iter().map(|link| VisitState::new(!link.fill.is_intersect())).collect()
324+
links
325+
.iter()
326+
.map(|link| VisitState::new(!link.fill.is_intersect()))
327+
.collect()
321328
}
322329

323330
#[inline]
324331
fn filter_union(links: &[OverlayLink]) -> Vec<VisitState> {
325-
links.iter().map(|link| VisitState::new(!link.fill.is_union())).collect()
332+
links
333+
.iter()
334+
.map(|link| VisitState::new(!link.fill.is_union()))
335+
.collect()
326336
}
327337

328338
#[inline]
329339
fn filter_difference(links: &[OverlayLink]) -> Vec<VisitState> {
330-
links.iter().map(|link| VisitState::new(!link.fill.is_difference())).collect()
340+
links
341+
.iter()
342+
.map(|link| VisitState::new(!link.fill.is_difference()))
343+
.collect()
331344
}
332345

333346
#[inline]
334347
fn filter_inverse_difference(links: &[OverlayLink]) -> Vec<VisitState> {
335-
links.iter().map(|link| VisitState::new(!link.fill.is_inverse_difference())).collect()
348+
links
349+
.iter()
350+
.map(|link| VisitState::new(!link.fill.is_inverse_difference()))
351+
.collect()
336352
}
337353

338354
#[inline]
339355
fn filter_xor(links: &[OverlayLink]) -> Vec<VisitState> {
340-
links.iter().map(|link| VisitState::new(!link.fill.is_xor())).collect()
356+
links
357+
.iter()
358+
.map(|link| VisitState::new(!link.fill.is_xor()))
359+
.collect()
341360
}
342361

343362
#[inline]
@@ -401,4 +420,4 @@ fn filter_xor_into(links: &[OverlayLink], buffer: &mut Vec<VisitState>) {
401420
for link in links.iter() {
402421
buffer.push(VisitState::new(!link.fill.is_xor()));
403422
}
404-
}
423+
}

iOverlay/src/build/builder.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use alloc::vec::Vec;
1+
use crate::core::link::OverlayLink;
22
use crate::core::solver::Solver;
33
use crate::geom::end::End;
4+
use crate::geom::id_point::IdPoint;
45
use crate::geom::v_segment::VSegment;
56
use crate::segm::segment::{NONE, Segment, SegmentFill};
67
use crate::segm::winding::WindingCount;
78
use crate::util::log::Int;
9+
use alloc::vec::Vec;
810
use i_float::triangle::Triangle;
911
use i_shape::util::reserve::Reserve;
1012
use i_tree::key::exp::KeyExpCollection;
1113
use i_tree::key::list::KeyExpList;
1214
use i_tree::key::tree::KeyExpTree;
13-
use crate::core::link::OverlayLink;
14-
use crate::geom::id_point::IdPoint;
1515

1616
pub(super) trait FillStrategy<C> {
1717
fn add_and_fill(this: C, bot: C) -> (C, SegmentFill);
@@ -35,7 +35,6 @@ pub(crate) struct GraphBuilder<C, N> {
3535
}
3636

3737
impl<C: WindingCount, N: GraphNode> GraphBuilder<C, N> {
38-
3938
#[inline]
4039
pub(crate) fn new() -> Self {
4140
Self {
@@ -49,7 +48,11 @@ impl<C: WindingCount, N: GraphNode> GraphBuilder<C, N> {
4948
}
5049

5150
#[inline]
52-
pub(super) fn build_fills_with_strategy<F: FillStrategy<C>>(&mut self, solver: &Solver, segments: &[Segment<C>]) {
51+
pub(super) fn build_fills_with_strategy<F: FillStrategy<C>>(
52+
&mut self,
53+
solver: &Solver,
54+
segments: &[Segment<C>],
55+
) {
5356
let count = segments.len();
5457
if solver.is_list_fill(segments) {
5558
let capacity = count.log2_sqrt().max(4) * 2;
@@ -65,7 +68,11 @@ impl<C: WindingCount, N: GraphNode> GraphBuilder<C, N> {
6568
}
6669

6770
#[inline]
68-
fn build_fills<F: FillStrategy<C>, S: KeyExpCollection<VSegment, i32, C>>(&mut self, scan_list: &mut S, segments: &[Segment<C>]) {
71+
fn build_fills<F: FillStrategy<C>, S: KeyExpCollection<VSegment, i32, C>>(
72+
&mut self,
73+
scan_list: &mut S,
74+
segments: &[Segment<C>],
75+
) {
6976
let mut node = Vec::with_capacity(4);
7077

7178
let n = segments.len();

0 commit comments

Comments
 (0)