Beispiel #1
0
        /// <summary>
        ///   Determines whether a given point is inside and close to the edge of a given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle within which the point should be located.</param>
        /// <param name="test">The point to test for.</param>
        /// <param name="tolerance">
        ///   The tolerance. This is subtracted from the bounds of the rectangle to create a border within which the
        ///   <paramref
        ///     name="test" />
        ///   point must be located.
        /// </param>
        /// <param name="toTest">The edges that should be tested.</param>
        /// <returns>A combination of Edge flags depending on which edges the point is close to.</returns>
        internal static Edge IsPointOnEdge( RectangleF rectangle, PointF test, float tolerance, EdgeTest toTest )
        {
            // If the point is not within the rectangle, then there is no need for further tests.
              if( !rectangle.Contains( test ) ) {
            return Edge.None;
              }

              Edge result = Edge.None;
              // Test vertical edges.
              if( ( toTest & EdgeTest.Vertical ) != 0 ) {
            if( test.Y >= rectangle.Y && test.Y <= rectangle.Y + tolerance ) {
              result |= Edge.Top;
            }
            if( test.Y <= rectangle.Y + rectangle.Height && test.Y >= rectangle.Y + rectangle.Height - tolerance ) {
              result |= Edge.Bottom;
            }
              }
              // Test horizontal edges.
              if( ( toTest & EdgeTest.Horizontal ) != 0 ) {
            if( test.X <= rectangle.X + rectangle.Width && test.X >= rectangle.X + rectangle.Width - tolerance ) {
              result |= Edge.Right;
            }
            if( test.X >= rectangle.X && test.X <= rectangle.X + tolerance ) {
              result |= Edge.Left;
            }
              }

              return result;
        }
Beispiel #2
0
        /// <summary>
        ///   Determines whether a given point is inside and close to the edge of a given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle within which the point should be located.</param>
        /// <param name="test">The point to test for.</param>
        /// <param name="tolerance">
        ///   The tolerance. This is subtracted from the bounds of the rectangle to create a border within which the
        ///   <paramref
        ///     name="test" />
        ///   point must be located.
        /// </param>
        /// <param name="toTest">The edges that should be tested.</param>
        /// <returns>A combination of Edge flags depending on which edges the point is close to.</returns>
        internal static Edge IsPointOnEdge(RectangleF rectangle, PointF test, float tolerance, EdgeTest toTest)
        {
            // If the point is not within the rectangle, then there is no need for further tests.
            if (!rectangle.Contains(test))
            {
                return(Edge.None);
            }

            Edge result = Edge.None;

            // Test vertical edges.
            if ((toTest & EdgeTest.Vertical) != 0)
            {
                if (test.Y >= rectangle.Y && test.Y <= rectangle.Y + tolerance)
                {
                    result |= Edge.Top;
                }
                if (test.Y <= rectangle.Y + rectangle.Height && test.Y >= rectangle.Y + rectangle.Height - tolerance)
                {
                    result |= Edge.Bottom;
                }
            }
            // Test horizontal edges.
            if ((toTest & EdgeTest.Horizontal) != 0)
            {
                if (test.X <= rectangle.X + rectangle.Width && test.X >= rectangle.X + rectangle.Width - tolerance)
                {
                    result |= Edge.Right;
                }
                if (test.X >= rectangle.X && test.X <= rectangle.X + tolerance)
                {
                    result |= Edge.Left;
                }
            }

            return(result);
        }