Exemple #1
0
        /// <summary>
        /// Returns distance between the right 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 DistanceBetweenRightEdgeAndRectangle(Rect first, Rect second)
        {
            double snap;
            double distance = double.NaN;
            double x = first.X + first.Width - 1;

            if (first.OverlapsVertically(second, Accuracy))
            {
                snap = second.X - 1 - SnapinMargin;
                if (x.IsNear(snap, SnapinDistance))
                {
                    distance = MathExtensions.AbsMin(snap - x, distance);
                }

                snap = second.X + second.Width - 1;
                if (x.IsNear(snap, SnapinDistance))
                {
                    distance = MathExtensions.AbsMin(snap - x, distance);
                }
            }

            return distance;
        }