/// <summary>
        /// Gets the relative point inside of the viewport represented by the plotted Point
        /// </summary>
        /// <param name="plottedPoint">Coordinate absolute position <see cref="PointF"/></param>
        /// <param name="viewPortExtent">Viewport <see cref="SizeF"/></param>
        /// <returns>Relative position</returns>
        public static PointF GetRelativePosition(PointF plottedPoint, SizeF viewPortExtent)
        {
            var actualResult = plottedPoint;

            if (plottedPoint.X >= viewPortExtent.GetCenterWidth())
            {
                actualResult.X = plottedPoint.X - viewPortExtent.GetCenterWidth();
            }
            else
            {
                actualResult.X = NEGATIVE * (viewPortExtent.GetCenterWidth() - plottedPoint.X);
            }

            actualResult.Y = viewPortExtent.GetCenterHeight() - plottedPoint.Y;

            return(actualResult);
        }
示例#2
0
        /// <summary>
        /// Find all contacts on the radar using a point and detection window
        /// </summary>
        /// <param name="checkPoint"><see cref="PointF"/>The center point of the search</param>
        /// <param name="detectionWindow"><see cref="SizeF"/>The size of the detction window</param>
        /// <param name="roundingDigits"></param>
        /// <returns><see cref="List{Contact}"/></returns>
        public List <IContact> FindContact(PointF checkPoint, SizeF detectionWindow, int roundingDigits)
        {
            var contactList = new List <IContact>();

            checkPoint.Offset(new PointF(-1 * detectionWindow.GetCenterWidth(), -1 * detectionWindow.GetCenterHeight()), roundingDigits);
            var detectionArea = new RectangleF(checkPoint, detectionWindow);

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug($"FindWindow: {detectionArea}");
            }

            // First check for any hits
            if (CurrentContacts.Values.Any(contact =>
            {
                return(detectionArea.IntersectsWith(contact.DetectionWindow));
            }) == true)
            {
                Logger.Info($"Contact(s) found");
                // There were hits so get the contacts
                contactList.AddRange(CurrentContacts.Values.ToList().FindAll(match =>
                {
                    return(detectionArea.IntersectsWith(match.DetectionWindow));
                }));
            }

            if (contactList.Count > 0)
            {
                Logger.Info($"Found {contactList.Count} contact(s) in {detectionArea}");
                if (Logger.IsDebugEnabled)
                {
                    contactList.ForEach(contact =>
                    {
                        Logger.Debug($"{contact}");
                    });
                }
            }
            else
            {
                Logger.Info($"No contacts found in {detectionArea}");
            }
            return(contactList);
        }
        /// <summary>
        /// Converts a position relative to (0,0) in the center of the view port to an absolute position from (0,0) from the top left corner of the viewport
        /// </summary>
        /// <param name="relativePosition">The relative position from (0,0) in the ViewPortExtent <see cref="PointF"/></param>
        /// <param name="viewPortExtent">The ViewPortExtent <seealso cref="Size"/></param>
        /// <returns>Absolute Postition</returns>
        public static PointF GetAbsolutePosition(PointF relativePosition, SizeF viewPortExtent)
        {
            var actualResult = relativePosition;

            var midX = viewPortExtent.GetCenterWidth();
            var midY = viewPortExtent.GetCenterHeight();

            if (relativePosition.Y <= 0)
            {
                actualResult.Y = midY + Math.Abs(relativePosition.Y);
            }
            else
            {
                actualResult.Y = midY - relativePosition.Y;
            }

            actualResult.X = midX + relativePosition.X;
            return(actualResult);
        }