diff options
Diffstat (limited to 'src/helpers/BezierCurve.cpp')
| -rw-r--r-- | src/helpers/BezierCurve.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/helpers/BezierCurve.cpp b/src/helpers/BezierCurve.cpp index bdf2c4b1..07726b8d 100644 --- a/src/helpers/BezierCurve.cpp +++ b/src/helpers/BezierCurve.cpp @@ -5,13 +5,13 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) { const auto BEGIN = std::chrono::high_resolution_clock::now(); - m_dPoints.emplace_back(Vector2D(0,0)); + m_dPoints.emplace_back(Vector2D(0, 0)); for (auto& p : *pVec) { m_dPoints.push_back(p); } - m_dPoints.emplace_back(Vector2D(1,1)); + m_dPoints.emplace_back(Vector2D(1, 1)); RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: %i)", m_dPoints.size()); @@ -21,7 +21,7 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) { m_aPointsBaked[i] = Vector2D(getXForT((i + 1) / (float)BAKEDPOINTS), getYForT((i + 1) / (float)BAKEDPOINTS)); } - const auto ELAPSEDUS = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGIN).count() / 1000.f; + const auto ELAPSEDUS = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGIN).count() / 1000.f; const auto POINTSSIZE = m_aPointsBaked.size() * sizeof(m_aPointsBaked[0]) / 1000.f; const auto BEGINCALC = std::chrono::high_resolution_clock::now(); @@ -29,9 +29,8 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) { getYForPoint(i); const auto ELAPSEDCALCAVG = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGINCALC).count() / 1000.f / 10.f; - Debug::log(LOG, "Created a bezier curve, baked %i points, mem usage: %.2fkB, time to bake: %.2fµs. Estimated average calc time: %.2fµs.", - BAKEDPOINTS, POINTSSIZE, ELAPSEDUS, ELAPSEDCALCAVG); - + Debug::log(LOG, "Created a bezier curve, baked %i points, mem usage: %.2fkB, time to bake: %.2fµs. Estimated average calc time: %.2fµs.", BAKEDPOINTS, POINTSSIZE, ELAPSEDUS, + ELAPSEDCALCAVG); } float CBezierCurve::getYForT(float t) { @@ -47,9 +46,9 @@ float CBezierCurve::getYForPoint(float x) { // binary search for the range UPDOWN X float upperT = 1; float lowerT = 0; - float mid = 0.5; + float mid = 0.5; - while(std::abs(upperT - lowerT) > INVBAKEDPOINTS) { + while (std::abs(upperT - lowerT) > INVBAKEDPOINTS) { if (m_aPointsBaked[((int)(mid * (float)BAKEDPOINTS))].x > x) { upperT = mid; } else { @@ -65,7 +64,7 @@ float CBezierCurve::getYForPoint(float x) { const auto PERCINDELTA = (x - LOWERPOINT->x) / (UPPERPOINT->x - LOWERPOINT->x); - if (std::isnan(PERCINDELTA) || std::isinf(PERCINDELTA)) // can sometimes happen for VERY small x + if (std::isnan(PERCINDELTA) || std::isinf(PERCINDELTA)) // can sometimes happen for VERY small x return 0.f; return LOWERPOINT->y + (UPPERPOINT->y - UPPERPOINT->y) * PERCINDELTA; |
