From dca773bdc65d52d10cd9e17a5e18bfea69ccc1ea Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Tue, 24 Jul 2018 20:55:35 +0200 Subject: [PATCH] Added adaptor for bounding box. --- include/deal.II/boost_adaptors/bounding_box.h | 108 ++++++++++++++++++ tests/boost/bounding_box_adaptor_01.cc | 43 +++++++ tests/boost/bounding_box_adaptor_01.output | 2 + 3 files changed, 153 insertions(+) create mode 100644 include/deal.II/boost_adaptors/bounding_box.h create mode 100644 tests/boost/bounding_box_adaptor_01.cc create mode 100644 tests/boost/bounding_box_adaptor_01.output diff --git a/include/deal.II/boost_adaptors/bounding_box.h b/include/deal.II/boost_adaptors/bounding_box.h new file mode 100644 index 0000000000..368452c462 --- /dev/null +++ b/include/deal.II/boost_adaptors/bounding_box.h @@ -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 + +#include + +#include + +namespace boost +{ + namespace geometry + { + namespace traits + { + /** + * Tag adaptor for dealii::BoundingBox. + */ + template + struct tag> + { + using type = box_tag; + }; + + /** + * Point type adaptor for dealii::BoundingBox. + */ + template + struct point_type> + { + using type = dealii::Point; + }; + + /** + * Access to the D-th coordinate of the lower left corner of a + * dealii::BoundingBox. + */ + template + struct indexed_access, 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 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 &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 + struct indexed_access, 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 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 &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 index 0000000000..6d25b7a198 --- /dev/null +++ b/tests/boost/bounding_box_adaptor_01.cc @@ -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 + +#include "../tests.h" + +namespace bg = boost::geometry; + +using bgPoint = bg::model::point; +using bgBox = bg::model::box; + +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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/boost/bounding_box_adaptor_01.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5