Fix brokenness in the curve smoothing

Originally committed to SVN as r6760.
This commit is contained in:
Thomas Goyne 2012-05-11 02:47:24 +00:00
parent a05d469741
commit c354dc9e30
2 changed files with 9 additions and 9 deletions

View file

@ -281,14 +281,14 @@ void Spline::Smooth(float smooth) {
if (size() < 3) return;
// Smooth curve
iterator curve1 = end();
--curve1;
iterator cur_curve = end();
--cur_curve;
for (iterator cur = begin(); cur != end(); ) {
iterator curve0 = curve1;
curve1 = cur;
iterator prev_curve = cur_curve;
cur_curve = cur;
++cur;
iterator curve2 = cur == end() ? begin() : cur;
iterator next_curve = cur == end() ? begin() : cur;
curve1->Smooth(curve0->p1, curve2->p2, smooth);
cur_curve->Smooth(prev_curve->p1, next_curve->EndPoint(), smooth);
}
}

View file

@ -74,18 +74,18 @@ std::pair<SplineCurve, SplineCurve> SplineCurve::Split(float t) {
return std::make_pair(SplineCurve(p1), SplineCurve(p1));
}
void SplineCurve::Smooth(Vector2D p0, Vector2D p3, float smooth) {
void SplineCurve::Smooth(Vector2D p0, Vector2D p5, float smooth) {
if (type != LINE || p1 == p2) return;
smooth = mid(0.f, smooth, 1.f);
// Calculate intermediate points
Vector2D c1 = (p0 + p1) / 2.f;
Vector2D c2 = (p1 + p2) / 2.f;
Vector2D c3 = (p2 + p3) / 2.f;
Vector2D c3 = (p2 + p5) / 2.f;
float len1 = (p1 - p0).Len();
float len2 = (p2 - p1).Len();
float len3 = (p3 - p2).Len();
float len3 = (p5 - p2).Len();
float k1 = len1 / (len1 + len2);
float k2 = len2 / (len2 + len3);