367 int sx = x0 < x3 ? 1 : -1;
368 int sy = y0 < y3 ? 1 : -1;
369 float xc = -Abs(x0 + x1 - x2 - x3);
370 float xa = xc - 4 * sx * (x1 - x2);
371 float xb = sx * (x0 - x1 - x2 + x3);
372 float yc = -Abs(y0 + y1 - y2 - y3);
373 float ya = yc - 4 * sy * (y1 - y2);
374 float yb = sy * (y0 - y1 - y2 + y3);
390 Debug.Assert((x1 - x0) * (x2 - x3) < EP && ((x3 - x0) * (x1 - x2) < EP || xb * xb < xa * xc + EP));
391 Debug.Assert((y1 - y0) * (y2 - y3) < EP && ((y3 - y0) * (y1 - y2) < EP || yb * yb < ya * yc + EP));
392 if (xa == 0 && ya == 0)
396 sx = (int)Floor((3 * x1 - x0 + 1) / 2);
397 sy = (int)Floor((3 * y1 - y0 + 1) / 2);
412 x1 = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + 1;
413 x2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3) + 1;
417 ab = xa * yb - xb * ya;
418 ac = xa * yc - xc * ya;
419 bc = xb * yc - xc * yb;
422 ex = ab * (ab + ac - 3 * bc) + ac * ac;
425 f = ex > 0 ? 1 : (int)Sqrt(1 + 1024 / x1);
434 xy = 9 * (ab + ac + bc) / 8;
436 dx = 27 * (8 * ab * (yb * yb - ya * yc) + ex * (ya + 2 * yb + yc)) / 64 - ya * ya * (xy - ya);
437 dy = 27 * (8 * ab * (xb * xb - xa * xc) - ex * (xa + 2 * xb + xc)) / 64 - xa * xa * (xy + xa);
439 xx = 3 * (3 * ab * (3 * yb * yb - ya * ya - 2 * ya * yc) - ya * (3 * ac * (ya + yb) + ya * cb)) / 4;
440 yy = 3 * (3 * ab * (3 * xb * xb - xa * xa - 2 * xa * xc) - xa * (3 * ac * (xa + xb) + xa * cb)) / 4;
441 xy = xa * ya * (6 * ab + 6 * ac - 3 * bc + cb);
444 xy = 3 * (xy + 9 * f * (cb * yb * yc - xb * xc * ac) - 18 * xb * yb * ab) / 8;
469 bool boundaryHit =
false;
472 for (fx = fy = f; x0 != x3 && y0 != y3;)
475 addPoint.Invoke(x0, y0);
480 if (dx > pxy || dy < pxy)
487 y1 = (float)(2 * ex - dy);
528 while (fx > 0 && fy > 0);
544 if (!boundaryHit && dx < 0 && dy > 0)
static void PlotLine(int x0, int y0, int x1, int y1, Action< int, int > addPoint)
From http://members.chello.at/easyfilter/bresenham.pdf
static void PlotQuadBezierSeg(int x0, int y0, int x1, int y1, int x2, int y2, Action< int, int > addPoint)
From http://members.chello.at/easyfilter/bresenham.pdf