mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared] Implemented function memoization
ContinuousFunction now has an attribute of type ContinuousFunctionCache, implementing methods to store and retrieve 320 float values, in order to speed up function display in Graph. Change-Id: I6f7ccdf3ae3c6dd8b08b93d786c8d0be7aa4dee8
This commit is contained in:
committed by
Émilie Feral
parent
0308b18400
commit
552dca9494
48
apps/shared/continuous_function_cache.h
Normal file
48
apps/shared/continuous_function_cache.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef SHARED_CONTINUOUS_FUNCTION_CACHE_H
|
||||
#define SHARED_CONTINUOUS_FUNCTION_CACHE_H
|
||||
|
||||
#include <ion/display.h>
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/coordinate_2D.h>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class ContinuousFunction;
|
||||
|
||||
class ContinuousFunctionCache {
|
||||
public:
|
||||
static void PrepareCache(void * f, void * c, float tMin, float tStep);
|
||||
|
||||
float step() const { return m_tStep; }
|
||||
bool filled() const { return m_filled; }
|
||||
void clear();
|
||||
Poincare::Coordinate2D<float> valueForParameter(const ContinuousFunction * function, float t) const;
|
||||
private:
|
||||
/* The size of the cache is chosen to optimize the display of cartesian
|
||||
* function */
|
||||
static constexpr int k_sizeOfCache = Ion::Display::Width;
|
||||
static constexpr float k_cacheHitTolerance = 1e-3;
|
||||
|
||||
static float StepFactor(ContinuousFunction * function);
|
||||
|
||||
void setRange(ContinuousFunction * function, float tMin, float tStep);
|
||||
void memoize(ContinuousFunction * function, Poincare::Context * context);
|
||||
void memoizeYForX(ContinuousFunction * function, Poincare::Context * context);
|
||||
void memoizeYForXBetweenIndices(ContinuousFunction * function, Poincare::Context * context, int iInf, int iSup);
|
||||
void memoizeXYForT(ContinuousFunction * function, Poincare::Context * context);
|
||||
float parameterForIndex(int i) const;
|
||||
int indexForParameter(const ContinuousFunction * function, float t) const;
|
||||
void pan(ContinuousFunction * function, Poincare::Context * context, float newTMin);
|
||||
|
||||
float m_tMin, m_tStep;
|
||||
float m_cache[k_sizeOfCache];
|
||||
/* m_startOfCache is used to implement a circular buffer for easy panning
|
||||
* with cartesian functions. When dealing with parametric or polar functions,
|
||||
* m_startOfCache should be zero.*/
|
||||
int m_startOfCache;
|
||||
bool m_filled;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user