|
Geometry : |
Subject: Re: [geometry] unexpected results from Boost.Geometry expand()
From: Vissarion Fisikopoulos (fisikop_at_[hidden])
Date: 2018-06-28 09:08:19
Hello,
On 27 June 2018 at 18:53, Brook Milligan via Geometry
<geometry_at_[hidden]> wrote:
> 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.
The problem is in the initialization of the box, if you initialize it
with your first point,
e.g. box_type box = boost::geometry::make<box_type>(0,0,0,0);
then the results are as expected.
Best,
Vissarion.
> 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();
> expand_example<double,cs::geographic<radian>>::apply();
> }
>
>
> _______________________________________________
> Geometry mailing list
> Geometry_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/geometry
Geometry list run by mateusz at loskot.net