예제 #1
0
        public BorderRule(int[,] regionMap, PointInt point, int direction)
        {
            touchingPoint1 = point;
            regionId1      = regionMap.getValue(point);

            touchingPoint2 = point.Neighbor(direction);
            regionId2      = regionMap.getValue(touchingPoint2);
        }
예제 #2
0
        private void calculateBounds(Edge edge, int direction, int[,] biomeMap)
        {
            Direction dir   = new Direction(direction);
            var       point = edge.touchPoint;

            MyMath.Point startFace = getFace(point, dir);
            int          previousNeighbourBiome = biomeMap.getBorderValue(point, dir);

            dir.Increment();
            if (holes.Any(x => x.Border.Any(y => y.Equal(startFace))))
            {
                return;
            }
            Hole     border       = new Hole(edge.otherTouchPoint);
            PointInt currentPoint = point;

            while (true)
            {
                int newNeighbourBiome = biomeMap.getBorderValue(currentPoint, dir);
                if (!biomeMap.sameAsNeighbor(currentPoint, dir))
                {
                    if (!dir.Diagonal())
                    {
                        if (previousNeighbourBiome != newNeighbourBiome)
                        {
                            border.Add(getCornerVertex(currentPoint, dir));
                            previousNeighbourBiome = newNeighbourBiome;
                        }
                        MyMath.Point face = getFace(currentPoint, dir);
                        if (face.Equal(startFace))
                        {
                            break;
                        }
                        else
                        {
                            border.Add(face);
                        }
                    }
                    dir.Increment();
                }
                else
                {
                    currentPoint = currentPoint.Neighbor(dir);
                    if (dir.Diagonal())
                    {
                        dir.Decrement();
                    }
                    dir.Decrement();
                    if (dir.Diagonal())
                    {
                        dir.Decrement();
                    }
                }
            }
            if (border.Border.Count == 0)
            {
                throw new Exception();
            }
            border.Add(startFace);
            holes.Add(border);
        }
예제 #3
0
        public static T getBorderValue <T>(this T[,] map, PointInt p, int direction)
        {
            var neighbor = p.Neighbor(direction);

            return(map.getValue(neighbor));
        }