コード例 #1
0
ファイル: ShapeRange.cs プロジェクト: CGX-GROUP/DotSpatial
        /// <summary>
        /// Test the intersection with a shape range.
        /// </summary>
        /// <param name="shape">The shape to do intersection calculations with.</param>
        /// <returns>True, if both intersect.</returns>
        public bool Intersects(ShapeRange shape)
        {
            // Extent check first. If the extents don't intersect, then this doesn't intersect.
            if (!Extent.Intersects(shape.Extent))
            {
                return(false);
            }

            switch (FeatureType)
            {
            case FeatureType.Polygon:
                PolygonShape.Epsilon = Epsilon;
                return(PolygonShape.Intersects(this, shape));

            case FeatureType.Line:
                LineShape.Epsilon = Epsilon;
                return(LineShape.Intersects(this, shape));

            case FeatureType.Point:
                PointShape.Epsilon = Epsilon;
                return(PointShape.Intersects(this, shape));

            default: return(false);
            }
        }
コード例 #2
0
ファイル: PolygonShape.cs プロジェクト: osome/DotSpatial
        /// <summary>
        /// Calculates the intersection of a polygon shape without relying on the NTS geometry
        /// </summary>
        /// <param name="polygonShape"></param>
        /// <param name="otherShape"></param>
        /// <returns></returns>
        public static bool Intersects(ShapeRange polygonShape, ShapeRange otherShape)
        {
            if (polygonShape.FeatureType != FeatureType.Polygon)
            {
                throw new ArgumentException("The First parameter should be a point shape, but it was featuretype:" + polygonShape.FeatureType);
            }

            // Extents will have already been tested by this point.
            // Regardless of what the other shapetype is, a coordinate inside this polygon indicates a hit.
            if (ContainsVertex(polygonShape, otherShape))
            {
                return(true);
            }

            // There is no other way for this polygon to intersect the other points
            if (otherShape.FeatureType == FeatureType.Point || otherShape.FeatureType == FeatureType.MultiPoint)
            {
                return(false);
            }

            // For lines and polygons, if any segment intersects any segment of this polygon shape, return true.
            // This is essentially looking for the rare case of crossing in and crossing out again with
            // no actual points inside this polygonShape.
            if (LineShape.SegmentsIntersect(polygonShape, otherShape))
            {
                return(true);
            }

            // There is no other way for this polygon to intersect the other lines
            if (otherShape.FeatureType == FeatureType.Line)
            {
                return(false);
            }

            // If the other polygon completely contains this polygon every other test has returned false,
            // but this will test for that case with only a single point.
            Vertex     v = polygonShape.First();
            ShapeRange onlyFirstPoint = new ShapeRange(v);

            return(ContainsVertex(otherShape, onlyFirstPoint));
        }