Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71492 - trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range
From: barend.gehrels_at_[hidden]
Date: 2011-04-25 17:25:18


Author: barendgehrels
Date: 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
New Revision: 71492
URL: http://svn.boost.org/trac/boost/changeset/71492

Log:
Added Boost.Range adaptors samples
Added:
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2 (contents, props changed)
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp (contents, props changed)
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp (contents, props changed)
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp (contents, props changed)
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp (contents, props changed)
   trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp (contents, props changed)

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
@@ -0,0 +1,22 @@
+# Boost.Geometry (aka GGL, Generic Geometry Library)
+#
+# Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
+# Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
+# Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
+
+# 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)
+
+
+project boost-geometry-doc-src-example-geometries-adapted-boost_range
+ : # requirements
+ ;
+
+exe filtered : filtered.cpp ;
+exe reversed : reversed.cpp ;
+exe sliced : sliced.cpp ;
+exe strided : strided.cpp ;
+# exe uniqued : uniqued.cpp ;
+
+

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp 2011-04-25 17:25:16 EDT (Mon, 25 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)
+
+//[boost_range_filtered
+//` Shows how to use a Boost.Geometry linestring, filtered by Boost.Range adaptor
+
+#include <iostream>
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
+
+struct not_two
+{
+ template <typename P>
+ bool operator()(P const& p) const
+ {
+ return boost::geometry::get<1>(p) != 2;
+ }
+};
+
+
+int main()
+{
+ typedef boost::geometry::model::d2::point_xy<int> xy;
+ boost::geometry::model::linestring<xy> line;
+ line.push_back(xy(0, 0));
+ line.push_back(xy(1, 1));
+ line.push_back(xy(2, 2));
+ line.push_back(xy(3, 1));
+ line.push_back(xy(4, 0));
+ line.push_back(xy(5, 1));
+ line.push_back(xy(6, 2));
+ line.push_back(xy(7, 1));
+ line.push_back(xy(8, 0));
+
+ using boost::adaptors::filtered;
+ std::cout
+ << boost::geometry::length(line) << std::endl
+ << boost::geometry::length(line | filtered(not_two())) << std::endl
+ << boost::geometry::dsv(line | filtered(not_two())) << std::endl;
+
+ return 0;
+}
+
+//]
+
+//[boost_range_filtered_output
+/*`
+Output:
+[pre
+11.3137
+9.65685
+((0, 0), (1, 1), (3, 1), (4, 0), (5, 1), (7, 1), (8, 0))
+]
+*/
+//]

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
@@ -0,0 +1,40 @@
+// 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)
+
+//[boost_range_reversed
+//` Shows how to use a Boost.Geometry linestring, reversed by Boost.Range adaptor
+
+#include <iostream>
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/adapted/boost_range/reversed.hpp>
+
+int main()
+{
+ typedef boost::geometry::model::d2::point_xy<int> xy;
+ boost::geometry::model::linestring<xy> line;
+ line.push_back(xy(0, 0));
+ line.push_back(xy(1, 1));
+
+ std::cout
+ << boost::geometry::dsv(line | boost::adaptors::reversed)
+ << std::endl;
+
+ return 0;
+}
+
+//]
+
+//[boost_range_reversed_output
+/*`
+Output:
+[pre
+((1, 1), (0, 0))
+]
+*/
+//]

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
@@ -0,0 +1,48 @@
+// 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)
+
+//[boost_range_sliced
+//` Shows how to use a Boost.Geometry linestring, sliced by Boost.Range adaptor
+
+#include <iostream>
+
+#include <boost/assign.hpp>
+
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/adapted/boost_range/sliced.hpp>
+
+
+int main()
+{
+ using namespace boost::assign;
+
+ typedef boost::geometry::model::d2::point_xy<int> xy;
+ boost::geometry::model::linestring<xy> line;
+ line += xy(0, 0);
+ line += xy(1, 1);
+ line += xy(2, 2);
+ line += xy(3, 3);
+ line += xy(4, 4);
+
+ std::cout
+ << boost::geometry::dsv(line | boost::adaptors::sliced(1, 3)) << std::endl;
+
+ return 0;
+}
+
+//]
+
+//[boost_range_sliced_output
+/*`
+Output:
+[pre
+((1, 1), (2, 2))
+]
+*/
+//]

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
@@ -0,0 +1,54 @@
+// 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)
+
+//[boost_range_strided
+//` Shows how to use a Boost.Geometry ring, strided by Boost.Range adaptor
+
+#include <iostream>
+
+#include <boost/assign.hpp>
+
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/adapted/boost_range/strided.hpp>
+
+
+int main()
+{
+ using namespace boost::assign;
+ using boost::adaptors::strided;
+
+ typedef boost::geometry::model::d2::point_xy<int> xy;
+ boost::geometry::model::ring<xy> ring;
+ ring += xy(0, 0);
+ ring += xy(0, 1);
+ ring += xy(0, 2);
+ ring += xy(1, 2);
+ ring += xy(2, 2);
+ ring += xy(2, 0);
+
+ boost::geometry::correct(ring);
+
+ std::cout
+ << "Normal : " << boost::geometry::dsv(ring) << std::endl
+ << "Strided: " << boost::geometry::dsv(ring | strided(2)) << std::endl;
+
+ return 0;
+}
+
+//]
+
+//[boost_range_strided_output
+/*`
+Output:
+[pre
+Normal : ((0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 0), (0, 0))
+Strided: ((0, 0), (0, 2), (2, 2), (0, 0))
+]
+*/
+//]

Added: trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp 2011-04-25 17:25:16 EDT (Mon, 25 Apr 2011)
@@ -0,0 +1,62 @@
+// 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)
+
+//[boost_range_uniqued
+//` Shows how to use a Boost.Geometry ring, made unique by Boost.Range adaptor
+
+#include <iostream>
+
+#include <boost/assign.hpp>
+
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp>
+
+typedef boost::geometry::model::d2::point_xy<int> xy;
+
+inline bool operator==(xy const& left, xy const& right)
+{
+ boost::geometry::equal_to<xy> eq;
+ return eq(left, right);
+}
+
+
+int main()
+{
+ using namespace boost::assign;
+ using boost::adaptors::uniqued;
+
+ boost::geometry::model::ring<xy> ring;
+ ring += xy(0, 0);
+ ring += xy(0, 1);
+ ring += xy(0, 2);
+ ring += xy(1, 2);
+ ring += xy(2, 2);
+ ring += xy(2, 2);
+ ring += xy(2, 2);
+ ring += xy(2, 0);
+ ring += xy(0, 0);
+
+ std::cout
+ << "Normal: " << boost::geometry::dsv(ring) << std::endl
+ << "Unique: " << boost::geometry::dsv(ring | uniqued) << std::endl;
+
+ return 0;
+}
+
+//]
+
+//[boost_range_uniqued_output
+/*`
+Output:
+[pre
+Normal : ((0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 0), (0, 0))
+uniqued: ((0, 0), (0, 2), (2, 2), (0, 0))
+]
+*/
+//]


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