mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/probability] Forbid impossible value in parameters and calculation
parameters Change-Id: I47aae775dc031d5b78d6995ca63f49d537848cb1
This commit is contained in:
committed by
Romain Goyet
parent
f636974c0f
commit
9b2bc019e4
@@ -7,8 +7,14 @@ namespace Probability {
|
||||
|
||||
class Calculation {
|
||||
public:
|
||||
enum class Type : uint8_t{
|
||||
LeftIntegral,
|
||||
RightIntegral,
|
||||
FiniteIntegral
|
||||
};
|
||||
Calculation();
|
||||
virtual ~Calculation() {};
|
||||
virtual Type type() = 0;
|
||||
void setLaw(Law * law);
|
||||
virtual int numberOfParameters() = 0;
|
||||
virtual const char * legendForParameterAtIndex(int index) = 0;
|
||||
|
||||
@@ -14,6 +14,10 @@ FiniteIntegralCalculation::FiniteIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type FiniteIntegralCalculation::type() {
|
||||
return Type::FiniteIntegral;
|
||||
}
|
||||
|
||||
int FiniteIntegralCalculation::numberOfParameters() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class FiniteIntegralCalculation : public Calculation {
|
||||
public:
|
||||
FiniteIntegralCalculation();
|
||||
~FiniteIntegralCalculation() override {};
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
const char * legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(float f, int index) override;
|
||||
|
||||
@@ -13,6 +13,10 @@ LeftIntegralCalculation::LeftIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type LeftIntegralCalculation::type() {
|
||||
return Type::LeftIntegral;
|
||||
}
|
||||
|
||||
int LeftIntegralCalculation::numberOfParameters() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class LeftIntegralCalculation : public Calculation {
|
||||
public:
|
||||
LeftIntegralCalculation();
|
||||
~LeftIntegralCalculation() override {};
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
const char * legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(float f, int index) override;
|
||||
|
||||
@@ -13,6 +13,10 @@ RightIntegralCalculation::RightIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type RightIntegralCalculation::type() {
|
||||
return Type::RightIntegral;
|
||||
}
|
||||
|
||||
int RightIntegralCalculation::numberOfParameters() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class RightIntegralCalculation : public Calculation {
|
||||
public:
|
||||
RightIntegralCalculation();
|
||||
~RightIntegralCalculation() override {};
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
const char * legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(float f, int index) override;
|
||||
|
||||
@@ -203,6 +203,14 @@ bool CalculationController::textFieldDidFinishEditing(TextField * textField, con
|
||||
App * probaApp = (App *)app();
|
||||
Context * globalContext = probaApp->container()->globalContext();
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext);
|
||||
if (m_calculation->type() != Calculation::Type::FiniteIntegral && m_highlightedSubviewIndex == 2) {
|
||||
if (floatBody < 0.0f) {
|
||||
floatBody = 0.0f;
|
||||
}
|
||||
if (floatBody > 1.0f) {
|
||||
floatBody = 1.0f;
|
||||
}
|
||||
}
|
||||
m_calculation->setParameterAtIndex(floatBody, m_highlightedSubviewIndex-1);
|
||||
for (int k = 0; k < m_calculation->numberOfParameters(); k++) {
|
||||
m_contentView.willDisplayEditableCellAtIndex(k);
|
||||
|
||||
@@ -99,7 +99,7 @@ float BinomialLaw::evaluateAtAbscissa(float x) const {
|
||||
|
||||
bool BinomialLaw::authorizedValueAtIndex(float x, int index) const {
|
||||
if (index == 0) {
|
||||
if (x != (int)x) {
|
||||
if (x != (int)x || x < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user