Fix brokenness in the curve smoothing
Originally committed to SVN as r6760.
This commit is contained in:
parent
a05d469741
commit
c354dc9e30
2 changed files with 9 additions and 9 deletions
|
@ -281,14 +281,14 @@ void Spline::Smooth(float smooth) {
|
||||||
if (size() < 3) return;
|
if (size() < 3) return;
|
||||||
|
|
||||||
// Smooth curve
|
// Smooth curve
|
||||||
iterator curve1 = end();
|
iterator cur_curve = end();
|
||||||
--curve1;
|
--cur_curve;
|
||||||
for (iterator cur = begin(); cur != end(); ) {
|
for (iterator cur = begin(); cur != end(); ) {
|
||||||
iterator curve0 = curve1;
|
iterator prev_curve = cur_curve;
|
||||||
curve1 = cur;
|
cur_curve = cur;
|
||||||
++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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,18 +74,18 @@ std::pair<SplineCurve, SplineCurve> SplineCurve::Split(float t) {
|
||||||
return std::make_pair(SplineCurve(p1), SplineCurve(p1));
|
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;
|
if (type != LINE || p1 == p2) return;
|
||||||
smooth = mid(0.f, smooth, 1.f);
|
smooth = mid(0.f, smooth, 1.f);
|
||||||
|
|
||||||
// Calculate intermediate points
|
// Calculate intermediate points
|
||||||
Vector2D c1 = (p0 + p1) / 2.f;
|
Vector2D c1 = (p0 + p1) / 2.f;
|
||||||
Vector2D c2 = (p1 + p2) / 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 len1 = (p1 - p0).Len();
|
||||||
float len2 = (p2 - p1).Len();
|
float len2 = (p2 - p1).Len();
|
||||||
float len3 = (p3 - p2).Len();
|
float len3 = (p5 - p2).Len();
|
||||||
|
|
||||||
float k1 = len1 / (len1 + len2);
|
float k1 = len1 / (len1 + len2);
|
||||||
float k2 = len2 / (len2 + len3);
|
float k2 = len2 / (len2 + len3);
|
||||||
|
|
Loading…
Reference in a new issue