Merge changes I25eb7608,I1cf5175e

* changes:
  [apps] Add angle unit preference in apps
  [apps] [poincare] Merge AngleUnit enum class (previously in preference and expression)
This commit is contained in:
Émilie Feral
2017-02-14 15:45:07 +01:00
committed by Gerrit
16 changed files with 50 additions and 36 deletions

View File

@@ -59,7 +59,7 @@ void Calculation::setContent(const char * c, Context * context, Preferences * pr
if (m_output != nullptr) {
delete m_output;
}
m_output = m_input->evaluate(*context);
m_output = m_input->evaluate(*context, preferences->angleUnit());
if (m_outputLayout != nullptr) {
delete m_outputLayout;
}

View File

@@ -23,7 +23,7 @@ bool EditableCellTableViewController::textFieldDidReceiveEvent(TextField * textF
bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * textField, const char * text) {
AppsContainer * appsContainer = (AppsContainer *)app()->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
setDataAtLocation(floatBody, m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
willDisplayCellAtLocation(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()), m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
m_selectableTableView.reloadData();

View File

@@ -34,7 +34,7 @@ void FloatParameterController::willDisplayCellForIndex(TableViewCell * cell, int
bool FloatParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) {
AppsContainer * appsContainer = (AppsContainer *)app()->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
setParameterAtIndex(m_selectableTableView.selectedRow(), floatBody);
willDisplayCellForIndex(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(),
m_selectableTableView.selectedRow()), activeCell());

View File

@@ -75,19 +75,19 @@ void Function::setDisplayDerivative(bool display) {
m_displayDerivative = display;
}
float Function::evaluateAtAbscissa(float x, Context * context) const {
float Function::evaluateAtAbscissa(float x, Context * context, Expression::AngleUnit angleUnit) const {
Symbol xSymbol = Symbol('x');
Float e = Float(x);
context->setExpressionForSymbolName(&e, &xSymbol);
return m_expression->approximate(*context);
return m_expression->approximate(*context, angleUnit);
}
float Function::approximateDerivative(float x, Context * context) const {
float Function::approximateDerivative(float x, Context * context, Expression::AngleUnit angleUnit) const {
Float abscissa = Float(x);
Expression * args[2] = {m_expression, &abscissa};
Derivative derivative = Derivative();
derivative.setArgument(args, 2, true);
return derivative.approximate(*context);
return derivative.approximate(*context, angleUnit);
}
}

View File

@@ -23,8 +23,8 @@ public:
void setDisplayDerivative(bool display);
void setContent(const char * c);
void setColor(KDColor m_color);
float evaluateAtAbscissa(float x, Context * context) const;
float approximateDerivative(float x, Context * context) const;
float evaluateAtAbscissa(float x, Context * context, Expression::AngleUnit angleUnit) const;
float approximateDerivative(float x, Context * context, Expression::AngleUnit angleUnit) const;
private:
constexpr static float k_epsilon = 0.0001f;
constexpr static float k_precision = 0.01f;

View File

@@ -1,5 +1,6 @@
#include "goto_parameter_controller.h"
#include "../app.h"
#include "../../apps_container.h"
#include <assert.h>
namespace Graph {
@@ -25,7 +26,8 @@ float GoToParameterController::parameterAtIndex(int index) {
void GoToParameterController::setParameterAtIndex(int parameterIndex, float f) {
assert(parameterIndex == 0);
App * graphApp = (Graph::App *)app();
float y = m_function->evaluateAtAbscissa(f, graphApp->localContext());
AppsContainer * container = (AppsContainer *)graphApp->container();
float y = m_function->evaluateAtAbscissa(f, graphApp->localContext(), container->preferences()->angleUnit());
m_graphRange->centerAxisAround(CurveViewRange::Axis::X, f);
m_graphRange->centerAxisAround(CurveViewRange::Axis::Y, y);
m_cursor->moveTo(f, y);

View File

@@ -41,6 +41,8 @@ void GraphController::didBecomeFirstResponder() {
if (m_view.context() == nullptr) {
App * graphApp = (Graph::App *)app();
m_view.setContext(graphApp->localContext());
AppsContainer * container = (AppsContainer *)graphApp->container();
m_view.setPreferences(container->preferences());
}
InteractiveCurveViewController::didBecomeFirstResponder();
}
@@ -50,6 +52,7 @@ bool GraphController::didChangeRange(InteractiveCurveViewRange * interactiveCurv
return false;
}
App * graphApp = (Graph::App *)app();
AppsContainer * myContainer = (AppsContainer *)graphApp->container();
if (m_functionStore->numberOfActiveFunctions() <= 0) {
return false;
}
@@ -63,7 +66,7 @@ bool GraphController::didChangeRange(InteractiveCurveViewRange * interactiveCurv
float y = 0.0f;
for (int i = 0; i <= Ion::Display::Width; i++) {
float x = xMin + i*step;
y = f->evaluateAtAbscissa(x, graphApp->localContext());
y = f->evaluateAtAbscissa(x, graphApp->localContext(), myContainer->preferences()->angleUnit());
if (!isnan(y) && !isinf(y)) {
min = min < y ? min : y;
max = max > y ? max : y;
@@ -127,7 +130,7 @@ void GraphController::reloadBannerView() {
buffer[0] = f->name()[0];
buffer[1] = '\'';
App * graphApp = (Graph::App *)app();
float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext());
float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext(), myContainer->preferences()->angleUnit());
Float(y).convertFloatToText(buffer + legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode());
m_bannerView.setLegendAtIndex(buffer, 2);
}
@@ -143,11 +146,12 @@ void GraphController::initCursorParameters() {
float x = (m_graphRange.xMin()+m_graphRange.xMax())/2.0f;
m_indexFunctionSelectedByCursor = 0;
App * graphApp = (Graph::App *)app();
AppsContainer * myContainer = (AppsContainer *)graphApp->container();
int functionIndex = 0;
float y = 0;
do {
Function * firstFunction = m_functionStore->activeFunctionAtIndex(functionIndex++);
y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext());
y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext(), myContainer->preferences()->angleUnit());
} while (isnan(y) && functionIndex < m_functionStore->numberOfActiveFunctions());
m_cursor.moveTo(x, y);
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
@@ -159,7 +163,8 @@ bool GraphController::moveCursorHorizontally(int direction) {
xCursorPosition - m_graphRange.xGridUnit()/k_numberOfCursorStepsInGradUnit;
Function * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
App * graphApp = (Graph::App *)app();
float y = f->evaluateAtAbscissa(x, graphApp->localContext());
AppsContainer * myContainer = (AppsContainer *)graphApp->container();
float y = f->evaluateAtAbscissa(x, graphApp->localContext(), myContainer->preferences()->angleUnit());
m_cursor.moveTo(x, y);
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
@@ -168,12 +173,13 @@ bool GraphController::moveCursorHorizontally(int direction) {
bool GraphController::moveCursorVertically(int direction) {
Function * actualFunction = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
App * graphApp = (Graph::App *)app();
float y = actualFunction->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext());
AppsContainer * myContainer = (AppsContainer *)graphApp->container();
float y = actualFunction->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext(), myContainer->preferences()->angleUnit());
Function * nextFunction = actualFunction;
float nextY = direction > 0 ? FLT_MAX : -FLT_MAX;
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
Function * f = m_functionStore->activeFunctionAtIndex(i);
float newY = f->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext());
float newY = f->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext(), myContainer->preferences()->angleUnit());
bool isNextFunction = direction > 0 ? (newY > y && newY < nextY) : (newY < y && newY > nextY);
if (isNextFunction) {
m_indexFunctionSelectedByCursor = i;

View File

@@ -5,10 +5,12 @@
namespace Graph {
GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView) :
GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange,
CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView) :
CurveView(graphRange, cursor, bannerView, cursorView),
m_functionStore(functionStore),
m_context(nullptr)
m_context(nullptr),
m_preferences(nullptr)
{
}
@@ -29,6 +31,10 @@ void GraphView::setContext(Context * context) {
m_context = context;
}
void GraphView::setPreferences(Preferences * preferences) {
m_preferences = preferences;
}
Context * GraphView::context() const {
return m_context;
}
@@ -39,7 +45,7 @@ char * GraphView::label(Axis axis, int index) const {
float GraphView::evaluateModelWithParameter(Model * curve, float abscissa) const {
Function * f = (Function *)curve;
return f->evaluateAtAbscissa(abscissa, m_context);
return f->evaluateAtAbscissa(abscissa, m_context, m_preferences->angleUnit());
}
}

View File

@@ -6,14 +6,17 @@
#include "../../constant.h"
#include "../function_store.h"
#include "../../interactive_curve_view_range.h"
#include "../../preferences.h"
namespace Graph {
class GraphView : public CurveView {
public:
GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView);
GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange,
CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setContext(Context * context);
void setPreferences(Preferences * preferences);
Context * context() const;
private:
char * label(Axis axis, int index) const override;
@@ -22,6 +25,7 @@ private:
char m_yLabels[k_maxNumberOfYLabels][Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
FunctionStore * m_functionStore;
Context * m_context;
Preferences * m_preferences;
};
}

View File

@@ -184,9 +184,9 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in
App * graphApp = (Graph::App *)app();
float x = m_interval.element(j-1);
if (isDerivativeColumn(i)) {
Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode());
Float(function->approximateDerivative(x, graphApp->localContext(), myContainer->preferences()->angleUnit())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode());
} else {
Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode());
Float(function->evaluateAtAbscissa(x, graphApp->localContext(), myContainer->preferences()->angleUnit())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode());
}
myValueCell->setText(buffer);
}

View File

@@ -1,7 +1,7 @@
#include "preferences.h"
Preferences::Preferences() :
m_angleUnit(AngleUnit::Degree),
m_angleUnit(Expression::AngleUnit::Degree),
m_displayMode(Expression::DisplayMode::Auto),
m_numberType(NumberType::Reel),
m_complexFormat(ComplexFormat::Algebric),
@@ -9,11 +9,11 @@ Preferences::Preferences() :
{
}
Preferences::AngleUnit Preferences::angleUnit() const {
Expression::AngleUnit Preferences::angleUnit() const {
return m_angleUnit;
}
void Preferences::setAngleUnit(AngleUnit angleUnit) {
void Preferences::setAngleUnit(Expression::AngleUnit angleUnit) {
if (angleUnit != m_angleUnit) {
m_angleUnit = angleUnit;
}

View File

@@ -5,10 +5,6 @@
class Preferences {
public:
enum class AngleUnit {
Degree = 0,
Radian = 1
};
enum class NumberType {
Reel = 0,
Complex = 1
@@ -22,8 +18,8 @@ public:
English = 1
};
Preferences();
AngleUnit angleUnit() const;
void setAngleUnit(AngleUnit angleUnit);
Expression::AngleUnit angleUnit() const;
void setAngleUnit(Expression::AngleUnit angleUnit);
Expression::DisplayMode displayMode() const;
void setDisplayMode(Expression::DisplayMode displayMode);
NumberType numberType() const;
@@ -33,7 +29,7 @@ public:
Language language() const;
void setLanguage(Language language);
private:
AngleUnit m_angleUnit;
Expression::AngleUnit m_angleUnit;
Expression::DisplayMode m_displayMode;
NumberType m_numberType;
ComplexFormat m_complexFormat;

View File

@@ -204,7 +204,7 @@ bool CalculationController::textFieldDidReceiveEvent(TextField * textField, Ion:
bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text) {
AppsContainer * appsContainer = (AppsContainer *)app()->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
m_calculation->setParameterAtIndex(floatBody, m_highlightedSubviewIndex-1);
for (int k = 0; k < m_calculation->numberOfParameters(); k++) {
m_contentView.willDisplayEditableCellAtIndex(k);

View File

@@ -34,7 +34,7 @@ void RangeParameterController::willDisplayCellForIndex(TableViewCell * cell, int
bool RangeParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) {
AppsContainer * appsContainer = (AppsContainer *)app()->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
setParameterAtIndex(m_selectableTableView.selectedRow(), floatBody);
willDisplayCellForIndex(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(),
m_selectableTableView.selectedRow()), activeCell());

View File

@@ -82,7 +82,7 @@ StackViewController * SubController::stackController() const {
void SubController::setPreferenceAtIndexWithValueIndex(int preferenceIndex, int valueIndex) {
switch (preferenceIndex) {
case 0:
m_preferences->setAngleUnit((Preferences::AngleUnit)valueIndex);
m_preferences->setAngleUnit((Expression::AngleUnit)valueIndex);
break;
case 1:
m_preferences->setDisplayMode((Expression::DisplayMode)valueIndex);

View File

@@ -55,7 +55,7 @@ void TitleBarView::setPreferences(Preferences * preferences) {
strlcpy(buffer+numberOfChar, "cplx/", 6);
numberOfChar += 5;
}
if (preferences->angleUnit() == Preferences::AngleUnit::Radian) {
if (preferences->angleUnit() == Expression::AngleUnit::Radian) {
strlcpy(buffer+numberOfChar, "rad", 4);
} else {
strlcpy(buffer+numberOfChar, "deg", 4);