123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "xmi.h"
- #include "mi_spans.h"
- #include "mi_api.h"
- #include "mi_fply.h"
- static int GetFPolyYBounds (const SppPoint *pts, int n, double yFtrans, int *by, int *ty);
- void
- miFillSppPoly (miPaintedSet *paintedSet, miPixel pixel, int count, const SppPoint *ptsIn, int xTrans, int yTrans, double xFtrans, double yFtrans)
- {
- double xl = 0.0,
- xr = 0.0,
- ml = 0.0,
- mr = 0.0,
- dy,
- i;
- int y,
- j,
- imin,
- ymin,
- ymax;
- int left, right,
- nextleft,
- nextright;
- int *Marked;
- unsigned int *width,
- *FirstWidth;
- miPoint *ptsOut,
- *FirstPoint;
- imin = GetFPolyYBounds (ptsIn, count, yFtrans, &ymin, &ymax);
- y = ymax - ymin + 1;
- if ((count < 3) || (y <= 0))
- return;
- ptsOut = FirstPoint = (miPoint *)mi_xmalloc(sizeof(miPoint) * y);
- width = FirstWidth = (unsigned int *)mi_xmalloc(sizeof(unsigned int) * y);
- Marked = (int *) mi_xmalloc(sizeof(int) * count);
- for (j = 0; j < count; j++)
- Marked[j] = 0;
- nextleft = nextright = imin;
- Marked[imin] = -1;
- y = ICEIL(ptsIn[nextleft].y + yFtrans);
-
- do
- {
-
- if ((y > (ptsIn[nextleft].y + yFtrans) ||
- ISEQUAL(y, ptsIn[nextleft].y + yFtrans))
- && Marked[nextleft] != 1)
- {
- Marked[nextleft]++;
- left = nextleft++;
-
- if (nextleft >= count)
- nextleft = 0;
-
- dy = ptsIn[nextleft].y - ptsIn[left].y;
- if (dy != 0.0)
- {
- ml = (ptsIn[nextleft].x - ptsIn[left].x) / dy;
- dy = y - (ptsIn[left].y + yFtrans);
- xl = (ptsIn[left].x + xFtrans) + ml * DMAX(dy, 0);
- }
- }
-
- if ((y > ptsIn[nextright].y + yFtrans)
- ||
- (ISEQUAL(y, ptsIn[nextright].y + yFtrans)
- && Marked[nextright] != 1))
- {
- Marked[nextright]++;
- right = nextright--;
-
-
- if (nextright < 0)
- nextright = count - 1;
-
-
- dy = ptsIn[nextright].y - ptsIn[right].y;
- if (dy != 0.0)
- {
- mr = (ptsIn[nextright].x - ptsIn[right].x) / dy;
- dy = y - (ptsIn[right].y + yFtrans);
- xr = (ptsIn[right].x + xFtrans) + mr * DMAX(dy, 0);
- }
- }
-
-
- i = (DMIN(ptsIn[nextleft].y, ptsIn[nextright].y) + yFtrans) - y;
- if (i < EPSILON)
- {
- if(Marked[nextleft] && Marked[nextright])
- {
-
- break;
- }
- continue;
- }
- else
- {
- j = (int) i;
- if (!j)
- j++;
- }
- while (j > 0)
- {
- int cxl, cxr;
- ptsOut->y = (y) + yTrans;
- cxl = ICEIL(xl);
- cxr = ICEIL(xr);
-
- if (xl < xr)
- {
- *(width++) = (unsigned int)(cxr - cxl);
- (ptsOut++)->x = cxl + xTrans;
- }
- else
- {
- *(width++) = (unsigned int)(cxl - cxr);
- (ptsOut++)->x = cxr + xTrans;
- }
- y++;
-
- xl += ml;
- xr += mr;
- j--;
- }
- } while (y <= ymax);
- free (Marked);
-
- MI_PAINT_SPANS(paintedSet, pixel, ptsOut - FirstPoint, FirstPoint, FirstWidth)
- }
- static int
- GetFPolyYBounds (const SppPoint *pts, int n, double yFtrans, int *by, int *ty)
- {
- const SppPoint *ptsStart = pts;
- const SppPoint *ptMin;
- double ymin, ymax;
- ptMin = pts;
- ymin = ymax = (pts++)->y;
- while (--n > 0)
- {
- if (pts->y < ymin)
- {
- ptMin = pts;
- ymin = pts->y;
- }
- if(pts->y > ymax)
- ymax = pts->y;
- pts++;
- }
- *by = ICEIL(ymin + yFtrans);
- *ty = ICEIL(ymax + yFtrans - 1);
- return (ptMin - ptsStart);
- }
|