diff --git a/aegisub/src/spline.cpp b/aegisub/src/spline.cpp index 515e78237..e3a202273 100644 --- a/aegisub/src/spline.cpp +++ b/aegisub/src/spline.cpp @@ -196,24 +196,6 @@ void Spline::MovePoint(iterator curve,int point,Vector2D pos) { } } -static int render_bicubic(Spline::iterator cur, std::vector &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& points, std::vector& first, std::vector& count) { points.clear(); first.clear(); @@ -224,30 +206,15 @@ void Spline::GetPointList(std::vector& points, std::vector& 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 &points, iterator curve) { break; case SplineCurve::BICUBIC: - render_bicubic(curve, points); + curve->GetPoints(points); break; default: break; diff --git a/aegisub/src/spline_curve.cpp b/aegisub/src/spline_curve.cpp index a9e206425..0e4569583 100644 --- a/aegisub/src/spline_curve.cpp +++ b/aegisub/src/spline_curve.cpp @@ -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 &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; + } +} diff --git a/aegisub/src/spline_curve.h b/aegisub/src/spline_curve.h index 42a5c0140..ad216a320 100644 --- a/aegisub/src/spline_curve.h +++ b/aegisub/src/spline_curve.h @@ -36,6 +36,10 @@ #include "vector2d.h" +#ifndef AGI_PRE +#include +#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 &points) const; };