mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[apps/graph] Changed cache tolerance
This fixes a bug where, when drawing 1/x, a vertical bar would appear on 0, because of false positive cache hits. Change-Id: I2eafeac5e254c8a556769a41c8edc532db44383a
This commit is contained in:
committed by
Émilie Feral
parent
beb228fa78
commit
b0533e6836
@@ -19,6 +19,14 @@ void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCa
|
||||
}
|
||||
|
||||
ContinuousFunction * function = static_cast<ContinuousFunction *>(fun);
|
||||
if (tStep < 3 * k_cacheHitTolerance) {
|
||||
/* If tStep is lower than twice the tolerance, we risk shifting the index
|
||||
* by 1 for cache hits. As an added safety, we add another buffer of
|
||||
* k_cacheHitTolerance, raising the threshold for caching to three times
|
||||
* the tolerance. */
|
||||
function->clearCache();
|
||||
return;
|
||||
}
|
||||
if (function->cache() != cache) {
|
||||
cache->clear();
|
||||
function->setCache(cache);
|
||||
|
||||
@@ -27,7 +27,15 @@ public:
|
||||
void clear();
|
||||
Poincare::Coordinate2D<float> valueForParameter(const ContinuousFunction * function, Poincare::Context * context, float t);
|
||||
private:
|
||||
static constexpr float k_cacheHitTolerance = 1e-3;
|
||||
/* We need a certain amount of tolerance since we try to evaluate the
|
||||
* equality of floats. But the value has to be chosen carefully. Too high of
|
||||
* a tolerance causes false positives, which lead to errors in curves
|
||||
* (ex : 1/x with a vertical line at 0). Too low of a tolerance causes false
|
||||
* negatives, which slows down the drawing.
|
||||
*
|
||||
* 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;
|
||||
|
||||
void invalidateBetween(int iInf, int iSup);
|
||||
void setRange(ContinuousFunction * function, float tMin, float tStep);
|
||||
|
||||
Reference in New Issue
Block a user