mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 21:08:12 +08:00
Bezier-rs: Subpath offset and bezier offset improvements (#1039)
* Added subpath offset * Enhanced offset to produce smooth curves * Lots of outline bugfixes * Fixed failing unit tests * Added subpath outline * Refactor bezier offset and outline to return Subpaths * Fix outline bug due to smooth joining and removed reduce optimization that causes jumping approximations * Bugfix when subpath angle is acute but doesn't intersect * Stylistic changes per review * Stylistic changes per review and updated doc comments --------- Co-authored-by: Hannah Li <hannahli2010@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Hannah Li
Keavon Chambers
parent
0512cb249f
commit
2fd5c26450
@@ -1,11 +1,15 @@
|
||||
/// Comparison functions used for tests in the bezier module
|
||||
use super::{Bezier, CircleArc, Subpath};
|
||||
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
|
||||
#[cfg(test)]
|
||||
use super::{CircleArc, Subpath};
|
||||
#[cfg(test)]
|
||||
use crate::utils::f64_compare;
|
||||
|
||||
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
|
||||
|
||||
use glam::DVec2;
|
||||
|
||||
// Compare two f64s with some maximum absolute difference to account for floating point errors
|
||||
#[cfg(test)]
|
||||
pub fn compare_f64s(f1: f64, f2: f64) -> bool {
|
||||
f64_compare(f1, f2, MAX_ABSOLUTE_DIFFERENCE)
|
||||
}
|
||||
@@ -16,19 +20,13 @@ pub fn compare_points(p1: DVec2, p2: DVec2) -> bool {
|
||||
}
|
||||
|
||||
/// Compare vectors of points by allowing some maximum absolute difference to account for floating point errors
|
||||
#[cfg(test)]
|
||||
pub fn compare_vec_of_points(a: Vec<DVec2>, b: Vec<DVec2>, max_absolute_difference: f64) -> bool {
|
||||
a.len() == b.len() && a.into_iter().zip(b.into_iter()).all(|(p1, p2)| p1.abs_diff_eq(p2, max_absolute_difference))
|
||||
}
|
||||
|
||||
/// Compare vectors of beziers by allowing some maximum absolute difference between points to account for floating point errors
|
||||
pub fn compare_vector_of_beziers(beziers: &[Bezier], expected_bezier_points: Vec<Vec<DVec2>>) -> bool {
|
||||
beziers
|
||||
.iter()
|
||||
.zip(expected_bezier_points.iter())
|
||||
.all(|(&a, b)| compare_vec_of_points(a.get_points().collect::<Vec<DVec2>>(), b.to_vec(), MAX_ABSOLUTE_DIFFERENCE))
|
||||
}
|
||||
|
||||
/// Compare circle arcs by allowing some maximum absolute difference between values to account for floating point errors
|
||||
#[cfg(test)]
|
||||
pub fn compare_arcs(arc1: CircleArc, arc2: CircleArc) -> bool {
|
||||
compare_points(arc1.center, arc2.center)
|
||||
&& f64_compare(arc1.radius, arc1.radius, MAX_ABSOLUTE_DIFFERENCE)
|
||||
@@ -38,6 +36,7 @@ pub fn compare_arcs(arc1: CircleArc, arc2: CircleArc) -> bool {
|
||||
|
||||
/// Compare Subpath by verifying that their bezier segments match.
|
||||
/// In this way, matching quadratic segments where the handles are on opposite manipulator groups will be considered equal.
|
||||
#[cfg(test)]
|
||||
pub fn compare_subpaths<ManipulatorGroupId: crate::Identifier>(subpath1: &Subpath<ManipulatorGroupId>, subpath2: &Subpath<ManipulatorGroupId>) -> bool {
|
||||
subpath1.len() == subpath2.len() && subpath1.closed() == subpath2.closed() && subpath1.iter().eq(subpath2.iter())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user