Skip to content

Commit

Permalink
[poincare, graph] Factor helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNumworks authored and LeaNumworks committed Dec 7, 2020
1 parent ffebd2e commit 71be09b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/graph/test/caching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions apps/graph/test/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define APPS_GRAPH_TEST_HELPER_H

#include "../app.h"
#include "../../poincare/test/helper.h"

using namespace Poincare;
using namespace Shared;
Expand All @@ -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);

}
Expand Down
5 changes: 4 additions & 1 deletion apps/graph/test/ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +33,7 @@ class AdHocGraphController : public InteractiveCurveViewRangeDelegate {
};

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>
Expand Down
4 changes: 2 additions & 2 deletions poincare/test/zoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 71be09b

Please sign in to comment.