# Geometry :

Subject: [geometry] unexpected results from Boost.Geometry expand()
From: Brook Milligan (brook_at_[hidden])
Date: 2018-06-27 15:53:17

I am testing my understanding of the Boost.Geometry expand() function but am getting unexpected results.

The program below produces the following output:

((0, 0), (5, 5))
((0, 0), (5, 5))
((-180, 0), (180, 5))
((-3.14159, 0), (3.14159, 5))

The first line basically recreates the documented example. The second does the same with using double as the coordinate type.

The third and fourth lines are unexpected. The only difference between the second and third/fourth is the change of coordinate system from cartesian to geographic. Why should the x coordinate be expanded to the entire possible range, instead of the expected [0,5]?

I would greatly appreciate any input that will help me understand what is occurring.

Thanks a lot.

Cheers,
Brook

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/expand.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <iostream>

// XXX -- default template parameters correspond to the Boost.Geometry
// example; see
// https://www.boost.org/doc/libs/1_67_0/libs/geometry/doc/html/geometry/reference/algorithms/expand/expand_2.html
//
template < typename Coordinate = short int
, typename CS = boost::geometry::cs::cartesian
>
struct expand_example
{
static void apply ()
{
using point_type = boost::geometry::model::d2::point_xy<Coordinate,CS>;
using box_type = boost::geometry::model::box<point_type>;

using boost::geometry::expand;

box_type box = boost::geometry::make_inverse<box_type>();

expand(box, point_type{0,0});
expand(box, point_type{1,2});
expand(box, point_type{5,4});
expand(box, boost::geometry::make<box_type>(3,3,5,5));

std::cout << boost::geometry::dsv(box) << std::endl;
}
};

int main ()
{
using namespace boost::geometry;
expand_example<>::apply();
expand_example<double,cs::cartesian>::apply();
expand_example<double,cs::geographic<degree>>::apply();