Skip to content

Commit c2f7a4b

Browse files
committed
Fix clippy lints
1 parent 5acde36 commit c2f7a4b

File tree

5 files changed

+22
-82
lines changed

5 files changed

+22
-82
lines changed

libraries/path-bool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "path-bool"
33
version = "0.1.0"
4-
rust-version = "1.79"
4+
rust-version = "1.81"
55
authors = ["Graphite Authors <[email protected]>"]
66
edition = "2021"
77
keywords = ["bezier", "boolean", "path", "ops", "operations", "2d"]

libraries/path-bool/benches/path_segment_intersection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use glam::DVec2;
33
use path_bool::*;
44

55
pub fn criterion_benchmark(crit: &mut Criterion) {
6-
crit.bench_function("intersect 1", |bench| bench.iter(|| path_segment_intersection(&a(), &b(), true, &EPS)));
7-
crit.bench_function("intersect 2", |bench| bench.iter(|| path_segment_intersection(&c(), &d(), true, &EPS)));
6+
crit.bench_function("intersect 1", |bench| bench.iter(|| path_segment_intersection(black_box(&a()), black_box(&b()), true, &EPS)));
7+
crit.bench_function("intersect 2", |bench| bench.iter(|| path_segment_intersection(black_box(&c()), black_box(&d()), true, &EPS)));
88
}
99

1010
criterion_group!(benches, criterion_benchmark);

libraries/path-bool/src/intersection_path_segment.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ pub fn path_segment_intersection(seg0: &PathSegment, seg1: &PathSegment, endpoin
143143
continue; // TODO: what to do?
144144
}
145145

146-
let diff1 = (seg0.start_param - seg0.end_param).abs();
147-
let diff2 = (seg1.start_param - seg1.end_param).abs();
148-
// dbg!(diff1.min(diff2));
149146
let is_linear0 = bounding_box_max_extent(&seg0.bounding_box) <= eps.linear || (seg0.end_param - seg0.start_param).abs() < eps.param;
150147
let is_linear1 = bounding_box_max_extent(&seg1.bounding_box) <= eps.linear || (seg1.end_param - seg1.start_param).abs() < eps.param;
151148

libraries/path-bool/src/path_boolean.rs

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use glam::DVec2;
21
use slotmap::{new_key_type, SlotMap};
32

43
new_key_type! {
@@ -19,12 +18,12 @@ use crate::intersection_path_segment::{path_segment_intersection, segments_equal
1918
use crate::path::Path;
2019
use crate::path_cubic_segment_self_intersection::path_cubic_segment_self_intersection;
2120
use crate::path_segment::{get_end_point, get_start_point, path_segment_bounding_box, reverse_path_segment, sample_path_segment_at, split_segment_at, PathSegment};
21+
#[cfg(feature = "logging")]
2222
use crate::path_to_path_data;
2323
use crate::quad_tree::QuadTree;
2424
use crate::vector::{vectors_equal, Vector};
2525
use std::cmp::Ordering;
2626
use std::collections::{HashMap, HashSet, VecDeque};
27-
use std::f64::consts::TAU;
2827

2928
#[derive(Debug, Clone, Copy)]
3029
pub enum PathBooleanOperation {
@@ -65,6 +64,7 @@ pub struct MajorGraphEdge {
6564

6665
#[derive(Debug, Clone, Default)]
6766
pub struct MajorGraphVertex {
67+
#[cfg_attr(not(feature = "logging"), expect(dead_code))]
6868
pub point: Vector,
6969
outgoing_edges: Vec<MajorEdgeKey>,
7070
}
@@ -85,25 +85,6 @@ struct MinorGraphEdge {
8585
}
8686

8787
impl MinorGraphEdge {
88-
#[cfg(feature = "logging")]
89-
fn format_path(&self) -> String {
90-
use std::fmt::Write;
91-
let mut output = String::new();
92-
let segments = self.segments.clone();
93-
for segment in segments.into_iter() {
94-
let _ = match segment {
95-
PathSegment::Line(mut start, mut end) | PathSegment::Cubic(mut start, _, _, mut end) => {
96-
if self.direction_flag.backwards() {
97-
(end, start) = (start, end);
98-
}
99-
write!(&mut output, "{:.1},{:.1}-{:.1},{:.1} ", start.x, start.y, end.x, end.y)
100-
}
101-
x => write!(&mut output, "{:?}", x),
102-
};
103-
}
104-
output
105-
}
106-
10788
fn start_segment(&self) -> PathSegment {
10889
let segment = self.segments[0];
10990
match self.direction_flag {
@@ -199,7 +180,7 @@ fn major_graph_to_dot(graph: &MajorGraph) -> String {
199180
for (vertex_key, vertex) in &graph.vertices {
200181
dot.push_str(&format!(" {:?} [label=\"{:.1},{:.1}\"]\n", (vertex_key.0.as_ffi() & 0xFF), vertex.point.x, vertex.point.y));
201182
}
202-
for (edge_key, edge) in &graph.edges {
183+
for (_, edge) in &graph.edges {
203184
dot.push_str(&format!(
204185
" {:?} -> {:?}: {:0b}\n",
205186
(edge.incident_vertices[0].0.as_ffi() & 0xFF),
@@ -393,9 +374,6 @@ impl Direction {
393374
pub fn forward(self) -> bool {
394375
self == Self::Forward
395376
}
396-
pub fn backwards(self) -> bool {
397-
self == Self::Backwards
398-
}
399377
}
400378

401379
// TODO:(@TrueDoctor) Optimize this by rounding each vertex up and down and then inserting them in a hashmap. This should remove the need for bbox calculations and the quad tree
@@ -667,7 +645,7 @@ fn get_incidence_angle(edge: &MinorGraphEdge) -> f64 {
667645
}
668646

669647
fn sort_outgoing_edges_by_angle(graph: &mut MinorGraph) {
670-
for vertex in graph.vertices.values_mut() {
648+
for (vertex_key, vertex) in graph.vertices.iter_mut() {
671649
if vertex.outgoing_edges.len() > 2 {
672650
vertex.outgoing_edges.sort_by(|&a, &b| {
673651
// TODO(@TrueDoctor): Make more robust. The js version seems to sort the data slightly differently when the angles are reallly close. In that case put the edge wich was discovered later first.
@@ -680,14 +658,14 @@ fn sort_outgoing_edges_by_angle(graph: &mut MinorGraph) {
680658
}
681659
new
682660
});
683-
let edges: Vec<_> = vertex
684-
.outgoing_edges
685-
.iter()
686-
.map(|key| (*key, &graph.edges[*key]))
687-
.map(|(key, edge)| ((key.0.as_ffi() & 0xFF), (edge.start_segment()).start_angle()))
688-
.collect();
689-
#[cfg(feature = "logging")]
690-
dbg!(edges);
661+
if cfg!(feature = "logging") {
662+
eprintln!("Outgoing edges for {:?}:", vertex_key);
663+
for &edge_key in &vertex.outgoing_edges {
664+
let edge = &graph.edges[edge_key];
665+
let angle = edge.start_segment().start_angle();
666+
eprintln!("{:?}: {}°", edge_key.0, angle.to_degrees())
667+
}
668+
}
691669
}
692670
}
693671
}
@@ -926,9 +904,6 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
926904
}
927905
#[cfg(feature = "logging")]
928906
eprintln!("component_vertices: {}", component_vertices.len());
929-
for edge in &dual_edges {
930-
// eprintln!("{:?}", edge.incident_vertex);
931-
}
932907

933908
let windings: Option<Vec<_>> = component_vertices
934909
.iter()
@@ -971,21 +946,13 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
971946
// return Err(BooleanError::MultipleOuterFaces);
972947
#[cfg(feature = "logging")]
973948
eprintln!("Found multiple outer faces: {areas:?}, falling back to area calculation");
974-
let (key, area) = *areas.iter().max_by_key(|(_, area)| ((area.abs() * 1000.) as u64)).unwrap();
975-
if area < 0. {
976-
reverse_winding = true;
977-
}
949+
let (key, _) = *areas.iter().max_by_key(|(_, area)| ((area.abs() * 1000.) as u64)).unwrap();
978950
*key
979951
} else {
980952
*windings.iter().find(|(&_, winding)| (winding < &0) ^ reverse_winding).expect("No outer face of a component found.").0
981953
};
982954
#[cfg(feature = "logging")]
983955
dbg!(outer_face_key);
984-
if reverse_winding {
985-
for &edge in component_edges.iter() {
986-
// dual_edges[edge].direction_flag = !dual_edges[edge].direction_flag;
987-
}
988-
}
989956

990957
components.push(DualGraphComponent {
991958
vertices: component_vertices,

node-graph/gstd/src/vector.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use graphene_core::{Color, GraphicElement, GraphicGroup};
1010

1111
use glam::{DAffine2, DVec2};
1212
use path_bool::PathBooleanOperation;
13-
#[cfg(target_arch = "wasm32")]
14-
use wasm_bindgen::prelude::*;
1513

1614
pub struct BooleanOperationNode<BooleanOp> {
1715
operation: BooleanOp,
@@ -211,6 +209,7 @@ fn to_path_segments(path: &mut Vec<path_bool::PathSegment>, subpath: &bezier_rs:
211209
path.push(segment);
212210
}
213211
}
212+
214213
fn from_path(path_data: &[Path]) -> VectorData {
215214
const EPSILON: f64 = 1e-5;
216215

@@ -302,50 +301,27 @@ pub fn convert_usvg_path(path: &usvg::Path) -> Vec<Subpath<PointId>> {
302301
subpaths
303302
}
304303

305-
// #[cfg(target_arch = "wasm32")]
306-
// #[wasm_bindgen(module = "/../../frontend/src/utility-functions/computational-geometry.ts")]
307-
// extern "C" {
308-
// #[wasm_bindgen(js_name = booleanUnion)]
309-
// fn boolean_union(path1: String, path2: String) -> String;
310-
// #[wasm_bindgen(js_name = booleanSubtract)]
311-
// fn boolean_subtract(path1: String, path2: String) -> String;
312-
// #[wasm_bindgen(js_name = booleanIntersect)]
313-
// fn boolean_intersect(path1: String, path2: String) -> String;
314-
// }
315-
// #[cfg(not(target_arch = "wasm32"))]
316-
317304
type Path = Vec<path_bool::PathSegment>;
318305
fn boolean_union(a: Path, b: Path) -> Vec<Path> {
319306
path_bool(a, b, PathBooleanOperation::Union)
320307
}
321308

322309
fn path_bool(a: Path, b: Path, op: PathBooleanOperation) -> Vec<Path> {
323310
use path_bool::FillRule;
324-
let a_path = path_bool::path_to_path_data(&a, 0.001);
325-
let b_path = path_bool::path_to_path_data(&b, 0.001);
326-
// log::debug!("{:?}\n{:?}", a, b);
327-
// let a = path_bool::path_from_path_data(&a_path);
328-
// let b = path_bool::path_from_path_data(&b_path);
329-
// log::debug!("{:?}\n{:?}", a, b);
330-
// log::error!("Boolean error encontered while processing {a_path}\n {op:?}\n {b_path}");
331-
let results = match path_bool::path_boolean(&a, FillRule::NonZero, &b, FillRule::NonZero, op) {
311+
match path_bool::path_boolean(&a, FillRule::NonZero, &b, FillRule::NonZero, op) {
332312
Ok(results) => results,
333313
Err(e) => {
334-
// log::error!("Boolean error {e:?} encontered while processing {a}\n {op:?}\n {b}");
314+
let a_path = path_bool::path_to_path_data(&a, 0.001);
315+
let b_path = path_bool::path_to_path_data(&b, 0.001);
316+
log::error!("Boolean error {e:?} encontered while processing {a_path}\n {op:?}\n {b_path}");
335317
Vec::new()
336318
}
337-
};
338-
results
339-
// let string = results.iter().map(|result| path_bool::path_to_path_data(result, 0.001)).fold(String::new(), |o, n| o + &n);
340-
// // log::debug!("result: {}", string);
341-
// string
319+
}
342320
}
343321

344-
// #[cfg(not(target_arch = "wasm32"))]
345322
fn boolean_subtract(a: Path, b: Path) -> Vec<Path> {
346323
path_bool(a, b, PathBooleanOperation::Difference)
347324
}
348-
// #[cfg(not(target_arch = "wasm32"))]
349325
fn boolean_intersect(a: Path, b: Path) -> Vec<Path> {
350326
path_bool(a, b, PathBooleanOperation::Intersection)
351327
}

0 commit comments

Comments
 (0)