Skip to content

Commit e564dc7

Browse files
Merge pull request #68 from iShape-Rust/feature/code_refactoring
Feature/code refactoring
2 parents 9455812 + aa196d2 commit e564dc7

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

.github/workflows/tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ on:
88
branches: ["main"]
99

1010
jobs:
11+
msrv:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: dtolnay/rust-toolchain@stable
16+
with:
17+
toolchain: 1.88.0
18+
- name: Run MSRV check
19+
working-directory: iOverlay
20+
run: cargo check --all-features --all-targets
21+
1122
test:
1223
runs-on: ubuntu-latest
1324
steps:

iOverlay/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "i_overlay"
33
version = "4.5.1"
44
authors = ["Nail Sharipov <nailxsharipov@gmail.com>"]
55
edition = "2024"
6+
rust-version = "1.88"
67
description = "Boolean Operations for 2D Polygons: Supports intersection, union, difference, xor, and self-intersections for all polygon varieties."
78
license = "MIT OR Apache-2.0"
89
repository = "https://github.com/iShape-Rust/iOverlay"

iOverlay/src/core/divide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl ContourDecomposition for IntContour {
4545
.map(|(i, &p)| IdPoint::new(i, p))
4646
.collect();
4747

48-
id_points.sort_by(|p0, p1| p0.point.cmp(&p1.point).then_with(|| p0.id.cmp(&p1.id)));
48+
id_points.sort_unstable_by(|p0, p1| p0.point.cmp(&p1.point).then_with(|| p0.id.cmp(&p1.id)));
4949

5050
let mut p0 = id_points.first().unwrap().point;
5151
let mut anchors = Vec::new();

iOverlay/src/core/extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl OverlayGraph<'_> {
170170
}
171171

172172
if !anchors_already_sorted {
173-
anchors.sort_by(|s0, s1| s0.v_segment.a.cmp(&s1.v_segment.a));
173+
anchors.sort_unstable_by(|s0, s1| s0.v_segment.a.cmp(&s1.v_segment.a));
174174
}
175175

176176
shapes.join_sorted_holes(holes, anchors, clockwise);

iOverlay/src/core/extract_ogc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl OverlayGraph<'_> {
168168
}
169169

170170
if !anchors_already_sorted {
171-
anchors.sort_by(|s0, s1| s0.v_segment.a.cmp(&s1.v_segment.a));
171+
anchors.sort_unstable_by(|s0, s1| s0.v_segment.a.cmp(&s1.v_segment.a));
172172
}
173173

174174
shapes.join_sorted_holes(holes, anchors, is_main_dir_cw);

iOverlay/src/split/solver_fragment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl SplitSolver {
108108
marks: Vec<LineMark>,
109109
}
110110

111-
let marks_capacity = self.marks.len() / buffer.groups.len();
111+
debug_assert!(!buffer.groups.is_empty(), "groups.len() >= 1");
112+
let marks_capacity = self.marks.capacity() / buffer.groups.len();
112113

113114
let results: Vec<TaskResult> = buffer
114115
.groups

iOverlay/src/split/solver_list.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ impl SplitSolver {
2424

2525
let radius: i64 = snap_radius.radius();
2626

27-
for i in 0..segments.len() - 1 {
28-
let ei = &segments[i].x_segment;
29-
let ri = ei.y_range();
30-
for (j, s) in segments.iter().enumerate().skip(i + 1) {
31-
let ej = &s.x_segment;
32-
if ei.b.x < ej.a.x {
27+
for (i, si) in segments.iter().enumerate() {
28+
let xsi = &si.x_segment;
29+
let ri = xsi.y_range();
30+
for (j, sj) in segments.iter().enumerate().skip(i + 1) {
31+
let xsj = &sj.x_segment;
32+
if xsi.b.x < xsj.a.x {
3333
break;
3434
}
3535

36-
if ej.is_not_intersect_y_range(&ri) {
36+
if xsj.is_not_intersect_y_range(&ri) {
3737
continue;
3838
}
3939

40-
let is_round = SplitSolver::cross(i, j, ei, ej, &mut self.marks, radius);
40+
let is_round = SplitSolver::cross(i, j, xsi, xsj, &mut self.marks, radius);
4141
need_to_fix = need_to_fix || is_round
4242
}
4343
}

0 commit comments

Comments
 (0)