public static bool PlotTileTale(Vector2 start, Vector2 end, float width, PerLinePoint plot) { float halfWidth = width / 2f; Vector2 value = end - start; Vector2 vector = value / value.Length(); Vector2 perpOffset = new Vector2(0f - vector.Y, vector.X); Point pointStart = start.ToTileCoordinates(); Point point = end.ToTileCoordinates(); int length = 0; PlotLine(pointStart.X, pointStart.Y, point.X, point.Y, delegate { length++; return(true); }); length--; int curLength = 0; return(PlotLine(pointStart.X, pointStart.Y, point.X, point.Y, delegate(int x, int y) { float scaleFactor = 1f - (float)curLength / (float)length; curLength++; Point point2 = (start - perpOffset * halfWidth * scaleFactor).ToTileCoordinates(); Point point3 = (start + perpOffset * halfWidth * scaleFactor).ToTileCoordinates(); Point point4 = new Point(point2.X - pointStart.X, point2.Y - pointStart.Y); Point point5 = new Point(point3.X - pointStart.X, point3.Y - pointStart.Y); return PlotLine(x + point4.X, y + point4.Y, x + point5.X, y + point5.Y, plot, false); })); }
private static bool PlotLine(int x0, int y0, int x1, int y1, PerLinePoint plot, bool jump = true) { if (x0 == x1 && y0 == y1) { return(plot(x0, y0)); } bool flag = Math.Abs(y1 - y0) > Math.Abs(x1 - x0); if (flag) { Swap(ref x0, ref y0); Swap(ref x1, ref y1); } int num = Math.Abs(x1 - x0); int num2 = Math.Abs(y1 - y0); int num3 = num / 2; int num4 = y0; int num5 = (x0 < x1) ? 1 : (-1); int num6 = (y0 < y1) ? 1 : (-1); for (int i = x0; i != x1; i += num5) { if (flag) { if (!plot(num4, i)) { return(false); } } else if (!plot(i, num4)) { return(false); } num3 -= num2; if (num3 >= 0) { continue; } num4 += num6; if (!jump) { if (flag) { if (!plot(num4, i)) { return(false); } } else if (!plot(i, num4)) { return(false); } } num3 += num; } return(true); }
public static bool PlotTileLine(Vector2 start, Vector2 end, float width, PerLinePoint plot) { float scaleFactor = width / 2f; Vector2 value = end - start; Vector2 vector = value / value.Length(); Vector2 value2 = new Vector2(0f - vector.Y, vector.X) * scaleFactor; Point point = (start - value2).ToTileCoordinates(); Point point2 = (start + value2).ToTileCoordinates(); Point point3 = start.ToTileCoordinates(); Point point4 = end.ToTileCoordinates(); Point lineMinOffset = new Point(point.X - point3.X, point.Y - point3.Y); Point lineMaxOffset = new Point(point2.X - point3.X, point2.Y - point3.Y); return(PlotLine(point3.X, point3.Y, point4.X, point4.Y, (int x, int y) => PlotLine(x + lineMinOffset.X, y + lineMinOffset.Y, x + lineMaxOffset.X, y + lineMaxOffset.Y, plot, false))); }
public static bool PlotLine(Point p0, Point p1, PerLinePoint plot, bool jump = true) { return(PlotLine(p0.X, p0.Y, p1.X, p1.Y, plot, jump)); }