-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Curve curve intersection tylers #219
base: main
Are you sure you want to change the base?
Changes from 19 commits
6e0ec0f
f52accd
4aeaeeb
d5d0be8
1375912
dc5b41a
f4cf191
84400ef
7398c23
cb5a672
6e993f9
fc0bdaf
1a2cb70
c23c4ef
5bfbf1e
9f1c40f
531d538
5a6ac30
7ddb666
64db1a8
099da3e
ba180f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
//! Cubic Bézier segments. | ||
|
||
use arrayvec::ArrayVec; | ||
use std::ops::{Mul, Range}; | ||
|
||
use crate::MAX_EXTREMA; | ||
use crate::{Line, QuadSpline, Vec2}; | ||
use arrayvec::ArrayVec; | ||
|
||
use crate::common::solve_quadratic; | ||
use crate::common::GAUSS_LEGENDRE_COEFFS_9; | ||
use crate::common::{solve_quadratic, GAUSS_LEGENDRE_COEFFS_9}; | ||
use crate::{ | ||
Affine, Nearest, ParamCurve, ParamCurveArclen, ParamCurveArea, ParamCurveCurvature, | ||
ParamCurveDeriv, ParamCurveExtrema, ParamCurveNearest, PathEl, Point, QuadBez, Rect, Shape, | ||
|
@@ -238,7 +237,9 @@ impl CubicBez { | |
}) | ||
} | ||
|
||
fn parameters(&self) -> (Vec2, Vec2, Vec2, Vec2) { | ||
/// Get the parameters such that the curve can be represented by the following formula: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It bothers me slightly that this is in decreasing exponent, where, for example, solve_cubic is in increasing order. Not a dealbreaker though, if it's documented. (and I realize this is existing code, just thinking about it more carefully when we're making it public) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also bothers me that these functions are inconsistent. Since they're both public though, wouldn't it be an issue to change them? Perhaps it's better to just document the exponent order? |
||
/// B(t) = a*t^3 + b*t^2 + c*t + d | ||
pub fn parameters(&self) -> (Vec2, Vec2, Vec2, Vec2) { | ||
let c = (self.p1 - self.p0) * 3.0; | ||
let b = (self.p2 - self.p1) * 3.0 - c; | ||
let d = self.p0.to_vec2(); | ||
|
@@ -309,6 +310,13 @@ impl CubicBez { | |
pub fn is_nan(&self) -> bool { | ||
self.p0.is_nan() || self.p1.is_nan() || self.p2.is_nan() || self.p3.is_nan() | ||
} | ||
|
||
/// Is this cubic Bezier curve a line? | ||
#[inline] | ||
pub fn is_linear(&self, accuracy: f64) -> bool { | ||
self.baseline().nearest(self.p1, accuracy).distance_sq <= accuracy | ||
&& self.baseline().nearest(self.p2, accuracy).distance_sq <= accuracy | ||
} | ||
} | ||
|
||
/// An iterator for cubic beziers. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if Option might be a cleaner type. It's essentially the same type, and far more idiomatic Rust, but on the other hand, maybe it's better to keep it as it is, for consistency with the other methods.
It would also be good to document the degenerate case, as is done for quadratic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I like the idea of keeping it consistent. You're absolutely right that what I have is the equivalent of option though. I think it comes down to personal preference, but since you maintain this repo, I'll let you have the final say.