Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

model::box

Class box: defines a box made of two describing points.

Description

Box is always described by a min_corner() and a max_corner() point. If another rectangle is used, use linear_ring or polygon.

Model of

Box Concept

Synopsis

template<typename Point>
class model::box
{
  // ...
};

Template parameter(s)

Parameter

Description

typename Point

point type. The box takes a point type as template parameter. The point type can be any point type. It can be 2D but can also be 3D or more dimensional. The box can also take a latlong point type as template parameter.

Constructor(s)

Function

Description

Parameters

box()

Default constructor, no initialization.

template<typename P, std::enable_if_t< ! std::is_copy_constructible< P >::value, int >>
box(Point const & min_corner, Point const & max_corner)

Constructor taking the minimum corner point and the maximum corner point.

Point const &: min_corner:

Point const &: max_corner:

template<typename P, std::enable_if_t< std::is_copy_constructible< P >::value, int >>
box(Point const & min_corner, Point const & max_corner)

Constructor taking the minimum corner point and the maximum corner point.

Point const &: min_corner:

Point const &: max_corner:

Member Function(s)

Function

Description

Parameters

Returns

constexpr Point const & min_corner()

constexpr Point const & max_corner()

Point & min_corner()

Point & max_corner()

Header

Either

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

Or

#include <boost/geometry/geometries/box.hpp>

Examples

Declaration and use of the Boost.Geometry model::box, modelling the Box Concept

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

namespace bg = boost::geometry;

int main()
{
    typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
    typedef bg::model::box<point_t> box_t;

    box_t box1; 1
    box_t box2(point_t(0.0, 0.0), point_t(5.0, 5.0)); 2
    box_t box3{{0.0, 0.0}, {5.0, 5.0}}; 3

    bg::set<bg::min_corner, 0>(box1, 1.0); 4
    bg::set<bg::min_corner, 1>(box1, 2.0);
    box1.max_corner().set<0>(3.0); 5
    box1.max_corner().set<1>(4.0);

    double min_x = bg::get<bg::min_corner, 0>(box1); 6
    double min_y = bg::get<bg::min_corner, 1>(box1);
    double max_x = box1.max_corner().get<0>(); 7
    double max_y = box1.max_corner().get<1>();

    std::cout << min_x << ", " << min_y << ", " << max_x << ", " << max_y << std::endl;

    return 0;
}

1

Default-construct a box.

2

Construct, assigning min and max corner point.

3

Construct, using C++11 unified initialization syntax.

4

Set a coordinate, generic.

5

Set a coordinate, class-specific (Note: prefer bg::set()).

6

Get a coordinate, generic.

7

Get a coordinate, class-specific (Note: prefer bg::get()).

Output:

1, 2, 3, 4

PrevUpHomeNext