Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80415 - in trunk: boost/polygon libs/polygon/test
From: sydorchuk.andriy_at_[hidden]
Date: 2012-09-05 18:16:39


Author: asydorchuk
Date: 2012-09-05 18:16:38 EDT (Wed, 05 Sep 2012)
New Revision: 80415
URL: http://svn.boost.org/trac/boost/changeset/80415

Log:
Polygon: adding voronoi_diagram unit test; updating rot_prev/rot_next behavior for infinite edges.
Added:
   trunk/libs/polygon/test/voronoi_diagram_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/polygon/voronoi_diagram.hpp | 8 ++++----
   trunk/libs/polygon/test/Jamfile.v2 | 1 +
   trunk/libs/polygon/test/voronoi_builder_test.cpp | 38 +++++++++++++++++++++++++++-----------
   3 files changed, 32 insertions(+), 15 deletions(-)

Modified: trunk/boost/polygon/voronoi_diagram.hpp
==============================================================================
--- trunk/boost/polygon/voronoi_diagram.hpp (original)
+++ trunk/boost/polygon/voronoi_diagram.hpp 2012-09-05 18:16:38 EDT (Wed, 05 Sep 2012)
@@ -197,19 +197,19 @@
   // Returns a pointer to the rotation next edge
   // over the starting point of the half-edge.
   voronoi_edge_type* rot_next() {
- return (vertex_) ? prev_->twin() : NULL;
+ return prev_->twin();
   }
   const voronoi_edge_type* rot_next() const {
- return (vertex_) ? prev_->twin() : NULL;
+ return prev_->twin();
   }
 
   // Returns a pointer to the rotation prev edge
   // over the starting point of the half-edge.
   voronoi_edge_type* rot_prev() {
- return (vertex_) ? twin_->next() : NULL;
+ return twin_->next();
   }
   const voronoi_edge_type* rot_prev() const {
- return (vertex_) ? twin_->next() : NULL;
+ return twin_->next();
   }
 
   // Returns true if the edge is finite (segment, parabolic arc).

Modified: trunk/libs/polygon/test/Jamfile.v2
==============================================================================
--- trunk/libs/polygon/test/Jamfile.v2 (original)
+++ trunk/libs/polygon/test/Jamfile.v2 2012-09-05 18:16:38 EDT (Wed, 05 Sep 2012)
@@ -26,6 +26,7 @@
     :
         [ run voronoi_builder_test.cpp ]
         [ run voronoi_ctypes_test.cpp ]
+ [ run voronoi_diagram_test.cpp ]
         [ run voronoi_geometry_type_test.cpp ]
         [ run voronoi_predicates_test.cpp ]
         [ run voronoi_robust_fpt_test.cpp ]

Modified: trunk/libs/polygon/test/voronoi_builder_test.cpp
==============================================================================
--- trunk/libs/polygon/test/voronoi_builder_test.cpp (original)
+++ trunk/libs/polygon/test/voronoi_builder_test.cpp 2012-09-05 18:16:38 EDT (Wed, 05 Sep 2012)
@@ -27,9 +27,9 @@
 typedef vd_type::const_vertex_iterator const_vertex_iterator;
 
 #define CHECK_OUTPUT_SIZE(output, cells, vertices, edges) \
- BOOST_CHECK(output.num_cells() == cells); \
- BOOST_CHECK(output.num_vertices() == vertices); \
- BOOST_CHECK(output.num_edges() == edges)
+ BOOST_CHECK_EQUAL(output.num_cells(), (std::size_t)cells); \
+ BOOST_CHECK_EQUAL(output.num_vertices(), (std::size_t)vertices); \
+ BOOST_CHECK_EQUAL(output.num_edges(), (std::size_t)edges)
 
 #define VERIFY_OUTPUT(output) \
     BOOST_CHECK(voronoi_test_helper::verify_output(output, \
@@ -79,13 +79,13 @@
 
   BOOST_CHECK(edge1_1->next() == edge1_1);
   BOOST_CHECK(edge1_1->prev() == edge1_1);
- BOOST_CHECK(edge1_1->rot_next() == NULL);
- BOOST_CHECK(edge1_1->rot_prev() == NULL);
+ BOOST_CHECK(edge1_1->rot_next() == edge1_2);
+ BOOST_CHECK(edge1_1->rot_prev() == edge1_2);
 
   BOOST_CHECK(edge1_2->next() == edge1_2);
   BOOST_CHECK(edge1_2->prev() == edge1_2);
- BOOST_CHECK(edge1_2->rot_next() == NULL);
- BOOST_CHECK(edge1_2->rot_prev() == NULL);
+ BOOST_CHECK(edge1_2->rot_next() == edge1_1);
+ BOOST_CHECK(edge1_2->rot_prev() == edge1_1);
 }
 
 // Sites: (0, 0), (1, 1), (2, 2).
@@ -111,11 +111,14 @@
   BOOST_CHECK(edge2_1->twin() == edge2_2 && edge2_2->twin() == edge2_1);
 
   BOOST_CHECK(edge1_1->next() == edge1_1 && edge1_1->prev() == edge1_1);
- BOOST_CHECK(edge1_1->rot_next() == NULL && edge1_1->rot_prev() == NULL);
- BOOST_CHECK(edge1_2->rot_next() == NULL && edge1_2->rot_prev() == NULL);
- BOOST_CHECK(edge2_1->rot_next() == NULL && edge2_1->rot_prev() == NULL);
+ BOOST_CHECK(edge1_2->next() == edge2_1 && edge1_2->prev() == edge2_1);
+ BOOST_CHECK(edge2_1->next() == edge1_2 && edge2_1->prev() == edge1_2);
   BOOST_CHECK(edge2_2->next() == edge2_2 && edge2_2->prev() == edge2_2);
- BOOST_CHECK(edge2_2->rot_next() == NULL && edge2_2->rot_prev() == NULL);
+
+ BOOST_CHECK(edge1_1->rot_next() == edge1_2 && edge1_1->rot_prev() == edge2_1);
+ BOOST_CHECK(edge1_2->rot_next() == edge2_2 && edge1_2->rot_prev() == edge1_1);
+ BOOST_CHECK(edge2_1->rot_next() == edge1_1 && edge2_1->rot_prev() == edge2_2);
+ BOOST_CHECK(edge2_2->rot_next() == edge2_1 && edge2_2->rot_prev() == edge1_2);
 
   BOOST_CHECK(edge1_2->next() == edge2_1 && edge1_2->prev() == edge2_1);
   BOOST_CHECK(edge2_1->next() == edge1_2 && edge2_1->prev() == edge1_2);
@@ -169,6 +172,10 @@
   BOOST_CHECK(edge1_1->rot_next() == edge3_1);
   BOOST_CHECK(edge3_1->rot_next() == edge2_1);
   BOOST_CHECK(edge2_1->rot_next() == edge1_1);
+
+ BOOST_CHECK(edge1_2->rot_next() == edge2_2);
+ BOOST_CHECK(edge2_2->rot_next() == edge3_2);
+ BOOST_CHECK(edge3_2->rot_next() == edge1_2);
 }
 
 // Sites: (0, 1), (2, 0), (2, 4).
@@ -219,6 +226,10 @@
   BOOST_CHECK(edge1_1->rot_next() == edge3_1);
   BOOST_CHECK(edge3_1->rot_next() == edge2_1);
   BOOST_CHECK(edge2_1->rot_next() == edge1_1);
+
+ BOOST_CHECK(edge1_2->rot_next() == edge2_2);
+ BOOST_CHECK(edge2_2->rot_next() == edge3_2);
+ BOOST_CHECK(edge3_2->rot_next() == edge1_2);
 }
 
 // Sites: (0, 0), (0, 1), (1, 0), (1, 1).
@@ -282,6 +293,11 @@
   BOOST_CHECK(edge4_1->rot_next() == edge3_1);
   BOOST_CHECK(edge3_1->rot_next() == edge2_1);
   BOOST_CHECK(edge2_1->rot_next() == edge1_1);
+
+ BOOST_CHECK(edge1_2->rot_next() == edge2_2);
+ BOOST_CHECK(edge2_2->rot_next() == edge3_2);
+ BOOST_CHECK(edge3_2->rot_next() == edge4_2);
+ BOOST_CHECK(edge4_2->rot_next() == edge1_2);
 }
 
 #ifdef NDEBUG

Added: trunk/libs/polygon/test/voronoi_diagram_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/polygon/test/voronoi_diagram_test.cpp 2012-09-05 18:16:38 EDT (Wed, 05 Sep 2012)
@@ -0,0 +1,112 @@
+// Boost.Polygon library voronoi_diagram_test.cpp file
+
+// Copyright Andrii Sydorchuk 2010-2012.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#define BOOST_TEST_MODULE voronoi_diagram_test
+#include <boost/test/test_case_template.hpp>
+
+#include <boost/polygon/voronoi_diagram.hpp>
+#include <boost/polygon/voronoi_geometry_type.hpp>
+using namespace boost::polygon;
+
+typedef voronoi_cell<double> voronoi_cell_type;
+typedef voronoi_vertex<double> voronoi_vertex_type;
+typedef voronoi_edge<double> voronoi_edge_type;
+typedef voronoi_diagram<double> voronoi_diagram_type;
+
+BOOST_AUTO_TEST_CASE(voronoi_cell_test) {
+ voronoi_cell_type cell(1, SOURCE_CATEGORY_INITIAL_SEGMENT, NULL);
+ cell.color(27);
+ BOOST_CHECK(!cell.contains_point());
+ BOOST_CHECK(cell.contains_segment());
+ BOOST_CHECK(cell.is_degenerate());
+ BOOST_CHECK(cell.source_index() == 1);
+ BOOST_CHECK(cell.source_category() == SOURCE_CATEGORY_INITIAL_SEGMENT);
+ BOOST_CHECK(cell.incident_edge() == NULL);
+ BOOST_CHECK(cell.color() == 27);
+
+ voronoi_edge_type edge(true, true);
+ cell.incident_edge(&edge);
+ BOOST_CHECK(!cell.is_degenerate());
+ BOOST_CHECK(cell.incident_edge() == &edge);
+}
+
+BOOST_AUTO_TEST_CASE(voronoi_vertex_test) {
+ voronoi_vertex_type vertex(1, 2, NULL);
+ vertex.color(27);
+ BOOST_CHECK(vertex.is_degenerate());
+ BOOST_CHECK(vertex.x() == 1);
+ BOOST_CHECK(vertex.y() == 2);
+ BOOST_CHECK(vertex.incident_edge() == NULL);
+ BOOST_CHECK(vertex.color() == 27);
+
+ voronoi_edge_type edge(true, true);
+ vertex.incident_edge(&edge);
+ BOOST_CHECK(!vertex.is_degenerate());
+ BOOST_CHECK(vertex.incident_edge() == &edge);
+}
+
+BOOST_AUTO_TEST_CASE(voronoi_edge_test) {
+ voronoi_edge_type edge1(false, false);
+ edge1.color(13);
+ BOOST_CHECK(!edge1.is_primary());
+ BOOST_CHECK(edge1.is_secondary());
+ BOOST_CHECK(!edge1.is_linear());
+ BOOST_CHECK(edge1.is_curved());
+ BOOST_CHECK(!edge1.is_finite());
+ BOOST_CHECK(edge1.is_infinite());
+ BOOST_CHECK(edge1.color() == 13);
+
+ voronoi_edge_type edge2(true, true);
+ edge2.color(14);
+ BOOST_CHECK(edge2.is_primary());
+ BOOST_CHECK(!edge2.is_secondary());
+ BOOST_CHECK(edge2.is_linear());
+ BOOST_CHECK(!edge2.is_curved());
+ BOOST_CHECK(!edge2.is_finite());
+ BOOST_CHECK(edge2.is_infinite());
+ BOOST_CHECK(edge2.color() == 14);
+
+ edge1.twin(&edge2);
+ edge2.twin(&edge1);
+ BOOST_CHECK(edge1.twin() == &edge2);
+ BOOST_CHECK(edge2.twin() == &edge1);
+
+ edge1.next(&edge2);
+ edge1.prev(&edge2);
+ edge2.next(&edge1);
+ edge2.prev(&edge1);
+ BOOST_CHECK(edge1.next() == &edge2);
+ BOOST_CHECK(edge1.prev() == &edge2);
+ BOOST_CHECK(edge1.rot_next() == &edge1);
+ BOOST_CHECK(edge1.rot_prev() == &edge1);
+
+ voronoi_cell_type cell(1, SOURCE_CATEGORY_INITIAL_SEGMENT, NULL);
+ edge1.cell(&cell);
+ BOOST_CHECK(edge1.cell() == &cell);
+
+ voronoi_vertex_type vertex0(1, 2, NULL);
+ edge1.vertex0(&vertex0);
+ BOOST_CHECK(edge1.vertex0() == &vertex0);
+
+ voronoi_vertex_type vertex1(2, 1, NULL);
+ edge1.vertex1(&vertex1);
+ BOOST_CHECK(edge1.vertex1() == &vertex1);
+
+ BOOST_CHECK(edge1.is_finite());
+ BOOST_CHECK(edge2.is_finite());
+}
+
+BOOST_AUTO_TEST_CASE(voronoi_diagram_test) {
+ voronoi_diagram_type vd;
+ BOOST_CHECK(vd.num_cells() == 0);
+ BOOST_CHECK(vd.num_vertices() == 0);
+ BOOST_CHECK(vd.num_edges() == 0);
+ BOOST_CHECK(vd.num_half_edges() == 0);
+ vd.clear();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk