Exemplo n.º 1
0
        void FindPathBetweenBlocks()
        {
            foreach (LineSegment l in spanningTree)
            {
                Path path = new Path();
                path.from = GetCellByPoint(l.p0.Value.x, l.p0.Value.y);
                path.to   = GetCellByPoint(l.p1.Value.x, l.p1.Value.y);

                Vector2 startPoint = l.p0.Value;
                Vector2 endPoint   = l.p1.Value;

                BlockPath bl1 = new BlockPath();
                bl1.start = startPoint;
                bl1.end   = new Vector2(endPoint.x, startPoint.y);

                BlockPath bl2 = new BlockPath();
                bl2.start = bl1.end;
                bl2.end   = endPoint;

                path.path.Add(bl1);
                path.path.Add(bl2);
                paths.Add(path);
            }

            spanningTree.Clear();
        }
Exemplo n.º 2
0
        bool LineRectangleInteresection(BlockPath line, GeneratorCell rect)
        {
            bool    retVal = false;
            Vector2 intersection;

            BlockPath topLine = new BlockPath();

            topLine.start = new Vector2(rect.posX, rect.posY + rect.height);
            topLine.end   = new Vector2(rect.posX + rect.width, rect.posY + rect.height);
            if (LineIntersects(line.start, line.end, topLine.start, topLine.end, out intersection))
            {
                retVal = true;
            }

            BlockPath rightLine = new BlockPath();

            rightLine.start = new Vector2(rect.posX + rect.width, rect.posY + rect.height);
            rightLine.end   = new Vector2(rect.posX + rect.width, rect.posY);
            if (LineIntersects(line.start, line.end, rightLine.start, rightLine.end, out intersection))
            {
                retVal = true;
            }


            BlockPath bottomLine = new BlockPath();

            bottomLine.start = new Vector2(rect.posX, rect.posY);
            bottomLine.end   = new Vector2(rect.posX + rect.width, rect.posY);
            if (LineIntersects(line.start, line.end, bottomLine.start, bottomLine.end, out intersection))
            {
                retVal = true;
            }


            BlockPath leftLine = new BlockPath();

            leftLine.start = new Vector2(rect.posX, rect.posY);
            leftLine.end   = new Vector2(rect.posX, rect.posY + rect.height);
            if (LineIntersects(line.start, line.end, leftLine.start, leftLine.end, out intersection))
            {
                retVal = true;
            }

            return(retVal);
        }