Added function to calculate bounds of a polygon.

SVN revision: 3280
This commit is contained in:
Tom Gilbert 2000-08-30 21:57:36 +00:00
parent b5ababf0b7
commit c46b591e82
4 changed files with 39 additions and 0 deletions

View File

@ -249,6 +249,7 @@ ImlibPolygon imlib_polygon_new(int type);
void imlib_polygon_free(ImlibPolygon poly);
void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
void imlib_image_draw_polygon(ImlibPolygon poly);
void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2);
Imlib_Color_Range imlib_create_color_range(void);
void imlib_free_color_range(void);

View File

@ -2748,3 +2748,9 @@ void imlib_image_draw_polygon(ImlibPolygon poly)
ctxt_color.blue, ctxt_color.alpha, ctxt_operation);
}
}
void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2)
{
CHECK_PARAM_POINTER("imlib_polygon_get_bounds", "polygon", poly);
__imlib_polygon_get_bounds(poly, px1, py1, px2, py2);
}

View File

@ -1705,3 +1705,18 @@ __imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
}
}
void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2)
{
int x1,y1,x2,y2;
int i;
if(!poly || !poly->points || (poly->pointcount < 2))
return;
for(i = 0; i < poly->pointcount; i++)
GROW_BOUNDS (x1, y1, x2, y2, poly->points[i].x, poly->points[i].y);
*px1 = x1;
*py1 = y1;
*px2 = x2;
*py2 = y2;
}

View File

@ -1,6 +1,22 @@
#ifndef __RGBADRAW
#define __RGBADRAW 1
#define GROW_BOUNDS(px1, py1, px2, py2, x, y) { \
if (x < px1) \
px1 = x; \
\
if (x > px2) \
px2 = x; \
\
if (y < py1) \
py1 = y; \
\
if (y > py2) \
py2 = y; \
}
typedef struct _imlib_point ImlibPoint;
struct _imlib_point
@ -76,4 +92,5 @@ void
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
DATA8 a, ImlibOp op);
void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2);
#endif