From 52f83eb68209fc35b59d449eaa8dd2ec365fdc28 Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Thu, 30 Jul 2020 17:59:19 +0200 Subject: [PATCH] [apps/shared] Halve k_parametricStepFactor to maximise cache hits Change-Id: Ibe3c441e4af88277d1e4594801b805336a1f3e0b --- apps/graph/graph/graph_view.cpp | 4 ++-- apps/shared/continuous_function_cache.cpp | 2 +- apps/shared/continuous_function_cache.h | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index d455cdb9d..907d4b100 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -41,7 +41,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const { float tmin = f->tMin(); float tmax = f->tMax(); - float tstep = (tmax-tmin)/k_graphStepDenominator; + float tstep = (tmax-tmin) / k_graphStepDenominator; float tCacheMin, tCacheStep; if (type == ContinuousFunction::PlotType::Cartesian) { @@ -50,7 +50,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const { tCacheStep = pixelWidth(); } else { tCacheMin = tmin; - tCacheStep = tstep / ContinuousFunctionCache::k_parametricStepFactor; + tCacheStep = int(k_graphStepDenominator) * tstep / ContinuousFunctionCache::k_numberOfParametricCacheablePoints; } ContinuousFunctionCache::PrepareForCaching(f.operator->(), cch, tCacheMin, tCacheStep); diff --git a/apps/shared/continuous_function_cache.cpp b/apps/shared/continuous_function_cache.cpp index 24435e926..ce43fd312 100644 --- a/apps/shared/continuous_function_cache.cpp +++ b/apps/shared/continuous_function_cache.cpp @@ -7,7 +7,7 @@ namespace Shared { constexpr int ContinuousFunctionCache::k_sizeOfCache; constexpr float ContinuousFunctionCache::k_cacheHitTolerance; constexpr int ContinuousFunctionCache::k_numberOfAvailableCaches; -constexpr int ContinuousFunctionCache::k_parametricStepFactor; +constexpr int ContinuousFunctionCache::k_numberOfParametricCacheablePoints; // public void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep) { diff --git a/apps/shared/continuous_function_cache.h b/apps/shared/continuous_function_cache.h index 60faca9b8..2d035c34c 100644 --- a/apps/shared/continuous_function_cache.h +++ b/apps/shared/continuous_function_cache.h @@ -17,7 +17,10 @@ private: static constexpr int k_sizeOfCache = Ion::Display::Width; public: static constexpr int k_numberOfAvailableCaches = 2; - static constexpr int k_parametricStepFactor = k_sizeOfCache / int(Graph::GraphView::k_graphStepDenominator); + /* Parametric and polar functions require caching both x and y values, + * with the same k_sizeOfCache. To cover the entire range, + * k_numberOfParametricCacheablePoints is halved. */ + static constexpr int k_numberOfParametricCacheablePoints = k_sizeOfCache / 2; static void PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep); @@ -35,7 +38,7 @@ private: * * The value 128*FLT_EPSILON has been found to be the lowest for which all * indices verify indexForParameter(tMin + index * tStep) = index. */ - static constexpr float k_cacheHitTolerance = 128 * FLT_EPSILON; + static constexpr float k_cacheHitTolerance = 128.0f * FLT_EPSILON; void invalidateBetween(int iInf, int iSup); void setRange(ContinuousFunction * function, float tMin, float tStep);