Struct stroke::quadratic_bezier::QuadraticBezier
source · pub struct QuadraticBezier<P: Point> { /* private fields */ }
Implementations§
source§impl<P> QuadraticBezier<P>where
P: Point,
impl<P> QuadraticBezier<P>where P: Point,
sourcepub fn new(start: P, ctrl: P, end: P) -> Self
pub fn new(start: P, ctrl: P, end: P) -> Self
Creates a new instance of QuadraticBezier from the given control points
sourcepub fn eval(&self, t: P::Scalar) -> P
pub fn eval(&self, t: P::Scalar) -> P
Evaluates the quadratic bezier curve at ‘t’ using direct evaluation, which may not be numerically stable
sourcepub fn eval_casteljau(&self, t: P::Scalar) -> P
pub fn eval_casteljau(&self, t: P::Scalar) -> P
Evaluates the cubic bezier curve at t using the numerically stable De Casteljau algorithm
pub fn control_points(&self) -> [P; 3]
pub fn split(&self, t: P::Scalar) -> (Self, Self)
sourcepub fn axis(&self, t: P::Scalar, axis: usize) -> P::Scalar
pub fn axis(&self, t: P::Scalar, axis: usize) -> P::Scalar
Sample the a particular coordinate axis of the curve at t (expecting t between 0 and 1). Shortcut for curve.eval(t).axis(k) This function can panic! TODO may add something like const_assert for Point’s const DIM
sourcepub fn derivative(&self) -> LineSegment<P>
pub fn derivative(&self) -> LineSegment<P>
Return the derivative curve. The derivative is also a bezier curve but of degree n-1. In the case of a quadratic derivative it is just a line segment which also implementes eval(), as it is just a linear bezier curve.
sourcepub fn dd(&self, t: P::Scalar, axis: usize) -> P::Scalar
pub fn dd(&self, t: P::Scalar, axis: usize) -> P::Scalar
Direct Derivative - Sample the axis coordinate at ‘axis’ of the curve’s derivative at t
without creating a new curve. This is a convenience function for .derivative().eval(t).axis(n)
Parameters:
t: the sampling parameter on the curve interval [0..1]
axis: the index of the coordinate axis [0..N]
Returns:
Scalar value of the points own type type F
May be deprecated in the future.
This function can cause out of bounds panic when axis is larger than dimension of P
sourcepub fn arclen(&self, nsteps: usize) -> P::Scalar
pub fn arclen(&self, nsteps: usize) -> P::Scalar
Approximates the arc length of the curve by flattening it with straight line segments. This works quite well, at ~32 segments it should already provide an error < 0.5 Remember arclen also works by linear approximation, not the integral, so we have to accept error! This approximation is unfeasable if desired accuracy is greater than 2 decimal places
sourcepub fn distance_to_point(&self, point: P) -> P::Scalar
pub fn distance_to_point(&self, point: P) -> P::Scalar
Calculates the minimum distance between given ‘point’ and the curve. Uses two passes with the same amount of steps in t:
- coarse search over the whole curve
- fine search around the minimum yielded by the coarse search
sourcepub fn baseline(&self) -> LineSegment<P>
pub fn baseline(&self) -> LineSegment<P>
Returns the line segment formed by the curve’s start and endpoint
sourcepub fn is_linear(&self, tolerance: P::Scalar) -> bool
pub fn is_linear(&self, tolerance: P::Scalar) -> bool
Checks if, given some tolerance, the curve can be considered equal to a line segment
sourcepub fn is_a_point(&self, tolerance: P::Scalar) -> bool
pub fn is_a_point(&self, tolerance: P::Scalar) -> bool
Determines if, given some tolerance, the control points of the curve can be considered equal. If true, the curve is just a singular point
sourcepub fn bounding_box(&self) -> [(P::Scalar, P::Scalar); P::DIM]
pub fn bounding_box(&self) -> [(P::Scalar, P::Scalar); P::DIM]
Return the bounding box of the curve as an array of (min, max) tuples for each dimension (its index)
Trait Implementations§
source§impl<P: Clone + Point> Clone for QuadraticBezier<P>
impl<P: Clone + Point> Clone for QuadraticBezier<P>
source§fn clone(&self) -> QuadraticBezier<P>
fn clone(&self) -> QuadraticBezier<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<P> From<QuadraticBezier<P>> for BezierSegment<P>where
P: Point,
impl<P> From<QuadraticBezier<P>> for BezierSegment<P>where P: Point,
source§fn from(s: QuadraticBezier<P>) -> Self
fn from(s: QuadraticBezier<P>) -> Self
source§impl<P: PartialEq + Point> PartialEq<QuadraticBezier<P>> for QuadraticBezier<P>
impl<P: PartialEq + Point> PartialEq<QuadraticBezier<P>> for QuadraticBezier<P>
source§fn eq(&self, other: &QuadraticBezier<P>) -> bool
fn eq(&self, other: &QuadraticBezier<P>) -> bool
self
and other
values to be equal, and is used
by ==
.