mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare][apps] Make preferences a const object accessible from
anywhere (poincare and apps) Change-Id: I49cc6bf940d1efeb6b153daac949ffcb23999a8d
This commit is contained in:
@@ -14,10 +14,10 @@ app_objs += $(addprefix apps/,\
|
||||
apps_window.o\
|
||||
battery_view.o\
|
||||
constant.o\
|
||||
global_preferences.o\
|
||||
main.o\
|
||||
node.o\
|
||||
node_list_view_controller.o\
|
||||
preferences.o\
|
||||
title_bar_view.o\
|
||||
toolbox_controller.o\
|
||||
toolbox_leaf_cell.o\
|
||||
|
||||
@@ -15,10 +15,9 @@ AppsContainer::AppsContainer() :
|
||||
m_calculationApp(this, &m_globalContext),
|
||||
m_regressionApp(this),
|
||||
m_sequenceApp(this, &m_globalContext),
|
||||
m_settingsApp(this, &m_preferences),
|
||||
m_settingsApp(this),
|
||||
m_statisticsApp(this),
|
||||
m_globalContext(GlobalContext()),
|
||||
m_preferences(Preferences()),
|
||||
m_variableBoxController(&m_globalContext)
|
||||
{
|
||||
refreshPreferences();
|
||||
@@ -49,10 +48,6 @@ Context * AppsContainer::globalContext() {
|
||||
return &m_globalContext;
|
||||
}
|
||||
|
||||
Preferences * AppsContainer::preferences() {
|
||||
return &m_preferences;
|
||||
}
|
||||
|
||||
ToolboxController * AppsContainer::toolboxController() {
|
||||
return &m_toolboxController;
|
||||
}
|
||||
@@ -80,7 +75,7 @@ void AppsContainer::switchTo(App * app) {
|
||||
}
|
||||
|
||||
void AppsContainer::refreshPreferences() {
|
||||
m_window.refreshPreferences(&m_preferences);
|
||||
m_window.refreshPreferences();
|
||||
}
|
||||
|
||||
Window * AppsContainer::window() {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "apps_window.h"
|
||||
#include "toolbox_controller.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include "preferences.h"
|
||||
|
||||
#define USE_PIC_VIEW_APP 0
|
||||
#if USE_PIC_VIEW_APP
|
||||
#include "picview/picview_app.h"
|
||||
@@ -25,7 +25,6 @@ public:
|
||||
int numberOfApps();
|
||||
App * appAtIndex(int index);
|
||||
Poincare::Context * globalContext();
|
||||
Preferences * preferences();
|
||||
ToolboxController * toolboxController();
|
||||
VariableBoxController * variableBoxController();
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
@@ -47,7 +46,6 @@ private:
|
||||
PicViewApp m_picViewApp;
|
||||
#endif
|
||||
Poincare::GlobalContext m_globalContext;
|
||||
Preferences m_preferences;
|
||||
ToolboxController m_toolboxController;
|
||||
VariableBoxController m_variableBoxController;
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ void AppsWindow::updateBatteryLevel() {
|
||||
m_titleBarView.setChargeState(Ion::Battery::Charge::EMPTY);
|
||||
}
|
||||
|
||||
void AppsWindow::refreshPreferences(Preferences * preferences) {
|
||||
m_titleBarView.setPreferences(preferences);
|
||||
void AppsWindow::refreshPreferences() {
|
||||
m_titleBarView.refreshPreferences();
|
||||
}
|
||||
|
||||
int AppsWindow::numberOfSubviews() const {
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
AppsWindow();
|
||||
void setTitle(const char * title);
|
||||
void updateBatteryLevel();
|
||||
void refreshPreferences(Preferences * preferences);
|
||||
void refreshPreferences();
|
||||
private:
|
||||
constexpr static KDCoordinate k_titleBarHeight = 18;
|
||||
int numberOfSubviews() const override;
|
||||
|
||||
@@ -51,7 +51,7 @@ void Calculation::reset() {
|
||||
m_outputLayout = nullptr;
|
||||
}
|
||||
|
||||
void Calculation::setContent(const char * c, Context * context, Preferences * preferences) {
|
||||
void Calculation::setContent(const char * c, Context * context) {
|
||||
strlcpy(m_text, c, sizeof(m_text));
|
||||
if (m_input != nullptr) {
|
||||
delete m_input;
|
||||
@@ -60,15 +60,15 @@ void Calculation::setContent(const char * c, Context * context, Preferences * pr
|
||||
if (m_inputLayout != nullptr) {
|
||||
delete m_inputLayout;
|
||||
}
|
||||
m_inputLayout = m_input->createLayout(preferences->displayMode());
|
||||
m_inputLayout = m_input->createLayout();
|
||||
if (m_output != nullptr) {
|
||||
delete m_output;
|
||||
}
|
||||
m_output = m_input->evaluate(*context, preferences->angleUnit());
|
||||
m_output = m_input->evaluate(*context);
|
||||
if (m_outputLayout != nullptr) {
|
||||
delete m_outputLayout;
|
||||
}
|
||||
m_outputLayout = m_output->createLayout(preferences->displayMode());
|
||||
m_outputLayout = m_output->createLayout();
|
||||
}
|
||||
|
||||
const char * Calculation::text() {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define CALCULATION_CALCULATION_H
|
||||
|
||||
#include <poincare.h>
|
||||
#include "../preferences.h"
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
@@ -22,7 +21,7 @@ public:
|
||||
Poincare::ExpressionLayout * inputLayout();
|
||||
Poincare::Expression * output();
|
||||
Poincare::ExpressionLayout * outputLayout();
|
||||
void setContent(const char * c, Poincare::Context * context, Preferences * preferences);
|
||||
void setContent(const char * c, Poincare::Context * context);
|
||||
bool isEmpty();
|
||||
constexpr static int k_maximalExpressionTextLength = 255;
|
||||
private:
|
||||
|
||||
@@ -9,9 +9,9 @@ CalculationStore::CalculationStore() :
|
||||
{
|
||||
}
|
||||
|
||||
Calculation * CalculationStore::push(const char * text, Context * context, Preferences * preferences) {
|
||||
Calculation * CalculationStore::push(const char * text, Context * context) {
|
||||
Calculation * result = m_start;
|
||||
m_start++->setContent(text, context, preferences);
|
||||
m_start++->setContent(text, context);
|
||||
if (m_start >= m_calculations + k_maxNumberOfCalculations) {
|
||||
m_start = m_calculations;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define CALCULATION_CALCULATION_STORE_H
|
||||
|
||||
#include "calculation.h"
|
||||
#include "../preferences.h"
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
@@ -12,7 +11,7 @@ class CalculationStore {
|
||||
public:
|
||||
CalculationStore();
|
||||
Calculation * calculationAtIndex(int i);
|
||||
Calculation * push(const char * text, Poincare::Context * context, Preferences * preferences);
|
||||
Calculation * push(const char * text, Poincare::Context * context);
|
||||
void deleteCalculationAtIndex(int i);
|
||||
void deleteAll();
|
||||
int numberOfCalculations();
|
||||
|
||||
@@ -82,7 +82,7 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField,
|
||||
|
||||
bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text) {
|
||||
App * calculationApp = (App *)app();
|
||||
m_calculationStore->push(textBody(), calculationApp->localContext(), calculationApp->container()->preferences());
|
||||
m_calculationStore->push(textBody(), calculationApp->localContext());
|
||||
m_historyController->reload();
|
||||
m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
|
||||
m_contentView.textField()->setText("");
|
||||
|
||||
@@ -71,7 +71,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
}
|
||||
m_selectableTableView.deselectTable();
|
||||
App * calculationApp = (App *)app();
|
||||
m_calculationStore->push(text, calculationApp->localContext(), calculationApp->container()->preferences());
|
||||
m_calculationStore->push(text, calculationApp->localContext());
|
||||
reload();
|
||||
m_selectableTableView.scrollToCell(0, numberOfRows()-1);
|
||||
app()->setFirstResponder(editController);
|
||||
|
||||
22
apps/global_preferences.cpp
Normal file
22
apps/global_preferences.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "global_preferences.h"
|
||||
|
||||
static GlobalPreferences s_globalPreferences;
|
||||
|
||||
GlobalPreferences::GlobalPreferences() :
|
||||
m_language(Language::French)
|
||||
{
|
||||
}
|
||||
|
||||
GlobalPreferences * GlobalPreferences::sharedGlobalPreferences() {
|
||||
return &s_globalPreferences;
|
||||
}
|
||||
|
||||
GlobalPreferences::Language GlobalPreferences::language() const {
|
||||
return m_language;
|
||||
}
|
||||
|
||||
void GlobalPreferences::setLanguage(Language language) {
|
||||
if (language != m_language) {
|
||||
m_language = language;
|
||||
}
|
||||
}
|
||||
19
apps/global_preferences.h
Normal file
19
apps/global_preferences.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef APPS_GLOBAL_PREFERENCES_H
|
||||
#define APPS_GLOBAL_PREFERENCES_H
|
||||
|
||||
class GlobalPreferences {
|
||||
public:
|
||||
enum class Language {
|
||||
French = 0,
|
||||
English = 1,
|
||||
Spanish = 2
|
||||
};
|
||||
GlobalPreferences();
|
||||
static GlobalPreferences * sharedGlobalPreferences();
|
||||
Language language() const;
|
||||
void setLanguage(Language language);
|
||||
private:
|
||||
Language m_language;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -16,12 +16,12 @@ void Function::setDisplayDerivative(bool display) {
|
||||
m_displayDerivative = display;
|
||||
}
|
||||
|
||||
float Function::approximateDerivative(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const {
|
||||
float Function::approximateDerivative(float x, Poincare::Context * context) const {
|
||||
Poincare::Complex abscissa = Poincare::Complex(x);
|
||||
Poincare::Expression * args[2] = {m_expression, &abscissa};
|
||||
Poincare::Derivative derivative = Poincare::Derivative();
|
||||
derivative.setArgument(args, 2, true);
|
||||
return derivative.approximate(*context, angleUnit);
|
||||
return derivative.approximate(*context);
|
||||
}
|
||||
|
||||
char Function::symbol() const {
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
Function(const char * text = nullptr, KDColor color = KDColorBlack);
|
||||
bool displayDerivative();
|
||||
void setDisplayDerivative(bool display);
|
||||
float approximateDerivative(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const;
|
||||
float approximateDerivative(float x, Poincare::Context * context) const;
|
||||
char symbol() const override;
|
||||
private:
|
||||
bool m_displayDerivative;
|
||||
|
||||
@@ -28,7 +28,7 @@ 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(), graphApp->container()->preferences()->angleUnit());
|
||||
float y = m_function->evaluateAtAbscissa(f, graphApp->localContext());
|
||||
m_graphRange->centerAxisAround(CurveViewRange::Axis::X, f);
|
||||
m_graphRange->centerAxisAround(CurveViewRange::Axis::Y, y);
|
||||
m_cursor->moveTo(f, y);
|
||||
|
||||
@@ -44,7 +44,6 @@ void GraphController::didBecomeFirstResponder() {
|
||||
if (m_view.context() == nullptr) {
|
||||
App * graphApp = (Graph::App *)app();
|
||||
m_view.setContext(graphApp->localContext());
|
||||
m_view.setPreferences(graphApp->container()->preferences());
|
||||
}
|
||||
InteractiveCurveViewController::didBecomeFirstResponder();
|
||||
}
|
||||
@@ -67,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(), graphApp->container()->preferences()->angleUnit());
|
||||
y = f->evaluateAtAbscissa(x, graphApp->localContext());
|
||||
if (!isnan(y) && !isinf(y)) {
|
||||
min = min < y ? min : y;
|
||||
max = max > y ? max : y;
|
||||
@@ -111,12 +110,11 @@ bool GraphController::handleEnter() {
|
||||
}
|
||||
|
||||
void GraphController::reloadBannerView() {
|
||||
App * graphApp = (App *)app();
|
||||
char buffer[k_maxNumberOfCharacters+Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
const char * legend = "x = ";
|
||||
int legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
Complex::convertFloatToText(m_cursor.x(), buffer+ legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(m_cursor.x(), buffer+ legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 0);
|
||||
|
||||
legend = "00(x) = ";
|
||||
@@ -127,15 +125,15 @@ void GraphController::reloadBannerView() {
|
||||
}
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
||||
buffer[1] = f->name()[0];
|
||||
Complex::convertFloatToText(m_cursor.y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(m_cursor.y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer+1, 1);
|
||||
|
||||
if (m_bannerView.displayDerivative()) {
|
||||
buffer[0] = f->name()[0];
|
||||
buffer[1] = '\'';
|
||||
App * graphApp = (Graph::App *)app();
|
||||
float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext(), graphApp->container()->preferences()->angleUnit());
|
||||
Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->container()->preferences()->displayMode());
|
||||
float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext());
|
||||
Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 2);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +152,7 @@ void GraphController::initCursorParameters() {
|
||||
float y = 0;
|
||||
do {
|
||||
Function * firstFunction = m_functionStore->activeFunctionAtIndex(functionIndex++);
|
||||
y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext(), graphApp->container()->preferences()->angleUnit());
|
||||
y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext());
|
||||
} 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);
|
||||
@@ -166,7 +164,7 @@ 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(), graphApp->container()->preferences()->angleUnit());
|
||||
float y = f->evaluateAtAbscissa(x, graphApp->localContext());
|
||||
m_cursor.moveTo(x, y);
|
||||
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
||||
return true;
|
||||
@@ -175,12 +173,12 @@ 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(), graphApp->container()->preferences()->angleUnit());
|
||||
float y = actualFunction->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext());
|
||||
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(), graphApp->container()->preferences()->angleUnit());
|
||||
float newY = f->evaluateAtAbscissa(m_cursor.x(), graphApp->localContext());
|
||||
bool isNextFunction = direction > 0 ? (newY > y && newY < nextY) : (newY < y && newY > nextY);
|
||||
if (isNextFunction) {
|
||||
m_indexFunctionSelectedByCursor = i;
|
||||
|
||||
@@ -11,8 +11,7 @@ GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange *
|
||||
CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
|
||||
CurveView(graphRange, cursor, bannerView, cursorView),
|
||||
m_functionStore(functionStore),
|
||||
m_context(nullptr),
|
||||
m_preferences(nullptr)
|
||||
m_context(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,10 +32,6 @@ void GraphView::setContext(Context * context) {
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
void GraphView::setPreferences(Preferences * preferences) {
|
||||
m_preferences = preferences;
|
||||
}
|
||||
|
||||
Context * GraphView::context() const {
|
||||
return m_context;
|
||||
}
|
||||
@@ -47,7 +42,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, m_preferences->angleUnit());
|
||||
return f->evaluateAtAbscissa(abscissa, m_context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "../../constant.h"
|
||||
#include "../function_store.h"
|
||||
#include "../../shared/interactive_curve_view_range.h"
|
||||
#include "../../preferences.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
@@ -16,7 +15,6 @@ public:
|
||||
Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setContext(Poincare::Context * context);
|
||||
void setPreferences(Preferences * preferences);
|
||||
Poincare::Context * context() const;
|
||||
private:
|
||||
char * label(Axis axis, int index) const override;
|
||||
@@ -25,7 +23,6 @@ private:
|
||||
char m_yLabels[k_maxNumberOfYLabels][Poincare::Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
|
||||
FunctionStore * m_functionStore;
|
||||
Poincare::Context * m_context;
|
||||
Preferences * m_preferences;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "initialisation_parameter_controller.h"
|
||||
#include "../app.h"
|
||||
#include "../../apps_container.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -30,15 +29,10 @@ void InitialisationParameterController::didBecomeFirstResponder() {
|
||||
}
|
||||
|
||||
bool InitialisationParameterController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK) {
|
||||
if (m_selectableTableView.selectedRow() == 0) {
|
||||
App * graphApp = (App *)app();
|
||||
m_graphRange->setTrigonometric(graphApp->container()->preferences()->angleUnit());
|
||||
} else {
|
||||
RangeMethodPointer rangeMethods[k_totalNumberOfCells-1] = {&InteractiveCurveViewRange::roundAbscissa,
|
||||
&InteractiveCurveViewRange::normalize, &InteractiveCurveViewRange::setDefault};
|
||||
(m_graphRange->*rangeMethods[m_selectableTableView.selectedRow()-1])();
|
||||
}
|
||||
if (event == Ion::Events::OK) {
|
||||
RangeMethodPointer rangeMethods[k_totalNumberOfCells] = {&InteractiveCurveViewRange::setTrigonometric,
|
||||
&InteractiveCurveViewRange::roundAbscissa, &InteractiveCurveViewRange::normalize, &InteractiveCurveViewRange::setDefault};
|
||||
(m_graphRange->*rangeMethods[m_selectableTableView.selectedRow()])();
|
||||
StackViewController * stack = (StackViewController *)parentResponder();
|
||||
stack->pop();
|
||||
return true;
|
||||
|
||||
@@ -126,7 +126,7 @@ int ValuesController::numberOfColumns() {
|
||||
|
||||
void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
|
||||
App * graphApp = (App *)app();
|
||||
willDisplayCellAtLocationWithDisplayMode(cell, i, j, graphApp->container()->preferences()->displayMode());
|
||||
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Default);
|
||||
if (cellAtLocationIsEditable(i, j)) {
|
||||
return;
|
||||
}
|
||||
@@ -170,9 +170,9 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in
|
||||
Function * function = functionAtColumn(i);
|
||||
float x = m_interval.element(j-1);
|
||||
if (isDerivativeColumn(i)) {
|
||||
Complex::convertFloatToText(function->approximateDerivative(x, graphApp->localContext(), graphApp->container()->preferences()->angleUnit()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(function->approximateDerivative(x, graphApp->localContext()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
} else {
|
||||
Complex::convertFloatToText(function->evaluateAtAbscissa(x, graphApp->localContext(), graphApp->container()->preferences()->angleUnit()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(function->evaluateAtAbscissa(x, graphApp->localContext()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
}
|
||||
myValueCell->setText(buffer);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ View * CalculationController::ContentView::subviewAtIndex(int index) {
|
||||
|
||||
void CalculationController::ContentView::willDisplayEditableCellAtIndex(int index) {
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(m_calculation->parameterAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Auto);
|
||||
Complex::convertFloatToText(m_calculation->parameterAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
m_calculationCell[index].setText(buffer);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ bool CalculationController::textFieldDidReceiveEvent(TextField * textField, Ion:
|
||||
bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text) {
|
||||
App * probaApp = (App *)app();
|
||||
Context * globalContext = probaApp->container()->globalContext();
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext, probaApp->container()->preferences()->angleUnit());
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext);
|
||||
m_calculation->setParameterAtIndex(floatBody, m_highlightedSubviewIndex-1);
|
||||
for (int k = 0; k < m_calculation->numberOfParameters(); k++) {
|
||||
m_contentView.willDisplayEditableCellAtIndex(k);
|
||||
@@ -243,7 +243,7 @@ void CalculationController::updateTitle() {
|
||||
strlcpy(m_titleBuffer+currentChar, " = ", 4);
|
||||
currentChar += 3;
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(m_law->parameterValueAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Auto);
|
||||
Complex::convertFloatToText(m_law->parameterValueAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
strlcpy(m_titleBuffer+currentChar, buffer, strlen(buffer)+1);
|
||||
currentChar += strlen(buffer);
|
||||
m_titleBuffer[currentChar++] = ' ';
|
||||
|
||||
@@ -127,7 +127,6 @@ void CalculationController::willDisplayCellAtLocation(TableViewCell * cell, int
|
||||
myCell->setText(titles[j-1]);
|
||||
return;
|
||||
}
|
||||
App * regApp = (App *)app();
|
||||
if (i == 1 && j > 0 && j < 6) {
|
||||
ArgCalculPointer calculationMethods[(k_totalNumberOfRows-1)/2] = {&Store::meanOfColumn, &Store::sumOfColumn,
|
||||
&Store::squaredValueSumOfColumn, &Store::standardDeviationOfColumn, &Store::varianceOfColumn};
|
||||
@@ -135,9 +134,9 @@ void CalculationController::willDisplayCellAtLocation(TableViewCell * cell, int
|
||||
float calculation2 = (m_store->*calculationMethods[j-1])(1);
|
||||
EvenOddDoubleBufferTextCell * myCell = (EvenOddDoubleBufferTextCell *)cell;
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(calculation1, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, regApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(calculation1, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
myCell->setFirstText(buffer);
|
||||
Complex::convertFloatToText(calculation2, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, regApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(calculation2, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
myCell->setSecondText(buffer);
|
||||
return;
|
||||
}
|
||||
@@ -147,7 +146,7 @@ void CalculationController::willDisplayCellAtLocation(TableViewCell * cell, int
|
||||
float calculation = (m_store->*calculationMethods[j-6])();
|
||||
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, regApp->container()->preferences()->displayMode());
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
myCell->setText(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,21 +57,20 @@ bool GraphController::handleEnter() {
|
||||
}
|
||||
|
||||
void GraphController::reloadBannerView() {
|
||||
AppsContainer * container = ((App *)app())->container();
|
||||
m_bannerView.setLegendAtIndex((char *)"y = ax+b", 0);
|
||||
char buffer[k_maxNumberOfCharacters + Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
const char * legend = "a = ";
|
||||
float slope = m_store->slope();
|
||||
int legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
Complex::convertFloatToText(slope, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(slope, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 1);
|
||||
|
||||
legend = "b = ";
|
||||
float yIntercept = m_store->yIntercept();
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
Complex::convertFloatToText(yIntercept, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(yIntercept, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 2);
|
||||
|
||||
legend = "x = ";
|
||||
@@ -84,7 +83,7 @@ void GraphController::reloadBannerView() {
|
||||
}
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
Complex::convertFloatToText(x, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(x, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 3);
|
||||
|
||||
legend = "y = ";
|
||||
@@ -96,7 +95,7 @@ void GraphController::reloadBannerView() {
|
||||
}
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
Complex::convertFloatToText(y, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(y, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <string.h>
|
||||
|
||||
using namespace Shared;
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Sequence {
|
||||
|
||||
@@ -80,7 +81,7 @@ void Sequence::setFirstInitialConditionContent(const char * c) {
|
||||
}
|
||||
m_firstInitialConditionLayout = nullptr;
|
||||
if (m_firstInitialConditionExpression) {
|
||||
m_firstInitialConditionLayout = m_firstInitialConditionExpression->createLayout();
|
||||
m_firstInitialConditionLayout = m_firstInitialConditionExpression->createLayout(Expression::FloatDisplayMode::Decimal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ void Sequence::setSecondInitialConditionContent(const char * c) {
|
||||
}
|
||||
m_secondInitialConditionLayout = nullptr;
|
||||
if (m_secondInitialConditionExpression) {
|
||||
m_secondInitialConditionLayout = m_secondInitialConditionExpression->createLayout();
|
||||
m_secondInitialConditionLayout = m_secondInitialConditionExpression->createLayout(Expression::FloatDisplayMode::Decimal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
namespace Settings {
|
||||
|
||||
App::App(Container * container, Preferences * preferences) :
|
||||
App::App(Container * container) :
|
||||
::App(container, &m_stackViewController, "Parametre", "PARAMETRE", ImageStore::SettingsIcon),
|
||||
m_mainController(MainController(nullptr, preferences)),
|
||||
m_mainController(MainController(nullptr)),
|
||||
m_stackViewController(StackViewController(&m_modalViewController, &m_mainController))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "main_controller.h"
|
||||
#include "../preferences.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class App : public ::App {
|
||||
public:
|
||||
App(Container * container, Preferences * preferences);
|
||||
App(Container * container);
|
||||
private:
|
||||
MainController m_mainController;
|
||||
StackViewController m_stackViewController;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "main_controller.h"
|
||||
#include "../global_preferences.h"
|
||||
#include <assert.h>
|
||||
#include <poincare.h>
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Settings {
|
||||
|
||||
@@ -14,15 +18,14 @@ const SettingsNode menu[5] = {SettingsNode("Unite d'angles", angleChildren, 2),
|
||||
SettingsNode("Langue", languageChildren, 3)};
|
||||
const SettingsNode model = SettingsNode("Parametres", menu, 5);
|
||||
|
||||
MainController::MainController(Responder * parentResponder, Preferences * preferences) :
|
||||
MainController::MainController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_cells{ChevronTextMenuListCell(KDText::FontSize::Large), ChevronTextMenuListCell(KDText::FontSize::Large), ChevronTextMenuListCell(KDText::FontSize::Large),
|
||||
ChevronTextMenuListCell(KDText::FontSize::Large), ChevronTextMenuListCell(KDText::FontSize::Large)},
|
||||
m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin,
|
||||
Metric::BottomMargin, Metric::LeftMargin)),
|
||||
m_nodeModel((Node *)&model),
|
||||
m_preferences(preferences),
|
||||
m_subController(this, m_preferences)
|
||||
m_subController(this)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -73,19 +76,19 @@ void MainController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
||||
myCell->setText(m_nodeModel->children(index)->label());
|
||||
switch (index) {
|
||||
case 0:
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)m_preferences->angleUnit())->label());
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->angleUnit())->label());
|
||||
break;
|
||||
case 1:
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)m_preferences->displayMode())->label());
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->displayMode())->label());
|
||||
break;
|
||||
case 2:
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)m_preferences->numberType())->label());
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->numberType())->label());
|
||||
break;
|
||||
case 3:
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)m_preferences->complexFormat())->label());
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->complexFormat())->label());
|
||||
break;
|
||||
case 4:
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)m_preferences->language())->label());
|
||||
myCell->setSubtitle(m_nodeModel->children(index)->children((int)GlobalPreferences::sharedGlobalPreferences()->language())->label());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
#include <escher.h>
|
||||
#include "sub_controller.h"
|
||||
#include "settings_node.h"
|
||||
#include "../preferences.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class MainController : public ViewController, public SimpleListViewDataSource {
|
||||
public:
|
||||
MainController(Responder * parentResponder, Preferences * preferences);
|
||||
MainController(Responder * parentResponder);
|
||||
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
@@ -28,7 +27,6 @@ private:
|
||||
ChevronTextMenuListCell m_cells[k_totalNumberOfCell];
|
||||
SelectableTableView m_selectableTableView;
|
||||
Node * m_nodeModel;
|
||||
Preferences * m_preferences;
|
||||
SubController m_subController;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "sub_controller.h"
|
||||
#include "../global_preferences.h"
|
||||
#include "../apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
@@ -6,15 +7,14 @@ using namespace Poincare;
|
||||
|
||||
namespace Settings {
|
||||
|
||||
SubController::SubController(Responder * parentResponder, Preferences * preferences) :
|
||||
SubController::SubController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_cells{MenuListCell(nullptr, KDText::FontSize::Large), MenuListCell(nullptr, KDText::FontSize::Large),
|
||||
MenuListCell(nullptr, KDText::FontSize::Large)},
|
||||
m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin,
|
||||
Metric::BottomMargin, Metric::LeftMargin)),
|
||||
m_nodeModel(nullptr),
|
||||
m_preferenceIndex(0),
|
||||
m_preferences(preferences)
|
||||
m_preferenceIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -87,19 +87,19 @@ StackViewController * SubController::stackController() const {
|
||||
void SubController::setPreferenceAtIndexWithValueIndex(int preferenceIndex, int valueIndex) {
|
||||
switch (preferenceIndex) {
|
||||
case 0:
|
||||
m_preferences->setAngleUnit((Expression::AngleUnit)valueIndex);
|
||||
Preferences::sharedPreferences()->setAngleUnit((Expression::AngleUnit)valueIndex);
|
||||
break;
|
||||
case 1:
|
||||
m_preferences->setDisplayMode((Expression::FloatDisplayMode)valueIndex);
|
||||
Preferences::sharedPreferences()->setDisplayMode((Expression::FloatDisplayMode)valueIndex);
|
||||
break;
|
||||
case 2:
|
||||
m_preferences->setNumberType((Preferences::NumberType)valueIndex);
|
||||
Preferences::sharedPreferences()->setNumberType((Preferences::NumberType)valueIndex);
|
||||
break;
|
||||
case 3:
|
||||
m_preferences->setComplexFormat((Preferences::ComplexFormat)valueIndex);
|
||||
Preferences::sharedPreferences()->setComplexFormat((Preferences::ComplexFormat)valueIndex);
|
||||
break;
|
||||
case 4:
|
||||
m_preferences->setLanguage((Preferences::Language)valueIndex);
|
||||
GlobalPreferences::sharedGlobalPreferences()->setLanguage((GlobalPreferences::Language)valueIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -107,15 +107,15 @@ void SubController::setPreferenceAtIndexWithValueIndex(int preferenceIndex, int
|
||||
int SubController::valueIndexAtPreferenceIndex(int preferenceIndex) {
|
||||
switch (preferenceIndex) {
|
||||
case 0:
|
||||
return (int)m_preferences->angleUnit();
|
||||
return (int)Preferences::sharedPreferences()->angleUnit();
|
||||
case 1:
|
||||
return (int)m_preferences->displayMode();
|
||||
return (int)Preferences::sharedPreferences()->displayMode();
|
||||
case 2:
|
||||
return (int)m_preferences->numberType();
|
||||
return (int)Preferences::sharedPreferences()->numberType();
|
||||
case 3:
|
||||
return (int)m_preferences->complexFormat();
|
||||
return (int)Preferences::sharedPreferences()->complexFormat();
|
||||
case 4:
|
||||
return (int)m_preferences->language();
|
||||
return (int)GlobalPreferences::sharedGlobalPreferences()->language();
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "settings_node.h"
|
||||
#include "../preferences.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class SubController : public ViewController, public SimpleListViewDataSource {
|
||||
public:
|
||||
SubController(Responder * parentResponder, Preferences * preferences);
|
||||
SubController(Responder * parentResponder);
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
@@ -30,7 +29,6 @@ private:
|
||||
SelectableTableView m_selectableTableView;
|
||||
Node * m_nodeModel;
|
||||
int m_preferenceIndex;
|
||||
Preferences * m_preferences;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ void CurveView::computeLabels(Axis axis) {
|
||||
for (int index = 0; index < numberOfLabels(axis); index++) {
|
||||
Complex::convertFloatToText(2.0f*step*(ceilf(min(axis)/(2.0f*step)))+index*2.0f*step, buffer,
|
||||
Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits),
|
||||
Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Auto);
|
||||
Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
//TODO: check for size of label?
|
||||
strlcpy(label(axis, index), buffer, strlen(buffer)+1);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ bool EditableCellTableViewController::textFieldDidReceiveEvent(TextField * textF
|
||||
bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * textField, const char * text) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext);
|
||||
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();
|
||||
@@ -67,7 +67,7 @@ int EditableCellTableViewController::indexFromCumulatedHeight(KDCoordinate offse
|
||||
return (offsetY-1) / k_cellHeight;
|
||||
}
|
||||
|
||||
void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(TableViewCell * cell, int i, int j, Expression::FloatDisplayMode FloatDisplayMode) {
|
||||
void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(TableViewCell * cell, int i, int j, Expression::FloatDisplayMode floatDisplayMode) {
|
||||
EvenOddCell * myCell = (EvenOddCell *)cell;
|
||||
myCell->setEven(j%2 == 0);
|
||||
// The cell is editable
|
||||
@@ -85,7 +85,7 @@ void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(T
|
||||
}
|
||||
}
|
||||
if (!myEditableValueCell->isEditing()) {
|
||||
Complex::convertFloatToText(dataAtLocation(i, j), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, FloatDisplayMode);
|
||||
Complex::convertFloatToText(dataAtLocation(i, j), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
|
||||
myEditableValueCell->setText(buffer);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -31,14 +31,14 @@ int FloatParameterController::activeCell() {
|
||||
void FloatParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
||||
EditableTextMenuListCell * myCell = (EditableTextMenuListCell *) cell;
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(parameterAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Auto);
|
||||
Complex::convertFloatToText(parameterAtIndex(index), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
myCell->setAccessoryText(buffer);
|
||||
}
|
||||
|
||||
bool FloatParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext);
|
||||
setParameterAtIndex(m_selectableTableView.selectedRow(), floatBody);
|
||||
willDisplayCellForIndex(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(),
|
||||
m_selectableTableView.selectedRow()), activeCell());
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
Function::Function(const char * text, KDColor color) :
|
||||
@@ -25,7 +27,7 @@ void Function::setContent(const char * c) {
|
||||
}
|
||||
m_layout = nullptr;
|
||||
if (m_expression) {
|
||||
m_layout = expression()->createLayout();
|
||||
m_layout = expression()->createLayout(Expression::FloatDisplayMode::Decimal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +70,11 @@ void Function::setActive(bool active) {
|
||||
m_active = active;
|
||||
}
|
||||
|
||||
float Function::evaluateAtAbscissa(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const {
|
||||
float Function::evaluateAtAbscissa(float x, Poincare::Context * context) const {
|
||||
Poincare::Symbol xSymbol = Poincare::Symbol(symbol());
|
||||
Poincare::Complex e = Poincare::Complex(x);
|
||||
context->setExpressionForSymbolName(&e, &xSymbol);
|
||||
return m_expression->approximate(*context, angleUnit);
|
||||
return m_expression->approximate(*context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
void setActive(bool active);
|
||||
void setContent(const char * c);
|
||||
void setColor(KDColor m_color);
|
||||
float evaluateAtAbscissa(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const;
|
||||
float evaluateAtAbscissa(float x, Poincare::Context * context) const;
|
||||
protected:
|
||||
constexpr static int k_bodyLength = 255;
|
||||
Poincare::Expression * m_expression;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "interactive_curve_view_range.h"
|
||||
#include <poincare.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
@@ -101,10 +102,10 @@ void InteractiveCurveViewRange::normalize() {
|
||||
m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax);
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::setTrigonometric(Expression::AngleUnit angleUnit) {
|
||||
void InteractiveCurveViewRange::setTrigonometric() {
|
||||
m_xMin = -10.5f;
|
||||
m_xMax = 10.5f;
|
||||
if (angleUnit == Expression::AngleUnit::Degree) {
|
||||
if (Preferences::sharedPreferences()->angleUnit() == Expression::AngleUnit::Degree) {
|
||||
m_xMin = -600;
|
||||
m_xMax = 600;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define SHARED_INTERACTIVE_CURVE_VIEW_RANGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <poincare.h>
|
||||
#include "memoized_curve_view_range.h"
|
||||
#include "curve_view_cursor.h"
|
||||
#include "interactive_curve_view_range_delegate.h"
|
||||
@@ -26,7 +25,7 @@ public:
|
||||
void panWithVector(float x, float y);
|
||||
void roundAbscissa();
|
||||
void normalize();
|
||||
void setTrigonometric(Poincare::Expression::AngleUnit angleUnit);
|
||||
void setTrigonometric();
|
||||
virtual void setDefault();
|
||||
void centerAxisAround(Axis axis, float position);
|
||||
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation);
|
||||
|
||||
@@ -39,7 +39,7 @@ void RangeParameterController::willDisplayCellForIndex(TableViewCell * cell, int
|
||||
bool RangeParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext, appsContainer->preferences()->angleUnit());
|
||||
float floatBody = Expression::parse(text)->approximate(*globalContext);
|
||||
setParameterAtIndex(m_selectableTableView.selectedRow(), floatBody);
|
||||
willDisplayCellForIndex(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(),
|
||||
m_selectableTableView.selectedRow()), activeCell());
|
||||
|
||||
@@ -67,7 +67,7 @@ int StoreController::typeAtLocation(int i, int j) {
|
||||
}
|
||||
|
||||
void StoreController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
|
||||
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Auto);
|
||||
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Decimal);
|
||||
}
|
||||
|
||||
bool StoreController::handleEvent(Ion::Events::Event event) {
|
||||
|
||||
@@ -72,8 +72,7 @@ void BoxController::reloadBannerView() {
|
||||
CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
|
||||
&Store::maxValue};
|
||||
float calculation = (m_store->*calculationMethods[(int)m_view.selectedQuantile()])();
|
||||
AppsContainer * container = ((App *)app())->container();
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_boxBannerView.setLegendAtIndex(buffer, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,7 @@ void CalculationController::willDisplayCellAtLocation(TableViewCell * cell, int
|
||||
float calculation = (m_store->*calculationMethods[j])();
|
||||
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
AppsContainer * container = ((App *)app())->container();
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(calculation, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
myCell->setText(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,16 +133,15 @@ Responder * HistogramController::tabController() const {
|
||||
}
|
||||
|
||||
void HistogramController::reloadBannerView() {
|
||||
AppsContainer * container = ((App *)app())->container();
|
||||
char buffer[k_maxNumberOfCharacters+ Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)*2];
|
||||
const char * legend = "Interval [";
|
||||
int legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float lowerBound = m_store->startOfBarAtIndex(m_selectedBarIndex);
|
||||
int lowerBoundNumberOfChar = Complex::convertFloatToText(lowerBound, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
int lowerBoundNumberOfChar = Complex::convertFloatToText(lowerBound, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
buffer[legendLength+lowerBoundNumberOfChar] = ';';
|
||||
float upperBound = m_store->endOfBarAtIndex(m_selectedBarIndex);
|
||||
int upperBoundNumberOfChar = Complex::convertFloatToText(upperBound, buffer+legendLength+lowerBoundNumberOfChar+1, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
int upperBoundNumberOfChar = Complex::convertFloatToText(upperBound, buffer+legendLength+lowerBoundNumberOfChar+1, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
buffer[legendLength+lowerBoundNumberOfChar+upperBoundNumberOfChar+1] = '[';
|
||||
buffer[legendLength+lowerBoundNumberOfChar+upperBoundNumberOfChar+2] = 0;
|
||||
m_bannerView.setLegendAtIndex(buffer, 0);
|
||||
@@ -151,14 +150,14 @@ void HistogramController::reloadBannerView() {
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float size = m_store->heightOfBarAtIndex(m_selectedBarIndex);
|
||||
Complex::convertFloatToText(size, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(size, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 1);
|
||||
|
||||
legend = "Frequence: ";
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float frequency = size/m_store->sumOfColumn(1);
|
||||
Complex::convertFloatToText(frequency, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, container->preferences()->displayMode());
|
||||
Complex::convertFloatToText(frequency, buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
#include <poincare.h>
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
@@ -46,18 +47,18 @@ void TitleBarView::layoutSubviews() {
|
||||
m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize));
|
||||
}
|
||||
|
||||
void TitleBarView::setPreferences(Preferences * preferences) {
|
||||
void TitleBarView::refreshPreferences() {
|
||||
char buffer[13];
|
||||
int numberOfChar = 0;
|
||||
if (preferences->displayMode() == Expression::FloatDisplayMode::Scientific) {
|
||||
if (Preferences::sharedPreferences()->displayMode() == Expression::FloatDisplayMode::Scientific) {
|
||||
strlcpy(buffer, "sci/", 5);
|
||||
numberOfChar += 4;
|
||||
}
|
||||
if (preferences->numberType() == Preferences::NumberType::Complex) {
|
||||
if (Preferences::sharedPreferences()->numberType() == Preferences::NumberType::Complex) {
|
||||
strlcpy(buffer+numberOfChar, "cplx/", 6);
|
||||
numberOfChar += 5;
|
||||
}
|
||||
if (preferences->angleUnit() == Expression::AngleUnit::Radian) {
|
||||
if (Preferences::sharedPreferences()->angleUnit() == Expression::AngleUnit::Radian) {
|
||||
strlcpy(buffer+numberOfChar, "rad", 4);
|
||||
} else {
|
||||
strlcpy(buffer+numberOfChar, "deg", 4);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "battery_view.h"
|
||||
#include "preferences.h"
|
||||
|
||||
class TitleBarView : public View {
|
||||
public:
|
||||
@@ -11,7 +10,7 @@ public:
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setTitle(const char * title);
|
||||
void setChargeState(Ion::Battery::Charge chargeState);
|
||||
void setPreferences(Preferences * preferences);
|
||||
void refreshPreferences();
|
||||
private:
|
||||
constexpr static KDCoordinate k_batteryLeftMargin = 5;
|
||||
int numberOfSubviews() const override;
|
||||
|
||||
@@ -31,6 +31,7 @@ objs += $(addprefix poincare/src/,\
|
||||
opposite.o\
|
||||
parenthesis.o\
|
||||
power.o\
|
||||
preferences.o\
|
||||
product.o\
|
||||
sine.o\
|
||||
square_root.o\
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/parenthesis.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/product.h>
|
||||
#include <poincare/sine.h>
|
||||
#include <poincare/square_root.h>
|
||||
|
||||
@@ -8,12 +8,13 @@ namespace Poincare {
|
||||
class AbsoluteValue : public Function {
|
||||
public:
|
||||
AbsoluteValue();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ class Addition : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
Type type() const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
bool isCommutative() const override;
|
||||
private:
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ public:
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
protected:
|
||||
Expression * m_operands[2];
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
virtual Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual Expression * evaluateOnMatrixAndComplex(Matrix * m, Complex * c, Context& context, AngleUnit angleUnit) const;
|
||||
virtual Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const;
|
||||
|
||||
@@ -12,9 +12,6 @@ public:
|
||||
const char * fractionalPart, int fractionalPartLength,
|
||||
const char * exponent, int exponentLength, bool exponentNegative);
|
||||
void setNumberOfSignificantDigits(int numberOfDigits);
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) override;
|
||||
@@ -34,12 +31,15 @@ public:
|
||||
* is truncated at the end of the buffer.
|
||||
* ConvertFloat to Text return the number of characters that have been written
|
||||
* in buffer (excluding the last \O character) */
|
||||
static int convertFloatToText(float f, char * buffer, int bufferSize, int numberOfSignificantDigits, FloatDisplayMode mode = FloatDisplayMode::Scientific);
|
||||
static int convertFloatToText(float f, char * buffer, int bufferSize, int numberOfSignificantDigits, FloatDisplayMode mode = FloatDisplayMode::Default);
|
||||
constexpr static int bufferSizeForFloatsWithPrecision(int numberOfSignificantDigits) {
|
||||
// The wors case is -1.234E-38
|
||||
return numberOfSignificantDigits + 7;
|
||||
}
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
/* We here define the buffer size to write the lengthest float possible.
|
||||
* At maximum, the number has 7 significant digits so, in the worst case it
|
||||
* has the form -1.999999e-38 (7+6+1 char) (the auto mode is always
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class Cosine : public Function {
|
||||
public:
|
||||
Cosine();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace Poincare {
|
||||
class Derivative : public Function {
|
||||
public:
|
||||
Derivative();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
float growthRateAroundAbscissa(float x, float h, VariableContext variableContext, AngleUnit angleUnit) const;
|
||||
float approximateDerivate2(float x, float h, VariableContext xContext, AngleUnit angleUnit) const;
|
||||
constexpr static float k_maxErrorRateOnApproximation = 0.001f;
|
||||
|
||||
@@ -9,95 +9,100 @@ namespace Poincare {
|
||||
class Context;
|
||||
|
||||
class Expression {
|
||||
public:
|
||||
enum class Type : uint8_t {
|
||||
AbsoluteValue,
|
||||
Addition,
|
||||
Complex,
|
||||
Cosine,
|
||||
Derivative,
|
||||
Float,
|
||||
HyperbolicCosine,
|
||||
HyperbolicSine,
|
||||
HyperbolicTangent,
|
||||
Integer,
|
||||
Integral,
|
||||
Logarithm,
|
||||
Matrix,
|
||||
Multiplication,
|
||||
NaperianLogarithm,
|
||||
NthRoot,
|
||||
Opposite,
|
||||
Fraction,
|
||||
Parenthesis,
|
||||
Power,
|
||||
Product,
|
||||
Sine,
|
||||
SquareRoot,
|
||||
Sum,
|
||||
Subtraction,
|
||||
Symbol,
|
||||
Tangent,
|
||||
};
|
||||
enum class AngleUnit {
|
||||
Degree = 0,
|
||||
Radian = 1
|
||||
};
|
||||
enum class FloatDisplayMode {
|
||||
Auto = 0,
|
||||
Scientific = 1
|
||||
};
|
||||
static Expression * parse(char const * string);
|
||||
virtual ~Expression();
|
||||
public:
|
||||
enum class Type : uint8_t {
|
||||
AbsoluteValue,
|
||||
Addition,
|
||||
Complex,
|
||||
Cosine,
|
||||
Derivative,
|
||||
Float,
|
||||
HyperbolicCosine,
|
||||
HyperbolicSine,
|
||||
HyperbolicTangent,
|
||||
Integer,
|
||||
Integral,
|
||||
Logarithm,
|
||||
Matrix,
|
||||
Multiplication,
|
||||
NaperianLogarithm,
|
||||
NthRoot,
|
||||
Opposite,
|
||||
Fraction,
|
||||
Parenthesis,
|
||||
Power,
|
||||
Product,
|
||||
Sine,
|
||||
SquareRoot,
|
||||
Sum,
|
||||
Subtraction,
|
||||
Symbol,
|
||||
Tangent,
|
||||
};
|
||||
enum class AngleUnit {
|
||||
Degree = 0,
|
||||
Radian = 1,
|
||||
Default = 2
|
||||
};
|
||||
enum class FloatDisplayMode {
|
||||
Decimal = 0,
|
||||
Scientific = 1,
|
||||
Default = 2
|
||||
};
|
||||
static Expression * parse(char const * string);
|
||||
virtual ~Expression();
|
||||
|
||||
virtual ExpressionLayout * createLayout(Expression::FloatDisplayMode FloatDisplayMode = Expression::FloatDisplayMode::Auto) const = 0; // Returned object must be deleted
|
||||
virtual const Expression * operand(int i) const = 0;
|
||||
virtual int numberOfOperands() const = 0;
|
||||
virtual Expression * clone() const = 0;
|
||||
virtual Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const = 0;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode floatDisplayMode = FloatDisplayMode::Default) const; // Returned object must be deleted
|
||||
virtual const Expression * operand(int i) const = 0;
|
||||
virtual int numberOfOperands() const = 0;
|
||||
virtual Expression * clone() const = 0;
|
||||
virtual Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const = 0;
|
||||
|
||||
// TODO: Consider std::unique_ptr - see https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers
|
||||
// TODO: Consider std::unique_ptr - see https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers
|
||||
|
||||
/* This tests whether two expressions are the same, this takes into account
|
||||
* commutativity of operators.
|
||||
*
|
||||
* For example 3+5 is identical to 5+3 but is not identical to 8.
|
||||
*/
|
||||
bool isIdenticalTo(const Expression * e) const;
|
||||
/* This tests whether two expressions are the same, this takes into account
|
||||
* commutativity of operators.
|
||||
*
|
||||
* For example 3+5 is identical to 5+3 but is not identical to 8.
|
||||
*/
|
||||
bool isIdenticalTo(const Expression * e) const;
|
||||
|
||||
/* This tests whether two expressions are equivalent.
|
||||
* This is done by testing wheter they simplify to the same expression.
|
||||
*
|
||||
* For example:
|
||||
* - 3+5 and 4+4 are equivalent.
|
||||
* - (x+y)*z and x*z+y*z are equivalent.
|
||||
*
|
||||
* Here we assume that two equivalent expressions have the same
|
||||
* simplification, we don't really know whether that's the case,
|
||||
* nevertheless we are sure that if two expressions simplify to the same
|
||||
* expression they are indeed equivalent.
|
||||
*/
|
||||
bool isEquivalentTo(Expression * e) const;
|
||||
/* This tests whether two expressions are equivalent.
|
||||
* This is done by testing wheter they simplify to the same expression.
|
||||
*
|
||||
* For example:
|
||||
* - 3+5 and 4+4 are equivalent.
|
||||
* - (x+y)*z and x*z+y*z are equivalent.
|
||||
*
|
||||
* Here we assume that two equivalent expressions have the same
|
||||
* simplification, we don't really know whether that's the case,
|
||||
* nevertheless we are sure that if two expressions simplify to the same
|
||||
* expression they are indeed equivalent.
|
||||
*/
|
||||
bool isEquivalentTo(Expression * e) const;
|
||||
|
||||
/* Compare the value of two expressions.
|
||||
* This only make sense if the two values are of the same type
|
||||
*/
|
||||
virtual bool valueEquals(const Expression * e) const;
|
||||
Expression * simplify() const;
|
||||
/* Compare the value of two expressions.
|
||||
* This only make sense if the two values are of the same type
|
||||
*/
|
||||
virtual bool valueEquals(const Expression * e) const;
|
||||
Expression * simplify() const;
|
||||
|
||||
virtual Type type() const = 0;
|
||||
virtual bool isCommutative() const;
|
||||
/* The function evaluate creates a new expression and thus mallocs memory.
|
||||
* Do not forget to delete the new expression to avoid leaking. */
|
||||
virtual Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const = 0;
|
||||
virtual float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const = 0;
|
||||
virtual int writeTextInBuffer(char * buffer, int bufferSize);
|
||||
private:
|
||||
bool sequentialOperandsIdentity(const Expression * e) const;
|
||||
bool commutativeOperandsIdentity(const Expression * e) const;
|
||||
bool combinatoryCommutativeOperandsIdentity(const Expression * e,
|
||||
bool * operandMatched, int leftToMatch) const;
|
||||
virtual Type type() const = 0;
|
||||
virtual bool isCommutative() const;
|
||||
/* The function evaluate creates a new expression and thus mallocs memory.
|
||||
* Do not forget to delete the new expression to avoid leaking. */
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Default) const;
|
||||
virtual int writeTextInBuffer(char * buffer, int bufferSize);
|
||||
private:
|
||||
virtual ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const = 0;
|
||||
virtual Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const = 0;
|
||||
virtual float privateApproximate(Context& context, AngleUnit angleUnit) const = 0;
|
||||
bool sequentialOperandsIdentity(const Expression * e) const;
|
||||
bool commutativeOperandsIdentity(const Expression * e) const;
|
||||
bool combinatoryCommutativeOperandsIdentity(const Expression * e,
|
||||
bool * operandMatched, int leftToMatch) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,27 +6,27 @@
|
||||
namespace Poincare {
|
||||
|
||||
class ExpressionLayout {
|
||||
public:
|
||||
ExpressionLayout();
|
||||
virtual ~ExpressionLayout();
|
||||
public:
|
||||
ExpressionLayout();
|
||||
virtual ~ExpressionLayout();
|
||||
|
||||
void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite);
|
||||
KDPoint origin();
|
||||
KDSize size();
|
||||
KDCoordinate baseline();
|
||||
void setParent(ExpressionLayout* parent);
|
||||
protected:
|
||||
virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) = 0;
|
||||
virtual KDSize computeSize() = 0;
|
||||
virtual ExpressionLayout * child(uint16_t index) = 0;
|
||||
virtual KDPoint positionOfChild(ExpressionLayout * child) = 0;
|
||||
KDCoordinate m_baseline;
|
||||
private:
|
||||
KDPoint absoluteOrigin();
|
||||
//void computeLayout();//ExpressionLayout * parent, uint16_t childIndex);
|
||||
ExpressionLayout* m_parent;
|
||||
bool m_sized, m_positioned;
|
||||
KDRect m_frame;
|
||||
void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite);
|
||||
KDPoint origin();
|
||||
KDSize size();
|
||||
KDCoordinate baseline();
|
||||
void setParent(ExpressionLayout* parent);
|
||||
protected:
|
||||
virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) = 0;
|
||||
virtual KDSize computeSize() = 0;
|
||||
virtual ExpressionLayout * child(uint16_t index) = 0;
|
||||
virtual KDPoint positionOfChild(ExpressionLayout * child) = 0;
|
||||
KDCoordinate m_baseline;
|
||||
private:
|
||||
KDPoint absoluteOrigin();
|
||||
//void computeLayout();//ExpressionLayout * parent, uint16_t childIndex);
|
||||
ExpressionLayout* m_parent;
|
||||
bool m_sized, m_positioned;
|
||||
KDRect m_frame;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Poincare {
|
||||
class Fraction : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const override;
|
||||
|
||||
@@ -15,12 +15,12 @@ public:
|
||||
~Function();
|
||||
void setArgument(Expression ** args, int numberOfArguments, bool clone = true);
|
||||
void setArgument(ListData * listData, bool clone = true);
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
protected:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression ** m_args;
|
||||
int m_numberOfArguments;
|
||||
const char * m_name;
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class HyperbolicCosine : public Function {
|
||||
public:
|
||||
HyperbolicCosine();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class HyperbolicSine : public Function {
|
||||
public:
|
||||
HyperbolicSine();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class HyperbolicTangent : public Function {
|
||||
public:
|
||||
HyperbolicTangent();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,40 +11,40 @@ typedef uint64_t double_native_uint_t;
|
||||
namespace Poincare {
|
||||
|
||||
class Integer : public LeafExpression {
|
||||
public:
|
||||
Integer(native_int_t i);
|
||||
Integer(Integer&& other); // C++11 move constructor
|
||||
Integer(const char * digits, bool negative = false); // Digits are NOT NULL-terminated
|
||||
Type type() const override;
|
||||
public:
|
||||
Integer(native_int_t i);
|
||||
Integer(Integer&& other); // C++11 move constructor
|
||||
Integer(const char * digits, bool negative = false); // Digits are NOT NULL-terminated
|
||||
Type type() const override;
|
||||
|
||||
~Integer();
|
||||
~Integer();
|
||||
|
||||
Integer& operator=(Integer&& other); // C++11 move assignment operator
|
||||
Integer& operator=(Integer&& other); // C++11 move assignment operator
|
||||
|
||||
// Arithmetic
|
||||
Integer add(const Integer &other) const;
|
||||
Integer subtract(const Integer &other) const;
|
||||
Integer multiply_by(const Integer &other) const;
|
||||
Integer divide_by(const Integer &other) const;
|
||||
// Arithmetic
|
||||
Integer add(const Integer &other) const;
|
||||
Integer subtract(const Integer &other) const;
|
||||
Integer multiply_by(const Integer &other) const;
|
||||
Integer divide_by(const Integer &other) const;
|
||||
|
||||
bool operator<(const Integer &other) const;
|
||||
bool operator==(const Integer &other) const;
|
||||
bool operator<(const Integer &other) const;
|
||||
bool operator==(const Integer &other) const;
|
||||
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
|
||||
Expression * clone() const override;
|
||||
virtual ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
Integer add(const Integer &other, bool inverse_other_negative) const;
|
||||
int8_t ucmp(const Integer &other) const; // -1, 0, or 1
|
||||
Integer usum(const Integer &other, bool subtract, bool output_negative) const;
|
||||
/* WARNING: This constructor takes ownership of the bits array and will free it! */
|
||||
Integer(native_uint_t * digits, uint16_t numberOfDigits, bool negative);
|
||||
native_uint_t * m_digits; // LITTLE-ENDIAN
|
||||
uint16_t m_numberOfDigits; // In base native_uint_max
|
||||
bool m_negative;
|
||||
Expression * clone() const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Integer add(const Integer &other, bool inverse_other_negative) const;
|
||||
int8_t ucmp(const Integer &other) const; // -1, 0, or 1
|
||||
Integer usum(const Integer &other, bool subtract, bool output_negative) const;
|
||||
/* WARNING: This constructor takes ownership of the bits array and will free it! */
|
||||
Integer(native_uint_t * digits, uint16_t numberOfDigits, bool negative);
|
||||
native_uint_t * m_digits; // LITTLE-ENDIAN
|
||||
uint16_t m_numberOfDigits; // In base native_uint_max
|
||||
bool m_negative;
|
||||
|
||||
/*
|
||||
// TODO: Small-int optimization
|
||||
|
||||
@@ -9,12 +9,12 @@ namespace Poincare {
|
||||
class Integral : public Function {
|
||||
public:
|
||||
Integral();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
struct DetailedResult
|
||||
{
|
||||
float integral;
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
namespace Poincare {
|
||||
|
||||
class LeafExpression : public Expression {
|
||||
public:
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
public:
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
namespace Poincare {
|
||||
|
||||
class ListData {
|
||||
public:
|
||||
ListData(Expression * operand);
|
||||
~ListData();
|
||||
int numberOfOperands() const;
|
||||
const Expression * operand(int i) const;
|
||||
void pushExpression(Expression * operand);
|
||||
private:
|
||||
int m_numberOfOperands;
|
||||
Expression ** m_operands;
|
||||
public:
|
||||
ListData(Expression * operand);
|
||||
~ListData();
|
||||
int numberOfOperands() const;
|
||||
const Expression * operand(int i) const;
|
||||
void pushExpression(Expression * operand);
|
||||
private:
|
||||
int m_numberOfOperands;
|
||||
Expression ** m_operands;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class Logarithm : public Function {
|
||||
public:
|
||||
Logarithm();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,27 +8,27 @@
|
||||
namespace Poincare {
|
||||
|
||||
class Matrix : public Expression {
|
||||
public:
|
||||
Matrix(MatrixData * matrixData);
|
||||
Matrix(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~Matrix();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
int numberOfRows() const;
|
||||
int numberOfColumns() const;
|
||||
/* If the buffer is too small, the function fills the buffer until reaching
|
||||
* buffer size */
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) override;
|
||||
private:
|
||||
MatrixData * m_matrixData;
|
||||
static Complex * defaultExpression();
|
||||
public:
|
||||
Matrix(MatrixData * matrixData);
|
||||
Matrix(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~Matrix();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
int numberOfRows() const;
|
||||
int numberOfColumns() const;
|
||||
/* If the buffer is too small, the function fills the buffer until reaching
|
||||
* buffer size */
|
||||
int writeTextInBuffer(char * buffer, int bufferSize) override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
MatrixData * m_matrixData;
|
||||
static Complex * defaultExpression();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
namespace Poincare {
|
||||
|
||||
class MatrixData {
|
||||
public:
|
||||
MatrixData(ListData * listData);
|
||||
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~MatrixData();
|
||||
void pushListData(ListData * listData);
|
||||
int numberOfRows();
|
||||
int numberOfColumns();
|
||||
Expression ** operands() const;
|
||||
private:
|
||||
int m_numberOfRows;
|
||||
int m_numberOfColumns;
|
||||
Expression ** m_operands;
|
||||
static Complex * defaultExpression();
|
||||
public:
|
||||
MatrixData(ListData * listData);
|
||||
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
|
||||
~MatrixData();
|
||||
void pushListData(ListData * listData);
|
||||
int numberOfRows();
|
||||
int numberOfColumns();
|
||||
Expression ** operands() const;
|
||||
private:
|
||||
int m_numberOfRows;
|
||||
int m_numberOfColumns;
|
||||
Expression ** m_operands;
|
||||
static Complex * defaultExpression();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ class Multiplication : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
Type type() const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrices(Matrix * m, Matrix * n, Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
@@ -8,10 +8,11 @@ namespace Poincare {
|
||||
class NaperianLogarithm : public Function {
|
||||
public:
|
||||
NaperianLogarithm();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,13 @@ namespace Poincare {
|
||||
class NthRoot : public Function {
|
||||
public:
|
||||
NthRoot();
|
||||
float approximate(Context & context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@
|
||||
namespace Poincare {
|
||||
|
||||
class Opposite : public Expression {
|
||||
public:
|
||||
Opposite(Expression * operand, bool cloneOperands = true);
|
||||
~Opposite();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
protected:
|
||||
Expression * m_operand;
|
||||
Expression * evaluateOnMatrix(Matrix * m, Context& context, AngleUnit angleUnit) const;
|
||||
public:
|
||||
Opposite(Expression * operand, bool cloneOperands = true);
|
||||
~Opposite();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * m_operand;
|
||||
Expression * evaluateOnMatrix(Matrix * m, Context& context, AngleUnit angleUnit) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
namespace Poincare {
|
||||
|
||||
class Parenthesis : public Expression {
|
||||
public:
|
||||
Parenthesis(Expression * operand, bool cloneOperands = true);
|
||||
~Parenthesis();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
protected:
|
||||
Expression * m_operand;
|
||||
public:
|
||||
Parenthesis(Expression * operand, bool cloneOperands = true);
|
||||
~Parenthesis();
|
||||
const Expression * operand(int i) const override;
|
||||
int numberOfOperands() const override;
|
||||
Expression * clone() const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * m_operand;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Poincare {
|
||||
class Power : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnMatrixAndComplex(Matrix * m, Complex * c, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef APPS_PREFERENCES_H
|
||||
#define APPS_PREFERENCES_H
|
||||
#ifndef POINCARE_PREFERENCES_H
|
||||
#define POINCARE_PREFERENCES_H
|
||||
|
||||
#include <poincare.h>
|
||||
#include <poincare/expression.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class Preferences {
|
||||
public:
|
||||
@@ -13,11 +15,8 @@ public:
|
||||
Algebric = 0,
|
||||
Polar = 1
|
||||
};
|
||||
enum class Language {
|
||||
French = 0,
|
||||
English = 1
|
||||
};
|
||||
Preferences();
|
||||
static Preferences * sharedPreferences();
|
||||
Poincare::Expression::AngleUnit angleUnit() const;
|
||||
void setAngleUnit(Poincare::Expression::AngleUnit angleUnit);
|
||||
Poincare::Expression::FloatDisplayMode displayMode() const;
|
||||
@@ -26,14 +25,13 @@ public:
|
||||
void setNumberType(NumberType numberType);
|
||||
ComplexFormat complexFormat() const;
|
||||
void setComplexFormat(ComplexFormat complexFormat);
|
||||
Language language() const;
|
||||
void setLanguage(Language language);
|
||||
private:
|
||||
Poincare::Expression::AngleUnit m_angleUnit;
|
||||
Poincare::Expression::FloatDisplayMode m_displayMode;
|
||||
NumberType m_numberType;
|
||||
ComplexFormat m_complexFormat;
|
||||
Language m_language;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,12 +8,13 @@ namespace Poincare {
|
||||
class Product : public Function {
|
||||
public:
|
||||
Product();
|
||||
float approximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class Sine : public Function {
|
||||
public:
|
||||
Sine();
|
||||
float approximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,13 @@ namespace Poincare {
|
||||
class SquareRoot : public Function {
|
||||
public:
|
||||
SquareRoot();
|
||||
float approximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Poincare {
|
||||
class Subtraction : public BinaryOperation {
|
||||
using BinaryOperation::BinaryOperation;
|
||||
public:
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * evaluateOnComplexAndMatrix(Complex * c, Matrix * m, Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
@@ -8,12 +8,13 @@ namespace Poincare {
|
||||
class Sum : public Function {
|
||||
public:
|
||||
Sum();
|
||||
float approximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numberOfOperands, bool cloneOperands = true) const override;
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,19 +7,19 @@ namespace Poincare {
|
||||
|
||||
class Symbol : public LeafExpression {
|
||||
public:
|
||||
enum SpecialSymbols : char {
|
||||
Ans = '^'
|
||||
};
|
||||
Symbol(char name);
|
||||
ExpressionLayout * createLayout(FloatDisplayMode FloatDisplayMode = FloatDisplayMode::Auto) const override;
|
||||
float approximate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
Type type() const override;
|
||||
const char name() const;
|
||||
Expression * clone() const override;
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
private:
|
||||
const char m_name;
|
||||
enum SpecialSymbols : char {
|
||||
Ans = '^'
|
||||
};
|
||||
Symbol(char name);
|
||||
Type type() const override;
|
||||
const char name() const;
|
||||
Expression * clone() const override;
|
||||
bool valueEquals(const Expression * e) const override;
|
||||
private:
|
||||
float privateApproximate(Context& context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode) const override;
|
||||
const char m_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ namespace Poincare {
|
||||
class Tangent : public Function {
|
||||
public:
|
||||
Tangent();
|
||||
float approximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Type type() const override;
|
||||
Expression * cloneWithDifferentOperands(Expression ** newOperands,
|
||||
int numnerOfOperands, bool cloneOperands = true) const override;
|
||||
Expression * evaluate(Context& context, AngleUnit angleUnit = AngleUnit::Radian) const override;
|
||||
private:
|
||||
float privateApproximate(Context & context, AngleUnit angleUnit) const override;
|
||||
Expression * privateEvaluate(Context& context, AngleUnit angleUnit) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ Expression * AbsoluteValue::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return a;
|
||||
}
|
||||
|
||||
float AbsoluteValue::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float AbsoluteValue::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
float result = 0.0f;
|
||||
@@ -40,7 +41,8 @@ float AbsoluteValue::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * AbsoluteValue::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * AbsoluteValue::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
@@ -53,8 +55,9 @@ Expression * AbsoluteValue::evaluate(Context& context, AngleUnit angleUnit) cons
|
||||
return result;
|
||||
}
|
||||
|
||||
ExpressionLayout * AbsoluteValue::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
return new AbsoluteValueLayout(m_args[0]->createLayout(FloatDisplayMode));
|
||||
ExpressionLayout * AbsoluteValue::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
return new AbsoluteValueLayout(m_args[0]->createLayout(floatDisplayMode));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,15 +13,17 @@ Expression::Type Addition::type() const {
|
||||
return Type::Addition;
|
||||
}
|
||||
|
||||
ExpressionLayout * Addition::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Addition::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *));
|
||||
children_layouts[0] = m_operands[0]->createLayout(FloatDisplayMode);
|
||||
children_layouts[0] = m_operands[0]->createLayout(floatDisplayMode);
|
||||
children_layouts[1] = new StringLayout("+", 1);
|
||||
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(FloatDisplayMode)) : m_operands[1]->createLayout(FloatDisplayMode);
|
||||
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(floatDisplayMode)) : m_operands[1]->createLayout(floatDisplayMode);
|
||||
return new HorizontalLayout(children_layouts, 3);
|
||||
}
|
||||
|
||||
float Addition::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Addition::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return m_operands[0]->approximate(context, angleUnit)+m_operands[1]->approximate(context, angleUnit);;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ Expression * BinaryOperation::clone() const {
|
||||
return this->cloneWithDifferentOperands((Expression**) m_operands, 2, true);
|
||||
}
|
||||
|
||||
Expression * BinaryOperation::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * BinaryOperation::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * leftOperandEvalutation = m_operands[0]->evaluate(context, angleUnit);
|
||||
Expression * rightOperandEvalutation = m_operands[1]->evaluate(context, angleUnit);
|
||||
if (leftOperandEvalutation == nullptr || rightOperandEvalutation == nullptr) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/preferences.h>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@@ -63,14 +64,16 @@ Expression * Complex::clone() const {
|
||||
return new Complex(m_a, m_b);
|
||||
}
|
||||
|
||||
float Complex::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Complex::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (m_b == 0.0f) {
|
||||
return m_a;
|
||||
}
|
||||
return NAN;
|
||||
}
|
||||
|
||||
Expression * Complex::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Complex::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return clone();
|
||||
}
|
||||
|
||||
@@ -78,14 +81,15 @@ Expression::Type Complex::type() const {
|
||||
return Type::Complex;
|
||||
}
|
||||
|
||||
ExpressionLayout * Complex::createLayout(FloatDisplayMode displayMode) const {
|
||||
ExpressionLayout * Complex::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
char buffer[k_maxComplexBufferLength];
|
||||
int numberOfChars = convertComplexToText(buffer, k_maxComplexBufferLength, displayMode);
|
||||
int numberOfChars = convertComplexToText(buffer, k_maxComplexBufferLength, floatDisplayMode);
|
||||
return new StringLayout(buffer, numberOfChars);
|
||||
}
|
||||
|
||||
int Complex::writeTextInBuffer(char * buffer, int bufferSize) {
|
||||
return convertComplexToText(buffer, bufferSize, FloatDisplayMode::Auto);
|
||||
return convertComplexToText(buffer, bufferSize, FloatDisplayMode::Decimal);
|
||||
}
|
||||
|
||||
float Complex::a() {
|
||||
@@ -117,6 +121,9 @@ float Complex::absoluteValue() {
|
||||
|
||||
int Complex::convertFloatToText(float f, char * buffer, int bufferSize,
|
||||
int numberOfSignificantDigits, FloatDisplayMode mode) {
|
||||
if (mode == FloatDisplayMode::Default) {
|
||||
return convertFloatToText(f, buffer, bufferSize, numberOfSignificantDigits, Preferences::sharedPreferences()->displayMode());
|
||||
}
|
||||
char tempBuffer[k_maxFloatBufferLength];
|
||||
int requiredLength = convertFloatToTextPrivate(f, tempBuffer, numberOfSignificantDigits, mode);
|
||||
/* if the required buffer size overflows the buffer size, we first force the
|
||||
@@ -124,7 +131,7 @@ int Complex::convertFloatToText(float f, char * buffer, int bufferSize,
|
||||
* fit the buffer size. If the buffer size is still to small, we only write
|
||||
* the beginning of the float and truncate it (which can result in a non sense
|
||||
* text) */
|
||||
if (mode == FloatDisplayMode::Auto && requiredLength >= bufferSize) {
|
||||
if (mode == FloatDisplayMode::Decimal && requiredLength >= bufferSize) {
|
||||
requiredLength = convertFloatToTextPrivate(f, tempBuffer, numberOfSignificantDigits, FloatDisplayMode::Scientific);
|
||||
}
|
||||
if (requiredLength >= bufferSize) {
|
||||
@@ -136,6 +143,7 @@ int Complex::convertFloatToText(float f, char * buffer, int bufferSize,
|
||||
}
|
||||
|
||||
int Complex::convertComplexToText(char * buffer, int bufferSize, FloatDisplayMode displayMode) const {
|
||||
assert(displayMode != FloatDisplayMode::Default);
|
||||
int numberOfChars = 0;
|
||||
if (m_a != 0.0f || m_b == 0.0f) {
|
||||
numberOfChars = convertFloatToText(m_a, buffer, bufferSize, m_numberOfSignificantDigits, displayMode);
|
||||
@@ -161,6 +169,7 @@ int Complex::convertComplexToText(char * buffer, int bufferSize, FloatDisplayMod
|
||||
|
||||
|
||||
int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSignificantDigits, FloatDisplayMode mode) {
|
||||
assert(mode != FloatDisplayMode::Default);
|
||||
if (isinf(f)) {
|
||||
buffer[0] = f > 0 ? '+' : '-';
|
||||
buffer[1] = 'I';
|
||||
@@ -188,7 +197,7 @@ int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSigni
|
||||
}
|
||||
|
||||
FloatDisplayMode displayMode = mode;
|
||||
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == FloatDisplayMode::Auto) {
|
||||
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == FloatDisplayMode::Decimal) {
|
||||
displayMode = FloatDisplayMode::Scientific;
|
||||
}
|
||||
|
||||
@@ -237,13 +246,13 @@ int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSigni
|
||||
}
|
||||
|
||||
// Suppress the decimal marker if no fractional part
|
||||
if (displayMode == FloatDisplayMode::Auto && availableCharsForMantissaWithoutSign == exponentInBase10+2) {
|
||||
if (displayMode == FloatDisplayMode::Decimal && availableCharsForMantissaWithoutSign == exponentInBase10+2) {
|
||||
availableCharsForMantissaWithSign--;
|
||||
}
|
||||
|
||||
// Print mantissa
|
||||
printBase10IntegerWithDecimalMarker(buffer, availableCharsForMantissaWithSign, mantissa, decimalMarkerPosition);
|
||||
if (displayMode == FloatDisplayMode::Auto) {
|
||||
if (displayMode == FloatDisplayMode::Decimal) {
|
||||
buffer[availableCharsForMantissaWithSign] = 0;
|
||||
return availableCharsForMantissaWithSign;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,16 @@ Expression * Cosine::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return c;
|
||||
}
|
||||
|
||||
float Cosine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Cosine::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (angleUnit == AngleUnit::Degree) {
|
||||
return cosf(m_args[0]->approximate(context, angleUnit)*M_PI/180.0f);
|
||||
}
|
||||
return cosf(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
Expression * Cosine::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Cosine::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
|
||||
@@ -28,7 +28,8 @@ Expression * Derivative::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return d;
|
||||
}
|
||||
|
||||
float Derivative::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Derivative::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
VariableContext xContext = VariableContext('x', &context);
|
||||
Symbol xSymbol = Symbol('x');
|
||||
float x = m_args[1]->approximate(context, angleUnit);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/function.h>
|
||||
#include <poincare/list_data.h>
|
||||
#include <poincare/matrix_data.h>
|
||||
@@ -37,6 +38,33 @@ Expression * Expression::parse(char const * string) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
ExpressionLayout * Expression::createLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
switch (floatDisplayMode) {
|
||||
case FloatDisplayMode::Default:
|
||||
return privateCreateLayout(Preferences::sharedPreferences()->displayMode());
|
||||
default:
|
||||
return privateCreateLayout(floatDisplayMode);
|
||||
}
|
||||
}
|
||||
|
||||
Expression * Expression::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
switch (angleUnit) {
|
||||
case AngleUnit::Default:
|
||||
return privateEvaluate(context, Preferences::sharedPreferences()->angleUnit());
|
||||
default:
|
||||
return privateEvaluate(context, angleUnit);
|
||||
}
|
||||
}
|
||||
|
||||
float Expression::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
switch (angleUnit) {
|
||||
case AngleUnit::Default:
|
||||
return privateApproximate(context, Preferences::sharedPreferences()->angleUnit());
|
||||
default:
|
||||
return privateApproximate(context, angleUnit);
|
||||
}
|
||||
}
|
||||
|
||||
Expression * Expression::simplify() const {
|
||||
/* We make sure that the simplification is deletable.
|
||||
* Indeed, we don't want an expression with some parts deletable and some not
|
||||
|
||||
@@ -15,11 +15,13 @@ Expression * Fraction::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return new Fraction(newOperands, cloneOperands);
|
||||
}
|
||||
|
||||
ExpressionLayout * Fraction::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
return new FractionLayout(m_operands[0]->createLayout(FloatDisplayMode), m_operands[1]->createLayout(FloatDisplayMode));
|
||||
ExpressionLayout * Fraction::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
return new FractionLayout(m_operands[0]->createLayout(floatDisplayMode), m_operands[1]->createLayout(floatDisplayMode));
|
||||
}
|
||||
|
||||
float Fraction::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Fraction::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return m_operands[0]->approximate(context, angleUnit)/m_operands[1]->approximate(context, angleUnit);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,13 +67,14 @@ Expression * Function::clone() const {
|
||||
return this->cloneWithDifferentOperands(m_args, m_numberOfArguments, true);
|
||||
}
|
||||
|
||||
ExpressionLayout * Function::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Function::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
ExpressionLayout ** grandChildrenLayouts = (ExpressionLayout **)malloc((2*m_numberOfArguments-1)*sizeof(ExpressionLayout *));
|
||||
int layoutIndex = 0;
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(FloatDisplayMode);
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(floatDisplayMode);
|
||||
for (int i = 1; i < m_numberOfArguments; i++) {
|
||||
grandChildrenLayouts[layoutIndex++] = new StringLayout(",", 1);
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(FloatDisplayMode);
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(floatDisplayMode);
|
||||
}
|
||||
ExpressionLayout * argumentLayouts = new HorizontalLayout(grandChildrenLayouts, 2*m_numberOfArguments-1);
|
||||
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
|
||||
@@ -91,7 +92,8 @@ int Function::numberOfOperands() const {
|
||||
return m_numberOfArguments;
|
||||
}
|
||||
|
||||
Expression * Function::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Function::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
/* Default function evaluation works for reel function */
|
||||
return new Complex(approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ Expression * HyperbolicCosine::cloneWithDifferentOperands(Expression** newOperan
|
||||
return hc;
|
||||
}
|
||||
|
||||
float HyperbolicCosine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float HyperbolicCosine::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))+expf(-m_args[0]->approximate(context, angleUnit)))/2.0f;
|
||||
}
|
||||
|
||||
Expression * HyperbolicCosine::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * HyperbolicCosine::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
|
||||
@@ -29,11 +29,13 @@ Expression * HyperbolicSine::cloneWithDifferentOperands(Expression** newOperands
|
||||
return hs;
|
||||
}
|
||||
|
||||
float HyperbolicSine::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float HyperbolicSine::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))-expf(-m_args[0]->approximate(context, angleUnit)))/2.0f;
|
||||
}
|
||||
|
||||
Expression * HyperbolicSine::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * HyperbolicSine::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
|
||||
@@ -28,12 +28,14 @@ Expression * HyperbolicTangent::cloneWithDifferentOperands(Expression** newOpera
|
||||
return ht;
|
||||
}
|
||||
|
||||
float HyperbolicTangent::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float HyperbolicTangent::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return (expf(m_args[0]->approximate(context, angleUnit))-expf(-m_args[0]->approximate(context, angleUnit)))/
|
||||
(expf(m_args[0]->approximate(context, angleUnit))+expf(-m_args[0]->approximate(context, angleUnit)));
|
||||
}
|
||||
|
||||
Expression * HyperbolicTangent::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * HyperbolicTangent::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * evaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
assert(evaluation->type() == Type::Matrix || evaluation->type() == Type::Complex);
|
||||
if (evaluation->type() == Type::Matrix) {
|
||||
|
||||
@@ -259,7 +259,8 @@ Expression * Integer::clone() const {
|
||||
return clone;
|
||||
}
|
||||
|
||||
float Integer::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Integer::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
union {
|
||||
uint32_t uint_result;
|
||||
float float_result;
|
||||
@@ -310,7 +311,8 @@ float Integer::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
return float_result;
|
||||
}
|
||||
|
||||
Expression * Integer::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Integer::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return new Complex(approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
@@ -318,7 +320,8 @@ Expression::Type Integer::type() const {
|
||||
return Type::Integer;
|
||||
}
|
||||
|
||||
ExpressionLayout * Integer::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Integer::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
char buffer[255];
|
||||
|
||||
Integer base = Integer(10);
|
||||
|
||||
@@ -32,7 +32,8 @@ Expression * Integral::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return i;
|
||||
}
|
||||
|
||||
float Integral::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Integral::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
VariableContext xContext = VariableContext('x', &context);
|
||||
float a = m_args[1]->approximate(context, angleUnit);
|
||||
float b = m_args[2]->approximate(context, angleUnit);
|
||||
@@ -46,11 +47,12 @@ float Integral::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
#endif
|
||||
}
|
||||
|
||||
ExpressionLayout * Integral::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Integral::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
|
||||
childrenLayouts[0] = m_args[0]->createLayout(FloatDisplayMode);
|
||||
childrenLayouts[0] = m_args[0]->createLayout(floatDisplayMode);
|
||||
childrenLayouts[1] = new StringLayout("dx", 2);
|
||||
return new IntegralLayout(m_args[1]->createLayout(FloatDisplayMode), m_args[2]->createLayout(FloatDisplayMode), new HorizontalLayout(childrenLayouts, 2));
|
||||
return new IntegralLayout(m_args[1]->createLayout(floatDisplayMode), m_args[2]->createLayout(floatDisplayMode), new HorizontalLayout(childrenLayouts, 2));
|
||||
}
|
||||
|
||||
float Integral::functionValueAtAbscissa(float x, VariableContext xContext, AngleUnit angleUnit) const {
|
||||
|
||||
@@ -29,20 +29,22 @@ Expression * Logarithm::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return l;
|
||||
}
|
||||
|
||||
float Logarithm::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Logarithm::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (m_numberOfArguments == 1) {
|
||||
return log10f(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
return log10f(m_args[1]->approximate(context, angleUnit))/log10f(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
ExpressionLayout * Logarithm::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Logarithm::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
if (m_numberOfArguments == 1) {
|
||||
return Function::createLayout(FloatDisplayMode);
|
||||
return Function::createLayout(floatDisplayMode);
|
||||
}
|
||||
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
|
||||
childrenLayouts[0] = new BaselineRelativeLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout(FloatDisplayMode), BaselineRelativeLayout::Type::Subscript);
|
||||
childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout(FloatDisplayMode));
|
||||
childrenLayouts[0] = new BaselineRelativeLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout(floatDisplayMode), BaselineRelativeLayout::Type::Subscript);
|
||||
childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout(floatDisplayMode));
|
||||
return new HorizontalLayout(childrenLayouts, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,19 +43,22 @@ Expression * Matrix::clone() const {
|
||||
return this->cloneWithDifferentOperands(m_matrixData->operands(), numberOfOperands(), true);
|
||||
}
|
||||
|
||||
ExpressionLayout * Matrix::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Matrix::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(numberOfOperands()*sizeof(ExpressionLayout *));
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
childrenLayouts[i] = operand(i)->createLayout(FloatDisplayMode);
|
||||
childrenLayouts[i] = operand(i)->createLayout(floatDisplayMode);
|
||||
}
|
||||
return new MatrixLayout(childrenLayouts, numberOfRows(), numberOfColumns());
|
||||
}
|
||||
|
||||
float Matrix::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Matrix::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return NAN;
|
||||
}
|
||||
|
||||
Expression * Matrix::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Matrix::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * operands[numberOfOperands()];
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
operands[i] = operand(i)->evaluate(context, angleUnit);
|
||||
|
||||
@@ -15,15 +15,17 @@ Expression::Type Multiplication::type() const {
|
||||
return Expression::Type::Multiplication;
|
||||
}
|
||||
|
||||
ExpressionLayout * Multiplication::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
ExpressionLayout * Multiplication::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *));
|
||||
children_layouts[0] = m_operands[0]->createLayout(FloatDisplayMode);
|
||||
children_layouts[0] = m_operands[0]->createLayout(floatDisplayMode);
|
||||
children_layouts[1] = new StringLayout("*", 1);
|
||||
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(FloatDisplayMode)) : m_operands[1]->createLayout(FloatDisplayMode);
|
||||
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(floatDisplayMode)) : m_operands[1]->createLayout(floatDisplayMode);
|
||||
return new HorizontalLayout(children_layouts, 3);
|
||||
}
|
||||
|
||||
float Multiplication::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float Multiplication::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return m_operands[0]->approximate(context, angleUnit)*m_operands[1]->approximate(context, angleUnit);;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ Expression * NaperianLogarithm::cloneWithDifferentOperands(Expression** newOpera
|
||||
return l;
|
||||
}
|
||||
|
||||
float NaperianLogarithm::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float NaperianLogarithm::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return logf(m_args[0]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,18 @@ Expression * NthRoot::cloneWithDifferentOperands(Expression** newOperands,
|
||||
return r;
|
||||
}
|
||||
|
||||
float NthRoot::approximate(Context& context, AngleUnit angleUnit) const {
|
||||
float NthRoot::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
return powf(m_args[0]->approximate(context, angleUnit), 1.0f/m_args[1]->approximate(context, angleUnit));
|
||||
}
|
||||
|
||||
ExpressionLayout * NthRoot::createLayout(FloatDisplayMode FloatDisplayMode) const {
|
||||
return new NthRootLayout(m_args[0]->createLayout(FloatDisplayMode), m_args[1]->createLayout(FloatDisplayMode));
|
||||
ExpressionLayout * NthRoot::privateCreateLayout(FloatDisplayMode floatDisplayMode) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
return new NthRootLayout(m_args[0]->createLayout(floatDisplayMode), m_args[1]->createLayout(floatDisplayMode));
|
||||
}
|
||||
|
||||
Expression * NthRoot::evaluate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * NthRoot::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * baseEvaluation = m_args[0]->evaluate(context, angleUnit);
|
||||
Expression * indexEvaluation = m_args[1]->evaluate(context, angleUnit);
|
||||
assert(baseEvaluation->type() == Type::Matrix || baseEvaluation->type() == Type::Complex);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user