void minkowskiSum( const Geometry& gA, const Polygon_2& gB, CGAL::Polygon_set_2< Kernel > & polygonSet ) { if ( gA.isEmpty() ) return ; switch ( gA.geometryTypeId() ){ case TYPE_POINT: return minkowskiSum( gA.as< Point >(), gB, polygonSet ) ; case TYPE_LINESTRING: return minkowskiSum( gA.as< LineString >(), gB, polygonSet ) ; case TYPE_POLYGON: return minkowskiSum( gA.as< Polygon >(), gB, polygonSet ) ; case TYPE_TRIANGLE: return minkowskiSum( gA.as< Triangle >().toPolygon(), gB, polygonSet ) ; case TYPE_SOLID: return minkowskiSum( gA.as< Solid >(), gB, polygonSet ) ; case TYPE_MULTIPOINT: case TYPE_MULTILINESTRING: case TYPE_MULTIPOLYGON: case TYPE_MULTISOLID: case TYPE_GEOMETRYCOLLECTION: case TYPE_TRIANGULATEDSURFACE: case TYPE_POLYHEDRALSURFACE: return minkowskiSumCollection( gA, gB, polygonSet ) ; } BOOST_THROW_EXCEPTION(Exception( ( boost::format("minkowskiSum( %s, 'Polygon' ) is not defined") % gA.geometryType() ).str() )); }
std::auto_ptr< Geometry > minkowskiSum( const Geometry& gA, const Polygon& gB ) { SFCGAL_ASSERT_GEOMETRY_VALIDITY_2D( gA ); SFCGAL_ASSERT_GEOMETRY_VALIDITY_2D( gB ); return minkowskiSum( gA, gB, NoValidityCheck() ); }
std::auto_ptr< Geometry > minkowskiSum( const Geometry& gA, const Polygon& gB, NoValidityCheck ) { if ( gB.isEmpty() ) { return std::auto_ptr< Geometry >( gA.clone() ); } Polygon_set_2 polygonSet ; minkowskiSum( gA, gB.toPolygon_2(), polygonSet ) ; return std::auto_ptr< Geometry >( detail::polygonSetToMultiPolygon( polygonSet ).release() ) ; }
void minkowskiSum( const Polygon& gA, const Polygon_2& gB, Polygon_set_2& polygonSet ) { if ( gA.isEmpty() ) { return ; } /* * Invoke minkowski_sum_2 for exterior ring */ { Polygon_with_holes_2 sum = minkowski_sum_2( gA.exteriorRing().toPolygon_2(), gB ) ; if ( polygonSet.is_empty() ) { polygonSet.insert( sum ); } else { polygonSet.join( sum ); } } /* * Compute the Minkowski sum for each segment of the interior rings * and perform the union of the result. The result is a polygon, and its holes * correspond to the inset. * */ if ( gA.hasInteriorRings() ) { Polygon_set_2 sumInteriorRings ; for ( size_t i = 0; i < gA.numInteriorRings(); i++ ) { minkowskiSum( gA.interiorRingN( i ), gB, sumInteriorRings ) ; } /* * compute the difference for each hole of the resulting polygons */ std::list<Polygon_with_holes_2> interiorPolygons ; sumInteriorRings.polygons_with_holes( std::back_inserter( interiorPolygons ) ) ; for ( std::list<Polygon_with_holes_2>::iterator it_p = interiorPolygons.begin(); it_p != interiorPolygons.end(); ++it_p ) { for ( Polygon_with_holes_2::Hole_iterator it_hole = it_p->holes_begin(); it_hole != it_p->holes_end(); ++it_hole ) { it_hole->reverse_orientation() ; polygonSet.difference( *it_hole ) ; } // foreach hole }// foreach polygon } }
void minkowskiSumCollection( const Geometry& gA, const Polygon_2& gB, Polygon_set_2& polygonSet ) { for ( size_t i = 0; i < gA.numGeometries(); i++ ) { minkowskiSum( gA.geometryN( i ), gB, polygonSet ); } }
std::auto_ptr< MultiPolygon > minkowskiSum( const Geometry& gA, const Polygon& gB ) { Polygon_set_2 polygonSet ; minkowskiSum( gA, gB.toPolygon_2(), polygonSet ) ; return detail::polygonSetToMultiPolygon( polygonSet ) ; }