Skip to content

Instantly share code, notes, and snippets.

@AhiyaHiya
Created June 1, 2017 13:44
Show Gist options
  • Select an option

  • Save AhiyaHiya/a1f956d7c61cb8e85e74fa00ee7b13e6 to your computer and use it in GitHub Desktop.

Select an option

Save AhiyaHiya/a1f956d7c61cb8e85e74fa00ee7b13e6 to your computer and use it in GitHub Desktop.
Coordinates, geometry using Boost Geometry
// Jaime O. Rios
#include <boost/algorithm/clamp.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <iostream>
namespace bg = boost::geometry;
using point_t = bg::model::point< int32_t, 2, bg::cs::cartesian >;
using point2d_t = bg::model::d2::point_xy< int32_t >;
using box_t = bg::model::box< point2d_t >;
auto create_a_box_and_print_corner_coordinates()
{
auto rect = box_t{point2d_t{0, 0}, point2d_t{100, 100}};
bg::set< bg::min_corner, 0 >(rect, 10);
bg::set< bg::min_corner, 1 >(rect, 11);
rect.max_corner().set< 0 >(90);
rect.max_corner().set< 1 >(91);
const auto min_x = bg::get< bg::min_corner, 0 >(rect);
const auto min_y = bg::get< bg::min_corner, 1 >(rect);
const auto max_x = rect.max_corner().get< 0 >();
const auto max_y = rect.max_corner().get< 1 >();
std::cout << min_x << ", " << min_y << ", " << max_x << ", " << max_y << std::endl;
}
int main(int argc, const char* argv[])
{
create_a_box_and_print_corner_coordinates()
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment