Boost logo

Geometry :

Subject: Re: [geometry] "Overlay invalid input exception" (fixed)
From: Volker Schöch (vschoech_at_[hidden])
Date: 2012-07-17 10:17:07


Barend,

Thank you very much for your continued support. Here is how I spent my day...

 

1. I tried working around the issue in 1.48.0 by converting int-based polygons to double-based polygons, calling boost::geometry::difference, and converting the result back to int. The "Overlay invalid input exception" was still thrown even for double-based polygons. The cause might have been in the rounding that was required to convert double-polygons to int-polygons, but whatever it was, I'm afraid there is no workaround that "just works" for all cases. I agree that 1.48.0 is obsolete anyway, but we'll have to make it work somehow because we cannot currently upgrade to 1.50.0 (for reasons outside geometry).

 

2. I tried 1.50.0 and applied your patch. The step where it previously failed in 1.50.0 did work after the patch was applied, but the step that originally failed in 1.48.0 still fails in 1.50.0 with your patch. Please find three reproductions below that all fail with "Overlay invalid input exception" in the last step, with 1.50.0, with your patch applied. The definitions of the operators can be found below the reproductions.

 

As always, my polygon type is oriented counter-clockwise and not closed, my point type is based on int.

Regards

   Volker

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_intPolygon polygon( "MULTIPOLYGON(((1031 1056,3232 1056,3232 2856,1031 2856)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((1032 1458,1032 1212,2136 2328,3234 2220,3234 2412,2136 2646)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((1032 1764,1032 1458,2136 2646,3234 2412,3234 2532,2136 2790)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((1032 2130,1032 1764,2052 2712)),((3234 2580,2558 2690,3234 2532)),((2558 2690,2136 2790,2052 2712,2136 2760)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((1032 2556,1032 2130,1778 2556)),((3234 2580,2136 2760,1778 2556,3234 2556)))" );

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_intPolygon polygon( "MULTIPOLYGON(((807 152,3958 152,3958 576,807 576)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((813 277,813 235,1341 235)),((3963 277,3441 235,3963 235)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((3963 277,3441 319,2913 235,3441 235)),((2391 403,1863 235,1341 319,813 277,1341 235,1863 151))) " );

polygon -= _intPolygon( "MULTIPOLYGON(((3441 319,2913 361,2391 403,2913 235)),((2391 403,1863 361,1341 319,1863 235)))" );

polygon -= _intPolygon( "MULTIPOLYGON(((2913 361,2391 571,1863 361,2391 403)))" );

_intPolygon const polygonB = _intPolygon("MULTIPOLYGON(((813 277,1341 319,1863 361,2391 571,2913 361,3441 319,3963 277,3963 32767,813 32767)))") ^ _intPolygon("MULTIPOLYGON(((813 277,1341 319,1863 571,2391 571,2913 571,3441 319,3963 277,3963 32767,813 32767)))");

polygon -= polygonB;

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_intPolygon polygon( "MULTIPOLYGON(((971 1402,5395 1402,5395 3353,971 3353)))" );

{

       _intPolygon const polygonB = _intPolygon("MULTIPOLYGON(((966 2862,1704 3348,2442 3186,3180 2376,3912 1722,4650 1398,5388 1560,5388 32767,966 32767)))") ^ _intPolygon("MULTIPOLYGON(((966 2700,1704 3348,2442 3186,3180 2376,3912 1884,4650 1398,5388 1560,5388 32767,966 32767)))");

       polygon -= polygonB;

}

{

       _intPolygon const polygonB = _intPolygon("MULTIPOLYGON(((966 2700,1704 3348,2442 3186,3180 2376,3912 1884,4650 1398,5388 1560,5388 32767,966 32767)))") ^ _intPolygon("MULTIPOLYGON(((966 2700,1704 3024,2442 3186,3180 2376,3912 1884,4650 1722,5388 1560,5388 32767,966 32767)))");

       polygon -= polygonB;

}

{

       _intPolygon const polygonB = _intPolygon("MULTIPOLYGON(((966 2700,1704 3024,2442 3186,3180 2376,3912 1884,4650 1722,5388 1560,5388 32767,966 32767)))") ^ _intPolygon("MULTIPOLYGON(((966 2208,1704 3024,2442 3186,3180 2376,3912 2376,4650 1722,5388 1560,5388 32767,966 32767)))");

       polygon -= polygonB;

}

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

template<typename T>

template<typename Geometry>

_TPolygon< T > _TPolygon< T >::operator-(Geometry const& geometry) const

{

       // In boost 1.48.0, a polygon or rectangle with no extent is considered invalid input:

       // http://lists.boost.org/geometry/2012/02/1879.php

       if( boost::geometry::area(geometry)==0 ) return *this;

 

       _TPolygon< T > polygonOut;

       boost::geometry::difference(*this, geometry, polygonOut);

 

       // There is a known problem in boost 1.48.0 that requires to call boost::geometry::correct(...)

       // on the output from boost::geometry::difference(...).

       // http://lists.boost.org/geometry/2012/02/1829.php

       boost::geometry::correct( polygonOut );

 

       return polygonOut;

}

 

template<typename T>

template<typename Geometry>

_TPolygon<T>& _TPolygon< T >::operator-=(Geometry const& geometry)

{

       // boost::geometry::difference cannot operate in-place

       // http://lists.boost.org/geometry/2012/02/1796.php

       *this = *this - geometry;

       return *this;

}

 

template<typename T>

template<typename Geometry>

_TPolygon< T > _TPolygon< T >::operator^(Geometry const& geometry) const

{

       _TPolygon< T > polygonOut;

       boost::geometry::sym_difference(*this, geometry, polygonOut);

 

       // There is a known problem in boost 1.48.0 that requires to call boost::geometry::correct(...)

       // on the output from boost::geometry::sym_difference(...).

       // http://lists.boost.org/geometry/2012/02/1850.php

       boost::geometry::correct( polygonOut );

 

       polygonOut.CheckInvariant();

       return polygonOut;

}

 

 

--
Volker Schöch | vschoech_at_[hidden]
Senior Software Engineer
think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091
Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl


Geometry list run by mateusz at loskot.net