Opened 8 years ago

Closed 8 years ago

#10562 closed Bugs (fixed)

Wrong number of Points returned by convex_hull()

Reported by: awulkiew Owned by: Barend Gehrels
Milestone: Boost 1.57.0 Component: geometry
Version: Boost Development Trunk Severity: Problem
Keywords: convex_hull Cc:

Description

If a valid Polygon is generated by a convex_hull() function, the Points of a closed Polygon are always returned (duplicated first Point at the end of a Range), even if an open Polygon is passed as the output.

Example:

    namespace bg = boost::geometry;

    typedef bg::model::point<double, 2, bg::cs::cartesian> point;
    typedef bg::model::polygon<point, true, false> polygon;
    typedef bg::model::polygon<point, true, true> polygon_closed;
    typedef bg::model::multi_point<point> multi_point;

    multi_point mp;
    bg::append(mp, point(1, 1));
    bg::append(mp, point(2, 2));
    bg::append(mp, point(2, 1));
    bg::append(mp, point(1, 2));

    polygon res;
    polygon_closed res_c;

    bg::convex_hull(mp, res);
    std::cout << bg::closure<polygon>::value << std::endl;
    std::cout << res.outer().size() << std::endl;
    std::cout << bg::wkt(res) << std::endl;

    bg::convex_hull(mp, res_c);
    std::cout << bg::closure<polygon_closed>::value << std::endl;
    std::cout << res_c.outer().size() << std::endl;
    std::cout << bg::wkt(res_c) << std::endl;

Output:

0
5
POLYGON((1 1,1 2,2 2,2 1,1 1))
1
5
POLYGON((1 1,1 2,2 2,2 1,1 1))

On the other hand when an invalid Polygon is generated, a convex hull of a 1-Point MultiPoint or 2-Point Linestring always 3-Point Polygon is generated. The smallest number of Points of a valid, closed Polygon should be 4. The generated Polygon isn't valid but the number of Points could be consistent.

Example:

    multi_point mp;
    bg::append(mp, point(1, 1));

Output:

0
3
POLYGON((1 1,1 1,1 1))

Example:

    multi_point mp;
    bg::append(mp, point(1, 1));
    bg::append(mp, point(2, 2));

Output:

0
3
POLYGON((1 1,2 2,1 1))

Change History (1)

comment:1 by awulkiew, 8 years ago

Milestone: To Be DeterminedBoost 1.57.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.