Esempio n. 1
0
        /// <summary>
        /// Get a matching grid point if it was clicked near enough to a grid point
        /// </summary>
        private bool hpr_GetMatchingGridPoint(PointerRoutedEventArgs eventArgs, out Point gridPointClicked)
        {
            // get the current point and find the nearest grid point
            PointerPoint ppClicked = eventArgs.GetCurrentPoint(null);

            gridPointClicked = GridBackgroundHelper.ConvertClickedPoint2NearestGridPoint_WithOffset(xMyCanvas, xMyStackPanel, ppClicked);

            // now check if the nearest grid point is close enough in order to uniquely identify which grid point the user intended to click
            Point  canvasOffset = GridBackgroundHelper.GetCanvasOffset(xMyCanvas, xMyStackPanel);
            double xGridAsPixel = (gridPointClicked.X * GridBackgroundHelper.gridDistance) + canvasOffset.X;
            double yGridAsPixel = (gridPointClicked.Y * GridBackgroundHelper.gridDistance) + canvasOffset.Y;
            // do the math
            double distance = Math.Sqrt(Math.Abs((xGridAsPixel - ppClicked.Position.X)) + Math.Abs((yGridAsPixel - ppClicked.Position.Y)));
            bool   match    = distance < GridBackgroundHelper.nearestGridPointDistanceTolerance;

            // only if the user clicked near enough an existing grid point we accept this as valid input
            return(match);

            // next lines for debugging only

            /*
             * this.xCoordinate.Text = ppClicked.Position.X.ToString();
             * this.yCoordinate.Text = ppClicked.Position.Y.ToString();
             * this.xGrid.Text = gridPointSelected.X.ToString();
             * this.yGrid.Text = gridPointSelected.Y.ToString();
             * this.distance.Text = distance.ToString();
             * this.match.Text = match.ToString();
             */
        }
Esempio n. 2
0
        /// <summary>
        /// Set the starting line grid points
        /// so that we can detect if the first click is on a starting line grid point
        ///
        /// A starting line is always horizontal
        /// </summary>
        private void SetStartingLineGridPoints(Point startingLineLeftPoint, Point startingLineRightPoint)
        {
            startingLineGridPointLeft  = GridBackgroundHelper.ConvertPoint2NearestGridPoint_NoOffset(startingLineLeftPoint);
            startingLineGridPointRight = GridBackgroundHelper.ConvertPoint2NearestGridPoint_NoOffset(startingLineRightPoint);

            if (startingLineGridPointLeft.Y != startingLineGridPointRight.Y)
            {
                throw new ArgumentException("starting line is not horizontal, left and right Y coordinate differ");
            }

            if (startingLineGridPointLeft.X > startingLineGridPointRight.X)
            {
                throw new ArgumentException("left and right points of starting line are mixed");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Paint the candidate grid points, i.e. the grid points that are candidates for being the next target
        /// i.e. end of the next movement vector
        /// </summary>
        private static IList <UIElement> PaintCGP(Point candidateGridPoint)
        {
            IList <UIElement> uiElements = new List <UIElement>();

            Point point = GridBackgroundHelper.ConvertGridPoint2Point(candidateGridPoint);

            // Draw the first line - left bottom to right top
            Point pointLeftBottom = new Point(point.X - pointDiff, point.Y + pointDiff);
            Point pointRightTop   = new Point(point.X + pointDiff, point.Y - pointDiff);

            uiElements.Add(CreateLine(pointLeftBottom, pointRightTop));

            // Draw the second line - left top to right bottom
            Point pointLeftTop     = new Point(point.X - pointDiff, point.Y - pointDiff);
            Point pointRightBottom = new Point(point.X + pointDiff, point.Y + pointDiff);

            uiElements.Add(CreateLine(pointLeftTop, pointRightBottom));

            return(uiElements);
        }
Esempio n. 4
0
        /// <summary>
        /// Paint the movement vector
        /// </summary>
        internal static IList <UIElement> PaintMovementVector(UIElementCollection children, Point gridPointLast, Point gridPointClicked)
        {
            IList <UIElement> uiElementsMovVector = new List <UIElement>();

            // Draw the main line
            Point pointLast    = GridBackgroundHelper.ConvertGridPoint2Point(gridPointLast);
            Point pointClicked = GridBackgroundHelper.ConvertGridPoint2Point(gridPointClicked);

            uiElementsMovVector.Add(AddLine(children, pointLast, pointClicked));

            // make the line an arrow - angle1
            Point p1 = VectorMath.CalculateLineEndpointSatisfyingAngle(pointLast, pointClicked, lengthOfArrowLines, angle1);

            uiElementsMovVector.Add(AddLine(children, pointClicked, p1));

            // make the line an arrow - angle2
            Point p2 = VectorMath.CalculateLineEndpointSatisfyingAngle(pointLast, pointClicked, lengthOfArrowLines, angle2);

            uiElementsMovVector.Add(AddLine(children, pointClicked, p2));

            return(uiElementsMovVector);
        }
Esempio n. 5
0
        public bool ValidateVector(IList <Point> routeGridPoints, Point gridPointClicked)
        {
            bool?baseValidationResult;

            BaseValidateVector(routeGridPoints, gridPointClicked, out baseValidationResult);
            if (baseValidationResult.HasValue)
            {
                // we are done, base class already made the decision
                return(baseValidationResult.Value);
            }

            // further checks
            Point point = GridBackgroundHelper.ConvertGridPoint2Point(gridPointClicked);
            bool  innerEllipseIncluded = Contains(innerEllipse, point);

            if (innerEllipseIncluded)
            {
                // point is in the inner ellipse so it is NOT on the track
                return(false);
            }
            // if it is NOT in the inner ellipse then simply check if it is included in the outer ellipse
            return(Contains(outerEllipse, point));
        }