/// <summary> /// Checks to see of this point touches the two points of a segment or the line between them. /// </summary> /// <param name="Sgmt">A LineSegment representing the line segment to check</param> /// <returns>True if the point and line segment intersect</returns> public bool Intersects(LineSegment Sgmt) { // prevent redundant code and simply use the segemnt if (Sgmt.Intersects(this)) { return(true); } return(false); }
/// <summary> /// Checks whether the borders of a polygon shape, lines of line shapes, or points of point shapes touch. /// </summary> /// <param name="Shape1">A MapWinGIS.Shape object to test</param> /// <param name="Shape2">A MapWinGIS.Shape object to test</param> /// <returns>True if the boundaries touch</returns> public static bool ShapeBoundariesTouch(MapWinGIS.Shape Shape1, MapWinGIS.Shape Shape2) { if (Shape1 == null || Shape1.ShapeType == MapWinGIS.ShpfileType.SHP_NULLSHAPE) { throw new ArgumentException("Argument Shape1 cannot be null"); } if (Shape2 == null || Shape2.ShapeType == MapWinGIS.ShpfileType.SHP_NULLSHAPE) { throw new ArgumentException("Argument Shape2 cannot be null"); } if (Shape1.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPATCH) { throw new ArgumentException("Multipatch is not supported"); } if (Shape2.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPATCH) { throw new ArgumentException("Multipatch is not supported"); } ShapeCategories Typ1, Typ2; Typ1 = GetCategory(Shape1); Typ2 = GetCategory(Shape2); // for single points, simply show if these specific points overlap if (Typ1 == ShapeCategories.Point && Typ2 == ShapeCategories.Point) { Point p1 = new Point(Shape1.get_Point(0)); Point p2 = new Point(Shape2.get_Point(0)); if (p1.Intersects(p2)) { return(true); } return(false); } // Point to Non-point if (Typ1 == ShapeCategories.Point) { Point p1 = new Point(Shape1.get_Point(0)); if (Typ2 == ShapeCategories.MultiPoint) { for (int I = 0; I < Shape2.numPoints; I++) { Point p2 = new Point(Shape2.get_Point(I)); if (p1.Intersects(p2)) { return(true); } } return(false); } else { for (int I = 0; I < Shape2.numPoints - 1; I++) { LineSegment seg = new LineSegment(Shape2.get_Point(I), Shape2.get_Point(I + 1)); if (seg.Intersects(p1)) { return(true); } } return(false); } } // Point2 to non-point if (Typ2 == ShapeCategories.Point) { Point p2 = new Point(Shape2.get_Point(0)); if (Typ1 == ShapeCategories.MultiPoint) { for (int I = 0; I < Shape1.numPoints; I++) { Point p1 = new Point(Shape1.get_Point(I)); if (p2.Intersects(p1)) { return(true); } } return(false); } else { for (int I = 0; I < Shape1.numPoints - 1; I++) { LineSegment seg = new LineSegment(Shape1.get_Point(I), Shape1.get_Point(I + 1)); if (seg.Intersects(p2)) { return(true); } } return(false); } } // for multipoint, test every point for intersection. if (Typ1 == ShapeCategories.MultiPoint && Typ2 == ShapeCategories.MultiPoint) { List <int> Points1 = PointsWithinEnvelope(Shape1, Shape2.Extents); List <int> Points2 = PointsWithinEnvelope(Shape2, Shape1.Extents); for (int I = 0; I < Points1.Count; I++) { for (int J = 0; J < Points2.Count; J++) { Point p1 = new Point(Shape1.get_Point(I)); Point p2 = new Point(Shape2.get_Point(J)); if (p1.Intersects(p2)) { return(true); } } } return(false); } // For lines and polygons simply test line segments in the area of interrest to see if they touch // (touching in this case just equates to having a minimum distance of 0. if ((Typ1 == ShapeCategories.Line || Typ1 == ShapeCategories.Polygon) && (Typ2 == ShapeCategories.Line || Typ2 == ShapeCategories.Polygon)) { List <LineSegment> Segs1 = LineSegmentsWithinEnvelope(Shape1, Shape2.Extents); List <LineSegment> Segs2 = LineSegmentsWithinEnvelope(Shape2, Shape1.Extents); for (int I = 0; I < Segs1.Count; I++) { for (int J = 0; J < Segs2.Count; J++) { if (Segs1[I].Intersects(Segs2[J])) { return(true); } } } return(false); } // multi-point to polygon if (Typ1 == ShapeCategories.MultiPoint) { List <int> Points1 = PointsWithinEnvelope(Shape1, Shape2.Extents); List <LineSegment> Segs2 = LineSegmentsWithinEnvelope(Shape2, Shape1.Extents); for (int I = 0; I < Points1.Count; I++) { for (int J = 0; J < Segs2.Count; J++) { if (Segs2[J].Intersects(Shape1.get_Point(Points1[I]))) { return(true); } } } return(false); } if (Typ2 == ShapeCategories.MultiPoint) { List <int> Points2 = PointsWithinEnvelope(Shape2, Shape1.Extents); List <LineSegment> Segs1 = LineSegmentsWithinEnvelope(Shape1, Shape2.Extents); for (int I = 0; I < Points2.Count; I++) { for (int J = 0; J < Segs1.Count; J++) { if (Segs1[J].Intersects(Shape2.get_Point(Points2[I]))) { return(true); } } } return(false); } return(false); }