Exemple #1
0
 /// <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);
Exemple #2
0
        /// <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
            }
        }
Exemple #3
0
 /// <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)
 {
 }
Exemple #4
0
 /// <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)
 {
 }
Exemple #5
0
 public static RegionMock Rectangle(Rectangle r, Action <RegionMock> innerCreation, Lines.Algorithm algorithm = Lines.Algorithm.Bresenham)
 => new RegionMock(r.MinExtent, (r.MaxExtentX, r.MinExtentY),
Exemple #6
0
 /// <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)
 {
 }
Exemple #7
0
        /// <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
            }
        }
Exemple #8
0
        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
            };
        }
Exemple #9
0
 // 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),
Exemple #10
0
        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
            };
        }
Exemple #11
0
 public PolygonAreaMock(Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm, params Point[] corners)
     : this(corners, drawFromCornersMethod, innerPointsCreationMethod, algorithm)
 {
 }
Exemple #12
0
 public PolygonAreaMock(ref List <Point> corners, Action <PolygonAreaMock> drawFromCornersMethod, Action <PolygonAreaMock> innerPointsCreationMethod, Lines.Algorithm algorithm = Lines.Algorithm.DDA)
     : this(corners, drawFromCornersMethod, innerPointsCreationMethod, algorithm)
 {
 }
Exemple #13
0
 // 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)
 {
 }