From: Luca Heltai Date: Sun, 22 Jul 2018 14:38:31 +0000 (+0200) Subject: Added boost::geometry point adaptor for deal.II X-Git-Tag: v9.1.0-rc1~895^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a22744132d64a5c0d9391db0d925a953f77620;p=dealii.git Added boost::geometry point adaptor for deal.II --- diff --git a/include/deal.II/boost_adaptors/point.h b/include/deal.II/boost_adaptors/point.h new file mode 100644 index 0000000000..376a55242f --- /dev/null +++ b/include/deal.II/boost_adaptors/point.h @@ -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 + +#include + + +namespace boost +{ + namespace geometry + { + namespace traits + { + /** + * Tag adaptor for dealii::Point. + */ + template + struct tag> + { + typedef point_tag type; + }; + + /** + * Coordinate type adaptor for dealii::Point. + */ + template + struct coordinate_type> + { + typedef Number type; + }; + + /** + * Coordinate system adaptor for dealii::Point. By default, we assume + * that a dealii Point is cartesian point. + */ + template + struct coordinate_system> + { + typedef cs::cartesian type; + }; + + /** + * Dimension adaptor. + */ + template + struct dimension> : boost::mpl::int_ + {}; + + /** + * Getter function for D-th coordinate of a dealii Point. + */ + template + struct access, D> + { + static inline double + get(dealii::Point const &p) + { + return p[D]; + } + + /** + * Setter function for D-th coordinate of a dealii Point. + */ + static inline void + set(dealii::Point &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 index 0000000000..d33eafa20b --- /dev/null +++ b/tests/boost/CMakeLists.txt @@ -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 index 0000000000..ebb17e0c6f --- /dev/null +++ b/tests/boost/boost_point_adaptor_01.cc @@ -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 + +#include "../tests.h" + +namespace bg = boost::geometry; + +using bgPoint = bg::model::point; + +int +main(int argc, char **argv) +{ + initlog(); + + Point<3> p(1, 2, 3); + if (bg::equals(p, bg::make>(1, 2, 3)) == false) + deallog << "NOT OK" << std::endl; + else + deallog << "OK" << std::endl; + + if (bg::equals(p, bg::make(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 index 0000000000..8b3b075900 --- /dev/null +++ b/tests/boost/boost_point_adaptor_01.output @@ -0,0 +1,3 @@ + +DEAL::OK +DEAL::OK