public static Polygon2f FromLine(Line2f line, float width) { if (!line.HasNormals) { throw new ArgumentException("Line must have normals to create a polygon from."); } if (line.VerticesCount < 2) { throw new ArgumentException("Line must have at least to positions to create a polygon from."); } int count = line.VerticesCount; float half = width * 0.5f; Polygon2f polygon = new Polygon2f(count * 2); for (int i = 0; i < count; i++) { polygon.Positions[i] = line.Positions[i] + line.Normals[i] * half; } for (int i = 0; i < count; i++) { int j = count - i - 1; polygon.Positions[i + count] = line.Positions[j] - line.Normals[j] * half; } return(polygon); }
public void printLineCut(Line2f lineCoords, Vec3f color) { int stride = (pixelWidth * 32) / 8; int pixelHeight = buf.Length / stride; Line2f line = clip.Clip(lineCoords); if (line == null) { return; } int x0 = (int)line.x0; int y0 = (int)line.y0; int x1 = (int)line.x1; int y1 = (int)line.y1; int dx = Math.Abs(x1 - x0); int sx = x0 < x1 ? 1 : -1; int dy = Math.Abs(y1 - y0); int sy = y0 < y1 ? 1 : -1; int err = (dx > dy ? dx : -dy) / 2; int e2; for (; ;) { printPixel(x0, y0, color); if (x0 == x1 && y0 == y1) { break; } e2 = err; if (e2 > -dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } }