Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PreparedLineString intersects against mixed GC #944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,27 @@ public Point getInteriorPoint()
* For example, a 0-dimensional geometry (e.g. a Point)
* may have a coordinate dimension of 3 (X,Y,Z).
*
*@return the topological dimension of this geometry.
* @return the topological dimension of this geometry.
*
* @see #hasDimension(int)
*/
public abstract int getDimension();

/**
* Tests whether an atomic geometry or any element of a collection
* has the specified dimension.
* In particular, this can be used with mixed-dimension {@link GeometryCollection}s
* to test if they contain an element of the specified dimension.
*
* @param dim the dimension to test
* @return true if the geometry has or contains an element with the dimension
*
* @see #getDimension()
*/
public boolean hasDimension(int dim) {
return dim == getDimension();
}

/**
* Returns the boundary, or an empty geometry of appropriate dimension
* if this <code>Geometry</code> is empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public int getDimension() {
return dimension;
}

public boolean hasDimension(int dim) {
for (int i = 0; i < geometries.length; i++) {
if (geometries[i].hasDimension(dim))
return true;
}
return false;
}

public int getBoundaryDimension() {
int dimension = Dimension.FALSE;
for (int i = 0; i < geometries.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public int getDimension() {
return 1;
}

public boolean hasDimension(int dim) {
return dim == 1;
}

public int getBoundaryDimension() {
if (isClosed()) {
return Dimension.FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public int getDimension() {
return 0;
}

public boolean hasDimension(int dim) {
return dim == 0;
}

public int getBoundaryDimension() {
return Dimension.FALSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public int getDimension() {
return 2;
}

public boolean hasDimension(int dim) {
return dim == 2;
}

public int getBoundaryDimension() {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public boolean intersects(Geometry geom)
if (segsIntersect)
return true;
}
/**
* For L/L case we are done
*/
if (geom.getDimension() == 1) return false;

/**
* For L/A case, need to check for proper inclusion of the target in the test
Expand All @@ -92,7 +88,7 @@ public boolean intersects(Geometry geom)
/**
* For L/P case, need to check if any points lie on line(s)
*/
if (geom.getDimension() == 0)
if (geom.hasDimension(0))
return isAnyTestPointInTarget(geom);

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import test.jts.GeometryTestCase;


/**
* Test for com.vividsolutions.jts.geom.GeometryCollectionImpl.
*
* @version 1.7
*/
public class GeometryCollectionImplTest extends TestCase {
public class GeometryCollectionImplTest extends GeometryTestCase {

PrecisionModel precisionModel = new PrecisionModel(1000);
GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
Expand All @@ -44,6 +45,29 @@ public void testGetDimension() throws Exception {
GeometryCollection g = (GeometryCollection) reader.read("GEOMETRYCOLLECTION (POINT (10 10), POINT (30 30), LINESTRING (15 15, 20 20))");
assertEquals(1, g.getDimension());
}

public void testHasDimension() {
Geometry mixedGC = read("GEOMETRYCOLLECTION (POINT (10 10), LINESTRING (15 15, 20 20), POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20)))");
assertTrue(mixedGC.hasDimension(0));
assertTrue(mixedGC.hasDimension(1));
assertTrue(mixedGC.hasDimension(2));

Geometry mA = read("MULTIPOLYGON (((10 20, 20 20, 20 10, 10 10, 10 20)), ((30 30, 30 20, 20 20, 20 30, 30 30)))");
assertFalse(mA.hasDimension(0));
assertFalse(mA.hasDimension(1));
assertTrue(mA.hasDimension(2));

Geometry mL = read("MULTILINESTRING ((5 5, 10 5), (15 5, 20 5))");
assertFalse(mL.hasDimension(0));
assertTrue(mL.hasDimension(1));
assertFalse(mL.hasDimension(2));

Geometry mP = read("MULTIPOINT ((10 10), (20 20))");
assertTrue(mP.hasDimension(0));
assertFalse(mP.hasDimension(1));
assertFalse(mP.hasDimension(2));

}

public void testGetCoordinates() throws Exception {
GeometryCollection g = (GeometryCollection) reader.read("GEOMETRYCOLLECTION (POINT (10 10), POINT (30 30), LINESTRING (15 15, 20 20))");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
<test> <op name="intersects" arg1="A" arg2="B"> true </op> </test>
</case>


<case>
<desc>LineString against GC, with point at endpoint
</desc>
<a>
LINESTRING (0 0, 1 1)
</a>
<b>
GEOMETRYCOLLECTION (POINT (1 1), LINESTRING (2 2, 3 3))
</b>
<test> <op name="intersects" arg1="A" arg2="B"> true </op> </test>
</case>

</run>