Skip to content

Commit

Permalink
replace redundant code in plot_vectors() with a call to draw_clip_arr…
Browse files Browse the repository at this point in the history
…ow()
  • Loading branch information
sfeam committed Oct 31, 2017
1 parent 6abe366 commit 962a6db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2017-10-30 Ethan A Merritt <[email protected]>

* src/gadgets.c (draw_clip_arrow): Do not call term->arrow() if the
entire arrow is out of range.

* src/graphics.c (plot_vectors): The code for 2D "plot with vectors"
is redundant. Replace the core of it with a call to draw_clip_arrow().

* src/boundary.c (do_key_sample): Illustrate revision of a
draw_clip_arrow() call site to use (double) rather than (int)
parameters. The only reason for this is to allow draw_clip_arrow()
itself to switch to (double) parameters if we decide that is useful,
e.g. to handle arrows with length approaching zero.

2017-10-13 Petr Mikulik <[email protected]>

* src/pm3d.c (pm3d_draw_one pm3d_plot): Move call of term->layer() with
Expand Down
68 changes: 13 additions & 55 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.575 2017-09-29 19:23:36 sfeam Exp $"); }
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.576 2017-10-31 18:52:59 sfeam Exp $"); }
#endif

/* GNUPLOT - graphics.c */
Expand Down Expand Up @@ -2414,17 +2414,18 @@ plot_vectors(struct curve_points *plot)
{
int i;
int x1, y1, x2, y2;
struct termentry *t = term;
struct coordinate points[2];
double ex, ey;
double lx[2], ly[2];
arrow_style_type ap;
BoundingBox *clip_save = clip_area;

/* Normally this is only necessary once because all arrows equal */
ap = plot->arrow_properties;
term_apply_lp_properties(&ap.lp_properties);
apply_head_properties(&ap);

/* Clip to plot */
clip_area = &plot_bounds;

for (i = 0; i < plot->p_count; i++) {

points[0] = plot->points[i];
Expand All @@ -2445,58 +2446,15 @@ plot_vectors(struct curve_points *plot)
/* variable color read from extra data column. */
check_for_variable_color(plot, &plot->varcolor[i]);

if (inrange(points[1].x, X_AXIS.min, X_AXIS.max)
&& inrange(points[1].y, Y_AXIS.min, Y_AXIS.max)) {
/* to inrange */
points[1].type = INRANGE;
x2 = map_x(points[1].x);
y2 = map_y(points[1].y);
if (points[0].type == INRANGE) {
x1 = map_x(points[0].x);
y1 = map_y(points[0].y);
(*t->arrow) (x1, y1, x2, y2, ap.head);
} else if (points[0].type == OUTRANGE) {
/* from outrange to inrange */
if (clip_lines1) {
edge_intersect(points, 1, &ex, &ey);
x1 = map_x(ex);
y1 = map_y(ey);
if (ap.head & END_HEAD)
(*t->arrow) (x1, y1, x2, y2, END_HEAD);
else
(*t->arrow) (x1, y1, x2, y2, NOHEAD);
}
}
} else {
/* to outrange */
points[1].type = OUTRANGE;
if (points[0].type == INRANGE) {
/* from inrange to outrange */
if (clip_lines1) {
x1 = map_x(points[0].x);
y1 = map_y(points[0].y);
edge_intersect(points, 1, &ex, &ey);
x2 = map_x(ex);
y2 = map_y(ey);
if (ap.head & BACKHEAD)
(*t->arrow) (x2, y2, x1, y1, BACKHEAD);
else
(*t->arrow) (x1, y1, x2, y2, NOHEAD);
}
} else if (points[0].type == OUTRANGE) {
/* from outrange to outrange */
if (clip_lines2) {
if (two_edge_intersect(points, 1, lx, ly)) {
x1 = map_x(lx[0]);
y1 = map_y(ly[0]);
x2 = map_x(lx[1]);
y2 = map_y(ly[1]);
(*t->arrow) (x1, y1, x2, y2, NOHEAD);
}
}
}
}
/* draw_clip_arrow does the hard work for us */
x1 = map_x(points[0].x);
y1 = map_y(points[0].y);
x2 = map_x(points[1].x);
y2 = map_y(points[1].y);
draw_clip_arrow(x1, y1, x2, y2, ap.head);
}

clip_area = clip_save;
}


Expand Down

0 comments on commit 962a6db

Please sign in to comment.