[geos-devel] Envelope of empty Polygon

Mateusz Łoskot mateusz at loskot.net
Sun Apr 2 22:23:18 EDT 2006


strk at refractions.net wrote:
> On Fri, Mar 31, 2006 at 08:14:03AM +0200, Mateusz Å?oskot wrote:
>> Hi,
>>
>> I'm bringing next subject to discuss.
>>
>> The main question is what should be returned by getEnvelope()
>> called on empty polygon?
>>
>> Here is simple use case:
>>
>> GeometryFactory factory(...);
>> //...
>>
>> // create empty polygon
>> Polygon* poly = factory.createPolygon();
>>
>> // request for its envelope
>> Geometry* geo = 0;
>> geo = poly->getEnvelope();
>> geo->isEmpty(); // <--- THE PROBLEM
>>
>>
>> As I revealed, when exterior ring is empty geometry,
>> getEnvelope() returns or creates instance of envelope object.
>> This object is initialized by Envelope::setToNull().
>> So, returned envelope for empty polygon has following coordinates:
>> minx = -1.0
>> maxx = 0.0
>> miny = -1.0
>> maxx = 0.0
>>
>> Is this correct behaviour?
>> Is empty polygon assumed to return non-empty envelope as above?
> 
> Doens't seem correct.
> Envelope does have a NULL representation, which is
> minx > maxx
> miny > maxy
> See Envelope::isNull()


Ups! It was my fail.
As I see, Envelope::setToNull() seems to be ok, as you said above:

void Envelope::setToNull()
{
   minx=0;
   maxx=-1;
   miny=0;
   maxy=-1;
}


> Generally speaking I'm sure NULL pointers would be much more
> appropriately used.

Yes, I think so.

> Also, for Geometry, check out  getEnvelopeInternal().
> That should return a pointer to internal cache, thus caller
> wouldn't need to free the result.
> JTS getEnvelope() is really what getEnvelopeInternal() is for
> GEOS.
> I'd drop the copying one and rename the *Internal() one.

Here, shared_ptr could be nice.

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the geos-devel mailing list