#ifndef hexpaint_H #define hexpaint_H /* Routines to paint figures on a hexagonal grid. */ /* Last edited on 2005-02-04 07:11:15 by stolfi */ #include #include #include #include #include #include #include typedef struct hxp_color_t { float R, G, B; } hxp_color_t; typedef unsigned char hxp_pixel_t; typedef struct hxp_canvas_t { hxp_pixel_t *pix; /* The pixels. */ r2_t org; /* Position of lower left grid point. */ r2_t step; /* Grid steps. */ i2_t size; /* Number of grid points along each axis. */ } hxp_canvas_t; /* A {hxp_canvas_t} is an array of byte "pixels", associated with points of an hexagonal grid. The bottom left point of the grid is {org}; points are spaced {step[0]} along each horizontal row, and each row is spaced {step[1]} vertically from the previous one. Both steps are positive. Odd rows are displaced by {0.5*step[0]} in the positive direction. Each row has {size[0]} points, and there are {size[1]} rows. */ hxp_canvas_t hxp_canvas_new(r2_t org, r2_t step, i2_t size, hxp_pixel_t v); /* Allocates a new canvas with the specified parameters, fills it with value {v}. */ r2_t hxp_pixel_pos(hxp_canvas_t *s, i2_t p); /* Returns the nominal coordinates of the point number {p.c[0]} on row {p.c[1]} of the grid of canvas {s}. */ void hxp_paint_polygon ( r2_vec_t p, /* Vertices of polygon, ccw around interior. */ hxp_canvas_t *s, /* Where to paint. */ hxp_pixel_t val /* Value to paint. */ ); /* Assigns {val} to all canvas pixels that lie inside the polygon {p}. */ void hxp_paint_circle ( r2_t ctr, /* Center of circle. */ double rad, /* Radius of circle. */ hxp_canvas_t *s, /* Where to paint. */ hxp_pixel_t val /* Value to paint. */ ); /* Assigns {val} to all canvas pixels that lie inside the circle with center {ctr} and radius {rad}. */ void hxp_paint_stroke ( r2_t a, /* Beginning of stroke axis. */ r2_t b, /* End of stroke axis. */ double r, /* Half-width of stroke. */ hxp_canvas_t *s, /* Where to paint. */ hxp_pixel_t val /* Value to paint. */ ); /* Assigns {val} to all canvas pixels that lie inside the rectangle whose axis is the segment {a,b} and whose extent perpendicular to that axis is {r} in each direction. */ i2_vec_t hxp_list_pixels (hxp_canvas_t *s, hxp_pixel_t v); /* Returns a list of the indices of all pixels in {s} that have value equal to {v}. */ void hxp_plot_canvas ( PSStream *ps, /* Where to plot. */ hxp_canvas_t *s, /* The canvas to plot. */ double rad(hxp_pixel_t v) /* Radius function. */ ); /* Plots the pixels of the canvas {s} the Postscript file {f}. A pixel with value {v} is plotted as a circle with radius {rad(v)}. If the X and Y ranges in {o} are not empty, clips the map to those ranges. */ #endif