diff --git a/doc/src/examples/algorithms/Jamfile.v2 b/doc/src/examples/algorithms/Jamfile.v2 index 60aa72c13..9731ce0f8 100644 --- a/doc/src/examples/algorithms/Jamfile.v2 +++ b/doc/src/examples/algorithms/Jamfile.v2 @@ -18,6 +18,7 @@ exe append : append.cpp ; 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 ; diff --git a/doc/src/examples/algorithms/assign.cpp b/doc/src/examples/algorithms/assign.cpp new file mode 100644 index 000000000..d7871680c --- /dev/null +++ b/doc/src/examples/algorithms/assign.cpp @@ -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 + +#include +#include + +int main() +{ + typedef boost::geometry::model::d2::point_xy point; + typedef boost::geometry::model::box box; + typedef boost::geometry::model::polygon 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 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) +] +*/ +//] diff --git a/doc/src/examples/algorithms/assign_2d_point.cpp b/doc/src/examples/algorithms/assign_2d_point.cpp index e01da8d7a..e32f5b5c7 100644 --- a/doc/src/examples/algorithms/assign_2d_point.cpp +++ b/doc/src/examples/algorithms/assign_2d_point.cpp @@ -23,15 +23,15 @@ int main() { - using boost::geometry::assign; + using boost::geometry::assign_values; boost::geometry::model::d2::point_xy p1; - assign(p1, 1.2345, 2.3456); + assign_values(p1, 1.2345, 2.3456); #if defined(HAVE_TTMATH) boost::geometry::model::d2::point_xy > 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. >*/ diff --git a/doc/src/examples/algorithms/assign_3d_point.cpp b/doc/src/examples/algorithms/assign_3d_point.cpp index 51e91ff31..aa3ddb683 100644 --- a/doc/src/examples/algorithms/assign_3d_point.cpp +++ b/doc/src/examples/algorithms/assign_3d_point.cpp @@ -19,7 +19,7 @@ int main() { boost::geometry::model::point 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; diff --git a/doc/src/examples/algorithms/assign_point_from_index.cpp b/doc/src/examples/algorithms/assign_point_from_index.cpp index 9b2da934b..2f5284693 100644 --- a/doc/src/examples/algorithms/assign_point_from_index.cpp +++ b/doc/src/examples/algorithms/assign_point_from_index.cpp @@ -23,7 +23,7 @@ int main() typedef model::segment 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); diff --git a/doc/src/examples/algorithms/assign_with_range.cpp b/doc/src/examples/algorithms/assign_with_range.cpp index 1a212245f..771ef233f 100644 --- a/doc/src/examples/algorithms/assign_with_range.cpp +++ b/doc/src/examples/algorithms/assign_with_range.cpp @@ -46,8 +46,8 @@ int main() 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(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(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; diff --git a/test/algorithms/assign.cpp b/test/algorithms/assign.cpp index 96bd35e0a..be7cc2d70 100644 --- a/test/algorithms/assign.cpp +++ b/test/algorithms/assign.cpp @@ -14,6 +14,7 @@ #include +#include #include #include @@ -48,25 +49,25 @@ void test_assign_linestring_2d() { bg::model::linestring 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 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 @@ namespace detail 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(geometry) == 1)); BOOST_CHECK((bg::get(geometry) == 2)); BOOST_CHECK((bg::get(geometry) == 3)); @@ -114,12 +115,12 @@ template 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 @@ void test_assign_point_3d() } +template +void test_assign_conversion() +{ + typedef bg::model::box

box_type; + typedef bg::model::ring

ring_type; + typedef bg::model::polygon

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(b, 1); + bg::set(b, 2); + bg::set(b, 3); + bg::set(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::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 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 @@ void test_assign_point_2d() BOOST_CHECK(bg::get<1>(p) == 0); } + + + + int test_main(int, char* []) { test_assign_point_3d(); @@ -165,6 +229,9 @@ int test_main(int, char* []) test_assign_point_2d >(); test_assign_point_2d >(); + test_assign_conversion >(); + + // Segment (currently) cannot handle array's because derived from std::pair test_assign_box_2d(); test_assign_box_2d(); diff --git a/test/algorithms/detail/convert.cpp b/test/algorithms/detail/convert.cpp index 2c6d227d3..fb1e704f3 100644 --- a/test/algorithms/detail/convert.cpp +++ b/test/algorithms/detail/convert.cpp @@ -32,7 +32,7 @@ void test_all() typedef bg::model::box

box_type; P p; - bg::assign(p, 1, 2); + bg::assign_values(p, 1, 2); box_type b; bg::detail::convert(p, b);