c02_custom_box_example.cpp

Besides custom points, custom boxes are possible as shown in this example.

    //Boost.Geometry(akaGGL,GenericGeometryLibrary)

    //Copyright(c)2007-2012BarendGehrels,Amsterdam,theNetherlands.
    //Copyright(c)2008-2012BrunoLalande,Paris,France.
    //Copyright(c)2009-2012MateuszLoskot,London,UK.

    //Use,modificationanddistributionissubjecttotheBoostSoftwareLicense,
    //Version1.0.(SeeaccompanyingfileLICENSE_1_0.txtorcopyat
    //http://www.boost.org/LICENSE_1_0.txt)
    //
    //CustomBoxExample

    #include<iostream>

    #include<boost/geometry/algorithms/make.hpp>
    #include<boost/geometry/algorithms/within.hpp>
    #include<boost/geometry/geometries/register/point.hpp>
    #include<boost/geometry/geometries/register/box.hpp>
    #include<boost/geometry/strategies/strategies.hpp>
    #include<boost/geometry/io/dsv/write.hpp>

    structmy_point
    {
    doublex,y;
    };

    structmy_int_point
    {
    intx,y;
    };

    structmy_box
    {
    my_pointll,ur;
    };

    structmy_box_ltrb
    {
    intleft,top,right,bottom;
    };

    structmy_box_4
    {
    doublecoors[4];
    };

    template<typenameP>
    structmy_box_t
    {
    Pll,ur;
    };

    BOOST_GEOMETRY_REGISTER_POINT_2D(my_point,double,cs::cartesian,x,y)
    BOOST_GEOMETRY_REGISTER_POINT_2D(my_int_point,int,cs::cartesian,x,y)
    BOOST_GEOMETRY_REGISTER_BOX(my_box,my_point,ll,ur)
    BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED(my_box_t,ll,ur)
    BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_ltrb,my_int_point,left,top,right,bottom)
    BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box_4,my_point,coors[0],coors[1],coors[2],coors[3])

    intmain()
    {
    my_pointp=boost::geometry::make<my_point>(3.5,3.5);
    my_boxb=boost::geometry::make<my_box>(0,0,2,2);
    my_box_ltrbb1=boost::geometry::make<my_box_ltrb>(0,0,3,3);
    my_box_4b4=boost::geometry::make<my_box_4>(0,0,4,4);
    my_box_t<my_point>bt=boost::geometry::make<my_box_t<my_point>>(0,0,5,5);

    std::cout<<boost::geometry::dsv(p)<<"IN"<<boost::geometry::dsv(b)
    <<":"<<int(boost::geometry::within(p,b))<<std::endl;
    std::cout<<boost::geometry::dsv(p)<<"IN"<<boost::geometry::dsv(b1)
    <<":"<<int(boost::geometry::within(p,b1))<<std::endl;
    std::cout<<boost::geometry::dsv(p)<<"IN"<<boost::geometry::dsv(b4)
    <<":"<<int(boost::geometry::within(p,b4))<<std::endl;
    std::cout<<boost::geometry::dsv(p)<<"IN"<<boost::geometry::dsv(bt)
    <<":"<<int(boost::geometry::within(p,bt))<<std::endl;

    return0;
    }