Skip to content

Commit

Permalink
rename macro STORE_WITH_LOG_AND_UPDATE_RANGE() to STORE_AND_UPDATE_RA…
Browse files Browse the repository at this point in the history
…NGE() to reflect its revised function in 5.3
  • Loading branch information
sfeam committed Aug 24, 2017
1 parent 0fc2979 commit 9146985
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 210 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2017-08-24 Ethan A Merritt <[email protected]>

* src/axis.c src/axis.h src/graphics.c src/interpol.c src/plot2d.c
src/plot3d.c: Revise macro name STORE_WITH_LOG_AND_UPDATE_RANGE to
STORE_AND_UPDATE_RANGE since we no longer handle log scaling at the
time data is stored. Take this opportunity to remove and unused
parameter (OUT_ACTION) from the macro. Go back to using the same
macro for the COLOR_AXIS that we use for all other axes.
This is intended solely to make the code easier to understand;
there is no change in the code actually executed.

2017-08-23 Ethan A Merritt <[email protected]>

* src/plot2d.c (parametric_fixup): Consolidate redundant code blocks
Expand Down
4 changes: 2 additions & 2 deletions src/axis.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: axis.c,v 1.238 2017-08-18 19:34:07 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: axis.c,v 1.239 2017-08-24 23:32:42 sfeam Exp $"); }
#endif

/* GNUPLOT - axis.c */
Expand Down Expand Up @@ -896,7 +896,7 @@ setup_tics(struct axis *this, int max)

/* Apply constraints on autoscaled axis if requested:
* The range is _expanded_ here only. Limiting the range is done
* in the macro STORE_WITH_LOG_AND_UPDATE_RANGE() of axis.h */
* in the macro STORE_AND_UPDATE_RANGE() of axis.h */
if (this->autoscale & AUTOSCALE_MIN) {
if (this->min_constraint & CONSTRAINT_UPPER) {
if (this->min > this->min_ub)
Expand Down
34 changes: 8 additions & 26 deletions src/axis.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: axis.h,v 1.175 2017-08-03 19:45:02 sfeam Exp $
* $Id: axis.h,v 1.176 2017-08-24 23:32:42 sfeam Exp $
*
*/

Expand Down Expand Up @@ -463,18 +463,17 @@ do { \
(store) = get_num_or_time(this_axis); \
} while(0)

/* store VALUE in STORE, set TYPE as appropriate
/* store VALUE in STORE, set TYPE to INRANGE/OUTRANGE/UNDEFINED
* VALUE must not be same as STORE
* Version 5: OK to store infinities or NaN
* Do OUT_ACTION or UNDEF_ACTION as appropriate
* Do UNDEF_ACTION as appropriate
* adjust range provided type is INRANGE (ie dont adjust y if x is outrange
* NOAUTOSCALE is per-plot property, whereas AUTOSCALE_XXX is per-axis.
* Note: see the particular implementation for COLOR AXIS below.
*/

#define ACTUAL_STORE_WITH_LOG_AND_UPDATE_RANGE(STORE, VALUE, TYPE, AXIS, \
NOAUTOSCALE, OUT_ACTION, \
UNDEF_ACTION) \
#define ACTUAL_STORE_AND_UPDATE_RANGE(STORE, VALUE, TYPE, AXIS, \
NOAUTOSCALE, UNDEF_ACTION) \
do { \
struct axis *axis = AXIS; \
double curval = (VALUE); \
Expand All @@ -491,7 +490,6 @@ do { \
break; \
} else if (curval == 0.0) { \
TYPE = OUTRANGE; \
OUT_ACTION; \
break; \
} \
} \
Expand All @@ -508,13 +506,11 @@ do { \
if (axis->min_lb > curval) { \
axis->min = axis->min_lb; \
TYPE = OUTRANGE; \
OUT_ACTION; \
break; \
} \
} \
} else if (curval != axis->max) { \
TYPE = OUTRANGE; \
OUT_ACTION; \
break; \
} \
} \
Expand All @@ -526,13 +522,11 @@ do { \
if (axis->max_ub < curval) { \
axis->max = axis->max_ub; \
TYPE =OUTRANGE; \
OUT_ACTION; \
break; \
} \
} \
} else if (curval != axis->min) { \
TYPE = OUTRANGE; \
OUT_ACTION; \
} \
} \
/* Only update data min/max if the point is INRANGE Jun 2016 */ \
Expand All @@ -545,23 +539,11 @@ do { \
} while(0)

/* normal calls go though this macro */
#define STORE_WITH_LOG_AND_UPDATE_RANGE(STORE, VALUE, TYPE, AXIS, NOAUTOSCALE, OUT_ACTION, UNDEF_ACTION) \
#define STORE_AND_UPDATE_RANGE(STORE, VALUE, TYPE, AXIS, NOAUTOSCALE, UNDEF_ACTION) \
if (AXIS != NO_AXIS) \
ACTUAL_STORE_WITH_LOG_AND_UPDATE_RANGE(STORE, VALUE, TYPE, (&axis_array[AXIS]), NOAUTOSCALE, OUT_ACTION, UNDEF_ACTION)
ACTUAL_STORE_AND_UPDATE_RANGE(STORE, VALUE, TYPE, (&axis_array[AXIS]), NOAUTOSCALE, UNDEF_ACTION)

/* Implementation of the above for the color axis. It should not change
* the type of the point (out-of-range color is plotted with the color
* of the min or max color value).
*/
#define COLOR_STORE_WITH_LOG_AND_UPDATE_RANGE(STORE, VALUE, TYPE, AXIS, \
NOAUTOSCALE, OUT_ACTION, UNDEF_ACTION) \
{ \
coord_type c_type_tmp = TYPE; \
ACTUAL_STORE_WITH_LOG_AND_UPDATE_RANGE(STORE, VALUE, c_type_tmp, &axis_array[AXIS], \
NOAUTOSCALE, OUT_ACTION, UNDEF_ACTION); \
}

/* #define NOOP (0) caused many warnings from gcc 3.2 */
/* Use NOOP for UNDEF_ACTION if no action is wanted */
#define NOOP ((void)0)

/* HBB 20000506: new macro to automatically build initializer lists
Expand Down
10 changes: 5 additions & 5 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.568 2017-08-23 00:54:52 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.569 2017-08-24 23:32:42 sfeam Exp $"); }
#endif

/* GNUPLOT - graphics.c */
Expand Down Expand Up @@ -4605,11 +4605,11 @@ process_image(void *plot, t_procimg_action action)

/* Update range and store value back into itself. */
dummy_type = INRANGE;
STORE_WITH_LOG_AND_UPDATE_RANGE(x, x, dummy_type, image_x_axis,
((struct curve_points *)plot)->noautoscale, NOOP, x = -VERYLARGE);
STORE_AND_UPDATE_RANGE(x, x, dummy_type, image_x_axis,
((struct curve_points *)plot)->noautoscale, x = -VERYLARGE);
dummy_type = INRANGE;
STORE_WITH_LOG_AND_UPDATE_RANGE(y, y, dummy_type, image_y_axis,
((struct curve_points *)plot)->noautoscale, NOOP, y = -VERYLARGE);
STORE_AND_UPDATE_RANGE(y, y, dummy_type, image_y_axis,
((struct curve_points *)plot)->noautoscale, y = -VERYLARGE);
}
return;
}
Expand Down
110 changes: 39 additions & 71 deletions src/interpol.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static char *RCSid() { return RCSid("$Id: interpol.c,v 1.62 2017-08-01 01:30:48 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: interpol.c,v 1.63 2017-08-24 23:32:42 sfeam Exp $"); }
#endif

/* GNUPLOT - interpol.c */
Expand Down Expand Up @@ -135,15 +135,14 @@ static char *RCSid() { return RCSid("$Id: interpol.c,v 1.62 2017-08-01 01:30:48
*/


/* store VALUE or log(VALUE) in STORE, set TYPE as appropriate Do
* OUT_ACTION or UNDEF_ACTION as appropriate. Adjust range provided
/* store VALUE in STORE, set TYPE to INRANGE/OUTRANGE
* Do UNDEF_ACTION as appropriate. Adjust range provided
* type is INRANGE (ie dont adjust y if x is outrange). VALUE must not
* be same as STORE */
/* FIXME 20010610: UNDEF_ACTION is completely unused ??? Furthermore,
* this is so similar to STORE_WITH_LOG_AND_UPDATE_RANGE() from axis.h
/* FIXME 20010610:
* this is so similar to STORE_AND_UPDATE_RANGE() from axis.h
* that the two should probably be merged. */
#define STORE_AND_FIXUP_RANGE(store, value, type, min, max, auto, \
out_action, undef_action) \
#define STORE_AND_FIXUP_RANGE(store, value, type, min, max, auto) \
do { \
store=value; \
if (type != INRANGE) \
Expand All @@ -153,24 +152,20 @@ do { \
(min) = (value); \
else { \
(type) = OUTRANGE; \
out_action; \
break; \
} \
} \
if ((value) > (max)) { \
if ((auto) & AUTOSCALE_MAX) \
(max) = (value); \
else { \
(type) = OUTRANGE; \
out_action; \
} \
} \
} while(0)

#define UPDATE_RANGE(TEST,OLD,NEW,AXIS) \
do { \
if (TEST) \
(OLD) = NEW; \
#define UPDATE_RANGE(TEST,OLD,NEW) \
do { \
if (TEST) (OLD) = NEW; \
} while(0)

#define spline_coeff_size 4
Expand Down Expand Up @@ -336,8 +331,8 @@ do_kdensity(
/* now we have to store the points and adjust the ranges */
dest[i].type = INRANGE;
dest[i].x = x;
STORE_WITH_LOG_AND_UPDATE_RANGE( dest[i].y, y, dest[i].type, y_axis,
cp->noautoscale, NOOP, NOOP);
STORE_AND_UPDATE_RANGE( dest[i].y, y, dest[i].type, y_axis,
cp->noautoscale, NOOP);
dest[i].xlow = dest[i].xhigh = dest[i].x;
dest[i].ylow = dest[i].yhigh = dest[i].y;
dest[i].z = -1;
Expand Down Expand Up @@ -474,19 +469,19 @@ do_bezier(
/* now we have to store the points and adjust the ranges */

dest[i].type = INRANGE;
STORE_AND_FIXUP_RANGE(dest[i].x, x, dest[i].type, ixmin, ixmax, X_AXIS.autoscale, NOOP, continue);
STORE_AND_FIXUP_RANGE(dest[i].y, y, dest[i].type, iymin, iymax, Y_AXIS.autoscale, NOOP, NOOP);
STORE_AND_FIXUP_RANGE(dest[i].x, x, dest[i].type, ixmin, ixmax, X_AXIS.autoscale);
STORE_AND_FIXUP_RANGE(dest[i].y, y, dest[i].type, iymin, iymax, Y_AXIS.autoscale);

dest[i].xlow = dest[i].xhigh = dest[i].x;
dest[i].ylow = dest[i].yhigh = dest[i].y;

dest[i].z = -1;
}

UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax, x_axis);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin, x_axis);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax, y_axis);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin, y_axis);
UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin);
}

/*
Expand Down Expand Up @@ -902,8 +897,8 @@ do_cubic(
}

dest[i].type = INRANGE;
STORE_AND_FIXUP_RANGE(dest[i].x, x, dest[i].type, ixmin, ixmax, X_AXIS.autoscale, NOOP, continue);
STORE_AND_FIXUP_RANGE(dest[i].y, y, dest[i].type, iymin, iymax, Y_AXIS.autoscale, NOOP, NOOP);
STORE_AND_FIXUP_RANGE(dest[i].x, x, dest[i].type, ixmin, ixmax, X_AXIS.autoscale);
STORE_AND_FIXUP_RANGE(dest[i].y, y, dest[i].type, iymin, iymax, Y_AXIS.autoscale);

dest[i].xlow = dest[i].xhigh = dest[i].x;
dest[i].ylow = dest[i].yhigh = dest[i].y;
Expand All @@ -912,10 +907,10 @@ do_cubic(

}

UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax, x_axis);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin, x_axis);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax, y_axis);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin, y_axis);
UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin);

}

Expand Down Expand Up @@ -960,18 +955,18 @@ do_freq(

this[i].type = INRANGE;

STORE_AND_FIXUP_RANGE(this[i].x, x, this[i].type, ixmin, ixmax, X_AXIS.autoscale, NOOP, continue);
STORE_AND_FIXUP_RANGE(this[i].y, y, this[i].type, iymin, iymax, Y_AXIS.autoscale, NOOP, NOOP);
STORE_AND_FIXUP_RANGE(this[i].x, x, this[i].type, ixmin, ixmax, X_AXIS.autoscale);
STORE_AND_FIXUP_RANGE(this[i].y, y, this[i].type, iymin, iymax, Y_AXIS.autoscale);

this[i].xlow = this[i].xhigh = this[i].x;
this[i].ylow = this[i].yhigh = this[i].y;
this[i].z = -1;
}

UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax, x_axis);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin, x_axis);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax, y_axis);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin, y_axis);
UPDATE_RANGE(ixmax > sxmax, X_AXIS.max, ixmax);
UPDATE_RANGE(ixmin < sxmin, X_AXIS.min, ixmin);
UPDATE_RANGE(iymax > symax, Y_AXIS.max, iymax);
UPDATE_RANGE(iymin < symin, Y_AXIS.min, iymin);
}


Expand Down Expand Up @@ -1228,34 +1223,19 @@ cp_implode(struct curve_points *cp)
cp->points[j].yhigh = suy / (double) k;
cp->points[j].ylow = sly / (double) k;
cp->points[j].z = weight / (double) k;
/* HBB 20000405: I wanted to use STORE_AND_FIXUP_RANGE
* here, but won't: it assumes we want to modify the
* range, and that the range is given in 'input'
* coordinates. For logarithmic axes, the overhead
* would be larger than the possible gain, so write it
* out explicitly, instead:
* */
/* HBB 20000405: I wanted to use STORE_AND_FIXUP_RANGE here,
* but won't: it assumes we want to modify the range, and
* that the range is given in 'input' coordinates.
*/
cp->points[j].type = INRANGE;
if (! all_inrange) {
if (X_AXIS.log) {
if (x <= -VERYLARGE) {
cp->points[j].type = OUTRANGE;
goto is_outrange;
}
}
if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN))
|| ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) {
|| ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) {
cp->points[j].type = OUTRANGE;
goto is_outrange;
}
if (Y_AXIS.log) {
if (y <= -VERYLARGE) {
cp->points[j].type = OUTRANGE;
goto is_outrange;
}
}
if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN))
|| ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX)))
|| ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX)))
cp->points[j].type = OUTRANGE;
is_outrange:
;
Expand All @@ -1282,25 +1262,13 @@ cp_implode(struct curve_points *cp)
cp->points[j].z = weight / (double) k;
cp->points[j].type = INRANGE;
if (! all_inrange) {
if (X_AXIS.log) {
if (x <= -VERYLARGE) {
cp->points[j].type = OUTRANGE;
goto is_outrange2;
}
}
if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN))
|| ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) {
|| ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) {
cp->points[j].type = OUTRANGE;
goto is_outrange2;
}
if (Y_AXIS.log) {
if (y <= -VERYLARGE) {
cp->points[j].type = OUTRANGE;
goto is_outrange2;
}
}
if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN))
|| ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX)))
|| ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX)))
cp->points[j].type = OUTRANGE;
is_outrange2:
;
Expand Down Expand Up @@ -1417,8 +1385,8 @@ mcs_interp(struct curve_points *plot)
/* FIXME: Log x? autoscale x? */
new_points[i].x = x;
new_points[i].type = INRANGE;
STORE_WITH_LOG_AND_UPDATE_RANGE(new_points[i].y, y, new_points[i].type,
plot->y_axis, plot->noautoscale, NOOP, NOOP);
STORE_AND_UPDATE_RANGE(new_points[i].y, y, new_points[i].type,
plot->y_axis, plot->noautoscale, NOOP);
}

/* Replace original data with the interpolated curve */
Expand Down
Loading

0 comments on commit 9146985

Please sign in to comment.