[apps/graph/test] Fix caching test

Change-Id: I536d1422ca6c9ecded66f7876ae019aaf5742005
This commit is contained in:
Hugo Saint-Vignes
2020-08-31 11:21:55 +02:00
committed by Émilie Feral
parent 70a628f2c8
commit 8fdec305c4
4 changed files with 35 additions and 17 deletions

View File

@@ -7,7 +7,6 @@ namespace Shared {
constexpr int ContinuousFunctionCache::k_sizeOfCache;
constexpr float ContinuousFunctionCache::k_cacheHitTolerance;
constexpr int ContinuousFunctionCache::k_numberOfAvailableCaches;
constexpr int ContinuousFunctionCache::k_numberOfParametricCacheablePoints;
// public
void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep) {
@@ -52,6 +51,26 @@ Poincare::Coordinate2D<float> ContinuousFunctionCache::valueForParameter(const C
return valuesAtIndex(function, context, t, resIndex);
}
void ContinuousFunctionCache::ComputeNonCartesianSteps(float * tStep, float * tCacheStep, float tMax, float tMin) {
// Expected step length
*tStep = (tMax - tMin) / 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,
* number of cacheable points is half the cache size. */
const int numberOfCacheablePoints = k_sizeOfCache / 2;
const int numberOfWholeSteps = static_cast<int>(Graph::GraphView::k_graphStepDenominator);
static_assert(numberOfCacheablePoints % numberOfWholeSteps == 0, "numberOfCacheablePoints should be a multiple of numberOfWholeSteps for optimal caching");
/* Define cacheStep such that every whole graph steps are equally divided
* For instance, with :
* graphStepDenominator = 10.1
* numberOfCacheablePoints = 160
* tMin [----------------|----------------| ... |----------------|**] tMax
* step1 step2 step10 step11
* There are 11 steps, the first 10 are whole and have an equal size (tStep).
* There are 16 cache points in the first 10 steps, 160 total cache points. */
*tCacheStep = *tStep * numberOfWholeSteps / numberOfCacheablePoints;
}
// private
void ContinuousFunctionCache::invalidateBetween(int iInf, int iSup) {
for (int i = iInf; i < iSup; i++) {