| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.noding; |
| 14 |
|
| 15 |
import java.util.Collection; |
| 16 |
|
| 17 |
/** |
| 18 |
* Finds if two sets of {@link SegmentString}s intersect. |
| 19 |
* Uses indexing for fast performance and to optimize repeated tests |
| 20 |
* against a target set of lines. |
| 21 |
* Short-circuited to return as soon an intersection is found. |
| 22 |
* |
| 23 |
* Immutable and thread-safe. |
| 24 |
* |
| 25 |
* @version 1.7 |
| 26 |
*/ |
| 27 |
public class FastSegmentSetIntersectionFinder |
| 28 |
{ |
| 29 |
private final SegmentSetMutualIntersector segSetMutInt; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* Creates an intersection finder against a given set of segment strings. |
| 35 |
* |
| 36 |
* @param baseSegStrings the segment strings to search for intersections |
| 37 |
*/ |
| 38 |
public FastSegmentSetIntersectionFinder(Collection baseSegStrings) |
| 39 |
{ |
| 40 |
segSetMutInt = new MCIndexSegmentSetMutualIntersector(baseSegStrings); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Gets the segment set intersector used by this class. |
| 45 |
* This allows other uses of the same underlying indexed structure. |
| 46 |
* |
| 47 |
* @return the segment set intersector used |
| 48 |
*/ |
| 49 |
public SegmentSetMutualIntersector getSegmentSetIntersector() |
| 50 |
{ |
| 51 |
return segSetMutInt; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Tests for intersections with a given set of target {@link SegmentString}s. |
| 56 |
* |
| 57 |
* @param segStrings the SegmentStrings to test |
| 58 |
* @return true if an intersection is found |
| 59 |
*/ |
| 60 |
public boolean intersects(Collection segStrings) |
| 61 |
{ |
| 62 |
SegmentIntersectionDetector intFinder = new SegmentIntersectionDetector(); |
| 63 |
return intersects(segStrings, intFinder); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Tests for intersections with a given set of target {@link SegmentString}s. |
| 68 |
* using a given SegmentIntersectionDetector. |
| 69 |
* |
| 70 |
* @param segStrings the SegmentStrings to test |
| 71 |
* @param intDetector the intersection detector to use |
| 72 |
* @return true if the detector reports intersections |
| 73 |
*/ |
| 74 |
public boolean intersects(Collection segStrings, SegmentIntersectionDetector intDetector) |
| 75 |
{ |
| 76 |
segSetMutInt.process(segStrings, intDetector); |
| 77 |
return intDetector.hasIntersection(); |
| 78 |
} |
| 79 |
} |
| 80 |
|