Interface PreparedGeometry

  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.GeometryCollection;
 16  
 17 /**
 18  * An interface for classes which prepare {@link Geometry}s 
 19  * in order to optimize the performance 
 20  * of repeated calls to specific geometric operations.
 21  * <p>
 22  * A given implementation may provide optimized implementations
 23  * for only some of the specified methods, 
 24  * and delegate the remaining methods to the original {@link Geometry} operations.
 25  * An implementation may also only optimize certain situations,
 26  * and delegate others. 
 27  * See the implementing classes for documentation about which methods and situations
 28  * they optimize.
 29  * <p>
 30  * Subclasses are intended to be thread-safe, to allow <code>PreparedGeometry</code>
 31  * to be used in a multi-threaded context 
 32  * (which allows extracting maximum benefit from the prepared state).
 33  * 
 34  * @author Martin Davis
 35  *
 36  */
 37 public interface PreparedGeometry 
 38 {
 39     
 40     /**
 41      * Gets the original {@link Geometry} which has been prepared.
 42      * 
 43      * @return the base geometry
 44      */
 45     Geometry getGeometry();
 46  
 47     /**
 48      * Tests whether the base {@link Geometry} contains a given geometry.
 49      * 
 50      * @param geom the Geometry to test
 51      * @return true if this Geometry contains the given Geometry
 52      * 
 53      * @see Geometry#contains(Geometry)
 54      */
 55     boolean contains(Geometry geom);
 56  
 57     /**
 58      * Tests whether the base {@link Geometry} properly contains a given geometry.
 59      * <p>
 60      * The <code>containsProperly</code> predicate has the following equivalent definitions:
 61      * <ul>
 62      * <li>Every point of the other geometry is a point of this geometry's interior.
 63      * <li>The DE-9IM Intersection Matrix for the two geometries matches 
 64      * <code>[T**FF*FF*]</code>
 65      * </ul>
 66      * In other words, if the test geometry has any interaction with the boundary of the target
 67      * geometry the result of <tt>containsProperly</tt> is <tt>false</tt>. 
 68      * This is different semantics to the {@link Geometry#contains} predicate,
 69      * in which test geometries can intersect the target's boundary and still be contained.
 70      * <p>
 71      * The advantage of using this predicate is that it can be computed
 72      * efficiently, since it avoids the need to compute the full topological relationship
 73      * of the input boundaries in cases where they intersect.
 74      * <p>
 75      * An example use case is computing the intersections
 76      * of a set of geometries with a large polygonal geometry.  
 77      * Since <tt>intersection</tt> is a fairly slow operation, it can be more efficient
 78      * to use <tt>containsProperly</tt> to filter out test geometries which lie
 79      * wholly inside the area.  In these cases the intersection is
 80      * known <i>a priori</i> to be exactly the original test geometry. 
 81      * 
 82      * @param geom the Geometry to test
 83      * @return true if this Geometry properly contains the given Geometry
 84      * 
 85      * @see Geometry#contains
 86      * 
 87      */
 88     boolean containsProperly(Geometry geom);
 89  
 90     /**
 91      * Tests whether the base {@link Geometry} is covered by a given geometry.
 92      * 
 93      * @param geom the Geometry to test
 94      * @return true if this Geometry is covered by the given Geometry
 95      * 
 96      * @see Geometry#coveredBy(Geometry)
 97      */
 98     boolean coveredBy(Geometry geom);
 99  
100     /**
101      * Tests whether the base {@link Geometry} covers a given geometry.
102      * 
103      * @param geom the Geometry to test
104      * @return true if this Geometry covers the given Geometry
105      * 
106      * @see Geometry#covers(Geometry)
107      */
108     boolean covers(Geometry geom);
109  
110     /**
111      * Tests whether the base {@link Geometry} crosses a given geometry.
112      * 
113      * @param geom the Geometry to test
114      * @return true if this Geometry crosses the given Geometry
115      * 
116      * @see Geometry#crosses(Geometry)
117      */
118     boolean crosses(Geometry geom);
119  
120     /**
121      * Tests whether the base {@link Geometry} is disjoint from a given geometry.
122      * This method supports {@link GeometryCollection}s as input
123      * 
124      * @param geom the Geometry to test
125      * @return true if this Geometry is disjoint from the given Geometry
126      * 
127      * @see Geometry#disjoint(Geometry)
128      */
129     boolean disjoint(Geometry geom);
130  
131     /**
132      * Tests whether the base {@link Geometry} intersects a given geometry.
133      * This method supports {@link GeometryCollection}s as input
134      * 
135      * @param geom the Geometry to test
136      * @return true if this Geometry intersects the given Geometry
137      * 
138      * @see Geometry#intersects(Geometry)
139      */
140     boolean intersects(Geometry geom);
141  
142     /**
143      * Tests whether the base {@link Geometry} overlaps a given geometry.
144      * 
145      * @param geom the Geometry to test
146      * @return true if this Geometry overlaps the given Geometry
147      * 
148      * @see Geometry#overlaps(Geometry)
149      */
150     boolean overlaps(Geometry geom);
151  
152     /**
153      * Tests whether the base {@link Geometry} touches a given geometry.
154      * 
155      * @param geom the Geometry to test
156      * @return true if this Geometry touches the given Geometry
157      * 
158      * @see Geometry#touches(Geometry)
159      */
160     boolean touches(Geometry geom);
161  
162     /**
163      * Tests whether the base {@link Geometry} is within a given geometry.
164      * 
165      * @param geom the Geometry to test
166      * @return true if this Geometry is within the given Geometry
167      * 
168      * @see Geometry#within(Geometry)
169      */
170     boolean within(Geometry geom);
171  
172 }
173