mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/graph] Fixed cache step quirks
Change-Id: I5b630301ab2a4b17a5a4d77c7d9a05120449e55e
This commit is contained in:
committed by
Émilie Feral
parent
1bee23cf4f
commit
beb228fa78
@@ -40,18 +40,8 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
}
|
||||
float tmin = f->tMin();
|
||||
float tmax = f->tMax();
|
||||
/* The step is a fraction of tmax-tmin. We will evaluate the function at
|
||||
* every step and if the consecutive dots are close enough, we won't
|
||||
* evaluate any more dot within the step. We pick a very strange fraction
|
||||
* denominator to avoid evaluating a periodic function periodically. For
|
||||
* example, if tstep was (tmax - tmin)/10, the polar function r(θ) = sin(5θ)
|
||||
* defined on 0..2π would be evaluated on r(0) = 0, r(π/5) = 0, r(2*π/5) = 0
|
||||
* which would lead to no curve at all. With 10.0938275501223, the
|
||||
* problematic functions are the functions whose period is proportionned to
|
||||
* 10.0938275501223 which are hopefully rare enough.
|
||||
* TODO: The drawCurve algorithm should use the derivative function to know
|
||||
* how fast the function moves... */
|
||||
float tstep = (tmax-tmin)/10.0938275501223f;
|
||||
|
||||
float tstep = (tmax-tmin)/k_graphStepDenominator;
|
||||
|
||||
float tCacheMin, tCacheStep;
|
||||
if (type == ContinuousFunction::PlotType::Cartesian) {
|
||||
@@ -60,7 +50,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
tCacheStep = pixelWidth();
|
||||
} else {
|
||||
tCacheMin = tmin;
|
||||
tCacheStep = tstep;
|
||||
tCacheStep = tstep / ContinuousFunctionCache::k_parametricStepFactor;
|
||||
}
|
||||
ContinuousFunctionCache::PrepareForCaching(f.operator->(), cch, tCacheMin, tCacheStep);
|
||||
|
||||
|
||||
@@ -7,6 +7,19 @@ namespace Graph {
|
||||
|
||||
class GraphView : public Shared::FunctionGraphView {
|
||||
public:
|
||||
/* The step is a fraction of tmax-tmin. We will evaluate the function at
|
||||
* every step and if the consecutive dots are close enough, we won't
|
||||
* evaluate any more dot within the step. We pick a very strange fraction
|
||||
* denominator to avoid evaluating a periodic function periodically. For
|
||||
* example, if tstep was (tmax - tmin)/10, the polar function r(θ) = sin(5θ)
|
||||
* defined on 0..2π would be evaluated on r(0) = 0, r(π/5) = 0, r(2*π/5) = 0
|
||||
* which would lead to no curve at all. With 10.0938275501223, the
|
||||
* problematic functions are the functions whose period is proportionned to
|
||||
* 10.0938275501223 which are hopefully rare enough.
|
||||
* TODO: The drawCurve algorithm should use the derivative function to know
|
||||
* how fast the function moves... */
|
||||
static constexpr float k_graphStepDenominator = 10.0938275501223f;
|
||||
|
||||
GraphView(Shared::InteractiveCurveViewRange * graphRange,
|
||||
Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, Shared::CursorView * cursorView);
|
||||
void reload() override;
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Shared {
|
||||
constexpr int ContinuousFunctionCache::k_sizeOfCache;
|
||||
constexpr float ContinuousFunctionCache::k_cacheHitTolerance;
|
||||
constexpr int ContinuousFunctionCache::k_numberOfAvailableCaches;
|
||||
constexpr int ContinuousFunctionCache::k_parametricStepFactor;
|
||||
|
||||
// public
|
||||
void ContinuousFunctionCache::PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep) {
|
||||
@@ -44,13 +45,6 @@ Poincare::Coordinate2D<float> ContinuousFunctionCache::valueForParameter(const C
|
||||
}
|
||||
|
||||
// private
|
||||
float ContinuousFunctionCache::StepFactor(ContinuousFunction * function) {
|
||||
/* When drawing a parametric or polar curve, the range is first divided by
|
||||
* ~10,9, creating 11 intervals which are filled by dichotomy.
|
||||
* We memoize 16 values for each of the 10 big intervals. */
|
||||
return (function->plotType() == ContinuousFunction::PlotType::Cartesian) ? 1.f : 16.f;
|
||||
}
|
||||
|
||||
void ContinuousFunctionCache::invalidateBetween(int iInf, int iSup) {
|
||||
for (int i = iInf; i < iSup; i++) {
|
||||
m_cache[i] = NAN;
|
||||
@@ -59,7 +53,7 @@ void ContinuousFunctionCache::invalidateBetween(int iInf, int iSup) {
|
||||
|
||||
void ContinuousFunctionCache::setRange(ContinuousFunction * function, float tMin, float tStep) {
|
||||
m_tMin = tMin;
|
||||
m_tStep = tStep / StepFactor(function);
|
||||
m_tStep = tStep;
|
||||
}
|
||||
|
||||
int ContinuousFunctionCache::indexForParameter(const ContinuousFunction * function, float t) const {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SHARED_CONTINUOUS_FUNCTION_CACHE_H
|
||||
#define SHARED_CONTINUOUS_FUNCTION_CACHE_H
|
||||
|
||||
#include "../graph/graph/graph_view.h"
|
||||
#include <ion/display.h>
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/coordinate_2D.h>
|
||||
@@ -10,10 +11,13 @@ namespace Shared {
|
||||
class ContinuousFunction;
|
||||
|
||||
class ContinuousFunctionCache {
|
||||
public:
|
||||
private:
|
||||
/* The size of the cache is chosen to optimize the display of cartesian
|
||||
* function */
|
||||
* functions */
|
||||
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);
|
||||
|
||||
static void PrepareForCaching(void * fun, ContinuousFunctionCache * cache, float tMin, float tStep);
|
||||
|
||||
@@ -23,13 +27,8 @@ public:
|
||||
void clear();
|
||||
Poincare::Coordinate2D<float> valueForParameter(const ContinuousFunction * function, Poincare::Context * context, float t);
|
||||
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 invalidateBetween(int iInf, int iSup);
|
||||
void setRange(ContinuousFunction * function, float tMin, float tStep);
|
||||
int indexForParameter(const ContinuousFunction * function, float t) const;
|
||||
|
||||
Reference in New Issue
Block a user