Code review previous commit, and improve G/R/S hints

This commit is contained in:
Keavon Chambers 2023-03-26 11:49:25 -07:00
parent 959e790cdf
commit d6ab417bcb
18 changed files with 135 additions and 83 deletions

View file

@ -435,7 +435,7 @@ impl Bezier {
let a = self.end.y - self.start.y;
let b = self.start.x - self.end.x;
let c = a * self.start.x + b * self.start.y;
if (a * target_point.x + b * target_point.y - c) * (resulting_sign as f64) <= 0.0 {
if (a * target_point.x + b * target_point.y - c) * (resulting_sign as f64) <= 0. {
resulting_sign
} else {
0
@ -448,14 +448,14 @@ impl Bezier {
if target_point.x >= self.start.x.max(self.end.x).max(p1.x) {
return resulting_sign;
}
let a = self.end.y - 2.0 * p1.y + self.start.y;
let b = 2.0 * (p1.y - self.start.y);
let a = self.end.y - 2. * p1.y + self.start.y;
let b = 2. * (p1.y - self.start.y);
let c = self.start.y - target_point.y;
let discriminant = b * b - 4. * a * c;
let two_times_a = 2. * a;
for t in solve_quadratic(discriminant, two_times_a, b, c) {
if (0.0..=1.0).contains(&t) {
if (0.0..=1.).contains(&t) {
let x = self.evaluate(TValue::Parametric(t)).x;
if target_point.x >= x {
return resulting_sign;
@ -473,12 +473,12 @@ impl Bezier {
if target_point.x >= self.start.x.max(self.end.x).max(p1.x).max(p2.x) {
return resulting_sign;
}
let a = self.end.y - 3.0 * p2.y + 3.0 * p1.y - self.start.y;
let b = 3.0 * (p2.y - 2.0 * p1.y + self.start.y);
let c = 3.0 * (p1.y - self.start.y);
let a = self.end.y - 3. * p2.y + 3. * p1.y - self.start.y;
let b = 3. * (p2.y - 2. * p1.y + self.start.y);
let c = 3. * (p1.y - self.start.y);
let d = self.start.y - target_point.y;
for t in solve_cubic(a, b, c, d) {
if (0.0..=1.0).contains(&t) {
if (0.0..=1.).contains(&t) {
let x = self.evaluate(TValue::Parametric(t)).x;
if target_point.x >= x {
return resulting_sign;

View file

@ -9,7 +9,7 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
self.closed
}
/// Set if the subpath is closed.
/// Set whether the subpath is closed.
pub fn set_closed(&mut self, new_closed: bool) {
self.closed = new_closed;
}
@ -29,12 +29,12 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
self.manipulator_groups.iter().position(|manipulator_group| manipulator_group.id == id)
}
/// Insert a manipulator group at an index
/// Insert a manipulator group at an index.
pub fn insert_manipulator_group(&mut self, index: usize, group: ManipulatorGroup<ManipulatorGroupId>) {
self.manipulator_groups.insert(index, group)
}
/// Remove a manipulator group at an index
/// Remove a manipulator group at an index.
pub fn remove_manipulator_group(&mut self, index: usize) -> ManipulatorGroup<ManipulatorGroupId> {
self.manipulator_groups.remove(index)
}