Opened 12 months ago

#13353 new Bugs

Distance segment-box wrong result for spherical CS

Reported by: Vissarion Fisikopoulos <fisikop@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

The distance algorithm for segment-box for spherical CS does not treat correctly some cases. For example when the segment endpoints are not inside the box but the segment intersects it (because of curvature, segment follow a geodesic/great circle but box horizontal segment not). An example code follows:

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

namespace bg = boost::geometry;

template <typename point, typename CT>
void test_all_geometry_types(CT radius_multiplier)
{
    bg::model::segment<point> s;
    bg::model::box<point> b;

    std::cout.precision(15);

    {
        bg::read_wkt("SEGMENT(10 9.99, 20 9.99)", s);
        bg::read_wkt("BOX(10 10, 20 20)", b);

        std::cout << "dist=" << bg::distance(b, s) * radius_multiplier  << std::endl;
        std::cout << "disj=" << bg::disjoint(b, s) << std::endl;
    }
    {
        bg::read_wkt("SEGMENT(10 10, 20 10)", s);
        bg::read_wkt("BOX(10 10, 20 20)", b);

        std::cout << "dist=" << bg::distance(b, s) * radius_multiplier  << std::endl;
        std::cout << "disj=" << bg::disjoint(b, s) << std::endl;
    }
}

int main()
{
    typedef double CT;

    std::cout << "Cartesian" << std::endl;
    typedef bg::model::point<CT, 2, bg::cs::cartesian > cpoint;
    test_all_geometry_types<cpoint>(1);

    std::cout << "Spherical" << std::endl;
    typedef bg::model::point<CT, 2, bg::cs::spherical_equatorial<bg::degree> > spoint;
    test_all_geometry_types<spoint>(bg::formula::mean_radius<CT>(bg::srs::spheroid<CT>()));

    return 0;
}

the output in my system (i.e. gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)) is

Cartesian
dist=0.00999999999999979
disj=1
dist=0
disj=0
Spherical
dist=63710.0877141492
disj=0
dist=0
disj=0

the case where dist=63710.0877141492 and disj=0 is wrong since the objects intersect but the distance is not 0.

Change History (0)

Note: See TracTickets for help on using tickets.