aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2023-03-03 13:33:52 +0000
committervaxerski <[email protected]>2023-03-03 13:33:52 +0000
commit64f35c0e3190f3b56a1c17e81c775966bd0a2251 (patch)
tree44a9a17734c35b59bfe9b9fae35ae1dca2e7ea8c /src
parent9c0e2bba54b8b14178c25c552d1be1089e2191ba (diff)
downloadHyprland-64f35c0e3190f3b56a1c17e81c775966bd0a2251.tar.gz
Hyprland-64f35c0e3190f3b56a1c17e81c775966bd0a2251.zip
Bezier: Fix incorrect binary search in bezier approx
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);