mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[shared/continuous_function_cache] Detach cache from function
When three functions or more, the third function and later don't use
caching. But it is still possible for them to have been linked to a
cache (for instance if previous functions had been deactivated earlier).
To avoid a function tapping into another function's cache, we reset the
cache.
e.g. Define 3 functions f(x)=1, g(x)=2, h(x)=3, and deactivate f.
Draw the graph, come back, reactivate f, then draw again.
---> The space between y=2 and y=3 will be filled with the color of h,
as h "remembers" using cache n°2, wich currently contains the values of
function g.
This commit is contained in:
committed by
LeaNumworks
parent
48bd7b6a77
commit
3501146e35
@@ -10,14 +10,16 @@ constexpr int ContinuousFunctionCache::k_numberOfAvailableCaches;
|
||||
|
||||
// public
|
||||
void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep) {
|
||||
ContinuousFunction * function = static_cast<ContinuousFunction *>(fun);
|
||||
|
||||
if (!cache) {
|
||||
/* ContinuousFunctionStore::cacheAtIndex has returned a nullptr : the index
|
||||
* of the function we are trying to draw is greater than the number of
|
||||
* available caches, so we do nothing.*/
|
||||
* available caches, so we just tell the function to not lookup any cache. */
|
||||
function->setCache(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -29,9 +31,7 @@ void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCa
|
||||
if (function->cache() != cache) {
|
||||
cache->clear();
|
||||
function->setCache(cache);
|
||||
}
|
||||
|
||||
if (tStep != 0. && tStep != cache->step()) {
|
||||
} else if (tStep != 0. && tStep != cache->step()) {
|
||||
cache->clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user