📄 mifillarc.c
字号:
x1 = Dcos(angle1) * w2; y1 = Dsin(angle1) * h2; } if ((angle2 == 0) || (angle2 == HALFCIRCLE)) { x2 = angle2 ? -w2 : w2; y2 = 0.0; } else if ((angle2 == QUADRANT) || (angle2 == QUADRANT3)) { x2 = 0.0; y2 = (angle2 == QUADRANT) ? h2 : -h2; } else { isInt2 = FALSE; x2 = Dcos(angle2) * w2; y2 = Dsin(angle2) * h2; } dx = x2 - x1; dy = y2 - y1; if (arc->height & 1) { y1 -= 0.5; y2 -= 0.5; } if (arc->width & 1) { x1 += 0.5; x2 += 0.5; } if (dy < 0.0) { dy = -dy; signdy = -1; } else signdy = 1; if (dx < 0.0) { dx = -dx; signdx = -1; } else signdx = 1; if (isInt1 && isInt2) { slice->edge1.dx = dx * 2; slice->edge1.dy = dy * 2; } else { scale = (dx > dy) ? dx : dy; slice->edge1.dx = floor((dx * 32768) / scale + .5); slice->edge1.dy = floor((dy * 32768) / scale + .5); } if (!slice->edge1.dy) { if (signdx < 0) { y = floor(y1 + 1.0); if (y >= 0) { slice->min_top_y = y; slice->min_bot_y = arc->height; } else { slice->max_bot_y = -y - (arc->height & 1); } } else { y = floor(y1); if (y >= 0) slice->max_top_y = y; else { slice->min_top_y = arc->height; slice->min_bot_y = -y - (arc->height & 1); } } slice->edge1_top = TRUE; slice->edge1.x = 65536; slice->edge1.stepx = 0; slice->edge1.e = 0; slice->edge1.dx = -1; slice->edge2 = slice->edge1; slice->edge2_top = FALSE; } else if (!slice->edge1.dx) { if (signdy < 0) x1 -= 1.0; slice->edge1.x = ceil(x1); slice->edge1_top = signdy < 0; slice->edge1.x += arc->x + (arc->width >> 1); slice->edge1.stepx = 0; slice->edge1.e = 0; slice->edge1.dx = -1; slice->edge2_top = !slice->edge1_top; slice->edge2 = slice->edge1; } else { if (signdx < 0) slice->edge1.dx = -slice->edge1.dx; if (signdy < 0) slice->edge1.dx = -slice->edge1.dx; k = ceil(((x1 + x2) * slice->edge1.dy - (y1 + y2) * slice->edge1.dx) / 2.0); slice->edge2.dx = slice->edge1.dx; slice->edge2.dy = slice->edge1.dy; slice->edge1_top = signdy < 0; slice->edge2_top = !slice->edge1_top; miGetArcEdge(arc, &slice->edge1, k, slice->edge1_top, !slice->edge1_top); miGetArcEdge(arc, &slice->edge2, k, slice->edge2_top, slice->edge2_top); } }}#define ADDSPANS() \ pts->x = xorg - x; \ pts->y = yorg - y; \ *wids = slw; \ pts++; \ wids++; \ if (miFillArcLower(slw)) \ { \ pts->x = xorg - x; \ pts->y = yorg + y + dy; \ pts++; \ *wids++ = slw; \ }static voidmiFillEllipseI(pDraw, pGC, arc) DrawablePtr pDraw; GCPtr pGC; xArc *arc;{ register int x, y, e; int yk, xk, ym, xm, dx, dy, xorg, yorg; int slw; miFillArcRec info; DDXPointPtr points; register DDXPointPtr pts; int *widths; register int *wids; points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height); if (!points) return; widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height); if (!widths) { DEALLOCATE_LOCAL(points); return; } miFillArcSetup(arc, &info); MIFILLARCSETUP(); if (pGC->miTranslate) { xorg += pDraw->x; yorg += pDraw->y; } pts = points; wids = widths; while (y > 0) { MIFILLARCSTEP(slw); ADDSPANS(); } (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); DEALLOCATE_LOCAL(widths); DEALLOCATE_LOCAL(points);}static voidmiFillEllipseD(pDraw, pGC, arc) DrawablePtr pDraw; GCPtr pGC; xArc *arc;{ register int x, y; int xorg, yorg, dx, dy, slw; double e, yk, xk, ym, xm; miFillArcDRec info; DDXPointPtr points; register DDXPointPtr pts; int *widths; register int *wids; points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height); if (!points) return; widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height); if (!widths) { DEALLOCATE_LOCAL(points); return; } miFillArcDSetup(arc, &info); MIFILLARCSETUP(); if (pGC->miTranslate) { xorg += pDraw->x; yorg += pDraw->y; } pts = points; wids = widths; while (y > 0) { MIFILLARCSTEP(slw); ADDSPANS(); } (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); DEALLOCATE_LOCAL(widths); DEALLOCATE_LOCAL(points);}#define ADDSPAN(l,r) \ if (r >= l) \ { \ pts->x = l; \ pts->y = ya; \ pts++; \ *wids++ = r - l + 1; \ }#define ADDSLICESPANS(flip) \ if (!flip) \ { \ ADDSPAN(xl, xr); \ } \ else \ { \ xc = xorg - x; \ ADDSPAN(xc, xr); \ xc += slw - 1; \ ADDSPAN(xl, xc); \ }static voidmiFillArcSliceI(pDraw, pGC, arc) DrawablePtr pDraw; GCPtr pGC; xArc *arc;{ int yk, xk, ym, xm, dx, dy, xorg, yorg, slw; register int x, y, e; miFillArcRec info; miArcSliceRec slice; int ya, xl, xr, xc; DDXPointPtr points; register DDXPointPtr pts; int *widths; register int *wids; miFillArcSetup(arc, &info); miFillArcSliceSetup(arc, &slice, pGC); MIFILLARCSETUP(); slw = arc->height; if (slice.flip_top || slice.flip_bot) slw += (arc->height >> 1) + 1; points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw); if (!points) return; widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw); if (!widths) { DEALLOCATE_LOCAL(points); return; } if (pGC->miTranslate) { xorg += pDraw->x; yorg += pDraw->y; slice.edge1.x += pDraw->x; slice.edge2.x += pDraw->x; } pts = points; wids = widths; while (y > 0) { MIFILLARCSTEP(slw); MIARCSLICESTEP(slice.edge1); MIARCSLICESTEP(slice.edge2); if (miFillSliceUpper(slice)) { ya = yorg - y; MIARCSLICEUPPER(xl, xr, slice, slw); ADDSLICESPANS(slice.flip_top); } if (miFillSliceLower(slice)) { ya = yorg + y + dy; MIARCSLICELOWER(xl, xr, slice, slw); ADDSLICESPANS(slice.flip_bot); } } (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); DEALLOCATE_LOCAL(widths); DEALLOCATE_LOCAL(points);}static voidmiFillArcSliceD(pDraw, pGC, arc) DrawablePtr pDraw; GCPtr pGC; xArc *arc;{ register int x, y; int dx, dy, xorg, yorg, slw; double e, yk, xk, ym, xm; miFillArcDRec info; miArcSliceRec slice; int ya, xl, xr, xc; DDXPointPtr points; register DDXPointPtr pts; int *widths; register int *wids; miFillArcDSetup(arc, &info); miFillArcSliceSetup(arc, &slice, pGC); MIFILLARCSETUP(); slw = arc->height; if (slice.flip_top || slice.flip_bot) slw += (arc->height >> 1) + 1; points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw); if (!points) return; widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw); if (!widths) { DEALLOCATE_LOCAL(points); return; } if (pGC->miTranslate) { xorg += pDraw->x; yorg += pDraw->y; slice.edge1.x += pDraw->x; slice.edge2.x += pDraw->x; } pts = points; wids = widths; while (y > 0) { MIFILLARCSTEP(slw); MIARCSLICESTEP(slice.edge1); MIARCSLICESTEP(slice.edge2); if (miFillSliceUpper(slice)) { ya = yorg - y; MIARCSLICEUPPER(xl, xr, slice, slw); ADDSLICESPANS(slice.flip_top); } if (miFillSliceLower(slice)) { ya = yorg + y + dy; MIARCSLICELOWER(xl, xr, slice, slw); ADDSLICESPANS(slice.flip_bot); } } (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); DEALLOCATE_LOCAL(widths); DEALLOCATE_LOCAL(points);}/* MIPOLYFILLARC -- The public entry for the PolyFillArc request. * Since we don't have to worry about overlapping segments, we can just * fill each arc as it comes. */voidmiPolyFillArc(pDraw, pGC, narcs, parcs) DrawablePtr pDraw; GCPtr pGC; int narcs; xArc *parcs;{ register int i; register xArc *arc; for(i = narcs, arc = parcs; --i >= 0; arc++) { if (miFillArcEmpty(arc)) continue;; if ((arc->angle2 >= FULLCIRCLE) || (arc->angle2 <= -FULLCIRCLE)) { if (miCanFillArc(arc)) miFillEllipseI(pDraw, pGC, arc); else miFillEllipseD(pDraw, pGC, arc); } else { if (miCanFillArc(arc)) miFillArcSliceI(pDraw, pGC, arc); else miFillArcSliceD(pDraw, pGC, arc); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -