forked from mia/Aegisub
Return a pair of SplineCurves from SplineCurve::Split rather than mutating the arguments, as it doesn't actually work in-place
Originally committed to SVN as r6100.
This commit is contained in:
parent
400b8252e9
commit
5e9339611b
3 changed files with 15 additions and 12 deletions
|
@ -51,10 +51,12 @@ SplineCurve::SplineCurve(Vector2D p1, Vector2D p2, Vector2D p3, Vector2D p4)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplineCurve::Split(SplineCurve &c1, SplineCurve &c2, float t) {
|
std::pair<SplineCurve, SplineCurve> SplineCurve::Split(float t) {
|
||||||
if (type == LINE) {
|
if (type == LINE) {
|
||||||
c1 = SplineCurve(p1, p1 * (1 - t) + p2 * t);
|
Vector2D m = p1 * (1 - t) + p2 * t;
|
||||||
c2 = SplineCurve(c1.p2, p2);
|
return std::make_pair(
|
||||||
|
SplineCurve(p1, m),
|
||||||
|
SplineCurve(m, p2));
|
||||||
}
|
}
|
||||||
else if (type == BICUBIC) {
|
else if (type == BICUBIC) {
|
||||||
float u = 1 - t;
|
float u = 1 - t;
|
||||||
|
@ -65,9 +67,11 @@ void SplineCurve::Split(SplineCurve &c1, SplineCurve &c2, float t) {
|
||||||
Vector2D p234 = p23 * u + p34 * t;
|
Vector2D p234 = p23 * u + p34 * t;
|
||||||
Vector2D p1234 = p123 * u + p234 * t;
|
Vector2D p1234 = p123 * u + p234 * t;
|
||||||
|
|
||||||
c1 = SplineCurve(p1, p12, p123, p1234);
|
return std::make_pair(
|
||||||
c2 = SplineCurve(p1234, p234, p34, p4);
|
SplineCurve(p1, p12, p123, p1234),
|
||||||
|
SplineCurve(p1234, p234, p34, p4));
|
||||||
}
|
}
|
||||||
|
return std::make_pair(SplineCurve(p1), SplineCurve(p1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplineCurve::Smooth(Vector2D p0, Vector2D p3, float smooth) {
|
void SplineCurve::Smooth(Vector2D p0, Vector2D p3, float smooth) {
|
||||||
|
|
|
@ -67,10 +67,9 @@ public:
|
||||||
SplineCurve(Vector2D p1, Vector2D p2, Vector2D p3, Vector2D p4);
|
SplineCurve(Vector2D p1, Vector2D p2, Vector2D p3, Vector2D p4);
|
||||||
|
|
||||||
/// @brief Split a curve in two using the de Casteljau algorithm
|
/// @brief Split a curve in two using the de Casteljau algorithm
|
||||||
/// @param[out] c1 Curve before split point
|
/// @param t Split point from 0-1
|
||||||
/// @param[out] c2 Curve after split point
|
/// @return Curve before and after the split point
|
||||||
/// @param t Split point
|
std::pair<SplineCurve, SplineCurve> Split(float t = 0.5f);
|
||||||
void Split(SplineCurve &c1, SplineCurve &c2, float t = 0.5f);
|
|
||||||
|
|
||||||
/// @brief Smooths the curve
|
/// @brief Smooths the curve
|
||||||
/// @note Based on http://antigrain.com/research/bezier_interpolation/index.html
|
/// @note Based on http://antigrain.com/research/bezier_interpolation/index.html
|
||||||
|
|
|
@ -289,9 +289,9 @@ bool VisualToolVectorClip::InitializeHold() {
|
||||||
spline.push_back(ct);
|
spline.push_back(ct);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SplineCurve c2;
|
std::pair<SplineCurve, SplineCurve> split = curve->Split(t);
|
||||||
curve->Split(*curve, c2, t);
|
*curve = split.first;
|
||||||
spline.insert(++curve, c2);
|
spline.insert(++curve, split.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue