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

Improve how zero-length linestring are handled by relate #346

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -292,6 +292,7 @@ private void addLineString(LineString line)
if (coord.length < 2) {
hasTooFewPoints = true;
invalidPoint = coord[0];
addPoint(coord[0]);
Copy link
Contributor

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.

return;
}

Expand Down
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));
}

}