Move bicubic point interpolation logic to SplineCurve
Originally committed to SVN as r6592.
This commit is contained in:
parent
ca76c5cf21
commit
d86d56d816
3 changed files with 52 additions and 41 deletions
|
@ -196,24 +196,6 @@ void Spline::MovePoint(iterator curve,int point,Vector2D pos) {
|
|||
}
|
||||
}
|
||||
|
||||
static int render_bicubic(Spline::iterator cur, std::vector<float> &points) {
|
||||
int len = int(
|
||||
(cur->p2 - cur->p1).Len() +
|
||||
(cur->p3 - cur->p2).Len() +
|
||||
(cur->p4 - cur->p3).Len());
|
||||
int steps = len/8;
|
||||
|
||||
for (int i = 0; i <= steps; ++i) {
|
||||
// Get t and t-1 (u)
|
||||
float t = i / float(steps);
|
||||
Vector2D p = cur->GetPoint(t);
|
||||
points.push_back(p.X());
|
||||
points.push_back(p.Y());
|
||||
}
|
||||
|
||||
return steps + 1;
|
||||
}
|
||||
|
||||
void Spline::GetPointList(std::vector<float>& points, std::vector<int>& first, std::vector<int>& count) {
|
||||
points.clear();
|
||||
first.clear();
|
||||
|
@ -224,30 +206,15 @@ void Spline::GetPointList(std::vector<float>& points, std::vector<int>& first, s
|
|||
|
||||
// Generate points for each curve
|
||||
for (iterator cur = begin(); cur != end(); ++cur) {
|
||||
switch (cur->type) {
|
||||
case SplineCurve::POINT:
|
||||
if (curCount > 0)
|
||||
count.push_back(curCount);
|
||||
if (cur->type == SplineCurve::POINT) {
|
||||
if (curCount > 0)
|
||||
count.push_back(curCount);
|
||||
|
||||
// start new path
|
||||
first.push_back(points.size() / 2);
|
||||
points.push_back(cur->p1.X());
|
||||
points.push_back(cur->p1.Y());
|
||||
curCount = 1;
|
||||
break;
|
||||
|
||||
case SplineCurve::LINE:
|
||||
points.push_back(cur->p2.X());
|
||||
points.push_back(cur->p2.Y());
|
||||
++curCount;
|
||||
break;
|
||||
|
||||
case SplineCurve::BICUBIC:
|
||||
curCount += render_bicubic(cur, points);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
// start new path
|
||||
first.push_back(points.size() / 2);
|
||||
curCount = 0;
|
||||
}
|
||||
curCount += cur->GetPoints(points);
|
||||
}
|
||||
|
||||
count.push_back(curCount);
|
||||
|
@ -265,7 +232,7 @@ void Spline::GetPointList(std::vector<float> &points, iterator curve) {
|
|||
break;
|
||||
|
||||
case SplineCurve::BICUBIC:
|
||||
render_bicubic(curve, points);
|
||||
curve->GetPoints(points);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
|
|
|
@ -169,3 +169,38 @@ float SplineCurve::GetClosestSegmentDistance(Vector2D pt1, Vector2D pt2, Vector2
|
|||
float t = GetClosestSegmentPart(pt1, pt2, pt3);
|
||||
return (pt1 * (1.f - t) + pt2 * t - pt3).Len();
|
||||
}
|
||||
|
||||
int SplineCurve::GetPoints(std::vector<float> &points) const {
|
||||
switch (type) {
|
||||
case POINT:
|
||||
points.push_back(p1.X());
|
||||
points.push_back(p1.Y());
|
||||
return 1;
|
||||
|
||||
case LINE:
|
||||
points.push_back(p2.X());
|
||||
points.push_back(p2.Y());
|
||||
return 1;
|
||||
|
||||
case BICUBIC: {
|
||||
int len = int(
|
||||
(p2 - p1).Len() +
|
||||
(p3 - p2).Len() +
|
||||
(p4 - p3).Len());
|
||||
int steps = len/8;
|
||||
|
||||
for (int i = 0; i <= steps; ++i) {
|
||||
// Get t and t-1 (u)
|
||||
float t = i / float(steps);
|
||||
Vector2D p = GetPoint(t);
|
||||
points.push_back(p.X());
|
||||
points.push_back(p.Y());
|
||||
}
|
||||
|
||||
return steps + 1;
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
|
||||
#include "vector2d.h"
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
/// DOCME
|
||||
/// @class SplineCurve
|
||||
/// @brief DOCME
|
||||
|
@ -83,4 +87,9 @@ public:
|
|||
float GetClosestParam(Vector2D ref) const;
|
||||
/// Get distance from ref to the closest point on the curve
|
||||
float GetQuickDistance(Vector2D ref) const;
|
||||
|
||||
/// Get the coordinates of each point on this curve
|
||||
/// @param[out] points Vector to add points to
|
||||
/// @return Number of points in the curve
|
||||
int GetPoints(std::vector<float> &points) const;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue