mirror of
https://github.com/boostorg/polygon.git
synced 2026-01-28 07:22:29 +00:00
Polygon: running new test headers over c++lint checker.
[SVN r80437]
This commit is contained in:
@@ -11,45 +11,51 @@
|
||||
#include <vector>
|
||||
|
||||
#include <boost/polygon/voronoi.hpp>
|
||||
using namespace boost::polygon;
|
||||
using boost::polygon::voronoi_builder;
|
||||
using boost::polygon::voronoi_diagram;
|
||||
|
||||
#include "voronoi_visual_utils.hpp"
|
||||
|
||||
struct Point {
|
||||
int a;
|
||||
int b;
|
||||
Point (int x, int y) : a(x), b(y) {}
|
||||
Point(int x, int y) : a(x), b(y) {}
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
Point p0;
|
||||
Point p1;
|
||||
Segment (int x1, int y1, int x2, int y2) : p0(x1, y1), p1(x2, y2) {}
|
||||
Segment(int x1, int y1, int x2, int y2) : p0(x1, y1), p1(x2, y2) {}
|
||||
};
|
||||
|
||||
namespace boost {
|
||||
namespace polygon {
|
||||
|
||||
template <>
|
||||
struct geometry_concept<Point> { typedef point_concept type; };
|
||||
|
||||
struct geometry_concept<Point> {
|
||||
typedef point_concept type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct point_traits<Point> {
|
||||
typedef int coordinate_type;
|
||||
|
||||
static inline coordinate_type get(const Point& point, orientation_2d orient) {
|
||||
static inline coordinate_type get(
|
||||
const Point& point, orientation_2d orient) {
|
||||
return (orient == HORIZONTAL) ? point.a : point.b;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct geometry_concept<Segment> { typedef segment_concept type; };
|
||||
struct geometry_concept<Segment> {
|
||||
typedef segment_concept type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct segment_traits<Segment> {
|
||||
typedef int coordinate_type;
|
||||
typedef Point point_type;
|
||||
|
||||
|
||||
static inline point_type get(const Segment& segment, direction_1d dir) {
|
||||
return dir.to_int() ? segment.p1 : segment.p0;
|
||||
}
|
||||
@@ -86,13 +92,13 @@ int iterate_primary_edges2(const voronoi_diagram<double> &vd) {
|
||||
}
|
||||
|
||||
// Traversing Voronoi edges using vertex iterator.
|
||||
// As opposite to the above two functions this one will not iterate through edges
|
||||
// without finite endpoints and will iterate only once through edges with single
|
||||
// finite endpoint.
|
||||
// As opposite to the above two functions this one will not iterate through
|
||||
// edges without finite endpoints and will iterate only once through edges
|
||||
// with single finite endpoint.
|
||||
int iterate_primary_edges3(const voronoi_diagram<double> &vd) {
|
||||
int result = 0;
|
||||
for (voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin();
|
||||
it != vd.vertices().end(); ++it) {
|
||||
for (voronoi_diagram<double>::const_vertex_iterator it =
|
||||
vd.vertices().begin(); it != vd.vertices().end(); ++it) {
|
||||
const voronoi_diagram<double>::vertex_type& vertex = *it;
|
||||
const voronoi_diagram<double>::edge_type* edge = vertex.incident_edge();
|
||||
// This is convenient way to iterate edges around Voronoi vertex.
|
||||
@@ -116,21 +122,26 @@ int main() {
|
||||
|
||||
// Construction of the Voronoi Diagram.
|
||||
voronoi_diagram<double> vd;
|
||||
construct_voronoi(points.begin(), points.end(), segments.begin(), segments.end(), &vd);
|
||||
construct_voronoi(points.begin(), points.end(),
|
||||
segments.begin(), segments.end(),
|
||||
&vd);
|
||||
|
||||
// Traversing Voronoi Graph.
|
||||
{
|
||||
printf("Traversing Voronoi graph.\n");
|
||||
printf("Number of visited primary edges using edge iterator: %d\n", iterate_primary_edges1(vd));
|
||||
printf("Number of visited primary edges using cell iterator: %d\n", iterate_primary_edges2(vd));
|
||||
printf("Number of visited primary edges using vertex iterator: %d\n", iterate_primary_edges3(vd));
|
||||
printf("Number of visited primary edges using edge iterator: %d\n",
|
||||
iterate_primary_edges1(vd));
|
||||
printf("Number of visited primary edges using cell iterator: %d\n",
|
||||
iterate_primary_edges2(vd));
|
||||
printf("Number of visited primary edges using vertex iterator: %d\n",
|
||||
iterate_primary_edges3(vd));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// Using color member of the Voronoi primitives to store the average number of edges
|
||||
// around each cell (including secondary edges).
|
||||
// Using color member of the Voronoi primitives to store the average number
|
||||
// of edges around each cell (including secondary edges).
|
||||
{
|
||||
printf("Number of edges (including secondary edges) around the Voronoi cells:\n");
|
||||
printf("Number of edges (including secondary) around the Voronoi cells:\n");
|
||||
for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin();
|
||||
it != vd.edges().end(); ++it) {
|
||||
std::size_t cnt = it->cell()->color();
|
||||
@@ -142,6 +153,6 @@ int main() {
|
||||
}
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user