예제 #1
0
        public PointInfo GetNextPoint(Direction direction)
        {
            PointInfo result = default(PointInfo);

            result.Index     = GetNextIndex(direction);
            result.Points    = Points;
            result.Point     = result.Points[result.Index];
            result.Path      = Path;
            result.Direction = direction;
            return(result);
        }
        private PointInfo GetNextPoint(PointInfo currentPoint, PointF previousPoint, Pen pen)
        {
            ArrayList arrayList = new ArrayList();

            for (int i = 0; i < boundsArray.Length; i++)
            {
                if (paths[i] != currentPoint.Path)
                {
                    RectangleF rectangleF = boundsArray[i];
                    rectangleF.Inflate(2f, 2f);
                    if (rectangleF.Contains(currentPoint.Point) && (paths[i].IsOutlineVisible(currentPoint.Point, pen) || paths[i].IsVisible(currentPoint.Point)))
                    {
                        DrawMarker(currentPoint.Point, 2f);
                        PointF[]  pathPoints   = GetPathPoints(paths[i]);
                        PointInfo closestPoint = GetClosestPoint(currentPoint.Point, pathPoints, paths[i]);
                        arrayList.Add(closestPoint);
                    }
                }
            }
            if (arrayList.Count == 0)
            {
                return(currentPoint.GetNextPoint(currentPoint.Direction));
            }
            PointInfo result = currentPoint.GetNextPoint(currentPoint.Direction);
            double    num    = CalculateAngle(previousPoint, currentPoint.Point, result.Point);

            foreach (PointInfo item in arrayList)
            {
                PointInfo nextPoint  = item.GetNextPoint(Direction.Forward);
                double    num2       = CalculateAngle(previousPoint, currentPoint.Point, nextPoint.Point);
                PointInfo nextPoint2 = item.GetNextPoint(Direction.Backward);
                double    num3       = CalculateAngle(previousPoint, currentPoint.Point, nextPoint2.Point);
                if (num2 > num && !visitedPoints.Contains(nextPoint.Point))
                {
                    num    = num2;
                    result = nextPoint;
                }
                if (num3 > num && !visitedPoints.Contains(nextPoint2.Point))
                {
                    num    = num3;
                    result = nextPoint2;
                }
            }
            return(result);
        }
        private PointInfo GetClosestPoint(PointF point, PointF[] points, GraphicsPath graphicsPath)
        {
            PointInfo result = default(PointInfo);

            result.Points = points;
            result.Path   = graphicsPath;
            double num = double.PositiveInfinity;

            for (int i = 0; i < points.Length; i++)
            {
                double num2 = points[i].X - point.X;
                double num3 = points[i].Y - point.Y;
                double num4 = num2 * num2 + num3 * num3;
                if (num4 < num)
                {
                    result.Point = points[i];
                    result.Index = i;
                    num          = num4;
                }
            }
            return(result);
        }