summaryrefslogtreecommitdiff
path: root/libs/geometry/doc/src/examples/views/box_view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/geometry/doc/src/examples/views/box_view.cpp')
-rw-r--r--libs/geometry/doc/src/examples/views/box_view.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/libs/geometry/doc/src/examples/views/box_view.cpp b/libs/geometry/doc/src/examples/views/box_view.cpp
new file mode 100644
index 000000000..e95b54ecb
--- /dev/null
+++ b/libs/geometry/doc/src/examples/views/box_view.cpp
@@ -0,0 +1,58 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// QuickBook Example
+
+// Copyright (c) 2011-2012 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)
+
+//[box_view
+//` Shows usage of the Boost.Range compatible view on a box
+
+#include <iostream>
+
+#include <boost/geometry.hpp>
+
+
+int main()
+{
+ typedef boost::geometry::model::box
+ <
+ boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
+ > box_type;
+
+ // Define the Boost.Range compatible type:
+ typedef boost::geometry::box_view<box_type> box_view;
+
+ box_type box;
+ boost::geometry::assign_values(box, 0, 0, 4, 4);
+
+ box_view view(box);
+
+ // Iterating in clockwise direction over the points of this box
+ for (boost::range_iterator<box_view const>::type it = boost::begin(view);
+ it != boost::end(view); ++it)
+ {
+ std::cout << " " << boost::geometry::dsv(*it);
+ }
+ std::cout << std::endl;
+
+ // Note that a box_view is tagged as a ring, so supports area etc.
+ std::cout << "Area: " << boost::geometry::area(view) << std::endl;
+
+ return 0;
+}
+
+//]
+
+
+//[box_view_output
+/*`
+Output:
+[pre
+ (0, 0) (0, 4) (4, 4) (4, 0) (0, 0)
+Area: 16
+]
+*/
+//]