Skip to content

Commit

Permalink
v.to.rast: Add points without segfault with densification flag (-d)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuidaeCho committed Feb 20, 2024
1 parent 4d2dac4 commit d868f5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions vector/v.to.rast/dense_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,15 @@ void dense_line(double x1, double y1, double x2, double y2,
}
point(ix2, iy2);
}

/* point plotting, alternative to G_plot_point()
* x, y are col, row numbers */
void plot_point(double east, double north)
{
int x, y;

x = ifloor(X(G_adjust_easting(east, &st->window)) + 0.5);
y = ifloor(Y(north) + 0.5);

st->dot(x, y);
}
14 changes: 9 additions & 5 deletions vector/v.to.rast/do_lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/* function prototypes */
static int plot_line(double *, double *, int, int, int);
static int plot_points(double *, double *, int);
static int plot_points(double *, double *, int, int);
static double v2angle(double[2], double[2], double, double);
static double deg_angle(double, double, double, double);

Expand Down Expand Up @@ -131,7 +131,7 @@ int do_lines(struct Map_info *Map, struct line_pnts *Points,
count++;
}
else if (type & GV_POINTS) {
plot_points(Points->x, Points->y, Points->n_points);
plot_points(Points->x, Points->y, Points->n_points, dense);
count++;
}
}
Expand Down Expand Up @@ -199,11 +199,15 @@ static double deg_angle(double x0, double y0, double x1, double y1)
return (v_ang * 360.0 / M_2PI);
}

static int plot_points(double *x, double *y, int n)
static int plot_points(double *x, double *y, int n, int dense)
{
/* only plot the first point */
if (n > 0)
G_plot_point(*x, *y);
if (n > 0) {
if (dense)
plot_point(*x, *y);
else
G_plot_point(*x, *y);
}

return 0;
}
1 change: 1 addition & 0 deletions vector/v.to.rast/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int do_lines(struct Map_info *, struct line_pnts *, dbCatValArray *, int, int,
struct cat_list *, int, double, int, int, int *, int);

void plot_line_dense(double, double, double, double);
void plot_point(double, double);
void setup_plot(double, double, double, double, int (*dot)(int, int));

/* raster.c */
Expand Down

0 comments on commit d868f5c

Please sign in to comment.