mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 05:18:19 +00:00
Upgrade to the Rust 2024 edition (#2367)
* Update to rust 2024 edition * Fixes * Clean up imports * Cargo fmt again --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
927d7dd9b2
commit
beb1c6ae64
253 changed files with 980 additions and 1371 deletions
|
@ -24,7 +24,7 @@ pub(crate) use util::*;
|
|||
pub use intersection_path_segment::path_segment_intersection;
|
||||
#[cfg(feature = "parsing")]
|
||||
pub use parsing::path_data::{path_from_path_data, path_to_path_data};
|
||||
pub use path_boolean::{path_boolean, BooleanError, FillRule, PathBooleanOperation, EPS};
|
||||
pub use path_boolean::{BooleanError, EPS, FillRule, PathBooleanOperation, path_boolean};
|
||||
pub use path_segment::PathSegment;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::path::{path_from_commands, path_to_commands, Path};
|
||||
use crate::path_command::{AbsolutePathCommand, PathCommand, RelativePathCommand};
|
||||
use crate::BooleanError;
|
||||
use crate::path::{Path, path_from_commands, path_to_commands};
|
||||
use crate::path_command::{AbsolutePathCommand, PathCommand, RelativePathCommand};
|
||||
use glam::DVec2;
|
||||
use regex::Regex;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ pub(crate) mod path_segment;
|
|||
use glam::DVec2;
|
||||
|
||||
#[cfg(feature = "parsing")]
|
||||
use crate::path_command::{to_absolute_commands, AbsolutePathCommand, PathCommand};
|
||||
use crate::path_command::{AbsolutePathCommand, PathCommand, to_absolute_commands};
|
||||
use crate::path_segment::PathSegment;
|
||||
|
||||
pub type Path = Vec<PathSegment>;
|
||||
|
@ -107,7 +107,7 @@ where
|
|||
let start = seg.start();
|
||||
let mut commands = Vec::new();
|
||||
|
||||
if last_point.map_or(true, |lp| !start.abs_diff_eq(lp, eps)) {
|
||||
if last_point.is_none_or(|lp| !start.abs_diff_eq(lp, eps)) {
|
||||
if last_point.is_some() {
|
||||
commands.push(PathCommand::Absolute(AbsolutePathCommand::Z));
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use crate::aabb::{bounding_box_max_extent, bounding_boxes_overlap, Aabb};
|
||||
use crate::aabb::{Aabb, bounding_box_max_extent, bounding_boxes_overlap};
|
||||
use crate::epsilons::Epsilons;
|
||||
use crate::line_segment::{line_segment_intersection, line_segments_intersect};
|
||||
use crate::line_segment_aabb::line_segment_aabb_intersect;
|
||||
use crate::math::lerp;
|
||||
use crate::path_segment::PathSegment;
|
||||
|
||||
use glam::DVec2;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -21,11 +21,7 @@ pub fn line_segment_intersection([p1, p2]: LineSegment, [p3, p4]: LineSegment, e
|
|||
let s = (c.x * b.y - c.y * b.x) / denom;
|
||||
let t = (a.x * c.y - a.y * c.x) / denom;
|
||||
|
||||
if (-eps..=1. + eps).contains(&s) && (-eps..=1. + eps).contains(&t) {
|
||||
Some((s, t))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if (-eps..=1. + eps).contains(&s) && (-eps..=1. + eps).contains(&t) { Some((s, t)) } else { None }
|
||||
}
|
||||
|
||||
pub fn line_segments_intersect(seg1: LineSegment, seg2: LineSegment, eps: f64) -> bool {
|
||||
|
|
|
@ -9,13 +9,12 @@
|
|||
//! The implementations in this module closely follow the SVG path specification,
|
||||
//! making it suitable for use in vector graphics applications.
|
||||
|
||||
use crate::EPS;
|
||||
use crate::aabb::{Aabb, bounding_box_around_point, expand_bounding_box, extend_bounding_box, merge_bounding_boxes};
|
||||
use crate::math::{lerp, vector_angle};
|
||||
use glam::{DMat2, DMat3, DVec2};
|
||||
use std::f64::consts::{PI, TAU};
|
||||
|
||||
use crate::aabb::{bounding_box_around_point, expand_bounding_box, extend_bounding_box, merge_bounding_boxes, Aabb};
|
||||
use crate::math::{lerp, vector_angle};
|
||||
use crate::EPS;
|
||||
|
||||
/// Represents a segment of a path in a 2D space, based on the SVG path specification.
|
||||
///
|
||||
/// This enum closely follows the path segment types defined in the SVG 2 specification.
|
||||
|
@ -155,11 +154,7 @@ impl PathSegment {
|
|||
let b = 6. * b;
|
||||
let numerator = a.x * b.y - a.y * b.x;
|
||||
let denominator = a.length_squared() * a.length();
|
||||
if denominator == 0. {
|
||||
0.
|
||||
} else {
|
||||
numerator / denominator
|
||||
}
|
||||
if denominator == 0. { 0. } else { numerator / denominator }
|
||||
}
|
||||
PathSegment::Quadratic(start, control, end) => {
|
||||
// First derivative
|
||||
|
@ -168,11 +163,7 @@ impl PathSegment {
|
|||
let b = 2. * (start - 2. * control + end);
|
||||
let numerator = a.x * b.y - a.y * b.x;
|
||||
let denominator = a.length_squared() * a.length();
|
||||
if denominator == 0. {
|
||||
0.
|
||||
} else {
|
||||
numerator / denominator
|
||||
}
|
||||
if denominator == 0. { 0. } else { numerator / denominator }
|
||||
}
|
||||
PathSegment::Arc(..) => self.arc_segment_to_cubics(0.001)[0].start_curvature(),
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ new_key_type! {
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::aabb::{bounding_box_around_point, bounding_box_max_extent, merge_bounding_boxes, Aabb};
|
||||
use crate::aabb::{Aabb, bounding_box_around_point, bounding_box_max_extent, merge_bounding_boxes};
|
||||
use crate::epsilons::Epsilons;
|
||||
use crate::intersection_path_segment::{path_segment_intersection, segments_equal};
|
||||
use crate::path::Path;
|
||||
|
@ -72,9 +72,8 @@ use crate::path_segment::PathSegment;
|
|||
#[cfg(feature = "logging")]
|
||||
use crate::path_to_path_data;
|
||||
use crate::quad_tree::QuadTree;
|
||||
|
||||
use glam::DVec2;
|
||||
use slotmap::{new_key_type, SlotMap};
|
||||
use slotmap::{SlotMap, new_key_type};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::fmt::Display;
|
||||
|
@ -1090,7 +1089,11 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
|
|||
let (key, _) = *areas.iter().max_by_key(|(_, area)| ((area.abs() * 1000.) as u64)).unwrap();
|
||||
*key
|
||||
} else {
|
||||
*windings.iter().find(|(&_, winding)| (winding < &0) ^ reverse_winding).expect("No outer face of a component found.").0
|
||||
*windings
|
||||
.iter()
|
||||
.find(|&&(&_, ref winding)| (winding < &0) ^ reverse_winding)
|
||||
.expect("No outer face of a component found.")
|
||||
.0
|
||||
};
|
||||
#[cfg(feature = "logging")]
|
||||
dbg!(outer_face_key);
|
||||
|
@ -1338,7 +1341,7 @@ fn get_selected_faces<'a>(predicate: &'a impl Fn(u8) -> bool, flags: &'a HashMap
|
|||
flags.iter().filter_map(|(key, &flag)| predicate(flag).then_some(*key))
|
||||
}
|
||||
|
||||
fn walk_faces<'a>(faces: &'a [DualVertexKey], edges: &SlotMap<DualEdgeKey, DualGraphHalfEdge>, vertices: &SlotMap<DualVertexKey, DualGraphVertex>) -> impl Iterator<Item = PathSegment> + 'a {
|
||||
fn walk_faces<'a>(faces: &'a [DualVertexKey], edges: &SlotMap<DualEdgeKey, DualGraphHalfEdge>, vertices: &SlotMap<DualVertexKey, DualGraphVertex>) -> impl Iterator<Item = PathSegment> + use<'a> {
|
||||
let face_set: HashSet<_> = faces.iter().copied().collect();
|
||||
// TODO: Try using a binary search to avoid the hashset construction
|
||||
let is_removed_edge = |edge: &DualGraphHalfEdge| face_set.contains(&edge.incident_vertex) == face_set.contains(&edges[edge.twin.unwrap()].incident_vertex);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::path_boolean::{self, FillRule, PathBooleanOperation};
|
||||
use crate::path_data::{path_from_path_data, path_to_path_data};
|
||||
|
||||
use core::panic;
|
||||
use glob::glob;
|
||||
use image::{DynamicImage, GenericImageView, RgbaImage};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue