/// <summary>
        /// Tests whether the given Geometry intersects the query rectangle.
        /// </summary>
        /// <param name="geom">The Geometry to test (may be of any type)</param>
        /// <returns><value>true</value> if an intersection must occur 
        /// or <value>false</value> if no conclusion about intersection can be made</returns>
        public bool Intersects(IGeometry geom)
        {
            if (!_rectEnv.Intersects(geom.EnvelopeInternal))
                return false;

            /**
             * Test if rectangle envelope intersects any component envelope.
             * This handles Point components as well
             */
            var visitor = new EnvelopeIntersectsVisitor(_rectEnv);
            visitor.ApplyTo(geom);
            if (visitor.Intersects)
                return true;

            /**
             * Test if any rectangle vertex is contained in the target geometry
             */
            var ecpVisitor = new GeometryContainsPointVisitor(_rectangle);
            ecpVisitor.ApplyTo(geom);
            if (ecpVisitor.ContainsPoint)
                return true;

            /**
             * Test if any target geometry line segment intersects the rectangle
             */
            var riVisitor = new RectangleIntersectsSegmentVisitor(_rectangle);
            riVisitor.ApplyTo(geom);
            return riVisitor.Intersects;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests whether the given Geometry intersects the query rectangle.
        /// </summary>
        /// <param name="geom">The Geometry to test (may be of any type)</param>
        /// <returns><value>true</value> if an intersection must occur
        /// or <value>false</value> if no conclusion about intersection can be made</returns>
        public bool Intersects(IGeometry geom)
        {
            if (!_rectEnv.Intersects(geom.EnvelopeInternal))
            {
                return(false);
            }

            /**
             * Test if rectangle envelope intersects any component envelope.
             * This handles Point components as well
             */
            var visitor = new EnvelopeIntersectsVisitor(_rectEnv);

            visitor.ApplyTo(geom);
            if (visitor.Intersects)
            {
                return(true);
            }

            /**
             * Test if any rectangle vertex is contained in the target geometry
             */
            var ecpVisitor = new GeometryContainsPointVisitor(_rectangle);

            ecpVisitor.ApplyTo(geom);
            if (ecpVisitor.ContainsPoint)
            {
                return(true);
            }

            /**
             * Test if any target geometry line segment intersects the rectangle
             */
            var riVisitor = new RectangleIntersectsSegmentVisitor(_rectangle);

            riVisitor.ApplyTo(geom);
            return(riVisitor.Intersects);
        }