Skip to content

Commit

Permalink
rework parsing and handling of filledcurve options
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeam committed Sep 29, 2017
1 parent 31c4cab commit aca4a1b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 61 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
range was inverted. The error was introduced by converting from a
macro to a subroutine in the run-up to 5.2.

* src/gadgets.h src/graphics.c src/misc.c src/plot2d.c src/set.c
src/tables.h: Rework parsing and handling of filledcurve options.

2017-09-25 Ethan A Merritt <[email protected]>

* src/plot2d.c: smoothing options csplines|acsplines|bezier|sbezier
Expand Down
3 changes: 1 addition & 2 deletions src/gadgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ typedef enum en_key_sample_positioning {
} t_key_sample_positioning;

typedef struct {
int opt_given; /* option given / not given (otherwise default) */
int closeto; /* from list FILLEDCURVES_CLOSED, ... */
enum filledcurves_opts_id closeto; /* from list FILLEDCURVES_CLOSED, ... */
double at; /* value for FILLEDCURVES_AT... */
double aty; /* the other value for FILLEDCURVES_ATXY */
int oneside; /* -1 if fill below bound only; +1 if fill above bound only */
Expand Down
26 changes: 14 additions & 12 deletions src/graphics.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.574 2017-09-13 22:59:29 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.575 2017-09-29 19:23:36 sfeam Exp $"); }
#endif

/* GNUPLOT - graphics.c */
Expand Down Expand Up @@ -796,7 +796,17 @@ do_plot(struct curve_points *plots, int pcount)
break;

case FILLEDCURVES:
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) {
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT) {
if (this_plot->plot_type == DATA)
memcpy(&this_plot->filledcurves_options,
&filledcurves_opts_data, sizeof(filledcurves_opts));
else
memcpy(&this_plot->filledcurves_options,
&filledcurves_opts_func, sizeof(filledcurves_opts));
}
if (this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_ABOVE
|| this_plot->filledcurves_options.closeto == FILLEDCURVES_BELOW) {
plot_betweencurves(this_plot);
} else if (!this_plot->plot_smooth &&
(this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
Expand Down Expand Up @@ -1245,16 +1255,6 @@ plot_filledcurves(struct curve_points *plot)
return;
}

if (!plot->filledcurves_options.opt_given) {
/* no explicitly given filledcurves option for the current plot =>
use the default for data or function, respectively
*/
if (plot->plot_type == DATA)
memcpy(&plot->filledcurves_options, &filledcurves_opts_data, sizeof(filledcurves_opts));
else
memcpy(&plot->filledcurves_options, &filledcurves_opts_func, sizeof(filledcurves_opts));
}

/* clip the "at" coordinate to the drawing area */
switch (plot->filledcurves_options.closeto) {
case FILLEDCURVES_ATX1:
Expand All @@ -1276,6 +1276,8 @@ plot_filledcurves(struct curve_points *plot)
cliptorange(plot->filledcurves_options.aty,
axis_array[FIRST_Y_AXIS].min, axis_array[FIRST_Y_AXIS].max);
break;
default:
break;
}

for (i = 0; i < plot->p_count; i++) {
Expand Down
70 changes: 33 additions & 37 deletions src/misc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: misc.c,v 1.213 2017-07-25 21:48:16 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: misc.c,v 1.214 2017-09-29 19:23:36 sfeam Exp $"); }
#endif

/* GNUPLOT - misc.c */
Expand Down Expand Up @@ -781,47 +781,43 @@ get_style()
}

/* Parse options for style filledcurves and fill fco accordingly.
* If no option given, then set fco->opt_given to 0.
* If no option given, set it to FILLEDCURVES_DEFAULT.
*/
void
get_filledcurves_style_options(filledcurves_opts *fco)
{
int p;
p = lookup_table(&filledcurves_opts_tbl[0], c_token);

if (p == FILLEDCURVES_ABOVE) {
fco->oneside = 1;
p = lookup_table(&filledcurves_opts_tbl[0], ++c_token);
} else if (p == FILLEDCURVES_BELOW) {
fco->oneside = -1;
p = lookup_table(&filledcurves_opts_tbl[0], ++c_token);
} else
fco->oneside = 0;

if (p == -1) {
fco->opt_given = 0;
return; /* no option given */
} else
fco->opt_given = 1;
enum filledcurves_opts_id p;
fco->closeto = FILLEDCURVES_DEFAULT;
fco->oneside = 0;

c_token++;
while ((p = lookup_table(&filledcurves_opts_tbl[0], c_token)) != -1) {
fco->closeto = p;
c_token++;

fco->closeto = p;
fco->at = 0;
if (!equals(c_token, "="))
return;
/* parameter required for filledcurves x1=... and friends */
if (p < FILLEDCURVES_ATXY)
fco->closeto += 4;
c_token++;
fco->at = real_expression();
if (p != FILLEDCURVES_ATXY)
return;
/* two values required for FILLEDCURVES_ATXY */
if (!equals(c_token, ","))
int_error(c_token, "syntax is xy=<x>,<y>");
c_token++;
fco->aty = real_expression();
if (p == FILLEDCURVES_ABOVE) {
fco->oneside = 1;
continue;
} else if (p == FILLEDCURVES_BELOW) {
fco->oneside = -1;
continue;
}

fco->at = 0;
if (!equals(c_token, "="))
return;
/* parameter required for filledcurves x1=... and friends */
if (p < FILLEDCURVES_ATXY)
fco->closeto += 4;
c_token++;
fco->at = real_expression();
if (p != FILLEDCURVES_ATXY)
return;
/* two values required for FILLEDCURVES_ATXY */
if (!equals(c_token, ","))
int_error(c_token, "syntax is xy=<x>,<y>");
c_token++;
fco->aty = real_expression();
}
return;
}

Expand All @@ -831,7 +827,7 @@ get_filledcurves_style_options(filledcurves_opts *fco)
void
filledcurves_options_tofile(filledcurves_opts *fco, FILE *fp)
{
if (!fco->opt_given)
if (fco->closeto == FILLEDCURVES_DEFAULT)
return;
if (fco->oneside)
fputs(fco->oneside > 0 ? "above " : "below ", fp);
Expand Down
9 changes: 5 additions & 4 deletions src/plot2d.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: plot2d.c,v 1.458 2017-09-25 16:44:52 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: plot2d.c,v 1.459 2017-09-29 19:23:37 sfeam Exp $"); }
#endif

/* GNUPLOT - plot2d.c */
Expand Down Expand Up @@ -969,7 +969,8 @@ get_data(struct curve_points *current_plot)
/* fall through */

case FILLEDCURVES:
current_plot->filledcurves_options.closeto = FILLEDCURVES_BETWEEN;
if (current_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT)
current_plot->filledcurves_options.closeto = FILLEDCURVES_BETWEEN;
store2d_point(current_plot, i++, v[0], v[1], v[0], v[0],
v[1], v[2], -1.0);
break;
Expand Down Expand Up @@ -2081,7 +2082,7 @@ eval_plots()
this_plot->plot_type = DATA;
this_plot->plot_style = data_style;
this_plot->plot_smooth = SMOOTH_NONE;
this_plot->filledcurves_options.opt_given = 0;
this_plot->filledcurves_options.closeto = FILLEDCURVES_DEFAULT;

/* Only relevant to "with table" */
free_at(table_filter_at);
Expand Down Expand Up @@ -2132,7 +2133,7 @@ eval_plots()
}
this_plot->plot_type = FUNC;
this_plot->plot_style = func_style;
this_plot->filledcurves_options.opt_given = 0;
this_plot->filledcurves_options.closeto = FILLEDCURVES_DEFAULT;
end_token = c_token - 1;
} /* end of IS THIS A FILE OR A FUNC block */

Expand Down
6 changes: 3 additions & 3 deletions src/set.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: set.c,v 1.570 2017-09-17 18:54:49 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: set.c,v 1.571 2017-09-29 19:23:37 sfeam Exp $"); }
#endif

/* GNUPLOT - set.c */
Expand Down Expand Up @@ -4615,7 +4615,7 @@ set_style()
data_style = get_style();
if (data_style == FILLEDCURVES) {
get_filledcurves_style_options(&filledcurves_opts_data);
if (!filledcurves_opts_data.opt_given) /* default value */
if (filledcurves_opts_func.closeto == FILLEDCURVES_DEFAULT)
filledcurves_opts_data.closeto = FILLEDCURVES_CLOSED;
}
break;
Expand All @@ -4632,7 +4632,7 @@ set_style()
func_style = temp_style;
if (func_style == FILLEDCURVES) {
get_filledcurves_style_options(&filledcurves_opts_func);
if (!filledcurves_opts_func.opt_given) /* default value */
if (filledcurves_opts_func.closeto == FILLEDCURVES_DEFAULT)
filledcurves_opts_func.closeto = FILLEDCURVES_CLOSED;
}
break;
Expand Down
7 changes: 4 additions & 3 deletions src/tables.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: tables.h,v 1.105 2017-09-11 20:13:24 sfeam Exp $
* $Id: tables.h,v 1.106 2017-09-29 19:23:37 sfeam Exp $
*/

/* GNUPLOT - tables.h */
Expand Down Expand Up @@ -199,14 +199,15 @@ enum show_style_id {
};

enum filledcurves_opts_id {
FILLEDCURVES_CLOSED,
FILLEDCURVES_CLOSED=0,
FILLEDCURVES_X1, FILLEDCURVES_Y1, FILLEDCURVES_X2, FILLEDCURVES_Y2,
/* requirement: FILLEDCURVES_ATX1 = FILLEDCURVES_X1+4 */
FILLEDCURVES_ATX1, FILLEDCURVES_ATY1, FILLEDCURVES_ATX2, FILLEDCURVES_ATY2,
FILLEDCURVES_ATXY,
FILLEDCURVES_ATR,
FILLEDCURVES_ABOVE, FILLEDCURVES_BELOW,
FILLEDCURVES_BETWEEN
FILLEDCURVES_BETWEEN,
FILLEDCURVES_DEFAULT
};

extern const struct gen_table command_tbl[];
Expand Down

0 comments on commit aca4a1b

Please sign in to comment.