Class SimpleNoder

 1  
 2 /*
 3  * Copyright (c) 2016 Vivid Solutions.
 4  *
 5  * All rights reserved. This program and the accompanying materials
 6  * are made available under the terms of the Eclipse Public License 2.0
 7  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 9  * and the Eclipse Distribution License is available at
10  *
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  */
13 package org.locationtech.jts.noding;
14  
15 import java.util.Collection;
16 import java.util.Iterator;
17  
18 import org.locationtech.jts.geom.Coordinate;
19  
20 /**
21  * Nodes a set of {@link SegmentString}s by
22  * performing a brute-force comparison of every segment to every other one.
23  * This has n^2 performance, so is too slow for use on large numbers
24  * of segments.
25  *
26  * @version 1.7
27  */
28 public class SimpleNoder
29     extends SinglePassNoder
30 {
31  
32   private Collection nodedSegStrings;
33  
34   public SimpleNoder() {
35   }
36  
37   public Collection getNodedSubstrings()
38   {
39     return  NodedSegmentString.getNodedSubstrings(nodedSegStrings);
40   }
41  
42   public void computeNodes(Collection inputSegStrings)
43   {
44     this.nodedSegStrings = inputSegStrings;
45     for (Iterator i0 = inputSegStrings.iterator(); i0.hasNext(); ) {
46       SegmentString edge0 = (SegmentString) i0.next();
47       for (Iterator i1 = inputSegStrings.iterator(); i1.hasNext(); ) {
48         SegmentString edge1 = (SegmentString) i1.next();
49         computeIntersects(edge0, edge1);
50       }
51     }
52   }
53  
54   private void computeIntersects(SegmentString e0, SegmentString e1)
55   {
56     Coordinate[] pts0 = e0.getCoordinates();
57     Coordinate[] pts1 = e1.getCoordinates();
58     for (int i0 = 0; i0 < pts0.length - 1; i0++) {
59       for (int i1 = 0; i1 < pts1.length - 1; i1++) {
60         segInt.processIntersections(e0, i0, e1, i1);
61       }
62     }
63   }
64  
65 }
66