]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added adaptor for bounding box.
authorLuca Heltai <luca.heltai@sissa.it>
Tue, 24 Jul 2018 18:55:35 +0000 (20:55 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Tue, 24 Jul 2018 18:55:35 +0000 (20:55 +0200)
include/deal.II/boost_adaptors/bounding_box.h [new file with mode: 0644]
tests/boost/bounding_box_adaptor_01.cc [new file with mode: 0644]
tests/boost/bounding_box_adaptor_01.output [new file with mode: 0644]

diff --git a/include/deal.II/boost_adaptors/bounding_box.h b/include/deal.II/boost_adaptors/bounding_box.h
new file mode 100644 (file)
index 0000000..368452c
--- /dev/null
@@ -0,0 +1,108 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii_boost_adaptor_bounding_box_h
+#define dealii_boost_adaptor_bounding_box_h
+
+#include <deal.II/base/bounding_box.h>
+
+#include <deal.II/boost_adaptors/point.h>
+
+#include <boost/geometry.hpp>
+
+namespace boost
+{
+  namespace geometry
+  {
+    namespace traits
+    {
+      /**
+       * Tag adaptor for dealii::BoundingBox.
+       */
+      template <int dim, class Number>
+      struct tag<dealii::BoundingBox<dim, Number>>
+      {
+        using type = box_tag;
+      };
+
+      /**
+       * Point type adaptor for dealii::BoundingBox.
+       */
+      template <int dim, class Number>
+      struct point_type<dealii::BoundingBox<dim, Number>>
+      {
+        using type = dealii::Point<dim, Number>;
+      };
+
+      /**
+       * Access to the D-th coordinate of the lower left  corner of a
+       * dealii::BoundingBox.
+       */
+      template <int dim, class Number, size_t D>
+      struct indexed_access<dealii::BoundingBox<dim, Number>, min_corner, D>
+      {
+        /**
+         * Getter function for the D-th coordinate of the lower left corner of
+         * a dealii::BoundingBox.
+         */
+        static inline double
+        get(dealii::BoundingBox<dim, Number> const &box)
+        {
+          return box.get_boundary_points().first[D];
+        }
+
+        /**
+         * Setter function for the D-th coordinate of the lower left corner of
+         * a dealii::BoundingBox.
+         */
+        static inline void
+        set(dealii::BoundingBox<dim, Number> &box, Number value)
+        {
+          box.get_boundary_points().first[D] = value;
+        }
+      };
+
+      /**
+       * Access to the D-th coordinate of the upper right corner of a
+       * dealii::BoundingBox.
+       */
+      template <int dim, class Number, size_t D>
+      struct indexed_access<dealii::BoundingBox<dim, Number>, max_corner, D>
+      {
+        /**
+         * Getter function for the D-th coordinate of the upper right corner of
+         * a dealii::BoundingBox.
+         */
+        static inline double
+        get(dealii::BoundingBox<dim, Number> const &box)
+        {
+          return box.get_boundary_points().second[D];
+        }
+
+        /**
+         * Setter function for the D-th coordinate of the upper right corner of
+         * a dealii::BoundingBox.
+         */
+        static inline void
+        set(dealii::BoundingBox<dim, Number> &box, Number value)
+        {
+          box.get_boundary_points().second[D] = value;
+        }
+      };
+    } // namespace traits
+  }   // namespace geometry
+} // namespace boost
+
+#endif
diff --git a/tests/boost/bounding_box_adaptor_01.cc b/tests/boost/bounding_box_adaptor_01.cc
new file mode 100644 (file)
index 0000000..6d25b7a
--- /dev/null
@@ -0,0 +1,43 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+// Check that boost adaptors for bounding boxes work
+
+#include <deal.II/boost_adaptors/bounding_box.h>
+
+#include "../tests.h"
+
+namespace bg = boost::geometry;
+
+using bgPoint = bg::model::point<double, 3, bg::cs::cartesian>;
+using bgBox   = bg::model::box<bgPoint>;
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Point<3> p1;
+  Point<3> p2(1, 2, 3);
+
+  BoundingBox<3> box({p1, p2});
+
+  bgBox boost_box(bgPoint(0, 0, 0), bgPoint(1, 2, 3));
+
+  if (bg::equals(boost_box, box) == false)
+    deallog << "NOT OK" << std::endl;
+  else
+    deallog << "OK" << std::endl;
+}
diff --git a/tests/boost/bounding_box_adaptor_01.output b/tests/boost/bounding_box_adaptor_01.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.