Exemple #1
0
        private Vector2 GetCenterPoint(ITrapezoid trapezoid)
        {
            double leftEdgeX  = trapezoid.LeftBound,
                   rightEdgeX = trapezoid.RightBound,
                   centerX    = (leftEdgeX + rightEdgeX) / 2;

            double   topY, bottomY;
            ISegment top    = trapezoid.TopSegment,
                     bottom = trapezoid.BottomSegment;

            if (top == null)
            {
                topY = trapezoidalMap.BoundingBox.Top;
            }
            else
            {
                topY = GetYComponent(top, centerX);
            }

            if (bottom == null)
            {
                bottomY = trapezoidalMap.BoundingBox.Bottom;
            }
            else
            {
                bottomY = GetYComponent(bottom, centerX);
            }

            double centerY = (topY + bottomY) / 2;

            return(new Vector2(centerX, centerY));
        }
Exemple #2
0
        public IEnumerable <Vector2> CalculatePath(Vector2 start, Vector2 goal)
        {
            var box = trapezoidalMap.BoundingBox;

            if (!box.Contains(start) || !box.Contains(goal))
            {
                yield break;
            }

            ITrapezoid startingTrapezoid = trapezoidalMap.PointLocation(start),
                       finalTrapezoid    = trapezoidalMap.PointLocation(goal);

            if (forbiddenSpace.Contains(startingTrapezoid) || forbiddenSpace.Contains(finalTrapezoid))
            {
                yield break;
            }

            Junction startingJunction = junctionByTrapezoid[startingTrapezoid],
                     finalJunction    = junctionByTrapezoid[finalTrapezoid];

            yield return(start);

            foreach (var junction in SearchForPath(startingJunction, finalJunction))
            {
                yield return(junction.Position);
            }

            yield return(goal);
        }
        private Vector2 GetCenterPoint(ITrapezoid trapezoid)
        {
            double leftEdgeX = trapezoid.LeftBound,
                rightEdgeX = trapezoid.RightBound,
                centerX = (leftEdgeX + rightEdgeX) / 2;

            double topY, bottomY;
            ISegment top = trapezoid.TopSegment,
                bottom = trapezoid.BottomSegment;

            if (top == null)
                topY = trapezoidalMap.BoundingBox.Top;
            else
                topY = GetYComponent(top, centerX);

            if (bottom == null)
                bottomY = trapezoidalMap.BoundingBox.Bottom;
            else
                bottomY = GetYComponent(bottom, centerX);

            double centerY = (topY + bottomY) / 2;

            return new Vector2(centerX, centerY);
        }