mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-08 17:58:12 +08: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:
co-authored by
Keavon Chambers
parent
927d7dd9b2
commit
beb1c6ae64
@@ -1,7 +1,6 @@
|
||||
use super::*;
|
||||
use utils::format_point;
|
||||
|
||||
use std::fmt::Write;
|
||||
use utils::format_point;
|
||||
|
||||
/// Functionality relating to core `Bezier` operations, such as constructors and `abs_diff_eq`.
|
||||
impl Bezier {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::utils::{TValue, TValueType};
|
||||
|
||||
use super::*;
|
||||
use crate::utils::{TValue, TValueType};
|
||||
|
||||
/// Functionality relating to looking up properties of the `Bezier` or points along the `Bezier`.
|
||||
impl Bezier {
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Bezier {
|
||||
/// - For a linear segment, the order of the points will be: `start`, `end`.
|
||||
/// - For a quadratic segment, the order of the points will be: `start`, `handle`, `end`.
|
||||
/// - For a cubic segment, the order of the points will be: `start`, `handle_start`, `handle_end`, `end`.
|
||||
pub fn get_points(&self) -> impl Iterator<Item = DVec2> {
|
||||
pub fn get_points(&self) -> impl Iterator<Item = DVec2> + use<> {
|
||||
match self.handles {
|
||||
BezierHandles::Linear => [self.start, self.end, DVec2::ZERO, DVec2::ZERO].into_iter().take(2),
|
||||
BezierHandles::Quadratic { handle } => [self.start, handle, self.end, DVec2::ZERO].into_iter().take(3),
|
||||
|
||||
@@ -7,11 +7,9 @@ mod transform;
|
||||
|
||||
use crate::consts::*;
|
||||
use crate::utils;
|
||||
|
||||
pub use structs::*;
|
||||
|
||||
use glam::DVec2;
|
||||
use std::fmt::{Debug, Formatter, Result};
|
||||
pub use structs::*;
|
||||
|
||||
/// Representation of the handle point(s) in a bezier segment.
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use super::*;
|
||||
use crate::polynomial::Polynomial;
|
||||
use crate::utils::{solve_cubic, solve_quadratic, TValue};
|
||||
use crate::{to_symmetrical_basis_pair, SymmetricalBasis};
|
||||
|
||||
use crate::utils::{TValue, solve_cubic, solve_quadratic};
|
||||
use crate::{SymmetricalBasis, to_symmetrical_basis_pair};
|
||||
use glam::DMat2;
|
||||
use std::ops::Range;
|
||||
|
||||
@@ -99,11 +98,7 @@ impl Bezier {
|
||||
pub fn tangent(&self, t: TValue) -> DVec2 {
|
||||
let t = self.t_value_to_parametric(t);
|
||||
let tangent = self.non_normalized_tangent(t);
|
||||
if tangent.length() > 0. {
|
||||
tangent.normalize()
|
||||
} else {
|
||||
tangent
|
||||
}
|
||||
if tangent.length() > 0. { tangent.normalize() } else { tangent }
|
||||
}
|
||||
|
||||
/// Find the `t`-value(s) such that the tangent(s) at `t` pass through the specified point.
|
||||
@@ -147,11 +142,7 @@ impl Bezier {
|
||||
|
||||
let numerator = d.x * dd.y - d.y * dd.x;
|
||||
let denominator = (d.x.powf(2.) + d.y.powf(2.)).powf(1.5);
|
||||
if denominator.abs() < MAX_ABSOLUTE_DIFFERENCE {
|
||||
0.
|
||||
} else {
|
||||
numerator / denominator
|
||||
}
|
||||
if denominator.abs() < MAX_ABSOLUTE_DIFFERENCE { 0. } else { numerator / denominator }
|
||||
}
|
||||
|
||||
/// Returns two lists of `t`-values representing the local extrema of the `x` and `y` parametric curves respectively.
|
||||
@@ -228,7 +219,7 @@ impl Bezier {
|
||||
}
|
||||
|
||||
/// Returns an `Iterator` containing all possible parametric `t`-values at the given `x`-coordinate.
|
||||
pub fn find_tvalues_for_x(&self, x: f64) -> impl Iterator<Item = f64> {
|
||||
pub fn find_tvalues_for_x(&self, x: f64) -> impl Iterator<Item = f64> + use<> {
|
||||
// Compute the roots of the resulting bezier curve
|
||||
match self.handles {
|
||||
BezierHandles::Linear => {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
use crate::compare::compare_points;
|
||||
use crate::utils::{f64_compare, Cap, TValue};
|
||||
use crate::utils::{Cap, TValue, f64_compare};
|
||||
use crate::{AppendType, ManipulatorGroup, Subpath};
|
||||
|
||||
use glam::DMat2;
|
||||
use std::f64::consts::PI;
|
||||
|
||||
@@ -476,11 +474,7 @@ impl Bezier {
|
||||
error,
|
||||
max_iterations,
|
||||
});
|
||||
if final_low_t != 1. {
|
||||
[auto_arcs, arc_approximations].concat()
|
||||
} else {
|
||||
auto_arcs
|
||||
}
|
||||
if final_low_t != 1. { [auto_arcs, arc_approximations].concat() } else { auto_arcs }
|
||||
}
|
||||
ArcStrategy::FavorLargerArcs => self.approximate_curve_with_arcs(0., 1., error, max_iterations, false).0,
|
||||
ArcStrategy::FavorCorrectness => self
|
||||
@@ -620,9 +614,9 @@ impl Bezier {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::EmptyId;
|
||||
use crate::compare::{compare_arcs, compare_points};
|
||||
use crate::utils::{Cap, TValue};
|
||||
use crate::EmptyId;
|
||||
|
||||
#[test]
|
||||
fn test_split() {
|
||||
@@ -777,14 +771,18 @@ mod tests {
|
||||
|
||||
// Check that the reduce helper is correct
|
||||
let (helper_curves, helper_t_values) = bezier.reduced_curves_and_t_values(None);
|
||||
assert!(reduced_curves
|
||||
.iter()
|
||||
.zip(helper_curves.iter())
|
||||
.all(|(bezier1, bezier2)| bezier1.abs_diff_eq(bezier2, MAX_ABSOLUTE_DIFFERENCE)));
|
||||
assert!(reduced_curves
|
||||
.iter()
|
||||
.zip(helper_t_values.iter())
|
||||
.all(|(curve, t_pair)| curve.abs_diff_eq(&bezier.trim(TValue::Parametric(t_pair[0]), TValue::Parametric(t_pair[1])), MAX_ABSOLUTE_DIFFERENCE)))
|
||||
assert!(
|
||||
reduced_curves
|
||||
.iter()
|
||||
.zip(helper_curves.iter())
|
||||
.all(|(bezier1, bezier2)| bezier1.abs_diff_eq(bezier2, MAX_ABSOLUTE_DIFFERENCE))
|
||||
);
|
||||
assert!(
|
||||
reduced_curves
|
||||
.iter()
|
||||
.zip(helper_t_values.iter())
|
||||
.all(|(curve, t_pair)| curve.abs_diff_eq(&bezier.trim(TValue::Parametric(t_pair[0]), TValue::Parametric(t_pair[1])), MAX_ABSOLUTE_DIFFERENCE))
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_valid_offset<PointId: crate::Identifier>(bezier: &Bezier, offset: &Subpath<PointId>, expected_distance: f64) {
|
||||
|
||||
Reference in New Issue
Block a user