X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Fxrow.c;h=7987ac15a0439cb306e63cae70eae37869ece7aa;hp=48fe7ad40eb8bd3133969803745d0a3d4e113065;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hpb=f5626be739a1e1b61f89d7a389be3c4b5d4d9128 diff --git a/lib/gfxpoly/xrow.c b/lib/gfxpoly/xrow.c index 48fe7ad..7987ac1 100644 --- a/lib/gfxpoly/xrow.c +++ b/lib/gfxpoly/xrow.c @@ -1,7 +1,9 @@ #include #include +#include #include "../mem.h" #include "xrow.h" +#include "poly.h" xrow_t* xrow_new() { @@ -46,19 +48,46 @@ void xrow_sort(xrow_t*r) r->num = pos; } +int xrow_find(xrow_t*r, int32_t x) +{ + int min, max, i, l; + + for(min=0, max=r->num, i=r->num/2, l=r->num; i != l; l=i, i=(min+max)/2) { + if(x < r->x[i]) max=i; + else min=i; + } + +#ifdef CHECKS + int t; + for(t=0;tnum;t++) { + if(x < r->x[t]) + break; + } + assert(max == t); +#endif + + return max; +} + +char xrow_contains(xrow_t*r, int32_t x) +{ + int pos = xrow_find(r,x) - 1; + return (pos>=0 && r->x[pos]==x); +} + void xrow_reset(xrow_t*r) { r->num = 0; } -void xrow_dump(xrow_t*xrow) +void xrow_dump(xrow_t*xrow, double gridsize) { fprintf(stderr, "x: "); int t; for(t=0;tnum;t++) { if(t) fprintf(stderr, ", "); - fprintf(stderr, "%d", xrow->x[t]); + fprintf(stderr, "%.2f", xrow->x[t] * gridsize); } fprintf(stderr, "\n"); }