From c811784bddae1708ba9a5481787c95120e5e3e2b Mon Sep 17 00:00:00 2001 From: Giovanni Alzetta Date: Thu, 10 Jan 2019 16:29:40 +0100 Subject: [PATCH] Added point constructor from boost point and test --- include/deal.II/base/point.h | 33 +++++++++++++++++++ tests/base/point_04.cc | 62 ++++++++++++++++++++++++++++++++++++ tests/base/point_04.output | 0 3 files changed, 95 insertions(+) create mode 100644 tests/base/point_04.cc create mode 100644 tests/base/point_04.output diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index 8bae4ecb03..38a87c6f24 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -22,6 +22,8 @@ #include #include +#include + #include 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 + Point(const boost::geometry::model:: + point &boost_pt, + typename std::enable_if<(dim == dummy_dim) && (dummy_dim != 0), + int>::type = 0); + /** * Return a unit vector in coordinate direction i, i.e., a vector * that is zero in all coordinates except for a single 1 in the ith @@ -358,6 +369,28 @@ inline Point::Point(const Number x, const Number y, const Number z) } + +template +template +inline Point::Point( + const boost::geometry::model:: + point &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(boost_pt); + + if (dim >= 3) + this->values[z_index] = boost::geometry::get(boost_pt); +} + + + template inline Point Point::unit_vector(unsigned int i) diff --git a/tests/base/point_04.cc b/tests/base/point_04.cc new file mode 100644 index 0000000000..7dbb62241b --- /dev/null +++ b/tests/base/point_04.cc @@ -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 + +#include + +#include + +#include "../tests.h" + +namespace bg = boost::geometry; + +template +void +check() +{ + bg::model::point 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(42.0 + dim); + + if (dim >= 3) + bg_point.set(42.0 + dim + 1); + + Point 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 index 0000000000..e69de29bb2 -- 2.39.5