Distance in the Boost::geometry negative buffer

你说的曾经没有我的故事 提交于 2019-12-23 17:22:07

问题


I continue from this post: Negative buffer of Boost::geometry::multi_polygon I am making some more tests to undrestand what is going on with the distance strategy when this distance is negative. Using the code below, I got empty MultiPolygons for some values of the buffer. This case only appears with the polygon imported from the given WKT for a buffer of -1e-4, -1e-5 or -1e-6. But it is not empty for -1e-7 and -1e-8. Could someone explain me why please?

#include <iostream>
#include <iomanip>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

typedef boost::geometry::model::d2::point_xy<double> point_2d;
typedef boost::geometry::model::polygon<point_2d> polygon_2d;
typedef boost::geometry::model::multi_polygon<polygon_2d> multi_polygon_2d;

template <typename T>
void test_buffer(T &geom)
{
    for (double i = -1; i < -1e-8; i/=10)
    {
        multi_polygon_2d tmp;
        boost::geometry::buffer(
            geom,
            tmp,
            boost::geometry::strategy::buffer::distance_symmetric<double>(i),
            boost::geometry::strategy::buffer::side_straight(),
            boost::geometry::strategy::buffer::join_round(),
            boost::geometry::strategy::buffer::end_round(),
            boost::geometry::strategy::buffer::point_circle(360)
            );
        std::cout<<"geom ("<<i<<"): "<<boost::geometry::wkt(tmp)<<std::endl<<std::endl;
    }
}

int main(int argc, const char *argv[])
{
    std::string wkt = "MULTIPOLYGON(((-203.3984972480392 326.87043766411114,-234.3294031269611 350.72117460025004,-234.32940582512484 350.7211767561067,-234.59541944833873 350.9413566745228,-234.5954246133754 350.9413612592119,-234.8456066177885 351.1793768235705,-234.84561145406377 351.179381753826,-235.078768547128 351.43409770182103,-235.07877303157431 351.43410295412707,-235.29379312442313 351.70430436766964,-235.29379723565108 351.7043099169743,-235.39951413618792 351.85781786966413,-240.86780715032046 350.38218215855835,-241.2049443604434 350.30361570297174,-241.20495115354115 350.3036143659985,-241.5467165739732 350.24856362767656,-241.54672344329876 350.24856276394,-241.89147886679623 350.21729162130026,-241.89148577942245 350.2172912349408,-242.23758558935015 350.20994967493,-242.58335698974216 350.2265727030494,-242.5833638895166 350.22657327470256,-242.9271563937872 350.26708130353956,-242.92716323747084 350.2670823512364,-243.26732892181855 350.3312812109238,-243.26733567660713 350.3312827296422,-243.60225063542637 350.4188666739157,-243.93029626301933 350.52941192532916,-243.93030274346452 350.52941436202866,-244.24991952642313 350.66239589829064,-244.55956286161836 350.81717054531686,-244.55956894361645 350.81717385333343,-244.8577608930744 350.99300259862656,-244.85776673160544 350.99300631954446,-245.14307795174008 351.18904635131906,-245.1430835188178 351.18905046730254,-245.41415167705114 351.40436658497003,-245.6696669314724 351.6379177381484,-245.66967187701746 351.63792258327567,-245.90841706208894 351.88859631483484,-266.58920031948566 375.16554041806563,-266.58920258870927 375.16554306360825,-266.8114462984894 375.433970996735,-266.8114505535744 375.43397651693255,-267.0144568842047 375.7172330288498,-267.0144607444406 375.7172388320306,-267.19724352509485 376.01394790994334,-267.1972469717292 376.0139539679166,-267.358918274207 376.32267424871253,-267.35892129049665 376.3226805320497,-267.49869574263016 376.6419123042001,-267.4986983139225 376.6419187823777,-267.6158969147833 376.97011127128593,-267.6158990285875 376.970117912834,-267.7099540930073 377.30568358689385,-267.7804054331035 377.6469788117333,-267.780406603398 377.6469856825949,-267.8269143132387 377.99236621139704,-267.8492510917757 378.34014040558645,-267.84925129584775 378.3401473724138,-267.84730904189666 378.68863970288874,-267.8210977526416 379.03614335774023,-267.8210969865306 379.036150285323,-267.7707424635338 379.3809909713855,-267.6964900867632 379.72148658265553,-267.59870274954784 380.0559764307823,-267.5987005618558 380.05598304835985,-267.4778489339802 380.38285544057135,-267.3345253662763 380.7005096185073,-267.334522280147 380.700515867838,-267.1694203712224 381.00741516970913,-267.1694168572867 381.0074211888939,-266.9833347199501 381.3020805089815,-266.77718414040345 381.58305694993714,-266.7771798240608 381.58306242236944,-266.5519583226944 381.8489968074004,-266.5519536356491 381.8490019658822,-266.30875282540296 382.09860488379184,-232.51589024775978 414.4450812583296,-232.51588002802416 414.4450898114167,-232.51586876173633 414.4450969296367,-232.51585664898366 414.445102486571,-232.51584390488657 414.4451063835295,-232.5158373664838 414.445107686701,-211.12681324719696 417.9713206571314,-211.12680695294904 417.97132149052527,-211.1267942693878 417.9713219522357,-211.12678793120457 417.971321578691,-211.1267816295017 417.9713208036793,-211.12676923690148 417.97131806335767,-211.1267572912145 417.97131377541353,-211.12675154646425 417.9713110717222,-177.1106691504801 400.6223337146699,-177.1106636027793 400.62233015463886,-177.11065830167098 400.6223262368518,-177.11064853019522 400.6223173975823,-177.11064000569968 400.62230735032404,-177.11063625823746 400.6223019274713,-177.11063287618194 400.6222962695118,-177.11062726542067 400.6222843475245,-177.11062327082684 400.622271791345,-177.11062190239758 400.6222653432285,-165.59426937600804 335.9234066092942,-162.6596781566315 302.06171116087233,-162.6596788436905 302.0616975137797,-162.65967988463825 302.06169075731424,-162.65968333706937 302.06167753627386,-162.65968573241835 302.0616711334854,-162.6596885596208 302.06166490931287,-162.65969545477958 302.06165311219564,-162.65970389380263 302.0616423651924,-162.65970864407186 302.06163744906183,-162.65971909523134 302.0616286463092,-162.65973064885196 302.0616213504858,-162.65974308921002 302.0616156978157,-162.6597561840252 302.0616117938428,-162.65976290080164 302.0616105217139,-162.65977651628992 302.06160936686865,-162.65979016210093 302.0616100789291,-162.65979691664793 302.06161113225346,-162.65981013134098 302.0616146089008,-162.65982274871268 302.0616198545771,-204.8758528204258 323.10306070098704,-204.8758584840069 323.10306427432,-204.87586903132672 323.1030725164298,-204.87587838335946 323.10308209337154,-204.87588255785658 323.1030873296329,-204.87588981029387 323.1030985804321,-204.8758928557106 323.103104544516,-204.87589549513 323.1031106990528,-204.87589771671574 323.10311701644275,-204.87590086845387 323.1031300258577,-204.87590225445257 323.1031433396602,-204.8759018498778 323.10315671929584,-204.8444560373964 323.42562807154223,-204.84445513319602 323.42563489982314,-204.78751382477697 323.76528940556193,-204.78751245267617 323.76529615540176,-204.70732324106254 324.10023186228716,-204.60427022620226 324.42884648764846,-204.60426794001853 324.4288529850604,-204.47883820282144 324.74959412196023,-204.47883547479194 324.74960044658303,-204.33162256579686 325.0609494910012,-203.3984972480392 326.87043766411114)))";

    polygon_2d hourglass, square;
    multi_polygon_2d tmp, poly;

    boost::geometry::read_wkt("Polygon ((0 0, 1 1, 1 0, 0 1, 0 0))", hourglass);
    boost::geometry::read_wkt("Polygon ((0 0, 0 1, 1 1, 1 0, 0 0))", square);
    boost::geometry::read_wkt(wkt, poly);

    std::cout<<"hourglass: "<<boost::geometry::wkt(hourglass)<<std::endl<<std::endl;
    test_buffer(hourglass);

    std::cout<<"square: "<<boost::geometry::wkt(square)<<std::endl<<std::endl;
    test_buffer(square);

    std::cout<<"poly: "<<boost::geometry::wkt(poly)<<std::endl<<std::endl;
    test_buffer(poly);

    return 0;
}

来源:https://stackoverflow.com/questions/39396028/distance-in-the-boostgeometry-negative-buffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!