]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added point constructor from boost point and test
authorGiovanni Alzetta <giovannialzetta@hotmail.it>
Thu, 10 Jan 2019 15:29:40 +0000 (16:29 +0100)
committerGiovanni Alzetta <giovannialzetta@hotmail.it>
Thu, 31 Jan 2019 13:12:09 +0000 (14:12 +0100)
include/deal.II/base/point.h
tests/base/point_04.cc [new file with mode: 0644]
tests/base/point_04.output [new file with mode: 0644]

index 8bae4ecb034452bdb6263040cc35d85b7c8930a8..38a87c6f24f44cbca0ca75b754206b82d6bc925e 100644 (file)
@@ -22,6 +22,8 @@
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/tensor.h>
 
+#include <boost/geometry.hpp>
+
 #include <cmath>
 
 DEAL_II_NAMESPACE_OPEN
@@ -143,6 +145,15 @@ public:
    */
   Point(const Number x, const Number y, const Number z);
 
+  /**
+   * Convert a boost::geometry::point to a dealii::Point.
+   */
+  template <int dummy_dim = dim>
+  Point(const boost::geometry::model::
+          point<Number, dim, boost::geometry::cs::cartesian> &boost_pt,
+        typename std::enable_if<(dim == dummy_dim) && (dummy_dim != 0),
+                                int>::type = 0);
+
   /**
    * Return a unit vector in coordinate direction <tt>i</tt>, i.e., a vector
    * that is zero in all coordinates except for a single 1 in the <tt>i</tt>th
@@ -358,6 +369,28 @@ inline Point<dim, Number>::Point(const Number x, const Number y, const Number z)
 }
 
 
+
+template <int dim, typename Number>
+template <int dummy_dim>
+inline Point<dim, Number>::Point(
+  const boost::geometry::model::
+    point<Number, dim, boost::geometry::cs::cartesian> &boost_pt,
+  typename std::enable_if<(dim == dummy_dim) && (dummy_dim != 0), int>::type)
+{
+  Assert(dim <= 3, ExcNotImplemented());
+  this->values[0]                = boost::geometry::get<0>(boost_pt);
+  constexpr unsigned int y_index = (dim < 2) ? 0 : 1;
+  constexpr unsigned int z_index = (dim < 3) ? 0 : 2;
+
+  if (dim >= 2)
+    this->values[y_index] = boost::geometry::get<y_index>(boost_pt);
+
+  if (dim >= 3)
+    this->values[z_index] = boost::geometry::get<z_index>(boost_pt);
+}
+
+
+
 template <int dim, typename Number>
 inline Point<dim, Number>
 Point<dim, Number>::unit_vector(unsigned int i)
diff --git a/tests/base/point_04.cc b/tests/base/point_04.cc
new file mode 100644 (file)
index 0000000..7dbb622
--- /dev/null
@@ -0,0 +1,62 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 2017 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.
+//
+// ---------------------------------------------------------------------
+
+
+// test for Point::operator()
+
+#include <deal.II/base/point.h>
+
+#include <deal.II/lac/vector.h>
+
+#include <boost/geometry.hpp>
+
+#include "../tests.h"
+
+namespace bg = boost::geometry;
+
+template <int dim>
+void
+check()
+{
+  bg::model::point<double, dim, bg::cs::cartesian> bg_point;
+
+  constexpr unsigned int y_index = (spacedim < 2) ? 0 : 1;
+  constexpr unsigned int z_index = (spacedim < 3) ? 0 : 2;
+
+  bg_point.set<0>(42.0);
+
+  if (dim >= 2)
+    bg_point.set<y_index>(42.0 + dim);
+
+  if (dim >= 3)
+    bg_point.set<z_index>(42.0 + dim + 1);
+
+  Point<dim> p(bg_point);
+
+  for (unsigned int i = 0; i < dim; ++i)
+    deallog << p(i) << ' ';
+  deallog << std::endl;
+}
+
+int
+main()
+{
+  initlog();
+  deallog << std::setprecision(3);
+
+  check<1>();
+  check<2>();
+  check<3>();
+}
diff --git a/tests/base/point_04.output b/tests/base/point_04.output
new file mode 100644 (file)
index 0000000..e69de29

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.