aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helpers/BezierCurve.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/helpers/BezierCurve.cpp b/src/helpers/BezierCurve.cpp
index 440a87c0..e018811c 100644
--- a/src/helpers/BezierCurve.cpp
+++ b/src/helpers/BezierCurve.cpp
@@ -45,24 +45,27 @@ float CBezierCurve::getXForT(float t) {
// Todo: this probably can be done better and faster
float CBezierCurve::getYForPoint(float x) {
+ if (x >= 1.0)
+ return 1.0;
+
// binary search for the range UPDOWN X
- float upperT = 1;
- float lowerT = 0;
- float mid = 0.5;
+ int upperT = BAKEDPOINTS - 1;
+ int lowerT = 0;
+ int mid = upperT / 2;
- while (std::abs(upperT - lowerT) > INVBAKEDPOINTS) {
- if (m_aPointsBaked[((int)(mid * (float)BAKEDPOINTS))].x > x) {
+ while (std::abs(upperT - lowerT) > 1) {
+ if (m_aPointsBaked[mid].x > x) {
upperT = mid;
} else {
lowerT = mid;
}
- mid = (upperT + lowerT) / 2.f;
+ mid = (upperT + lowerT) / 2;
}
// in the name of performance i shall make a hack
- const auto LOWERPOINT = &m_aPointsBaked[std::clamp((int)((float)BAKEDPOINTS * lowerT), 0, BAKEDPOINTS - 1)];
- const auto UPPERPOINT = &m_aPointsBaked[std::clamp((int)((float)BAKEDPOINTS * upperT), 0, BAKEDPOINTS - 1)];
+ const auto LOWERPOINT = &m_aPointsBaked[std::clamp(lowerT, 0, BAKEDPOINTS - 1)];
+ const auto UPPERPOINT = &m_aPointsBaked[std::clamp(upperT, 0, BAKEDPOINTS - 1)];
const auto PERCINDELTA = (x - LOWERPOINT->x) / (UPPERPOINT->x - LOWERPOINT->x);