geometry icon indicating copy to clipboard operation
geometry copied to clipboard

Buffer makes polygon unexpectedly disappear

Open gastald88 opened this issue 3 months ago • 0 comments

After applying the buffer function of a positive amount on a polygon, it becomes empty. My platform toolset is Visual Studio 2019 (v142) and the Boost version is 1.89.0. Below a code to replicate the problem, let me know if further details are needed, thank you.

#include <boost/geometry.hpp>
#include <iostream>

namespace bg = boost::geometry;
using namespace bg::strategy::buffer;

using point_t = bg::model::point<double, 2, bg::cs::cartesian>;
using polygon_t = bg::model::polygon<point_t>;
using GPolygon = bg::model::multi_polygon<polygon_t>;

GPolygon apply_buffer(const GPolygon& poly, double amount)
{
    //buffer parameters
    distance_symmetric<double> distance_strategy(amount);
    end_round end_strategy;
    point_circle circle_strategy(10);
    side_straight side_strategy;
    join_round join_strategy;

    //apply buffering
    GPolygon buffered_poly;
    bg::buffer(poly, buffered_poly, distance_strategy, side_strategy,
        join_strategy, end_strategy, circle_strategy);

    return buffered_poly;
}


int main() {
    std::cout << "Using Boost "
        << BOOST_VERSION / 100000 << "."  // maj. version
        << BOOST_VERSION / 100 % 1000 << "."  // min. version
        << BOOST_VERSION % 100                // patch version
        << std::endl;

    //polygon to buffer
    GPolygon poly;
    bg::read_wkt("MULTIPOLYGON(((925.2271 -349.3228,925.2271 -323.3228,927.5271 -323.3228,927.5271 -294.3228,910.2271 -294.3228,910.2271 -226.6035,900.0271 -226.6035,900.0271 236.477,909.4271 245.877,900.0271 255.277,900.0271 1199.477,909.4271 1208.877,900.0271 1218.277,900.0271 1291.417,907.891 1299.281,908.05 1299.4881,908.1499 1299.7293,908.1839 1299.9881,908.1499 1300.2469,908.05 1300.4881,907.891 1300.6952,905.0271 1303.5591,905.0271 1314.5628,909.4271 1325.7903,909.4271 1343.277,911.9271 1343.277,911.9271 1349.277,925.0271 1349.277,925.0271 1340.777,925.0647 1340.4432,925.1756 1340.1262,925.3543 1339.8418,925.5918 1339.6043,925.8763 1339.4256,926.1933 1339.3146,926.5271 1339.277,926.8609 1339.3146,927.1779 1339.4256,927.4623 1339.6043,927.6998 1339.8418,927.8785 1340.1262,927.9895 1340.4432,928.0271 1340.777,928.0271 1349.277,1331.0271 1349.277,1331.0271 1340.777,1331.0647 1340.4432,1331.1756 1340.1262,1331.3543 1339.8418,1331.5918 1339.6043,1331.8763 1339.4256,1332.1933 1339.3146,1332.5271 1339.277,1332.8609 1339.3146,1333.1779 1339.4256,1333.4623 1339.6043,1333.6998 1339.8418,1333.8785 1340.1262,1333.9895 1340.4432,1334.0271 1340.777,1334.0271 1349.277,1347.1271 1349.277,1347.1271 1343.277,1349.6271 1343.277,1349.6271 1325.7903,1354.0271 1314.5628,1354.0271 1303.5591,1351.1631 1300.6952,1351.0042 1300.4881,1350.9043 1300.2469,1350.8702 1299.9881,1350.9043 1299.7293,1351.0042 1299.4881,1351.1631 1299.281,1359.0271 1291.417,1359.0271 1218.277,1349.6271 1208.877,1359.0271 1199.477,1359.0271 255.277,1349.6271 245.877,1359.0271 236.477,1359.0271 -226.6035,1348.8271 -226.6035,1348.8271 -294.3228,1331.5271 -294.3228,1331.5271 -323.3228,1333.8271 -323.3228,1333.8271 -349.3228,925.2271 -349.3228)))", poly);

    std::cout << std::boolalpha
        << "is polygon valid? " << bg::is_valid(poly)
        << std::endl << std::endl;

    double amount = 0.5;
    GPolygon buffered_poly = apply_buffer(poly, amount);

	std::cout << "buffering polygon of " << amount << " ..." << std::endl;

    std::cout << "is polygon empty? " << std::boolalpha << boost::geometry::is_empty(buffered_poly) << std::endl;
}

Output is:

Using Boost 1.89.0
is polygon valid? true

buffering polygon of 0.5 ...
is polygon empty? true

gastald88 avatar Sep 10 '25 15:09 gastald88