// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2022 - 2024 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_cgal_point_conversion_h #define dealii_cgal_point_conversion_h #include #include #ifdef DEAL_II_WITH_CGAL # include # if CGAL_VERSION_MAJOR >= 6 # include # endif # include # include # include # include DEAL_II_NAMESPACE_OPEN namespace CGALWrappers { /** * Convert from a deal.II Point to any compatible CGAL point. * * @tparam CGALPointType Any of the CGAL point types * @tparam dim Dimension of the point * @param [in] p An input deal.II Point * @return CGALPointType A CGAL point */ template inline CGALPointType dealii_point_to_cgal_point(const dealii::Point &p); /** * Convert from various CGAL point types to deal.II Point. * * @tparam dim Dimension of the point * @tparam CGALPointType Any of the CGAL point types * @param p An input CGAL point type * @return dealii::Point The corresponding deal.II point. */ template inline dealii::Point cgal_point_to_dealii_point(const CGALPointType &p); # ifndef DOXYGEN // Template implementations template inline CGALPointType dealii_point_to_cgal_point(const dealii::Point &p) { constexpr int cdim = CGALPointType::Ambient_dimension::value; static_assert(dim <= cdim, "Only dim <= cdim supported"); if constexpr (cdim == 1) return CGALPointType(p[0]); else if constexpr (cdim == 2) return CGALPointType(p[0], dim > 1 ? p[1] : 0); else if constexpr (cdim == 3) return CGALPointType(p[0], dim > 1 ? p[1] : 0, dim > 2 ? p[2] : 0); else DEAL_II_NOT_IMPLEMENTED(); return CGALPointType(); } template inline dealii::Point cgal_point_to_dealii_point(const CGALPointType &p) { constexpr int cdim = CGALPointType::Ambient_dimension::value; if constexpr (dim == 1) return dealii::Point(CGAL::to_double(p.x())); else if constexpr (dim == 2) return dealii::Point(CGAL::to_double(p.x()), cdim > 1 ? CGAL::to_double(p.y()) : 0); else if constexpr (dim == 3) return dealii::Point(CGAL::to_double(p.x()), cdim > 1 ? CGAL::to_double(p.y()) : 0, cdim > 2 ? CGAL::to_double(p.z()) : 0); else DEAL_II_NOT_IMPLEMENTED(); } } // namespace CGALWrappers # endif DEAL_II_NAMESPACE_CLOSE #else // Make sure the scripts that create the C++20 module input files have // something to latch on if the preprocessor #ifdef above would // otherwise lead to an empty content of the file. DEAL_II_NAMESPACE_OPEN DEAL_II_NAMESPACE_CLOSE #endif #endif