Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71209 - in trunk/libs/geometry: doc/src/examples/algorithms test/algorithms test/algorithms/detail
From: barend.gehrels_at_[hidden]
Date: 2011-04-12 14:29:40


Author: barendgehrels
Date: 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
New Revision: 71209
URL: http://svn.boost.org/trac/boost/changeset/71209

Log:
Changes in test/doc to reflect changes in assign
Added:
   trunk/libs/geometry/doc/src/examples/algorithms/assign.cpp (contents, props changed)
Text files modified:
   trunk/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 | 1
   trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp | 6 +-
   trunk/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp | 2
   trunk/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp | 2
   trunk/libs/geometry/doc/src/examples/algorithms/assign_with_range.cpp | 4
   trunk/libs/geometry/test/algorithms/assign.cpp | 93 ++++++++++++++++++++++++++++++++++-----
   trunk/libs/geometry/test/algorithms/detail/convert.cpp | 2
   7 files changed, 89 insertions(+), 21 deletions(-)

Modified: trunk/libs/geometry/doc/src/examples/algorithms/Jamfile.v2
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -18,6 +18,7 @@
 exe area : area.cpp ;
 exe area_with_strategy : area_with_strategy.cpp ;
 
+exe assign : assign.cpp ;
 exe assign_2d_point : assign_2d_point.cpp ;
 exe assign_3d_point : assign_3d_point.cpp ;
 exe assign_inverse : assign_inverse.cpp ;

Added: trunk/libs/geometry/doc/src/examples/algorithms/assign.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -0,0 +1,61 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// QuickBook Example
+
+// Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
+
+// Use, modification and distribution is subject to 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)
+
+//[assign
+//` Shows how to assign a geometry to another
+
+#include <iostream>
+
+#include <boost/geometry/geometry.hpp>
+#include <boost/geometry/geometries/adapted/tuple_cartesian.hpp>
+
+int main()
+{
+ typedef boost::geometry::model::d2::point_xy<double> point;
+ typedef boost::geometry::model::box<point> box;
+ typedef boost::geometry::model::polygon<point> polygon;
+
+ point p1;
+ box b;
+ boost::geometry::assign_values(p1, 1, 1);
+ boost::geometry::assign_values(b, 1, 1, 2, 2);
+
+ // Assign a box to a polygon (conversion box->poly)
+ polygon p;
+ boost::geometry::assign(b, p);
+
+ // Assign a point to another point type (conversion of point-type)
+ boost::tuple<double, double> p2;
+ boost::geometry::assign(p1, p2);
+
+
+ using boost::geometry::dsv;
+ std::cout
+ << "box: " << dsv(b) << std::endl
+ << "polygon: " << dsv(p) << std::endl
+ << "point: " << dsv(p) << std::endl
+ << "point tuples: " << dsv(p2) << std::endl
+ ;
+
+ return 0;
+}
+
+//]
+
+
+//[assign_output
+/*`
+Output:
+[pre
+box: ((1, 1), (2, 2))
+first: (1, 1)
+second: (2, 2)
+]
+*/
+//]

Modified: trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -23,15 +23,15 @@
 
 int main()
 {
- using boost::geometry::assign;
+ using boost::geometry::assign_values;
 
 
     boost::geometry::model::d2::point_xy<double> p1;
- assign(p1, 1.2345, 2.3456);
+ assign_values(p1, 1.2345, 2.3456);
 
 #if defined(HAVE_TTMATH)
     boost::geometry::model::d2::point_xy<ttmath::Big<1,4> > p2;
- assign(p2, "1.2345", "2.3456"); /*< It is possible to assign coordinates with other types than the coordinate type.
+ assign_values(p2, "1.2345", "2.3456"); /*< It is possible to assign coordinates with other types than the coordinate type.
         For ttmath, you can e.g. conveniently use strings. The advantage is that it then has higher precision, because
         if doubles are used for assignments the double-precision is used.
>*/

Modified: trunk/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -19,7 +19,7 @@
 int main()
 {
     boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> p;
- boost::geometry::assign(p, 1.2345, 2.3456, 3.4567);
+ boost::geometry::assign_values(p, 1.2345, 2.3456, 3.4567);
 
     std::cout << boost::geometry::dsv(p) << std::endl;
 

Modified: trunk/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -23,7 +23,7 @@
     typedef model::segment<point> segment;
 
     segment s;
- assign(s, 1, 1, 2, 2);
+ assign_values(s, 1, 1, 2, 2);
 
     point first, second;
     assign_point_from_index<0>(s, first);

Modified: trunk/libs/geometry/doc/src/examples/algorithms/assign_with_range.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/assign_with_range.cpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign_with_range.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -46,8 +46,8 @@
     ls line1, line2, line3;
 
     line1 = tuple_list_of(0, 0)(2, 3)(4, 0)(6, 3)(8, 0)(10, 3)(12, 0); /*< tuple_list_of is part of Boost.Assign and can be used for Boost.Geometry if points are tuples >*/
- boost::geometry::assign(line2, tuple_list_of(0, 0)(2, 2)(4, 0)(6, 2)(8, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::assign >*/
- boost::geometry::assign(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); /*< Boost.Range adaptors can also be used in boost::geometry::assign >*/
+ boost::geometry::assign_points(line2, tuple_list_of(0, 0)(2, 2)(4, 0)(6, 2)(8, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::assign >*/
+ boost::geometry::assign_points(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); /*< Boost.Range adaptors can also be used in boost::geometry::assign >*/
 
     std::cout << "line 1: " << boost::geometry::dsv(line1) << std::endl;
     std::cout << "line 2: " << boost::geometry::dsv(line2) << std::endl;

Modified: trunk/libs/geometry/test/algorithms/assign.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/assign.cpp (original)
+++ trunk/libs/geometry/test/algorithms/assign.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -14,6 +14,7 @@
 
 #include <geometry_test_common.hpp>
 
+#include <boost/geometry/arithmetic/arithmetic.hpp>
 #include <boost/geometry/algorithms/assign.hpp>
 #include <boost/geometry/algorithms/num_points.hpp>
 
@@ -48,25 +49,25 @@
 {
     bg::model::linestring<Point> line;
 
- // Test assignment of plain array (note that this is only possible if adapted c-array is included!
+ // Test assignment of plain array (note that this is only possible if adapted c-array is included!)
     const double coors[3][2] = { {1, 2}, {3, 4}, {5, 6} };
- bg::assign(line, coors);
+ bg::assign_points(line, coors);
     check_linestring_2d(line);
 
     // Test assignment of point array
     Point points[3];
- bg::assign(points[0], 1, 2);
- bg::assign(points[1], 3, 4);
- bg::assign(points[2], 5, 6);
- bg::assign(line, points);
+ bg::assign_values(points[0], 1, 2);
+ bg::assign_values(points[1], 3, 4);
+ bg::assign_values(points[2], 5, 6);
+ bg::assign_points(line, points);
     check_linestring_2d(line);
 
- // Test assignment of array with different point-type
+ // Test assignment of array with different point-type (tuple adaption should be included)
     boost::tuple<float, float> tuples[3];
     tuples[0] = boost::make_tuple(1, 2);
     tuples[1] = boost::make_tuple(3, 4);
     tuples[2] = boost::make_tuple(5, 6);
- bg::assign(line, tuples);
+ bg::assign_points(line, tuples);
     check_linestring_2d(line);
 }
 
@@ -76,7 +77,7 @@
     void test_assign_box_or_segment_2d()
     {
         BoxOrSegment geometry;
- bg::assign(geometry, 1, 2, 3, 4);
+ bg::assign_values(geometry, 1, 2, 3, 4);
         BOOST_CHECK((bg::get<bg::min_corner, 0>(geometry) == 1));
         BOOST_CHECK((bg::get<bg::min_corner, 1>(geometry) == 2));
         BOOST_CHECK((bg::get<bg::max_corner, 0>(geometry) == 3));
@@ -114,12 +115,12 @@
 void test_assign_point_3d()
 {
     Point p;
- bg::assign(p, 1, 2, 3);
+ bg::assign_values(p, 1, 2, 3);
     BOOST_CHECK(bg::get<0>(p) == 1);
     BOOST_CHECK(bg::get<1>(p) == 2);
     BOOST_CHECK(bg::get<2>(p) == 3);
 
- bg::detail::assign::assign_value(p, 123);
+ bg::assign_value(p, 123);
     BOOST_CHECK(bg::get<0>(p) == 123);
     BOOST_CHECK(bg::get<1>(p) == 123);
     BOOST_CHECK(bg::get<2>(p) == 123);
@@ -131,15 +132,74 @@
 
 }
 
+template <typename P>
+void test_assign_conversion()
+{
+ typedef bg::model::box<P> box_type;
+ typedef bg::model::ring<P> ring_type;
+ typedef bg::model::polygon<P> polygon_type;
+
+ P p;
+ bg::assign_values(p, 1, 2);
+
+ box_type b;
+ bg::assign(p, b);
+
+ BOOST_CHECK_CLOSE((bg::get<0, 0>(b)), 1.0, 0.001);
+ BOOST_CHECK_CLOSE((bg::get<0, 1>(b)), 2.0, 0.001);
+ BOOST_CHECK_CLOSE((bg::get<1, 0>(b)), 1.0, 0.001);
+ BOOST_CHECK_CLOSE((bg::get<1, 1>(b)), 2.0, 0.001);
+
+
+ bg::set<bg::min_corner, 0>(b, 1);
+ bg::set<bg::min_corner, 1>(b, 2);
+ bg::set<bg::max_corner, 0>(b, 3);
+ bg::set<bg::max_corner, 1>(b, 4);
+
+ ring_type ring;
+ bg::assign(b, ring);
+
+ //std::cout << bg::wkt(b) << std::endl;
+ //std::cout << bg::wkt(ring) << std::endl;
+
+ typename boost::range_const_iterator<ring_type>::type it = ring.begin();
+ BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
+ BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
+ it++;
+ BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
+ BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
+ it++;
+ BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
+ BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
+ it++;
+ BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
+ BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
+ it++;
+ BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
+ BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
+
+ BOOST_CHECK_EQUAL(ring.size(), 5u);
+
+
+ polygon_type polygon;
+
+ bg::assign(ring, polygon);
+ BOOST_CHECK_EQUAL(bg::num_points(polygon), 5u);
+
+ bg::assign(polygon, ring);
+ BOOST_CHECK_EQUAL(bg::num_points(ring), 5u);
+}
+
+
 template <typename Point>
 void test_assign_point_2d()
 {
     Point p;
- bg::assign(p, 1, 2);
+ bg::assign_values(p, 1, 2);
     BOOST_CHECK(bg::get<0>(p) == 1);
     BOOST_CHECK(bg::get<1>(p) == 2);
 
- bg::detail::assign::assign_value(p, 123);
+ bg::assign_value(p, 123);
     BOOST_CHECK(bg::get<0>(p) == 123);
     BOOST_CHECK(bg::get<1>(p) == 123);
 
@@ -148,6 +208,10 @@
     BOOST_CHECK(bg::get<1>(p) == 0);
 }
 
+
+
+
+
 int test_main(int, char* [])
 {
     test_assign_point_3d<int[3]>();
@@ -165,6 +229,9 @@
     test_assign_point_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
     test_assign_point_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
 
+ test_assign_conversion<bg::model::point<double, 2, bg::cs::cartesian> >();
+
+
     // Segment (currently) cannot handle array's because derived from std::pair
     test_assign_box_2d<int[2]>();
     test_assign_box_2d<float[2]>();

Modified: trunk/libs/geometry/test/algorithms/detail/convert.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/detail/convert.cpp (original)
+++ trunk/libs/geometry/test/algorithms/detail/convert.cpp 2011-04-12 14:29:39 EDT (Tue, 12 Apr 2011)
@@ -32,7 +32,7 @@
     typedef bg::model::box<P> box_type;
 
     P p;
- bg::assign(p, 1, 2);
+ bg::assign_values(p, 1, 2);
 
     box_type b;
     bg::detail::convert(p, b);


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