]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added boost::geometry point adaptor for deal.II
authorLuca Heltai <luca.heltai@sissa.it>
Sun, 22 Jul 2018 14:38:31 +0000 (16:38 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Mon, 23 Jul 2018 07:35:14 +0000 (09:35 +0200)
include/deal.II/boost_adaptors/point.h [new file with mode: 0644]
tests/boost/CMakeLists.txt [new file with mode: 0644]
tests/boost/boost_point_adaptor_01.cc [new file with mode: 0644]
tests/boost/boost_point_adaptor_01.output [new file with mode: 0644]

diff --git a/include/deal.II/boost_adaptors/point.h b/include/deal.II/boost_adaptors/point.h
new file mode 100644 (file)
index 0000000..376a552
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+//
+// 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_point_h
+#define dealii_boost_adaptor_point_h
+
+#include <deal.II/base/point.h>
+
+#include <boost/geometry.hpp>
+
+
+namespace boost
+{
+  namespace geometry
+  {
+    namespace traits
+    {
+      /**
+       * Tag adaptor for dealii::Point.
+       */
+      template <int dim, class Number>
+      struct tag<dealii::Point<dim, Number>>
+      {
+        typedef point_tag type;
+      };
+
+      /**
+       * Coordinate type adaptor for dealii::Point.
+       */
+      template <int dim, class Number>
+      struct coordinate_type<dealii::Point<dim, Number>>
+      {
+        typedef Number type;
+      };
+
+      /**
+       * Coordinate system adaptor for dealii::Point. By default, we assume
+       * that a dealii Point is cartesian point.
+       */
+      template <int dim, class Number>
+      struct coordinate_system<dealii::Point<dim, Number>>
+      {
+        typedef cs::cartesian type;
+      };
+
+      /**
+       * Dimension adaptor.
+       */
+      template <int dim, class Number>
+      struct dimension<dealii::Point<dim, Number>> : boost::mpl::int_<dim>
+      {};
+
+      /**
+       * Getter function for D-th coordinate of a dealii Point.
+       */
+      template <size_t D, int dim, class Number>
+      struct access<dealii::Point<dim, Number>, D>
+      {
+        static inline double
+        get(dealii::Point<dim, Number> const &p)
+        {
+          return p[D];
+        }
+
+        /**
+         * Setter function for D-th coordinate of a dealii Point.
+         */
+        static inline void
+        set(dealii::Point<dim, Number> &p, Number value)
+        {
+          p[D] = value;
+        }
+      };
+    } // namespace traits
+  }   // namespace geometry
+} // namespace boost
+
+
+
+#endif
diff --git a/tests/boost/CMakeLists.txt b/tests/boost/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d33eafa
--- /dev/null
@@ -0,0 +1,4 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
+INCLUDE(../setup_testsubproject.cmake)
+PROJECT(testsuite CXX)
+DEAL_II_PICKUP_TESTS()
diff --git a/tests/boost/boost_point_adaptor_01.cc b/tests/boost/boost_point_adaptor_01.cc
new file mode 100644 (file)
index 0000000..ebb17e0
--- /dev/null
@@ -0,0 +1,41 @@
+// ---------------------------------------------------------------------
+//
+// 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 points work
+
+#include <deal.II/boost_adaptors/point.h>
+
+#include "../tests.h"
+
+namespace bg = boost::geometry;
+
+using bgPoint = bg::model::point<double, 3, bg::cs::cartesian>;
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Point<3> p(1, 2, 3);
+  if (bg::equals(p, bg::make<Point<3>>(1, 2, 3)) == false)
+    deallog << "NOT OK" << std::endl;
+  else
+    deallog << "OK" << std::endl;
+
+  if (bg::equals(p, bg::make<bgPoint>(1., 2., 3.)) == false)
+    deallog << "NOT OK" << std::endl;
+  else
+    deallog << "OK" << std::endl;
+}
diff --git a/tests/boost/boost_point_adaptor_01.output b/tests/boost/boost_point_adaptor_01.output
new file mode 100644 (file)
index 0000000..8b3b075
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::OK
+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.