-
Notifications
You must be signed in to change notification settings - Fork 447
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
Improve how zero-length linestring are handled by relate #346
Open
mukoki
wants to merge
2
commits into
locationtech:master
Choose a base branch
from
mukoki:zero-length-linestring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...es/core/src/test/java/org/locationtech/jts/operation/relate/ZeroLengthLineStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.locationtech.jts.operation.relate; | ||
|
||
import junit.framework.TestCase; | ||
import junit.textui.TestRunner; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.io.WKTReader; | ||
|
||
public class ZeroLengthLineStringTest extends TestCase { | ||
|
||
public static void main(String args[]) { | ||
TestRunner.run(ZeroLengthLineStringTest.class); | ||
} | ||
|
||
private GeometryFactory factory = new GeometryFactory(); | ||
private WKTReader reader = new WKTReader(factory); | ||
|
||
public ZeroLengthLineStringTest(String name) | ||
{ | ||
super(name); | ||
} | ||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* 0-length LineString is invalid (not clear from the spec, refers | ||
* to the ticket about this question) | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testZeroLengthLineStringInvalid() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 0 0)"; | ||
Geometry geom1 = reader.read(a); | ||
assertTrue(!geom1.isValid()); | ||
} | ||
|
||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* Intersects a geom with itself should return true, even if geom | ||
* is a 0-length (degenerated) LineString | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testIntersectsZeroLengthLineStringWithItself() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 0 0)"; | ||
Geometry geom = reader.read(a); | ||
assertTrue(geom.intersects(geom)); | ||
} | ||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* Intersects geom with a buffer around it should return true, | ||
* even if geom is a 0-length (degenerated) LineString | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testIntersectsZeroLengthLineStringWithBuffer() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 0 0)"; | ||
Geometry geom = reader.read(a); | ||
assertTrue(geom.intersects(geom.buffer(1.0))); | ||
} | ||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* Boundary of a zero-length LineString is empty | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testZeroLengthLineStringBoundary() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 0 0)"; | ||
Geometry geom = reader.read(a); | ||
assertTrue(geom.getBoundary().isEmpty()); | ||
} | ||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* Intersects a valid LineString with a 0-dimensional LineString | ||
* located on one of its boundary should return true | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testIntersectsBetweenLineStringAndItsBoundary() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 1 0)"; | ||
String b = "LINESTRING (0 0, 0 0)"; | ||
Geometry geom1 = reader.read(a); | ||
Geometry geom2 = reader.read(b); | ||
assertTrue(geom1.intersects(geom2)); | ||
} | ||
|
||
/** | ||
* From JTS #345 | ||
* | ||
* WARNING touches between a LineString and a 0-length LineString lying | ||
* on its boundary returns false but it should return true as for the | ||
* punctal case. | ||
* The test with 0-length linestring is deactivated. | ||
* One way to return true as for the Point is to say that 0-length LineString | ||
* has dimension 1. IMHO, it LineString#getDimension() should return one, but | ||
* it breaks other tests which check that empty LineString#getDimension return | ||
* 1 (which can probably be discussed). | ||
* | ||
* @throws Exception | ||
*/ | ||
public void testTouchesBetweenLineStringAndItsBoundary() | ||
throws Exception | ||
{ | ||
String a = "LINESTRING (0 0, 1 0)"; | ||
String b = "LINESTRING (0 0, 0 0)"; | ||
String c = "POINT (0 0)"; | ||
Geometry geom1 = reader.read(a); | ||
Geometry geom2 = reader.read(b); | ||
Geometry geom3 = reader.read(c); | ||
//assertTrue(geom1.touches(geom2)); | ||
//assertTrue(geom2.touches(geom1)); | ||
assertTrue(geom1.touches(geom3)); | ||
assertTrue(geom3.touches(geom1)); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a BIG comment here indicating that this is an enhancement to standard OGC semantics, and is potentially a source of (as yet unknown) logic bugs.