以下是一些个人使用的C++ boost::geometry模块中的linestring 向量测试案例
包括了boost::geometry中的函数、linestring的函数以及部分STL函数
#pragma once
#include <iostream>
#include <string>
#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/assign.hpp>
#include <boost/foreach.hpp>
#include <vector>
namespace bg = boost::geometry;
namespace bga = boost::assign;
using namespace std;
using namespace bga;
typedef bg::model::d2::point_xy<int> BGPoint;
typedef bg::model::linestring<BGPoint> BGVector;
// linestring 测试使用
namespace linestringTest {
void test_init();
void test_point();
void test_append();
void test_add();
void test_size();
void test_distance();
void test_output_vector();
void test_foreach();
void test_namespace_assign();
void test_reverse();
void test_length();
void test_delete_insert();
void test_simplify();
void test_foreach_point();
void test_intersects();
void test_output_as_json();
void test_init() {
BGVector vector{ {0, 1}, {2, 1} };
int len = bg::length(vector);
cout << "length: " << len << endl;
}
void test_point() {
BGPoint point(1, 2);
cout << point.x() << " " << point.y() << endl;
}
void test_append() {
BGVector vector;
// 一条经过三个点的折线
bg::append(vector, BGPoint(0, 0));
bg::append(vector, BGPoint(1, 1));
bg::append(vector, BGPoint(2, 0));
double len = bg::length(vector);
cout << "长度为: " << len << endl;
}
void test_add() {
BGVector vector;
// namespace boost::assign 中包含的运算符 +=
vector += BGPoint(1, 1);
vector += BGPoint(1, 3), BGPoint(3, 3);
double len = bg::length(vector);
// dsv()
cout << "add--长度为: " << len << endl;
cout << "dsv(输出所有点): " << bg::dsv(vector) << endl;
}
void test_size() {
BGVector vector;
bg::append(vector, BGPoint(1, 1));
bg::append(vector, BGPoint(2, 2));
bg::append(vector, BGPoint(2, 3));
bg::append(vector, BGPoint(3, 4));
// linestring.size : 输出点(BGPoint)的个数
cout << "linestring.size : " << vector.size() << endl;
cout << "boost::size : " << boost::size(