-1

How transfer data between structures like geometry::point and geometry::box to simple float array?

Only way that i have found is get method. For each transfer i am need to use this?

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <iostream>
#include <vector>

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

typedef bg::model::point<float, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;

int main()
{
    box B(point(10,10), point(20,20));
    float VertexQuad[4][2];

    VertexQuad[0][0] = bg::get<bg::min_corner, 0>(B);
    VertexQuad[0][1] = bg::get<bg::min_corner, 1>(B);
    VertexQuad[1][0] = bg::get<bg::min_corner, 0>(B);
    VertexQuad[1][1] = bg::get<bg::max_corner, 1>(B);
    VertexQuad[2][0] = bg::get<bg::max_corner, 0>(B);
    VertexQuad[2][1] = bg::get<bg::max_corner, 1>(B);
    VertexQuad[3][0] = bg::get<bg::max_corner, 0>(B);
    VertexQuad[3][1] = bg::get<bg::min_corner, 1>(B);

    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
SomeCoder
  • 21
  • 4

1 Answers1

0

Your way of doing it is not wrong, but you can simplify the process by creating a struct, with a boxvariable in it's constructor:

struct VertexQuad
{
    float array[2][2];

    VertexQuad(box B)
    {
      array[0][0] = bg::get<bg::min_corner, 0>(B);
      array[0][1] = bg::get<bg::min_corner, 1>(B);
      array[1][0] = bg::get<bg::max_corner, 0>(B);
      array[1][1] = bg::get<bg::max_corner, 1>(B);
    };
};

This way, you don't have to assign the values each time you want to use the values with an array.

EDIT: boxonly has 2 corners (2 points) -> your array size should be float array[2][2] and you can remove the other assignments.

SAlex
  • 361
  • 2
  • 10