Opened 18 years ago

Last modified 15 years ago

#87 closed defect (worksforme)

Strange result of isValid() for LinearRing — at Initial Version

Reported by: mateusz@… Owned by: mateusz@…
Priority: major Milestone:
Component: Core Version: main
Severity: Significant Keywords: imported, phpbugtracker
Cc:

Description

I'm getting strange result of isValid() call for non-empty, simple and closed LinearRing.

Here is a code of one of my tests for LinearRing:

// 1. Create non-empty sequence of coordiantes
CoordinateArraySequence* pseq = new CoordinateArraySequence();
ensure( "sequence is null pointer.", pseq != 0 );

// 2. Add 4 points to get closed ring
pseq->add(Coordinate(0, 0, 0));
pseq->add(Coordinate(5, 5, 5));
pseq->add(Coordinate(10, 10, 10));
pseq->add(Coordinate(0, 0, 0)); // <--- [1]

ensure_equals( pseq->size(), 4 );

// 3. Create non-empty linearring instance
geos::geom::LinearRing ring(pseq, &amp;factory_);

// 4. Simple tests
ensure( !ring.isEmpty() );
ensure( ring.isClosed() );
ensure( ring.isRing() );
ensure( ring.isSimple() );

// 5. THIS TEST FAILS
ensure( ring.isValid() ); // <--- [2]


From my point of view, the code above seems to be valid.
I add 4 points with first point repeated [1] at the end to get closed ring.
Next, I create LinearRing instance and all tests pass besides isValid() in line [2].

I debugged step by step and what I revealed - and what seems to be quite strange for me - it that checkValid() operation called in IsValidOp::isValid() returns validError.

The error id is eRingSelfIntersection and the messge is "Ring Self-intersection".

In my opinion, the problem is in checkValid() function which validates LinearRing object incorrectly.
I suppose that checkValid() recognizes first and last point of LinearRing as self-intersection.

I did a test with not adding the last repeated point in line [1] but then LinearRing ctor throws exception because isClosed() returns false.

Summary:
The IsValidOp::checkValid(const Geometry *g) function needs to be checked for LinearRing geometries.

Change History (0)

Note: See TracTickets for help on using tickets.