-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
CubicBezier should not allow constructing discontinuous curves #13726
Description
What's wrong?
CubicBezier says that it produces continuous output, but it actually just constructs a bunch of cubic Bézier segments which a priori have nothing to do with each other. The problem is that its input is essentially a Vec<[P; 4]> — an array of quadruples of control points which it takes ownership of:
/// Create a new cubic Bezier curve from sets of control points.
pub fn new(control_points: impl Into<Vec<[P; 4]>>) -> Self {
Self {
control_points: control_points.into(),
}
}Each quadruple of control points is then used to construct a single CubicSegment. The problem here is that the guarantees from the Bézier construction do not relate these sets of control points to each other at all. For instance, the first segment of the curve will end at the last control point of the first quadruple and start at the first control point of the next.
Generally, the expectation for this kind of construction is that the last control point of one quadruple is the same as the first control point of the next. Thus, the correct input data to such a construction is actually 4 + 3k control points, and the output is actually guaranteed to be continuous from the inputs alone.
In case users actually want to construct arbitrary unions of Bézier segments for some reason, that should be done through CubicCurve or CubicSegment. (I am not sure this is very ergonomic right now, but it probably does not need to be.)