// ----------------------------------------------------------------------
        public static bool IsPositionOnRectEdge(Vector2 pos, Rect r, iCS_EdgeEnum edge)
        {
            float maxDistance = iCS_EditorConfig.PortDiameter;
            float distance    = 2f * maxDistance;
            float leftX       = r.xMin;
            float rightX      = r.xMax;
            float topY        = r.yMin;
            float bottomY     = r.yMax;

            switch (edge)
            {
            case iCS_EdgeEnum.Top:
                distance = Math3D.DistanceFromHorizontalLineSegment(pos, leftX, rightX, topY);
                break;

            case iCS_EdgeEnum.Bottom:
                distance = Math3D.DistanceFromHorizontalLineSegment(pos, leftX, rightX, bottomY);
                break;

            case iCS_EdgeEnum.Left:
                distance = Math3D.DistanceFromVerticalLineSegment(pos, topY, bottomY, leftX);
                break;

            case iCS_EdgeEnum.Right:
                distance = Math3D.DistanceFromVerticalLineSegment(pos, topY, bottomY, rightX);
                break;
            }
            return(distance <= maxDistance);
        }
        // ----------------------------------------------------------------------
        public iCS_EdgeEnum GetClosestEdge(Vector2 localPosition)
        {
            // Don't change edge if parent is iconized.
            var parent = ParentNode;

            if (parent.IsIconizedOnDisplay)
            {
                return(Edge);
            }
            var   parentSize = parent.LocalSize;
            float leftX      = -0.5f * parentSize.x;
            float rightX     = 0.5f * parentSize.x;
            float topY       = -0.5f * parentSize.y;
            float bottomY    = 0.5f * parentSize.y;
            var   edge       = iCS_EdgeEnum.Top;
            float distance   = Math3D.DistanceFromHorizontalLineSegment(localPosition, leftX, rightX, topY);
            float d          = Math3D.DistanceFromHorizontalLineSegment(localPosition, leftX, rightX, bottomY);

            if (d < distance)
            {
                distance = d;
                edge     = iCS_EdgeEnum.Bottom;
            }
            d = Math3D.DistanceFromVerticalLineSegment(localPosition, topY, bottomY, leftX);
            if (d < distance)
            {
                distance = d;
                edge     = iCS_EdgeEnum.Left;
            }
            d = Math3D.DistanceFromVerticalLineSegment(localPosition, topY, bottomY, rightX);
            if (d < distance)
            {
                edge = iCS_EdgeEnum.Right;
            }
            return(edge);
        }