|
@@ -45,69 +45,7 @@ namespace bbiwarg.Images
|
|
|
|
|
|
public void drawLine(Line2D line, FingerImageState state)
|
|
|
{
|
|
|
- Vector2D start = line.P1;
|
|
|
- Vector2D end = line.P2;
|
|
|
-
|
|
|
- int width = image.Width;
|
|
|
- int height = image.Height;
|
|
|
-
|
|
|
- // bresenham from wikipedia
|
|
|
- int xstart = (int)start.X, xend = (int)end.X, ystart = (int)start.Y, yend = (int)end.Y;
|
|
|
- int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
|
|
|
-
|
|
|
- /* Entfernung in beiden Dimensionen berechnen */
|
|
|
- dx = xend - xstart;
|
|
|
- dy = yend - ystart;
|
|
|
-
|
|
|
- /* Vorzeichen des Inkrements bestimmen */
|
|
|
- incx = dx < 0 ? -1 : 1;
|
|
|
- incy = dy < 0 ? -1 : 1;
|
|
|
- if (dx < 0) dx = -dx;
|
|
|
- if (dy < 0) dy = -dy;
|
|
|
-
|
|
|
- /* feststellen, welche Entfernung größer ist */
|
|
|
- if (dx > dy)
|
|
|
- {
|
|
|
- /* x ist schnelle Richtung */
|
|
|
- pdx = incx; pdy = 0; /* pd. ist Parallelschritt */
|
|
|
- ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */
|
|
|
- es = dy; el = dx; /* Fehlerschritte schnell, langsam */
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- /* y ist schnelle Richtung */
|
|
|
- pdx = 0; pdy = incy; /* pd. ist Parallelschritt */
|
|
|
- ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */
|
|
|
- es = dx; el = dy; /* Fehlerschritte schnell, langsam */
|
|
|
- }
|
|
|
-
|
|
|
- /* Initialisierungen vor Schleifenbeginn */
|
|
|
- x = xstart;
|
|
|
- y = ystart;
|
|
|
- err = el / 2;
|
|
|
- setFingerAt(Math.Min(width - 1, Math.Max(0, x)), Math.Min(height - 1, Math.Max(0, y)), state);
|
|
|
-
|
|
|
- /* Pixel berechnen */
|
|
|
- for (t = 0; t < el; ++t) /* t zaehlt die Pixel, el ist auch Anzahl */
|
|
|
- {
|
|
|
- /* Aktualisierung Fehlerterm */
|
|
|
- err -= es;
|
|
|
- if (err < 0)
|
|
|
- {
|
|
|
- /* Fehlerterm wieder positiv (>=0) machen */
|
|
|
- err += el;
|
|
|
- /* Schritt in langsame Richtung, Diagonalschritt */
|
|
|
- x += ddx;
|
|
|
- y += ddy;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- /* Schritt in schnelle Richtung, Parallelschritt */
|
|
|
- x += pdx;
|
|
|
- y += pdy;
|
|
|
- }
|
|
|
- setFingerAt(Math.Min(width - 1, Math.Max(0, x)), Math.Min(height - 1, Math.Max(0, y)), state);
|
|
|
- }
|
|
|
+ image.Draw(new LineSegment2DF(line.P1, line.P2), new Gray((byte)state), 1);
|
|
|
}
|
|
|
}
|
|
|
}
|