示例#1
0
        /// <summary>
        /// Returns distance between the top edge of the rectangle and another rectangle.
        /// </summary>
        /// <param name="first">First rectangle.</param>
        /// <param name="second">Second rectangle.</param>
        /// <returns>Minimal distance.</returns>
        private double DistanceBetweenTopEdgeAndRectangle(Rect first, Rect second)
        {
            double snap;
            double distance = double.NaN;

            if (first.OverlapsHorizontally(second, Accuracy))
            {
                snap = second.Y;
                if (first.Y.IsNear(snap, SnapinDistance))
                {
                    distance = MathExtensions.AbsMin(snap - first.Y, distance);
                }

                snap = second.Y + second.Height + SnapinMargin;
                if (first.Y.IsNear(snap, SnapinDistance))
                {
                    distance = MathExtensions.AbsMin(snap - first.Y, distance);
                }
            }

            return distance;
        }