Index: src/Common/NetTopologySuite/Operation/IsSimpleOp.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/Operation/IsSimpleOp.cs (.../IsSimpleOp.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/Operation/IsSimpleOp.cs (.../IsSimpleOp.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -19,7 +19,7 @@ /// /// /// - public IsSimpleOp() { } + public IsSimpleOp() {} /// /// @@ -46,19 +46,23 @@ /// public bool IsSimple(IMultiPoint mp) { - if (mp.IsEmpty) + if (mp.IsEmpty) + { return true; + } Set points = new Set(); for (int i = 0; i < mp.NumGeometries; i++) { IPoint pt = (IPoint) mp.GetGeometryN(i); ICoordinate p = pt.Coordinate; if (points.Contains(p)) + { return false; + } points.Add(p); } return true; - } + } /// /// @@ -67,17 +71,31 @@ /// private bool IsSimpleLinearGeometry(IGeometry geom) { - if (geom.IsEmpty) + if (geom.IsEmpty) + { return true; + } GeometryGraph graph = new GeometryGraph(0, geom); LineIntersector li = new RobustLineIntersector(); SegmentIntersector si = graph.ComputeSelfNodes(li, true); // if no self-intersection, must be simple - if (!si.HasIntersection) return true; - if (si.HasProperIntersection) return false; - if (HasNonEndpointIntersection(graph)) return false; - if (HasClosedEndpointIntersection(graph)) return false; + if (!si.HasIntersection) + { + return true; + } + if (si.HasProperIntersection) + { + return false; + } + if (HasNonEndpointIntersection(graph)) + { + return false; + } + if (HasClosedEndpointIntersection(graph)) + { + return false; + } return true; } @@ -88,80 +106,22 @@ /// private bool HasNonEndpointIntersection(GeometryGraph graph) { - for (IEnumerator i = graph.GetEdgeEnumerator(); i.MoveNext(); ) + for (IEnumerator i = graph.GetEdgeEnumerator(); i.MoveNext();) { Edge e = (Edge) i.Current; int maxSegmentIndex = e.MaximumSegmentIndex; - for (IEnumerator eiIt = e.EdgeIntersectionList.GetEnumerator(); eiIt.MoveNext(); ) + for (IEnumerator eiIt = e.EdgeIntersectionList.GetEnumerator(); eiIt.MoveNext();) { EdgeIntersection ei = (EdgeIntersection) eiIt.Current; if (!ei.IsEndPoint(maxSegmentIndex)) + { return true; + } } } return false; } - /// - /// - /// - public class EndpointInfo - { - private ICoordinate pt; - - /// - /// - /// - public ICoordinate Point - { - get { return pt; } - set { pt = value; } - } - - private bool isClosed = false; - - /// - /// - /// - public bool IsClosed - { - get { return isClosed; } - set { isClosed = value; } - } - - private int degree; - - /// - /// - /// - public int Degree - { - get { return degree; } - set { degree = value; } - } - - /// - /// - /// - /// - public EndpointInfo(ICoordinate pt) - { - this.pt = pt; - isClosed = false; - degree = 0; - } - - /// - /// - /// - /// - public void AddEndpoint(bool isClosed) - { - Degree++; - this.IsClosed |= isClosed; - } - } - /// /// Test that no edge intersection is the /// endpoint of a closed line. To check this we compute the @@ -172,20 +132,22 @@ private bool HasClosedEndpointIntersection(GeometryGraph graph) { IDictionary endPoints = new OrderedDictionary(); - for (IEnumerator i = graph.GetEdgeEnumerator(); i.MoveNext(); ) + for (IEnumerator i = graph.GetEdgeEnumerator(); i.MoveNext();) { Edge e = (Edge) i.Current; - bool isClosed = e.IsClosed; + bool isClosed = e.IsClosed; ICoordinate p0 = e.GetCoordinate(0); AddEndpoint(endPoints, p0, isClosed); ICoordinate p1 = e.GetCoordinate(e.NumPoints - 1); AddEndpoint(endPoints, p1, isClosed); } - for (IEnumerator i = endPoints.Values.GetEnumerator(); i.MoveNext(); ) + for (IEnumerator i = endPoints.Values.GetEnumerator(); i.MoveNext();) { EndpointInfo eiInfo = (EndpointInfo) i.Current; if (eiInfo.IsClosed && eiInfo.Degree != 2) + { return true; + } } return false; } @@ -206,5 +168,59 @@ } eiInfo.AddEndpoint(isClosed); } + + /// + /// + /// + public class EndpointInfo + { + private bool isClosed = false; + + /// + /// + /// + /// + public EndpointInfo(ICoordinate pt) + { + this.Point = pt; + isClosed = false; + Degree = 0; + } + + /// + /// + /// + public ICoordinate Point { get; set; } + + /// + /// + /// + public bool IsClosed + { + get + { + return isClosed; + } + set + { + isClosed = value; + } + } + + /// + /// + /// + public int Degree { get; set; } + + /// + /// + /// + /// + public void AddEndpoint(bool isClosed) + { + Degree++; + IsClosed |= isClosed; + } + } } -} +} \ No newline at end of file