Add separate PlotFunction

Adding a separate command that plots a function taken from the stack.

Moving forward, I am considering maintaining two parallel set of
commands for plotting:

1/ `Draw` (aka `DrawPlot`) would be the higher-level one, obeying the
   semantics of RPL on HP48, i.e. fetching a function from `EQ` with
   `PPAR` specifying the type of function to plot and the independent
   variable.

2/ `PlotFunction` would be the lower-level one, taking its function
   from the stack, and assuming the function itself takes its input
   from the stack.

Fixes: #339

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2023-08-17 10:32:33 +02:00
parent 228d68f484
commit 2f44f52977
6 changed files with 35 additions and 12 deletions

View file

@ -7,7 +7,7 @@ extern const unsigned char EditorFont_sparse_font_data[];
const unsigned char EditorFont_sparse_font_data[73676] FONT_QSPI =
{
0xAB, 0x02, 0xC7, 0xBF, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0xAC, 0x02, 0xC7, 0xBF, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x20, 0x5F, 0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x02, 0x0B,
0x05, 0x21, 0x09, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7,
0x1E, 0x00, 0x00, 0xB8, 0xFF, 0xFF, 0xFF, 0x0E, 0x03, 0x0B, 0x0B, 0x0F, 0x11, 0x8F, 0x7F, 0xFC,

View file

@ -7,7 +7,7 @@ extern const unsigned char HelpFont_sparse_font_data[];
const unsigned char HelpFont_sparse_font_data[15010] FONT_QSPI =
{
0xAB, 0x02, 0x9E, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
0xAC, 0x02, 0x9E, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
0x11, 0x01, 0x01, 0x03, 0x00, 0x20, 0x5F, 0x00, 0x11, 0x01, 0x01, 0x03, 0x00, 0x01, 0x04, 0x02,
0x0D, 0x04, 0xFF, 0xFF, 0xF3, 0x03, 0x01, 0x04, 0x04, 0x05, 0x06, 0xFF, 0xFF, 0x0F, 0x01, 0x04,
0x08, 0x0D, 0x0A, 0x12, 0x12, 0x14, 0x7F, 0x7F, 0x24, 0x24, 0x24, 0xFE, 0xFE, 0x28, 0x48, 0x48,

View file

@ -7,7 +7,7 @@ extern const unsigned char StackFont_sparse_font_data[];
const unsigned char StackFont_sparse_font_data[36409] FONT_QSPI =
{
0xAB, 0x02, 0xB4, 0x9C, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0xAC, 0x02, 0xB4, 0x9C, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x20, 0x5F, 0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x02, 0x05,
0x03, 0x17, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xC0, 0xFF, 0x1F, 0x02, 0x05, 0x08, 0x0A,
0x0C, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0x01, 0x05, 0x0E, 0x17, 0x10,

View file

@ -426,7 +426,7 @@ CMD(Modes)
CMD(ResetModes)
CMD(Version)
CMD(PlotFunction)
// ============================================================================

View file

@ -65,20 +65,16 @@ COMMAND_BODY(Polar)
}
object::result DrawFunctionPlot(const PlotParameters &ppar)
object::result DrawFunctionPlot(const PlotParameters &ppar, object_g eq)
// ----------------------------------------------------------------------------
// Draw a function plot
// Draw an equation that takes input from the stack
// ----------------------------------------------------------------------------
{
object::result result = object::ERROR;
algebraic_g step = ppar.resolution;
if (step->is_zero())
step = (ppar.xmax - ppar.xmin) / integer::make(ScreenWidth());
algebraic_g x = ppar.xmin;
object_g eq = directory::recall_all(symbol::make("eq"));
if (!eq)
return object::ERROR;
object::result result = object::ERROR;
coord lx = -1;
coord ly = -1;
uint then = sys_current_ms();
@ -141,6 +137,18 @@ err:
}
object::result DrawFunctionPlot(const PlotParameters &ppar)
// ----------------------------------------------------------------------------
// Draw a function plot
// ----------------------------------------------------------------------------
{
object_g eq = directory::recall_all(symbol::make("eq"));
if (!eq)
return object::ERROR;
return DrawFunctionPlot(ppar, eq);
}
object::result DrawParametricPlot(const PlotParameters &ppar)
// ----------------------------------------------------------------------------
// Draw a parametric plot
@ -159,6 +167,20 @@ object::result DrawPolarPlot(const PlotParameters &ppar)
}
COMMAND_BODY(PlotFunction)
// ----------------------------------------------------------------------------
// Draw plot from function on the stack taking stack arguments
// ----------------------------------------------------------------------------
{
if (object_g eq = rt.pop())
{
PlotParameters ppar;
return DrawFunctionPlot(ppar, eq);
}
return ERROR;
}
COMMAND_BODY(Draw)
// ----------------------------------------------------------------------------
// Draw plot in EQ according to PPAR

View file

@ -30,12 +30,13 @@
// ****************************************************************************
#include "command.h"
#include "graphics.h"
COMMAND_DECLARE(Function);
COMMAND_DECLARE(Polar);
COMMAND_DECLARE(Parametric);
COMMAND_DECLARE(Draw);
COMMAND_DECLARE(Drax);
COMMAND_DECLARE(PlotFunction);
#endif // PLOT_H