Class PreparedLineString

 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.geom.prep;
13  
14 import org.locationtech.jts.geom.Geometry;
15 import org.locationtech.jts.geom.Lineal;
16 import org.locationtech.jts.noding.FastSegmentSetIntersectionFinder;
17 import org.locationtech.jts.noding.SegmentStringUtil;
18  
19 /**
20  * A prepared version for {@link Lineal} geometries.
21  * <p>
22  * Instances of this class are thread-safe.
23  * 
24  * @author mbdavis
25  *
26  */
27 public class PreparedLineString
28   extends BasicPreparedGeometry
29 {
30   private FastSegmentSetIntersectionFinder segIntFinder = null;
31  
32   public PreparedLineString(Lineal line) {
33     super((Geometry) line);
34   }
35  
36   public synchronized FastSegmentSetIntersectionFinder getIntersectionFinder()
37   {
38       /**
39        * MD - Another option would be to use a simple scan for 
40        * segment testing for small geometries.  
41        * However, testing indicates that there is no particular advantage 
42        * to this approach.
43        */
44       if (segIntFinder == null)
45           segIntFinder = new FastSegmentSetIntersectionFinder(SegmentStringUtil.extractSegmentStrings(getGeometry()));
46     return segIntFinder;
47   }
48   
49   public boolean intersects(Geometry g)
50   {
51       if (! envelopesIntersect(g)) return false;
52     return PreparedLineStringIntersects.intersects(this, g);
53   }
54   
55   /**
56    * There's not much point in trying to optimize contains, since 
57    * contains for linear targets requires the entire test geometry 
58    * to exactly match the target linework.
59    */
60 }
61