Class IntersectionFinderAdder

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12 package org.locationtech.jts.noding;
13  
14 import java.util.ArrayList;
15 import java.util.List;
16  
17 import org.locationtech.jts.algorithm.LineIntersector;
18 import org.locationtech.jts.geom.Coordinate;
19  
20 /**
21  * Finds <b>interior</b> intersections between line segments in {@link NodedSegmentString}s,
22  * and adds them as nodes
23  * using {@link NodedSegmentString#addIntersection(LineIntersector, int, int, int)}.
24  * <p>
25  * This class is used primarily for Snap-Rounding.  
26  * For general-purpose noding, use {@link IntersectionAdder}.
27  *
28  * @version 1.7
29  * @see IntersectionAdder
30  * @deprecated see InteriorIntersectionFinderAdder
31  */
32 public class IntersectionFinderAdder
33     implements SegmentIntersector
34 {
35   private LineIntersector li;
36   private final List interiorIntersections;
37  
38  
39   /**
40    * Creates an intersection finder which finds all proper intersections
41    *
42    * @param li the LineIntersector to use
43    */
44   public IntersectionFinderAdder(LineIntersector li)
45   {
46     this.li = li;
47     interiorIntersections = new ArrayList();
48   }
49  
50   public List getInteriorIntersections()  {    return interiorIntersections;  }
51  
52   /**
53    * This method is called by clients
54    * of the {@link SegmentIntersector} class to process
55    * intersections for two segments of the {@link SegmentString}s being intersected.
56    * Note that some clients (such as <code>MonotoneChain</code>s) may optimize away
57    * this call for segment pairs which they have determined do not intersect
58    * (e.g. by an disjoint envelope test).
59    */
60   public void processIntersections(
61       SegmentString e0,  int segIndex0,
62       SegmentString e1,  int segIndex1
63       )
64   {
65     // don't bother intersecting a segment with itself
66     if (e0 == e1 && segIndex0 == segIndex1) return;
67  
68     Coordinate p00 = e0.getCoordinates()[segIndex0];
69     Coordinate p01 = e0.getCoordinates()[segIndex0 + 1];
70     Coordinate p10 = e1.getCoordinates()[segIndex1];
71     Coordinate p11 = e1.getCoordinates()[segIndex1 + 1];
72  
73     li.computeIntersection(p00, p01, p10, p11);
74 //if (li.hasIntersection() && li.isProper()) Debug.println(li);
75  
76     if (li.hasIntersection()) {
77       if (li.isInteriorIntersection()) {
78         for (int intIndex = 0; intIndex < li.getIntersectionNum(); intIndex++) {
79           interiorIntersections.add(li.getIntersection(intIndex));
80         }
81         ((NodedSegmentString) e0).addIntersections(li, segIndex0, 0);
82         ((NodedSegmentString) e1).addIntersections(li, segIndex1, 1);
83       }
84     }
85   }
86   
87   /**
88    * Always process all intersections
89    * 
90    * @return false always
91    */
92   public boolean isDone() { return false; }
93  
94 }
95