mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/graph] fix banner view for polar and parametric
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "calculation_graph_controller.h"
|
||||
#include "../app.h"
|
||||
#include "../../apps_container.h"
|
||||
|
||||
using namespace Shared;
|
||||
using namespace Poincare;
|
||||
@@ -42,7 +43,7 @@ void CalculationGraphController::setRecord(Ion::Storage::Record record) {
|
||||
}
|
||||
|
||||
void CalculationGraphController::reloadBannerView() {
|
||||
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore());
|
||||
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), AppsContainer::sharedAppsContainer()->globalContext());
|
||||
}
|
||||
|
||||
Coordinate2D<double> CalculationGraphController::computeNewPointOfInteresetFromAbscissa(double start, int direction) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "tangent_graph_controller.h"
|
||||
#include "../../shared/poincare_helpers.h"
|
||||
#include "../app.h"
|
||||
#include "../../apps_container.h"
|
||||
#include "../../shared/poincare_helpers.h"
|
||||
#include <poincare/preferences.h>
|
||||
|
||||
using namespace Shared;
|
||||
@@ -64,7 +65,7 @@ void TangentGraphController::reloadBannerView() {
|
||||
if (m_record.isNull()) {
|
||||
return;
|
||||
}
|
||||
FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, Shared::FunctionApp::app()->functionStore());
|
||||
FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, Shared::FunctionApp::app()->functionStore(), AppsContainer::sharedAppsContainer()->globalContext());
|
||||
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record);
|
||||
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits);
|
||||
char buffer[bufferSize];
|
||||
|
||||
@@ -145,6 +145,24 @@ void CartesianFunction::setDisplayDerivative(bool display) {
|
||||
return recordData()->setDisplayDerivative(display);
|
||||
}
|
||||
|
||||
int CartesianFunction::printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context) {
|
||||
PlotType type = plotType();
|
||||
if (type == PlotType::Cartesian) {
|
||||
return Function::printValue(cursorT, cursorX, cursorY, buffer, bufferSize, precision, context);
|
||||
}
|
||||
if (type == PlotType::Polar) {
|
||||
return PoincareHelpers::ConvertFloatToText<double>(evaluate2DAtParameter(cursorT, context).x2(), buffer, bufferSize, precision);
|
||||
}
|
||||
assert(type == PlotType::Parametric);
|
||||
int result = 0;
|
||||
result += UTF8Decoder::CodePointToChars('(', buffer+result, bufferSize-result);
|
||||
result += PoincareHelpers::ConvertFloatToText<double>(cursorX, buffer+result, bufferSize-result, precision);
|
||||
result += UTF8Decoder::CodePointToChars(';', buffer+result, bufferSize-result);
|
||||
result += PoincareHelpers::ConvertFloatToText<double>(cursorY, buffer+result, bufferSize-result, precision);
|
||||
result += UTF8Decoder::CodePointToChars(')', buffer+result, bufferSize-result);
|
||||
return result;
|
||||
}
|
||||
|
||||
double CartesianFunction::approximateDerivative(double x, Poincare::Context * context) const {
|
||||
Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol::Builder(UCodePointUnknownX), Poincare::Float<double>::Builder(x)); // derivative takes ownership of Poincare::Float<double>::Builder(x) and the clone of expression
|
||||
/* TODO: when we approximate derivative, we might want to simplify the
|
||||
|
||||
@@ -41,6 +41,9 @@ public:
|
||||
void setDisplayDerivative(bool display);
|
||||
int derivativeNameWithArgument(char * buffer, size_t bufferSize);
|
||||
double approximateDerivative(double x, Poincare::Context * context) const;
|
||||
|
||||
int printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context) override;
|
||||
|
||||
// tMin and tMax
|
||||
bool shouldClipTRangeToXRange() const override { return plotType() == PlotType::Cartesian; }
|
||||
double tMin() const override;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "function.h"
|
||||
#include "poincare_helpers.h"
|
||||
#include "poincare/src/parsing/parser.h"
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
@@ -60,6 +61,10 @@ void Function::setActive(bool active) {
|
||||
recordData()->setActive(active);
|
||||
}
|
||||
|
||||
int Function::printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context) {
|
||||
return PoincareHelpers::ConvertFloatToText<double>(cursorY, buffer, bufferSize, precision);
|
||||
}
|
||||
|
||||
int Function::nameWithArgument(char * buffer, size_t bufferSize) {
|
||||
const char * functionName = fullName();
|
||||
size_t result = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize);
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
|
||||
// Name
|
||||
int nameWithArgument(char * buffer, size_t bufferSize);
|
||||
virtual int printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context);
|
||||
|
||||
// Evaluation
|
||||
virtual Poincare::Coordinate2D<float> evaluateXYAtParameter(float t, Poincare::Context * context) const = 0;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore) {
|
||||
void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore, Poincare::Context * context) {
|
||||
ExpiringPointer<Function> function = functionStore->modelForRecord(record);
|
||||
constexpr int bufferSize = k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits);
|
||||
char buffer[bufferSize];
|
||||
@@ -20,7 +20,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
|
||||
|
||||
constexpr int precision = Preferences::MediumNumberOfSignificantDigits;
|
||||
|
||||
numberOfChar = PoincareHelpers::ConvertFloatToText<double>(cursor->x(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(precision), precision);
|
||||
numberOfChar = PoincareHelpers::ConvertFloatToText<double>(cursor->t(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(precision), precision);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
|
||||
bannerView()->abscissaValue()->setText(buffer);
|
||||
@@ -28,7 +28,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
|
||||
numberOfChar = function->nameWithArgument(buffer, bufferSize);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
numberOfChar += strlcpy(buffer+numberOfChar, "=", bufferSize-numberOfChar);
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, precision);
|
||||
numberOfChar += function->printValue(cursor->t(), cursor->x(),cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, precision, context);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar);
|
||||
bannerView()->ordinateView()->setText(buffer);
|
||||
|
||||
@@ -11,7 +11,7 @@ class FunctionBannerDelegate {
|
||||
public:
|
||||
constexpr static int k_maxNumberOfCharacters = 50;
|
||||
protected:
|
||||
void reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore);
|
||||
void reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore, Poincare::Context * context);
|
||||
virtual XYBannerView * bannerView() = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "function_graph_controller.h"
|
||||
#include "function_app.h"
|
||||
#include "../apps_container.h"
|
||||
#include <poincare/coordinate_2D.h>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
@@ -71,7 +72,7 @@ void FunctionGraphController::selectFunctionWithCursor(int functionIndex) {
|
||||
void FunctionGraphController::reloadBannerView() {
|
||||
assert(functionStore()->numberOfActiveFunctions() > 0);
|
||||
Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor());
|
||||
reloadBannerViewForCursorOnFunction(m_cursor, record, functionStore());
|
||||
reloadBannerViewForCursorOnFunction(m_cursor, record, functionStore(), AppsContainer::sharedAppsContainer()->globalContext());
|
||||
}
|
||||
|
||||
InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) {
|
||||
|
||||
Reference in New Issue
Block a user