示例#1
0
        public bool IsValid(IList <Point> routeGridPoints, Point gridPointClicked)
        {
            if ((routeGridPoints == null) | (routeGridPoints.Count == 0))
            {
                // very first click - nothing to validate here
                return(true);
            }

            if (routeGridPoints.Count == 1)
            {
                return(CarHelper.CheckSecondPoint(routeGridPoints.Last(), gridPointClicked));
            }

            return(CarHelper.CheckNextPoint
                       (routeGridPoints[routeGridPoints.Count - 2], routeGridPoints.Last(), gridPointClicked, mAcceleration));
        }
示例#2
0
        /// <summary>
        /// Get the list of candidate grid points, i.e. the possible grid points for the next move
        /// </summary>
        /// <returns></returns>
        public IList <Point> GetCandidateGridPoints(IList <Point> routeGridPoints)
        {
            IList <Point> cgp;

            if (routeGridPoints.Count == 0)
            {
                // nothing to do, return empty list
                cgp = new List <Point>();
            }
            else if (routeGridPoints.Count == 1)
            {
                // special case, we are on the starting line
                Point  currentPosition = routeGridPoints.Last();
                double leftX           = currentPosition.X - mAcceleration;
                double rightX          = currentPosition.X + mAcceleration;
                double topY            = currentPosition.Y - mAcceleration;
                double bottomY         = currentPosition.Y - 1;         // need to be above the starting line

                cgp = AddCandidates(leftX, rightX, topY, bottomY);
            }
            else
            {
                // standard case, we have a movement vector
                Point currentPosition  = routeGridPoints.Last();
                Point previousPosition = routeGridPoints[routeGridPoints.Count - 2];
                Point nextMiddlePoint  = CarHelper.CalculateNextMiddlePoint(previousPosition, currentPosition);

                // now collect all points that are around the nextMiddlePoint, including the nextMiddlePoint
                double leftX   = nextMiddlePoint.X - mAcceleration;
                double rightX  = nextMiddlePoint.X + mAcceleration;
                double topY    = nextMiddlePoint.Y - mAcceleration;
                double bottomY = nextMiddlePoint.Y + mAcceleration;

                cgp = AddCandidates(leftX, rightX, topY, bottomY);
            }

            return(cgp);
        }