Example #1
0
        internal RectifyRectangle(Position bottomLeft, Position topRight,
                                  //RectNeighbor[] LeftEdge, RectNeighbor[] RightEdge,
                                  //RectNeighbor[] TopEdge, RectNeighbor[] BottomEdge,
                                  int pathGroup)
        {
            this.bottomLeft = bottomLeft;
            this.topRight   = topRight;
            this.LeftEdge   = new RectNeighbor[topRight.yPos - bottomLeft.yPos];
            this.RightEdge  = new RectNeighbor[topRight.yPos - bottomLeft.yPos];
            this.TopEdge    = new RectNeighbor[topRight.xPos - bottomLeft.xPos];
            this.BottomEdge = new RectNeighbor[topRight.xPos - bottomLeft.xPos];
            this.PathGroup  = pathGroup;

            //instantiate the edgearrays

            //get all the edges w/ firstPosition x == topLeft.x && secondPosition x == topLeft.x

            for (int i = 0; i < LeftEdge.Length; i++)
            {
                LeftEdge[i]  = new RectNeighbor(null, EdgeType.None);
                RightEdge[i] = new RectNeighbor(null, EdgeType.None);
            }

            for (int i = 0; i < TopEdge.Length; i++)
            {
                TopEdge[i]    = new RectNeighbor(null, EdgeType.None);
                BottomEdge[i] = new RectNeighbor(null, EdgeType.None);
            }
        }
Example #2
0
        public RectifyRectangle(RectShape shape, bool validateRectangle = true)
        {
            if (validateRectangle)
            {
                if (shape.Vertices.Count != 4)
                {
                    throw new Exception("Rectangle w/o exactly 4 vertices");
                }
                RectEdge startEdge = shape.Perimeter.First();
                RectEdge endEdge   = startEdge;
                for (int i = 0; i < shape.Perimeter.Count; i++)
                {
                    endEdge = endEdge.Next;
                }
                if (startEdge != endEdge)
                {
                    throw new Exception("Rectangle w/o contiguous perimeter");
                }
            }
            this.PathGroup = shape.PathGroup;
            //get the defining positions from the verts
            //temporary assignment
            topRight   = shape.Vertices.First().VertPosition;
            bottomLeft = topRight;
            for (int i = 1; i < 4; i++)
            {
                if (shape.Vertices[i].VertPosition.xPos < bottomLeft.xPos ||
                    shape.Vertices[i].VertPosition.yPos < bottomLeft.yPos)
                {
                    bottomLeft = shape.Vertices[i].VertPosition;
                }

                if (shape.Vertices[i].VertPosition.xPos > topRight.xPos ||
                    shape.Vertices[i].VertPosition.yPos > topRight.yPos)
                {
                    topRight = shape.Vertices[i].VertPosition;
                }
            }

            //instantiate the edgearrays

            //get all the edges w/ firstPosition x == topLeft.x && secondPosition x == topLeft.x
            LeftEdge = new RectNeighbor[this.Height];
            var workingEdges = shape.Perimeter.FindAll(e => e.HeadingDirection == Direction.North).OrderBy(e => e.SecondPosition.yPos).ToArray();

            for (int i = 0; i < workingEdges.Count(); i++)
            {
                LeftEdge[i] = new RectNeighbor(null, workingEdges[i].EdgeType);
            }

            RightEdge    = new RectNeighbor[this.Height];
            workingEdges = shape.Perimeter.FindAll(e => e.HeadingDirection == Direction.South).OrderBy(e => e.FirstPosition.yPos).ToArray();
            for (int i = 0; i < workingEdges.Count(); i++)
            {
                RightEdge[i] = new RectNeighbor(null, workingEdges[i].EdgeType);
            }

            //get all the edges w/ firstPosition y == topLeft.y && secondPosition y == topLeft.y
            TopEdge      = new RectNeighbor[this.Width];
            workingEdges = shape.Perimeter.FindAll(e => e.HeadingDirection == Direction.East).OrderBy(e => e.SecondPosition.xPos).ToArray();
            for (int i = 0; i < workingEdges.Count(); i++)
            {
                TopEdge[i] = new RectNeighbor(null, workingEdges[i].EdgeType);
            }

            BottomEdge   = new RectNeighbor[this.Width];
            workingEdges = shape.Perimeter.FindAll(e => e.HeadingDirection == Direction.West).OrderBy(e => e.FirstPosition.xPos).ToArray();
            for (int i = 0; i < workingEdges.Count(); i++)
            {
                BottomEdge[i] = new RectNeighbor(null, workingEdges[i].EdgeType);
            }
        }