[apps/shared] Halve k_parametricStepFactor to maximise cache hits

Change-Id: Ibe3c441e4af88277d1e4594801b805336a1f3e0b
This commit is contained in:
Hugo Saint-Vignes
2020-07-30 17:59:19 +02:00
committed by Émilie Feral
parent db4a1b0265
commit 52f83eb682
3 changed files with 8 additions and 5 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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);