mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare, graph] Factor helper function
This commit is contained in:
committed by
LeaNumworks
parent
ffebd2e987
commit
71be09b4e7
@@ -10,7 +10,7 @@ namespace Graph {
|
||||
bool floatEquals(float a, float b, float tolerance = 1.f/static_cast<float>(Ion::Display::Height)) {
|
||||
/* The default value for the tolerance is chosen so that the error introduced
|
||||
* by caching would not typically be visible on screen. */
|
||||
return a == b || std::abs(a - b) <= tolerance * std::abs(a + b) / 2.f || (std::isnan(a) && std::isnan(b));
|
||||
return (std::isnan(a) && std::isnan(b)) || IsApproximatelyEqual(a, b, tolerance, 0.);
|
||||
}
|
||||
|
||||
void assert_check_cartesian_cache_against_function(ContinuousFunction * function, ContinuousFunctionCache * cache, Context * context, float tMin) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define APPS_GRAPH_TEST_HELPER_H
|
||||
|
||||
#include "../app.h"
|
||||
#include "../../poincare/test/helper.h"
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
@@ -12,10 +13,6 @@ constexpr ContinuousFunction::PlotType Cartesian = ContinuousFunction::PlotType:
|
||||
constexpr ContinuousFunction::PlotType Polar = ContinuousFunction::PlotType::Polar;
|
||||
constexpr ContinuousFunction::PlotType Parametric = ContinuousFunction::PlotType::Parametric;
|
||||
|
||||
constexpr Preferences::AngleUnit Radian = Preferences::AngleUnit::Radian;
|
||||
constexpr Preferences::AngleUnit Degree = Preferences::AngleUnit::Degree;
|
||||
constexpr Preferences::AngleUnit Gradian = Preferences::AngleUnit::Gradian;
|
||||
|
||||
ContinuousFunction * addFunction(const char * definition, ContinuousFunction::PlotType type, ContinuousFunctionStore * store, Context * context);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace Graph {
|
||||
|
||||
class AdHocGraphController : public InteractiveCurveViewRangeDelegate {
|
||||
public:
|
||||
/* These margins are obtained from instance methods of the various derived
|
||||
* class of SimpleInteractiveCurveViewController. As we cannot create an
|
||||
* instance of this class here, we define those directly. */
|
||||
static constexpr float k_topMargin = 0.068f;
|
||||
static constexpr float k_bottomMargin = 0.132948f;
|
||||
static constexpr float k_leftMargin = 0.04f;
|
||||
@@ -30,7 +33,7 @@ private:
|
||||
};
|
||||
|
||||
bool float_equal(float a, float b, float tolerance = 10.f * FLT_EPSILON) {
|
||||
return std::fabs(a - b) <= tolerance * std::fabs(a + b);
|
||||
return IsApproximatelyEqual(a, b, tolerance, 0.);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
// When adding the graph window margins, this ratio gives an orthonormal window
|
||||
constexpr float NormalRatio = 0.442358822;
|
||||
constexpr float StandardTolerance = 10.f * FLT_EPSILON;
|
||||
constexpr float StandardTolerance = 50.f * FLT_EPSILON;
|
||||
|
||||
class ParametersPack {
|
||||
public:
|
||||
@@ -35,7 +35,7 @@ float evaluate_expression(float x, Context * context, const void * auxiliary) {
|
||||
bool float_equal(float a, float b, float tolerance = StandardTolerance) {
|
||||
assert(std::isfinite(tolerance));
|
||||
return !(std::isnan(a) || std::isnan(b))
|
||||
&& std::fabs(a - b) <= tolerance * std::fabs(a + b);
|
||||
&& IsApproximatelyEqual(a, b, tolerance, 0.);
|
||||
}
|
||||
|
||||
bool range1D_matches(float min, float max, float targetMin, float targetMax, float tolerance = StandardTolerance) {
|
||||
|
||||
Reference in New Issue
Block a user