[geos-devel] Envelope of empty Polygon

Mateusz Łoskot mateusz at loskot.net
Wed Apr 5 04:52:14 EDT 2006


strk at refractions.net wrote:
> Mateusz Łoskot wrote:
> 
>> As you see above, copy ctor calls init() passing 'env' - a null 
>> Envelope returned from getEnvelopeInternal() call.
>> 
>> But the Envelope::init(double x1, double x2, double y1, double y2)
>>  call reorganizes min/max values of corners to make Envelope 
>> properly oriented. This reorganizations brokes the state of 
>> Envelope - null state. So, null Envelope stops to be null with some
>>  magic :-)
> 
> Good report Mateus! I guess the solution here is to just remove 
> explicit definition of the copy ctor and let compiler syntetize it 
> for us (Envelope doesn't contain any pointer). What do you think ?

Yes, this approach would be better.
Now, copy constructor causes a kind of side effect - Envelope
normalization. But it should just make a copy, even if Envelope is not
normalized/oriented correctly.

I see two choices:
1. Let compiler to generate copy ctor for us. It should work because it
have to copy 4 members field-by-field.
2. We can define this copy ctor, even if it's a bit trivial. This will
help us to have it under control for debugging, etc.

Additional suggestion:
Copy contructor is a kind of twin with assignment operator, so it is a
good practice to define them both (rule: if there is copy ctor,
assignment op should be defined, and vice versa).
This will make the type well copyable.

Assignment operator (mostly) has the same semantic as copy ctor (same
implementation).

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



More information about the geos-devel mailing list