Exemplo n.º 1
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
            };
        }
Exemplo n.º 2
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
            };
        }
Exemplo n.º 3
0
        public void GlobalSetup()
        {
            // Use KnownSizeHasher so that the hashing algorithm is very efficient for the use case
            var areas = new Area[NumAreas];

            for (int i = 0; i < areas.Length; i++)
            {
                areas[i] = new Area(new KnownSizeHasher(Size));
            }

            var divisor = Size * Size / NumAreas;

            for (int i = 0; i < Size * Size; i++)
            {
                // Ensure we cap at the max index, to avoid rounding error if the divisor doesn't evenly distribute
                int idx = Math.Min(i / divisor, NumAreas - 1);
                areas[idx].Add(Point.FromIndex(i, Size));
            }

            _multiArea = new MultiArea(areas);
        }
Exemplo n.º 4
0
 public AreaContainsDefaultHashMapAreaFinder(IGridView <bool> areasView, AdjacencyRule adjacencyMethod)
 {
     AreasView       = areasView;
     AdjacencyMethod = adjacencyMethod;
     _foundAreas     = new MultiArea();
 }