public ScreenPositionData GetClosestScreenPosition(Point screenPosition, double positionSelectionMinDistance)
        {
            if (ShownScreenPositions == null)
            {
                return(null);
            }


            ScreenPositionData closestScreenPositionData = null;
            double             closestDistance           = double.MaxValue;

            for (int i = 0; i < ShownScreenPositions.Count; i++)
            {
                var rectangleDistance = (screenPosition - ShownScreenPositions[i].ScreenCenterPosition).Length;

                if (rectangleDistance < closestDistance)
                {
                    closestDistance           = rectangleDistance;
                    closestScreenPositionData = ShownScreenPositions[i];
                }
            }

            if (closestDistance <= positionSelectionMinDistance) // Do we have a position that is within accepted distance from the specified screenPosition?
            {
                return(closestScreenPositionData);
            }

            return(null);
        }
        // Updates shown screen positions on a 2D Canvas - called after camera or size change
        public void UpdateScreenPosition(ScreenPositionData screenPositionData)
        {
            if (screenPositionData == null || this.Camera == null)
            {
                return;
            }

            var position3D     = screenPositionData.WorldPosition;
            var screenPosition = this.Camera.Point3DTo2D(position3D);

            screenPositionData.ScreenCenterPosition = screenPosition;


            var rectangle = screenPositionData.PositionRectangle;

            if (rectangle != null)
            {
                Canvas.SetLeft(rectangle, screenPosition.X - rectangle.Width * 0.5);
                Canvas.SetTop(rectangle, screenPosition.Y - rectangle.Height * 0.5);
            }


            rectangle = screenPositionData.SelectionRectangle;

            if (rectangle != null)
            {
                Canvas.SetLeft(rectangle, screenPosition.X - rectangle.Width * 0.5);
                Canvas.SetTop(rectangle, screenPosition.Y - rectangle.Height * 0.5);
            }
        }
        public void SelectScreenPosition(ScreenPositionData screenPositionData)
        {
            if (screenPositionData == null || screenPositionData.IsSelected)
            {
                return;
            }

            var rectangle = CreateSelectionRectangle(screenPositionData.ScreenCenterPosition, SceneEditorContext.Current.SelectedBrush);

            this.Children.Add(rectangle);

            screenPositionData.IsSelected         = true;
            screenPositionData.SelectionRectangle = rectangle;
        }
        public void ClearSelectedScreenPosition(ScreenPositionData screenPositionData)
        {
            if (screenPositionData == null || !screenPositionData.IsSelected)
            {
                return;
            }

            if (!screenPositionData.IsHighlighted && screenPositionData.SelectionRectangle != null) // Preserve the rectangle if this position is also highlighted
            {
                this.Children.Remove(screenPositionData.SelectionRectangle);
                screenPositionData.SelectionRectangle = null;
            }

            screenPositionData.IsSelected = false;
        }