Use wxStack instead of simulating a stack with array

We have a dedicated wxStack class so there is no need
to simulate a stack with array.
This commit is contained in:
Artur Wieczorek
2021-07-04 19:35:48 +02:00
parent cc5bfc0fb1
commit 4423f6d256

View File

@@ -27,6 +27,7 @@
#include "wx/dcprint.h" #include "wx/dcprint.h"
#include "wx/prntbase.h" #include "wx/prntbase.h"
#include "wx/scopeguard.h" #include "wx/scopeguard.h"
#include "wx/stack.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/math.h" #include "wx/math.h"
@@ -791,7 +792,7 @@ void wx_quadratic_spline(double a1, double b1, double a2, double b2,
static static
void wx_clear_stack(); void wx_clear_stack();
static static
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, bool wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
double *y3, double *x4, double *y4); double *y3, double *x4, double *y4);
static static
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
@@ -837,47 +838,44 @@ typedef struct wx_spline_stack_struct {
double x1, y1, x2, y2, x3, y3, x4, y4; double x1, y1, x2, y2, x3, y3, x4, y4;
} Stack; } Stack;
#define SPLINE_STACK_DEPTH 20 static wxStack<Stack> gs_wx_spline_stack;
static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
static Stack *wx_stack_top;
static int wx_stack_count;
void wx_clear_stack() void wx_clear_stack()
{ {
wx_stack_top = wx_spline_stack; gs_wx_spline_stack = wxStack<Stack>();
wx_stack_count = 0;
} }
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{ {
wx_stack_top->x1 = x1; Stack rec;
wx_stack_top->y1 = y1; rec.x1 = x1;
wx_stack_top->x2 = x2; rec.y1 = y1;
wx_stack_top->y2 = y2; rec.x2 = x2;
wx_stack_top->x3 = x3; rec.y2 = y2;
wx_stack_top->y3 = y3; rec.x3 = x3;
wx_stack_top->x4 = x4; rec.y3 = y3;
wx_stack_top->y4 = y4; rec.x4 = x4;
wx_stack_top++; rec.y4 = y4;
wx_stack_count++; gs_wx_spline_stack.push(rec);
} }
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, bool wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
double *x3, double *y3, double *x4, double *y4) double *x3, double *y3, double *x4, double *y4)
{ {
if (wx_stack_count == 0) if ( gs_wx_spline_stack.empty() )
return (0); return false;
wx_stack_top--;
wx_stack_count--; const Stack& top = gs_wx_spline_stack.top();
*x1 = wx_stack_top->x1; *x1 = top.x1;
*y1 = wx_stack_top->y1; *y1 = top.y1;
*x2 = wx_stack_top->x2; *x2 = top.x2;
*y2 = wx_stack_top->y2; *y2 = top.y2;
*x3 = wx_stack_top->x3; *x3 = top.x3;
*y3 = wx_stack_top->y3; *y3 = top.y3;
*x4 = wx_stack_top->x4; *x4 = top.x4;
*y4 = wx_stack_top->y4; *y4 = top.y4;
return (1); gs_wx_spline_stack.pop();
return true;
} }
static bool wx_spline_add_point(double x, double y) static bool wx_spline_add_point(double x, double y)