mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/shared] FloatPairStore -> DoublePairStore
This commit is contained in:
@@ -141,7 +141,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
|
||||
}
|
||||
|
||||
int seriesNumber = m_store->indexOfKthNonEmptySeries(i - 1);
|
||||
assert(i >= 0 && seriesNumber < FloatPairStore::k_numberOfSeries);
|
||||
assert(i >= 0 && seriesNumber < DoublePairStore::k_numberOfSeries);
|
||||
|
||||
// Coordinate and series title
|
||||
if (j == 0 && i > 0) {
|
||||
|
||||
@@ -30,7 +30,7 @@ bool GraphController::isEmpty() const {
|
||||
if (m_store->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (int series = 0; series < FloatPairStore::k_numberOfSeries; series++) {
|
||||
for (int series = 0; series < DoublePairStore::k_numberOfSeries; series++) {
|
||||
if (!m_store->seriesIsEmpty(series) && !std::isinf(m_store->slope(series)) && !std::isnan(m_store->slope(series))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const Expression * RegressionContext::expressionForSymbol(const Symbol * symbol)
|
||||
assert(strlen(seriesName) == 2);
|
||||
|
||||
int series = (int)(seriesName[1] - '0') - 1;
|
||||
assert(series >= 0 && series < FloatPairStore::k_numberOfSeries);
|
||||
assert(series >= 0 && series < DoublePairStore::k_numberOfSeries);
|
||||
|
||||
assert((seriesName[0] == 'X') || (seriesName[0] == 'Y'));
|
||||
int storeI = seriesName[0] == 'X' ? 0 : 1;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#define REGRESSION_REGRESSION_CONTEXT_H
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include "../shared/float_pair_store.h"
|
||||
#include "../shared/double_pair_store.h"
|
||||
|
||||
namespace Regression {
|
||||
|
||||
class RegressionContext : public Poincare::Context {
|
||||
public:
|
||||
RegressionContext(Shared::FloatPairStore * store, Poincare::Context * parentContext = nullptr) :
|
||||
RegressionContext(Shared::DoublePairStore * store, Poincare::Context * parentContext = nullptr) :
|
||||
Poincare::Context(),
|
||||
m_store(store),
|
||||
m_seriesPairIndex(-1),
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void setExpressionForSymbolName(const Poincare::Expression * expression, const Poincare::Symbol * symbol, Poincare::Context & context) override;
|
||||
const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
private:
|
||||
Shared::FloatPairStore * m_store;
|
||||
Shared::DoublePairStore * m_store;
|
||||
int m_seriesPairIndex;
|
||||
Poincare::Context * m_parentContext;
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ static inline float min(float x, float y) { return (x<y ? x : y); }
|
||||
|
||||
Store::Store() :
|
||||
InteractiveCurveViewRange(nullptr, this),
|
||||
FloatPairStore()
|
||||
DoublePairStore()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ bool Store::seriesIsEmpty(int series) const {
|
||||
}
|
||||
|
||||
int Store::indexOfKthNonEmptySeries(int k) const {
|
||||
// TODO put in FloatPairStore (it is also in stats/store)
|
||||
// TODO put in DoublePairStore (it is also in stats/store)
|
||||
assert(k >= 0 && k < numberOfNonEmptySeries());
|
||||
int nonEmptySeriesCount = 0;
|
||||
for (int i = 0; i < k_numberOfSeries; i++) {
|
||||
@@ -214,7 +214,7 @@ int Store::indexOfKthNonEmptySeries(int k) const {
|
||||
/* Calculations */
|
||||
|
||||
double Store::doubleCastedNumberOfPairsOfSeries(int series) const {
|
||||
return FloatPairStore::numberOfPairsOfSeries(series);
|
||||
return DoublePairStore::numberOfPairsOfSeries(series);
|
||||
}
|
||||
|
||||
float Store::maxValueOfColumn(int series, int i) const {
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#define REGRESSION_STORE_H
|
||||
|
||||
#include "../shared/interactive_curve_view_range.h"
|
||||
#include "../shared/float_pair_store.h"
|
||||
#include "../shared/double_pair_store.h"
|
||||
extern "C" {
|
||||
#include <float.h>
|
||||
}
|
||||
|
||||
namespace Regression {
|
||||
|
||||
class Store : public Shared::InteractiveCurveViewRange, public Shared::FloatPairStore, public Shared::InteractiveCurveViewRangeDelegate {
|
||||
class Store : public Shared::InteractiveCurveViewRange, public Shared::DoublePairStore, public Shared::InteractiveCurveViewRangeDelegate {
|
||||
public:
|
||||
Store();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ void StoreController::fillColumnWithFormula(Expression * formula) {
|
||||
const char * seriesName = Symbol::textForSpecialSymbols(variables[index]);
|
||||
assert(strlen(seriesName) == 2);
|
||||
int series = (int)(seriesName[1] - '0') - 1;
|
||||
assert(series >= 0 && series < FloatPairStore::k_numberOfSeries);
|
||||
assert(series >= 0 && series < DoublePairStore::k_numberOfSeries);
|
||||
if (numberOfValuesToCompute == -1) {
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(series);
|
||||
} else {
|
||||
@@ -46,7 +46,7 @@ void StoreController::fillColumnWithFormula(Expression * formula) {
|
||||
index++;
|
||||
}
|
||||
if (numberOfValuesToCompute == -1) {
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(selectedColumn()/FloatPairStore::k_numberOfColumnsPerSeries);
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(selectedColumn()/DoublePairStore::k_numberOfColumnsPerSeries);
|
||||
}
|
||||
|
||||
RegressionContext regressionContext(m_store, const_cast<AppsContainer *>(static_cast<const AppsContainer *>(app()->container()))->globalContext());
|
||||
|
||||
@@ -10,7 +10,7 @@ app_objs += $(addprefix apps/shared/,\
|
||||
editable_cell_table_view_controller.o\
|
||||
expression_field_delegate_app.o\
|
||||
expression_layout_field_delegate.o\
|
||||
float_pair_store.o\
|
||||
double_pair_store.o\
|
||||
float_parameter_controller.o\
|
||||
function.o\
|
||||
function_app.o\
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "float_pair_store.h"
|
||||
#include "double_pair_store.h"
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Shared {
|
||||
|
||||
void FloatPairStore::set(double f, int series, int i, int j) {
|
||||
void DoublePairStore::set(double f, int series, int i, int j) {
|
||||
assert(series >= 0 && series < k_numberOfSeries);
|
||||
if (j >= k_maxNumberOfPairs) {
|
||||
return;
|
||||
@@ -19,7 +19,7 @@ void FloatPairStore::set(double f, int series, int i, int j) {
|
||||
}
|
||||
}
|
||||
|
||||
int FloatPairStore::numberOfPairs() const {
|
||||
int DoublePairStore::numberOfPairs() const {
|
||||
int result = 0;
|
||||
for (int i = 0; i < k_numberOfSeries; i++) {
|
||||
result += m_numberOfPairs[i];
|
||||
@@ -27,7 +27,7 @@ int FloatPairStore::numberOfPairs() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void FloatPairStore::deletePairOfSeriesAtIndex(int series, int j) {
|
||||
void DoublePairStore::deletePairOfSeriesAtIndex(int series, int j) {
|
||||
m_numberOfPairs[series]--;
|
||||
for (int k = j; k < m_numberOfPairs[series]; k++) {
|
||||
m_data[series][0][k] = m_data[series][0][k+1];
|
||||
@@ -39,7 +39,7 @@ void FloatPairStore::deletePairOfSeriesAtIndex(int series, int j) {
|
||||
m_data[series][1][m_numberOfPairs[series]] = 0;
|
||||
}
|
||||
|
||||
void FloatPairStore::deleteAllPairsOfSeries(int series) {
|
||||
void DoublePairStore::deleteAllPairsOfSeries(int series) {
|
||||
assert(series >= 0 && series < k_numberOfSeries);
|
||||
/* We reset all values to 0 to ensure the correctness of the checksum.*/
|
||||
for (int k = 0; k < m_numberOfPairs[series]; k++) {
|
||||
@@ -49,13 +49,13 @@ void FloatPairStore::deleteAllPairsOfSeries(int series) {
|
||||
m_numberOfPairs[series] = 0;
|
||||
}
|
||||
|
||||
void FloatPairStore::deleteAllPairs() {
|
||||
void DoublePairStore::deleteAllPairs() {
|
||||
for (int i = 0; i < k_numberOfSeries; i ++) {
|
||||
deleteAllPairsOfSeries(i);
|
||||
}
|
||||
}
|
||||
|
||||
void FloatPairStore::resetColumn(int series, int i) {
|
||||
void DoublePairStore::resetColumn(int series, int i) {
|
||||
assert(series >= 0 && series < k_numberOfSeries);
|
||||
assert(i == 0 || i == 1);
|
||||
for (int k = 0; k < m_numberOfPairs[series]; k++) {
|
||||
@@ -63,7 +63,7 @@ void FloatPairStore::resetColumn(int series, int i) {
|
||||
}
|
||||
}
|
||||
|
||||
double FloatPairStore::sumOfColumn(int series, int i) const {
|
||||
double DoublePairStore::sumOfColumn(int series, int i) const {
|
||||
assert(series >= 0 && series < k_numberOfSeries);
|
||||
assert(i == 0 || i == 1);
|
||||
double result = 0;
|
||||
@@ -73,7 +73,7 @@ double FloatPairStore::sumOfColumn(int series, int i) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t FloatPairStore::storeChecksum() const {
|
||||
uint32_t DoublePairStore::storeChecksum() const {
|
||||
/* Ideally, we would only compute the checksum of the first m_numberOfPairs
|
||||
* pairs. However, the two values of a pair are not stored consecutively. We
|
||||
* thus compute the checksum on all pairs and ensure to set the pair at 0
|
||||
@@ -83,7 +83,7 @@ uint32_t FloatPairStore::storeChecksum() const {
|
||||
return Ion::crc32((uint32_t *)m_data, dataLengthInBytes/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
double FloatPairStore::defaultValue(int series, int i, int j) const {
|
||||
double DoublePairStore::defaultValue(int series, int i, int j) const {
|
||||
assert(series >= 0 && series < k_numberOfSeries);
|
||||
if(i == 0 && j > 1) {
|
||||
return 2*m_data[series][i][j-1]-m_data[series][i][j-2];
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef SHARED_FLOAT_PAIR_STORE_H
|
||||
#define SHARED_FLOAT_PAIR_STORE_H
|
||||
#ifndef SHARED_DOUBLE_PAIR_STORE_H
|
||||
#define SHARED_DOUBLE_PAIR_STORE_H
|
||||
|
||||
#include <kandinsky/color.h>
|
||||
#include <escher/palette.h>
|
||||
@@ -8,17 +8,17 @@
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class FloatPairStore {
|
||||
class DoublePairStore {
|
||||
public:
|
||||
constexpr static int k_numberOfSeries = 3;
|
||||
constexpr static int k_numberOfColumnsPerSeries = 2;
|
||||
constexpr static int k_maxNumberOfPairs = 100;
|
||||
FloatPairStore() :
|
||||
DoublePairStore() :
|
||||
m_data{},
|
||||
m_numberOfPairs{}
|
||||
{}
|
||||
// Delete the implicit copy constructor: the object is heavy
|
||||
FloatPairStore(const FloatPairStore&) = delete;
|
||||
DoublePairStore(const DoublePairStore&) = delete;
|
||||
double get(int series, int i, int j) const {
|
||||
assert(j < m_numberOfPairs[series]);
|
||||
return m_data[series][i][j];
|
||||
@@ -8,7 +8,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
StoreController::ContentView::ContentView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate) :
|
||||
StoreController::ContentView::ContentView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate) :
|
||||
View(),
|
||||
Responder(parentResponder),
|
||||
m_dataView(store, this, dataSource, selectionDataSource),
|
||||
@@ -48,7 +48,7 @@ KDRect StoreController::ContentView::formulaFrame() const {
|
||||
return KDRect(0, bounds().height() - BufferTextViewWithTextField::k_height, bounds().width(), m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0);
|
||||
}
|
||||
|
||||
StoreController::StoreController(Responder * parentResponder, FloatPairStore * store, ButtonRowController * header) :
|
||||
StoreController::StoreController(Responder * parentResponder, DoublePairStore * store, ButtonRowController * header) :
|
||||
EditableCellTableViewController(parentResponder),
|
||||
ButtonRowDelegate(header, nullptr),
|
||||
m_editableCells{},
|
||||
@@ -108,7 +108,7 @@ bool StoreController::textFieldDidAbortEditing(TextField * textField) {
|
||||
|
||||
|
||||
int StoreController::numberOfColumns() {
|
||||
return FloatPairStore::k_numberOfColumnsPerSeries * FloatPairStore::k_numberOfSeries;
|
||||
return DoublePairStore::k_numberOfColumnsPerSeries * DoublePairStore::k_numberOfSeries;
|
||||
}
|
||||
|
||||
KDCoordinate StoreController::columnWidth(int i) {
|
||||
@@ -149,7 +149,7 @@ int StoreController::typeAtLocation(int i, int j) {
|
||||
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
|
||||
// Handle the separator
|
||||
if (cellAtLocationIsEditable(i, j)) {
|
||||
bool shouldHaveLeftSeparator = i % FloatPairStore::k_numberOfColumnsPerSeries == 0;
|
||||
bool shouldHaveLeftSeparator = i % DoublePairStore::k_numberOfColumnsPerSeries == 0;
|
||||
static_cast<StoreCell *>(cell)->setSeparatorLeft(shouldHaveLeftSeparator);
|
||||
}
|
||||
// Handle empty cells
|
||||
@@ -184,14 +184,14 @@ bool StoreController::handleEvent(Ion::Events::Event event) {
|
||||
assert(selectedColumn() >= 0 && selectedColumn() < numberOfColumns());
|
||||
int series = seriesAtColumn(selectedColumn());
|
||||
if ((event == Ion::Events::OK || event == Ion::Events::EXE) && selectedRow() == 0) {
|
||||
m_storeParameterController.selectXColumn(selectedColumn()%FloatPairStore::k_numberOfColumnsPerSeries == 0);
|
||||
m_storeParameterController.selectXColumn(selectedColumn()%DoublePairStore::k_numberOfColumnsPerSeries == 0);
|
||||
m_storeParameterController.selectSeries(series);
|
||||
StackViewController * stack = ((StackViewController *)parentResponder()->parentResponder());
|
||||
stack->push(&m_storeParameterController);
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Backspace) {
|
||||
if (selectedRow() == 0 || selectedRow() > m_store->numberOfPairsOfSeries(selectedColumn()/FloatPairStore::k_numberOfColumnsPerSeries)) {
|
||||
if (selectedRow() == 0 || selectedRow() > m_store->numberOfPairsOfSeries(selectedColumn()/DoublePairStore::k_numberOfColumnsPerSeries)) {
|
||||
return false;
|
||||
}
|
||||
m_store->deletePairOfSeriesAtIndex(series, selectedRow()-1);
|
||||
@@ -225,24 +225,24 @@ bool StoreController::cellAtLocationIsEditable(int columnIndex, int rowIndex) {
|
||||
}
|
||||
|
||||
bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int rowIndex) {
|
||||
m_store->set(floatBody, seriesAtColumn(columnIndex), columnIndex%FloatPairStore::k_numberOfColumnsPerSeries, rowIndex-1);
|
||||
m_store->set(floatBody, seriesAtColumn(columnIndex), columnIndex%DoublePairStore::k_numberOfColumnsPerSeries, rowIndex-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
double StoreController::dataAtLocation(int columnIndex, int rowIndex) {
|
||||
return m_store->get(seriesAtColumn(columnIndex), columnIndex%FloatPairStore::k_numberOfColumnsPerSeries, rowIndex-1);
|
||||
return m_store->get(seriesAtColumn(columnIndex), columnIndex%DoublePairStore::k_numberOfColumnsPerSeries, rowIndex-1);
|
||||
}
|
||||
|
||||
int StoreController::numberOfElements() {
|
||||
int result = 0;
|
||||
for (int i = 0; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
result = max(result, m_store->numberOfPairsOfSeries(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int StoreController::maxNumberOfElements() const {
|
||||
return FloatPairStore::k_maxNumberOfPairs;
|
||||
return DoublePairStore::k_maxNumberOfPairs;
|
||||
}
|
||||
|
||||
View * StoreController::loadView() {
|
||||
@@ -262,7 +262,7 @@ void StoreController::unloadView(View * view) {
|
||||
}
|
||||
|
||||
bool StoreController::cellShouldBeTransparent(int i, int j) {
|
||||
int seriesIndex = i/FloatPairStore::k_numberOfColumnsPerSeries;
|
||||
int seriesIndex = i/DoublePairStore::k_numberOfColumnsPerSeries;
|
||||
return j > 1 + m_store->numberOfPairsOfSeries(seriesIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher.h>
|
||||
#include "buffer_text_view_with_text_field.h"
|
||||
#include "editable_cell_table_view_controller.h"
|
||||
#include "float_pair_store.h"
|
||||
#include "double_pair_store.h"
|
||||
#include "store_cell.h"
|
||||
#include "store_parameter_controller.h"
|
||||
#include "store_selectable_table_view.h"
|
||||
@@ -13,7 +13,7 @@ namespace Shared {
|
||||
|
||||
class StoreController : public EditableCellTableViewController, public ButtonRowDelegate {
|
||||
public:
|
||||
StoreController(Responder * parentResponder, FloatPairStore * store, ButtonRowController * header);
|
||||
StoreController(Responder * parentResponder, DoublePairStore * store, ButtonRowController * header);
|
||||
|
||||
void displayFormulaInput();
|
||||
virtual void setFormulaLabel() = 0;
|
||||
@@ -44,14 +44,14 @@ protected:
|
||||
static constexpr KDCoordinate k_cellWidth = 116;
|
||||
static constexpr KDCoordinate k_margin = 8;
|
||||
static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin;
|
||||
constexpr static int k_maxNumberOfEditableCells = 22 * FloatPairStore::k_numberOfSeries;
|
||||
constexpr static int k_maxNumberOfEditableCells = 22 * DoublePairStore::k_numberOfSeries;
|
||||
constexpr static int k_numberOfTitleCells = 4;
|
||||
static constexpr int k_titleCellType = 0;
|
||||
static constexpr int k_editableCellType = 1;
|
||||
|
||||
class ContentView : public View , public Responder {
|
||||
public:
|
||||
ContentView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate);
|
||||
ContentView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate);
|
||||
StoreSelectableTableView * dataView() { return &m_dataView; }
|
||||
BufferTextViewWithTextField * formulaInputView() { return &m_formulaInputView; }
|
||||
void displayFormulaInput(bool display);
|
||||
@@ -80,9 +80,9 @@ protected:
|
||||
int maxNumberOfElements() const override;
|
||||
virtual HighlightCell * titleCells(int index) = 0;
|
||||
char m_draftTextBuffer[TextField::maxBufferSize()];
|
||||
int seriesAtColumn(int column) const { return column / FloatPairStore::k_numberOfColumnsPerSeries; }
|
||||
int seriesAtColumn(int column) const { return column / DoublePairStore::k_numberOfColumnsPerSeries; }
|
||||
StoreCell * m_editableCells[k_maxNumberOfEditableCells];
|
||||
FloatPairStore * m_store;
|
||||
DoublePairStore * m_store;
|
||||
StoreParameterController m_storeParameterController;
|
||||
private:
|
||||
bool cellShouldBeTransparent(int i, int j);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace Shared {
|
||||
|
||||
StoreParameterController::StoreParameterController(Responder * parentResponder, FloatPairStore * store, StoreController * storeController) :
|
||||
StoreParameterController::StoreParameterController(Responder * parentResponder, DoublePairStore * store, StoreController * storeController) :
|
||||
ViewController(parentResponder),
|
||||
m_deleteColumn(I18n::Message::ClearColumn),
|
||||
m_fillWithFormula(I18n::Message::FillWithFormula),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define SHARED_STORE_PARAM_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "float_pair_store.h"
|
||||
#include "double_pair_store.h"
|
||||
#include "../i18n.h"
|
||||
|
||||
namespace Shared {
|
||||
@@ -11,7 +11,7 @@ class StoreController;
|
||||
|
||||
class StoreParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
|
||||
public:
|
||||
StoreParameterController(Responder * parentResponder, FloatPairStore * store, StoreController * storeController);
|
||||
StoreParameterController(Responder * parentResponder, DoublePairStore * store, StoreController * storeController);
|
||||
void selectXColumn(bool xColumnSelected) { m_xColumnSelected = xColumnSelected; }
|
||||
void selectSeries(int series) { m_series = series; }
|
||||
View * view() override { return &m_selectableTableView; }
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
MessageTableCell m_deleteColumn;
|
||||
MessageTableCell m_fillWithFormula;
|
||||
SelectableTableView m_selectableTableView;
|
||||
FloatPairStore * m_store;
|
||||
DoublePairStore * m_store;
|
||||
StoreController * m_storeController;
|
||||
bool m_xColumnSelected;
|
||||
int m_series;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Shared {
|
||||
|
||||
StoreSelectableTableView::StoreSelectableTableView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, SelectableTableViewDelegate * delegate) :
|
||||
StoreSelectableTableView::StoreSelectableTableView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, SelectableTableViewDelegate * delegate) :
|
||||
SelectableTableView(parentResponder, dataSource, selectionDataSource, delegate),
|
||||
m_store(store)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ bool StoreSelectableTableView::selecNonHiddenCellAtLocation(int i, int j) {
|
||||
if (j < 0 || j >= dataSource()->numberOfRows()) {
|
||||
return false;
|
||||
}
|
||||
int seriesIndex = i/FloatPairStore::k_numberOfColumnsPerSeries;
|
||||
int seriesIndex = i/DoublePairStore::k_numberOfColumnsPerSeries;
|
||||
int numberOfPairsOfCurrentSeries = m_store->numberOfPairsOfSeries(seriesIndex);
|
||||
if (j > 1 + numberOfPairsOfCurrentSeries) {
|
||||
return selectCellAtLocation(i, 1 + numberOfPairsOfCurrentSeries);
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
#define APPS_SHARED_STORE_SELECTABLE_TABLE_VIEW_H
|
||||
|
||||
#include <escher/selectable_table_view.h>
|
||||
#include "float_pair_store.h"
|
||||
#include "double_pair_store.h"
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class StoreSelectableTableView : public SelectableTableView {
|
||||
public:
|
||||
StoreSelectableTableView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource = nullptr, SelectableTableViewDelegate * delegate = nullptr);
|
||||
StoreSelectableTableView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource = nullptr, SelectableTableViewDelegate * delegate = nullptr);
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
private:
|
||||
bool selecNonHiddenCellAtLocation(int i, int j);
|
||||
FloatPairStore * m_store;
|
||||
DoublePairStore * m_store;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
|
||||
char titleBuffer[] = {'V', static_cast<char>('0'+seriesNumber), '/', 'N', static_cast<char>('0'+seriesNumber), 0};
|
||||
StoreTitleCell * storeTitleCell = static_cast<StoreTitleCell *>(cell);
|
||||
storeTitleCell->setText(titleBuffer);
|
||||
storeTitleCell->setColor(FloatPairStore::colorOfSeriesAtIndex(seriesNumber));
|
||||
storeTitleCell->setColor(DoublePairStore::colorOfSeriesAtIndex(seriesNumber));
|
||||
return;
|
||||
}
|
||||
if (i == 0) {
|
||||
|
||||
@@ -43,19 +43,19 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl
|
||||
}
|
||||
|
||||
// There should be at least one value in the drawn bin
|
||||
for (int i = 0; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
if (m_store->firstDrawnBarAbscissa() <= m_store->maxValue(i)+f) {
|
||||
break;
|
||||
} else if (i == FloatPairStore::k_numberOfSeries - 1) {
|
||||
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
||||
app()->displayWarning(I18n::Message::ForbiddenValue);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The number of bars cannot be above the max
|
||||
assert(FloatPairStore::k_numberOfSeries > 0);
|
||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||
double maxNewNumberOfBars = std::ceil((m_store->maxValue(0) - m_store->minValue(0))/f);
|
||||
for (int i = 1; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
double numberOfBars = std::ceil((m_store->maxValue(i) - m_store->minValue(i))/f);
|
||||
if (maxNewNumberOfBars < numberOfBars) {
|
||||
maxNewNumberOfBars = numberOfBars;
|
||||
@@ -70,9 +70,9 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl
|
||||
m_store->setBarWidth(f);
|
||||
} else {
|
||||
// The number of bars cannot be above the max
|
||||
assert(FloatPairStore::k_numberOfSeries > 0);
|
||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||
double maxNewNumberOfBars = ceilf((m_store->maxValue(0) - f)/m_store->barWidth());
|
||||
for (int i = 1; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
double numberOfBars = ceilf((m_store->maxValue(i) - f)/m_store->barWidth());
|
||||
if (maxNewNumberOfBars < numberOfBars) {
|
||||
maxNewNumberOfBars = numberOfBars;
|
||||
@@ -83,10 +83,10 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl
|
||||
return false;
|
||||
}
|
||||
// There should be at least one value in the drawn bin
|
||||
for (int i = 0; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
if (f <= m_store->maxValue(i)+m_store->barWidth()) {
|
||||
break;
|
||||
} else if (i == FloatPairStore::k_numberOfSeries - 1) {
|
||||
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
||||
app()->displayWarning(I18n::Message::ForbiddenValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace Statistics {
|
||||
|
||||
MultipleBoxesView::MultipleBoxesView(BoxController * controller, Store * store, BoxView::Quantile * selectedQuantile) :
|
||||
MultipleDataView(store),
|
||||
m_boxView1(controller, store, 0, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(0), FloatPairStore::colorLightOfSeriesAtIndex(0)),
|
||||
m_boxView2(controller, store, 1, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(1), FloatPairStore::colorLightOfSeriesAtIndex(1)),
|
||||
m_boxView3(controller, store, 2, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(2), FloatPairStore::colorLightOfSeriesAtIndex(2)),
|
||||
m_boxView1(controller, store, 0, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(0), DoublePairStore::colorLightOfSeriesAtIndex(0)),
|
||||
m_boxView2(controller, store, 1, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(1), DoublePairStore::colorLightOfSeriesAtIndex(1)),
|
||||
m_boxView3(controller, store, 2, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(2), DoublePairStore::colorLightOfSeriesAtIndex(2)),
|
||||
m_axisView(store),
|
||||
m_bannerView()
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace Statistics {
|
||||
|
||||
MultipleHistogramsView::MultipleHistogramsView(HistogramController * controller, Store * store) :
|
||||
MultipleDataView(store),
|
||||
m_histogramView1(controller, store, 0, nullptr, FloatPairStore::colorOfSeriesAtIndex(0)),
|
||||
m_histogramView2(controller, store, 1, nullptr, FloatPairStore::colorOfSeriesAtIndex(1)),
|
||||
m_histogramView3(controller, store, 2, nullptr, FloatPairStore::colorOfSeriesAtIndex(2)),
|
||||
m_histogramView1(controller, store, 0, nullptr, DoublePairStore::colorOfSeriesAtIndex(0)),
|
||||
m_histogramView2(controller, store, 1, nullptr, DoublePairStore::colorOfSeriesAtIndex(1)),
|
||||
m_histogramView3(controller, store, 2, nullptr, DoublePairStore::colorOfSeriesAtIndex(2)),
|
||||
m_bannerView(),
|
||||
m_okView()
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ const Expression * SeriesContext::expressionForSymbol(const Symbol * symbol) {
|
||||
assert(strlen(seriesName) == 2);
|
||||
|
||||
int series = (int)(seriesName[1] - '0') - 1;
|
||||
assert(series >= 0 && series < FloatPairStore::k_numberOfSeries);
|
||||
assert(series >= 0 && series < DoublePairStore::k_numberOfSeries);
|
||||
|
||||
assert((seriesName[0] == 'V') || (seriesName[0] == 'N'));
|
||||
int storeI = seriesName[0] == 'V' ? 0 : 1;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#define STATISTICS_SERIES_CONTEXT_H
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include "../shared/float_pair_store.h"
|
||||
#include "../shared/double_pair_store.h"
|
||||
|
||||
namespace Statistics {
|
||||
|
||||
class SeriesContext : public Poincare::Context {
|
||||
public:
|
||||
SeriesContext(Shared::FloatPairStore * store, Poincare::Context * parentContext = nullptr) :
|
||||
SeriesContext(Shared::DoublePairStore * store, Poincare::Context * parentContext = nullptr) :
|
||||
Poincare::Context(),
|
||||
m_store(store),
|
||||
m_seriesPairIndex(-1),
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void setExpressionForSymbolName(const Poincare::Expression * expression, const Poincare::Symbol * symbol, Poincare::Context & context) override;
|
||||
const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override;
|
||||
private:
|
||||
Shared::FloatPairStore * m_store;
|
||||
Shared::DoublePairStore * m_store;
|
||||
int m_seriesPairIndex;
|
||||
Poincare::Context * m_parentContext;
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ static_assert(Store::k_numberOfSeries == 3, "The constructor of Statistics::Stor
|
||||
|
||||
Store::Store() :
|
||||
MemoizedCurveViewRange(),
|
||||
FloatPairStore(),
|
||||
DoublePairStore(),
|
||||
m_barWidth(1.0),
|
||||
m_firstDrawnBarAbscissa(0.0),
|
||||
m_seriesEmpty{true, true, true},
|
||||
@@ -119,9 +119,9 @@ double Store::sumOfOccurrences(int series) const {
|
||||
}
|
||||
|
||||
double Store::maxValueForAllSeries() const {
|
||||
assert(FloatPairStore::k_numberOfSeries > 0);
|
||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||
double result = maxValue(0);
|
||||
for (int i = 1; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
double maxCurrentSeries = maxValue(i);
|
||||
if (result < maxCurrentSeries) {
|
||||
result = maxCurrentSeries;
|
||||
@@ -131,9 +131,9 @@ double Store::maxValueForAllSeries() const {
|
||||
}
|
||||
|
||||
double Store::minValueForAllSeries() const {
|
||||
assert(FloatPairStore::k_numberOfSeries > 0);
|
||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||
double result = minValue(0);
|
||||
for (int i = 1; i < FloatPairStore::k_numberOfSeries; i++) {
|
||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||
double minCurrentSeries = minValue(i);
|
||||
if (result > minCurrentSeries) {
|
||||
result = minCurrentSeries;
|
||||
@@ -225,19 +225,19 @@ double Store::squaredValueSum(int series) const {
|
||||
}
|
||||
|
||||
void Store::set(double f, int series, int i, int j) {
|
||||
FloatPairStore::set(f, series, i, j);
|
||||
DoublePairStore::set(f, series, i, j);
|
||||
m_seriesEmpty[series] = sumOfOccurrences(series) == 0;
|
||||
updateNonEmptySeriesCount();
|
||||
}
|
||||
|
||||
void Store::deletePairOfSeriesAtIndex(int series, int j) {
|
||||
FloatPairStore::deletePairOfSeriesAtIndex(series, j);
|
||||
DoublePairStore::deletePairOfSeriesAtIndex(series, j);
|
||||
m_seriesEmpty[series] = sumOfOccurrences(series) == 0;
|
||||
updateNonEmptySeriesCount();
|
||||
}
|
||||
|
||||
void Store::deleteAllPairsOfSeries(int series) {
|
||||
FloatPairStore::deleteAllPairsOfSeries(series);
|
||||
DoublePairStore::deleteAllPairsOfSeries(series);
|
||||
m_seriesEmpty[series] = true;
|
||||
updateNonEmptySeriesCount();
|
||||
}
|
||||
@@ -255,7 +255,7 @@ void Store::updateNonEmptySeriesCount() {
|
||||
/* Private methods */
|
||||
|
||||
double Store::defaultValue(int series, int i, int j) const {
|
||||
return i == 0 ? FloatPairStore::defaultValue(series, i, j) : 1.0;
|
||||
return i == 0 ? DoublePairStore::defaultValue(series, i, j) : 1.0;
|
||||
}
|
||||
|
||||
double Store::sumOfValuesBetween(int series, double x1, double x2) const {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
#define STATISTICS_STORE_H
|
||||
|
||||
#include "../shared/memoized_curve_view_range.h"
|
||||
#include "../shared/float_pair_store.h"
|
||||
#include "../shared/double_pair_store.h"
|
||||
|
||||
namespace Statistics {
|
||||
|
||||
class Store : public Shared::MemoizedCurveViewRange, public Shared::FloatPairStore {
|
||||
class Store : public Shared::MemoizedCurveViewRange, public Shared::DoublePairStore {
|
||||
public:
|
||||
Store();
|
||||
uint32_t barChecksum() const;
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
constexpr static int k_bottomMargin = 20;
|
||||
constexpr static float k_displayLeftMarginRatio = 0.04f;
|
||||
|
||||
// FloatPairStore
|
||||
// DoublePairStore
|
||||
void set(double f, int series, int i, int j) override;
|
||||
void deletePairOfSeriesAtIndex(int series, int j) override;
|
||||
void deleteAllPairsOfSeries(int series) override;
|
||||
|
||||
@@ -37,7 +37,7 @@ void StoreController::fillColumnWithFormula(Expression * formula) {
|
||||
const char * seriesName = Symbol::textForSpecialSymbols(variables[index]);
|
||||
assert(strlen(seriesName) == 2);
|
||||
int series = (int)(seriesName[1] - '0') - 1;
|
||||
assert(series >= 0 && series < FloatPairStore::k_numberOfSeries);
|
||||
assert(series >= 0 && series < DoublePairStore::k_numberOfSeries);
|
||||
if (numberOfValuesToCompute == -1) {
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(series);
|
||||
} else {
|
||||
@@ -46,7 +46,7 @@ void StoreController::fillColumnWithFormula(Expression * formula) {
|
||||
index++;
|
||||
}
|
||||
if (numberOfValuesToCompute == -1) {
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(selectedColumn()/FloatPairStore::k_numberOfColumnsPerSeries);
|
||||
numberOfValuesToCompute = m_store->numberOfPairsOfSeries(selectedColumn()/DoublePairStore::k_numberOfColumnsPerSeries);
|
||||
}
|
||||
|
||||
SeriesContext seriesContext(m_store, const_cast<AppsContainer *>(static_cast<const AppsContainer *>(app()->container()))->globalContext());
|
||||
@@ -69,7 +69,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int
|
||||
bool isValuesColumn = i%Store::k_numberOfColumnsPerSeries == 0;
|
||||
mytitleCell->setSeparatorLeft(isValuesColumn);
|
||||
int seriesIndex = i/Store::k_numberOfColumnsPerSeries;
|
||||
assert(seriesIndex >= 0 && seriesIndex < FloatPairStore::k_numberOfSeries);
|
||||
assert(seriesIndex >= 0 && seriesIndex < DoublePairStore::k_numberOfSeries);
|
||||
if (isValuesColumn) {
|
||||
I18n::Message valuesMessages[] = {I18n::Message::Values1, I18n::Message::Values2, I18n::Message::Values3};
|
||||
mytitleCell->setText(I18n::translate(valuesMessages[seriesIndex]));
|
||||
|
||||
Reference in New Issue
Block a user