/// <summary> /// Returns an IEnumerable of every point, in order, closest to a line between the two points /// specified, using the line drawing algorithm given. The start and end points will be included. /// </summary> /// <param name="start">The start point of the line.</param> /// <param name="end">The end point of the line.</param> /// <param name="type">The line-drawing algorithm to use to generate the line.</param> /// <returns> /// An IEnumerable of every point, in order, closest to a line between the two points /// specified (according to the algorithm given). /// </returns> static public IEnumerable <Coord> Get(Coord start, Coord end, Lines.Algorithm type = Algorithm.BRESENHAM) => Get(start.X, start.Y, end.X, end.Y, type);
/// <summary> /// Returns an IEnumerable of every point, in order, closest to a line between the two points /// specified, using the line drawing algorithm given. The start and end points will be included. /// </summary> /// <param name="startX">X-coordinate of the starting point of the line.</param> /// <param name="startY">Y-coordinate of the starting point of the line.</param> /// <param name="endX">X-coordinate of the ending point of the line.</param> /// /// /// <param name="endY">Y-coordinate of the ending point of the line.</param> /// <param name="type">The line-drawing algorithm to use to generate the line.</param> /// <returns> /// An IEnumerable of every point, in order, closest to a line between the two points /// specified (according to the algorithm given). /// </returns> static public IEnumerable <Coord> Get(int startX, int startY, int endX, int endY, Lines.Algorithm type = Algorithm.BRESENHAM) { switch (type) { case Algorithm.BRESENHAM: return(bresenham(startX, startY, endX, endY)); case Algorithm.BRESENHAM_ORDERED: var line = bresenham(startX, startY, endX, endY).Reverse(); if (line.First() == Coord.Get(startX, startY)) { return(line); } else { return(line.Reverse()); } case Algorithm.DDA: return(dda(startX, startY, endX, endY)); case Algorithm.ORTHO: return(ortho(startX, startY, endX, endY)); default: throw new Exception("Unsupported line-drawing algorithm."); // Should not occur } }
/// <summary> /// Creates a new Polygon, with corners at the provided points /// </summary> /// <param name="corners">The corners of this polygon</param> /// <param name="algorithm">Which Line Algorithm to use</param> /// <exception cref="ArgumentException">Must have 3 or more corners; Algorithm must produce ordered lines.</exception> public PolygonArea(ref List <Point> corners, Lines.Algorithm algorithm = Lines.Algorithm.DDA) : this(corners, algorithm) { }
/// <summary> /// Returns a new PolygonArea with corners at the provided points. /// </summary> /// <param name="algorithm">Which Line-drawing algorithm to use</param> /// <param name="corners">The points which are corners for this polygon</param> /// <exception cref="ArgumentException">Must have 3 or more corners; Algorithm must produce ordered lines.</exception> public PolygonArea(Lines.Algorithm algorithm, params Point[] corners) : this(corners, algorithm) { }
public static RegionMock Rectangle(Rectangle r, Action <RegionMock> innerCreation, Lines.Algorithm algorithm = Lines.Algorithm.Bresenham) => new RegionMock(r.MinExtent, (r.MaxExtentX, r.MinExtentY),
/// <summary> /// Creates a new Polygon, with corners at the provided points /// </summary> /// <param name="corners">Each corner of the polygon, which is copied into a new list</param> /// <param name="algorithm">Which Line Algorithm to use</param> /// <exception cref="ArgumentException">Must have 3 or more corners; Algorithm must produce ordered lines.</exception> public PolygonArea(IEnumerable <Point> corners, Lines.Algorithm algorithm = Lines.Algorithm.DDA) : this(corners.ToList(), algorithm) { }
/// <summary> /// Returns an IEnumerable of every point, in order, closest to a line between the two points /// specified, using the line drawing algorithm given. The start and end points will be included. /// </summary> /// <param name="startX">X-coordinate of the starting point of the line.</param> /// <param name="startY">Y-coordinate of the starting point of the line.</param> /// <param name="endX">X-coordinate of the ending point of the line.</param> /// /// /// <param name="endY">Y-coordinate of the ending point of the line.</param> /// <param name="type">The line-drawing algorithm to use to generate the line.</param> /// <returns> /// An IEnumerable of every point, in order, closest to a line between the two points /// specified (according to the algorithm given). /// </returns> static public IEnumerable <Coord> Get(int startX, int startY, int endX, int endY, Lines.Algorithm type = Algorithm.BRESENHAM) { switch (type) { case Algorithm.BRESENHAM: return(bresenham(startX, startY, endX, endY)); case Algorithm.DDA: return(dda(startX, startY, endX, endY)); case Algorithm.ORTHO: return(ortho(startX, startY, endX, endY)); default: throw new Exception("Unsupported line-drawing algorithm."); // Should not occur } }
public RegionMock(Point northWest, Point northEast, Point southEast, Point southWest, Action <RegionMock> innerCreation, Lines.Algorithm algoToUse = Lines.Algorithm.Bresenham) { SouthEastCorner = southEast; NorthEastCorner = northEast; NorthWestCorner = northWest; SouthWestCorner = southWest; // This isn't a fully accurate max-x value; a more accurate one could be calculated by taking the max x/y // of the corners being used to create the line. However, it is still mathematically valid. int maxX = Math.Max(NorthEastCorner.X, SouthEastCorner.X); var hasher = new KnownSizeHasher(maxX); // Determine outer boundaries between each corner WestBoundary = new Area(Lines.Get(NorthWestCorner, SouthWestCorner, algoToUse), hasher); SouthBoundary = new Area(Lines.Get(SouthWestCorner, SouthEastCorner, algoToUse), hasher); EastBoundary = new Area(Lines.Get(SouthEastCorner, NorthEastCorner, algoToUse), hasher); NorthBoundary = new Area(Lines.Get(NorthEastCorner, NorthWestCorner, algoToUse), hasher); OuterPoints = new MultiArea { WestBoundary, NorthBoundary, EastBoundary, SouthBoundary }; innerCreation(this); Points = new MultiArea { OuterPoints, InnerPoints }; }
// Functions that generate PolygonAreaMocks that are equivalent to PolygonArea, for comparison #region Equivalent PolygonArea Creation public static PolygonAreaMock Rectangle(Rectangle r, Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm = Lines.Algorithm.DDA) => new PolygonAreaMock(drawFromCornersMethod, innerPointsCreationMethod, algorithm, r.MinExtent, (r.MaxExtentX, r.MinExtentY),
private PolygonAreaMock(List <Point> corners, Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm) { Corners = corners; LineAlgorithm = algorithm; CheckCorners(); CheckAlgorithm(); OuterPoints = new MultiArea(); // Rearranged ordering relative to original, in order to enable full customization of the generated areas // (including the hashing algorithm used). The functions themselves must perform InnerPoints allocation drawFromCornersMethod(this); innerPointsCreationMethod(this); // Must occur after above function calls because those functions must allocate InnerPoints Points = new MultiArea { OuterPoints, InnerPoints }; }
public PolygonAreaMock(Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm, params Point[] corners) : this(corners, drawFromCornersMethod, innerPointsCreationMethod, algorithm) { }
public PolygonAreaMock(ref List <Point> corners, Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm = Lines.Algorithm.DDA) : this(corners, drawFromCornersMethod, innerPointsCreationMethod, algorithm) { }
// Constructors that mimic PolygonArea; with minimal modifications to allow full customization of performance-relevant portions #region Constructors public PolygonAreaMock(IEnumerable <Point> corners, Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm = Lines.Algorithm.DDA) : this(corners.ToList(), drawFromCornersMethod, innerPointsCreationMethod, algorithm) { }