| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package org.locationtech.jts.noding; |
| 13 |
|
| 14 |
import java.util.Collection; |
| 15 |
import java.util.Iterator; |
| 16 |
|
| 17 |
import org.locationtech.jts.geom.Coordinate; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* Intersects two sets of {@link SegmentString}s using |
| 23 |
* brute-force comparison. |
| 24 |
* |
| 25 |
* @version 1.7 |
| 26 |
*/ |
| 27 |
public class SimpleSegmentSetMutualIntersector implements SegmentSetMutualIntersector |
| 28 |
{ |
| 29 |
private final Collection baseSegStrings; |
| 30 |
|
| 31 |
/** |
| 32 |
* Constructs a new intersector for a given set of {@link SegmentString}s. |
| 33 |
* |
| 34 |
* @param segStrings the base segment strings to intersect |
| 35 |
*/ |
| 36 |
public SimpleSegmentSetMutualIntersector(Collection segStrings) |
| 37 |
{ |
| 38 |
this.baseSegStrings = segStrings; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Calls {@link SegmentIntersector#processIntersections(SegmentString, int, SegmentString, int)} |
| 43 |
* for all <i>candidate</i> intersections between |
| 44 |
* the given collection of SegmentStrings and the set of base segments. |
| 45 |
* |
| 46 |
* @param a set of segments to intersect |
| 47 |
* @param the segment intersector to use |
| 48 |
*/ |
| 49 |
public void process(Collection segStrings, SegmentIntersector segInt) { |
| 50 |
for (Iterator i = baseSegStrings.iterator(); i.hasNext(); ) { |
| 51 |
SegmentString baseSS = (SegmentString) i.next(); |
| 52 |
for (Iterator j = segStrings.iterator(); j.hasNext(); ) { |
| 53 |
SegmentString ss = (SegmentString) j.next(); |
| 54 |
intersect(baseSS, ss, segInt); |
| 55 |
if (segInt.isDone()) |
| 56 |
return; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Processes all of the segment pairs in the given segment strings |
| 63 |
* using the given SegmentIntersector. |
| 64 |
* |
| 65 |
* @param ss0 a Segment string |
| 66 |
* @param ss1 a segment string |
| 67 |
* @param segInt the segment intersector to use |
| 68 |
*/ |
| 69 |
private void intersect(SegmentString ss0, SegmentString ss1, SegmentIntersector segInt) |
| 70 |
{ |
| 71 |
Coordinate[] pts0 = ss0.getCoordinates(); |
| 72 |
Coordinate[] pts1 = ss1.getCoordinates(); |
| 73 |
for (int i0 = 0; i0 < pts0.length - 1; i0++) { |
| 74 |
for (int i1 = 0; i1 < pts1.length - 1; i1++) { |
| 75 |
segInt.processIntersections(ss0, i0, ss1, i1); |
| 76 |
if (segInt.isDone()) |
| 77 |
return; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|