Debian Codegraph @

include/deal.II/cgal/point_conversion.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2022 - 2024 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_cgal_point_conversion_h
16 #define dealii_cgal_point_conversion_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/point.h>
21
22 #ifdef DEAL_II_WITH_CGAL
23
24 # include <CGAL/version.h>
25 # if CGAL_VERSION_MAJOR >= 6
26 # include <CGAL/Installation/internal/disable_deprecation_warnings_and_errors.h>
27 # endif
28 # include <CGAL/Cartesian.h>
29 # include <CGAL/Exact_predicates_exact_constructions_kernel.h>
30 # include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
31 # include <CGAL/Simple_cartesian.h>
32
33
34 DEAL_II_NAMESPACE_OPEN
35 namespace CGALWrappers
36 {
37 /**
38 * Convert from a deal.II Point to any compatible CGAL point.
39 *
40 * @tparam CGALPointType Any of the CGAL point types
41 * @tparam dim Dimension of the point
42 * @param [in] p An input deal.II Point<dim>
43 * @return CGALPointType A CGAL point
44 */
45 template <typename CGALPointType, int dim>
46 inline CGALPointType
47 dealii_point_to_cgal_point(const dealii::Point<dim> &p);
48
49 /**
50 * Convert from various CGAL point types to deal.II Point.
51 *
52 * @tparam dim Dimension of the point
53 * @tparam CGALPointType Any of the CGAL point types
54 * @param p An input CGAL point type
55 * @return dealii::Point<dim> The corresponding deal.II point.
56 */
57 template <int dim, typename CGALPointType>
58 inline dealii::Point<dim>
59 cgal_point_to_dealii_point(const CGALPointType &p);
60
61
62 # ifndef DOXYGEN
63 // Template implementations
64
65 template <typename CGALPointType, int dim>
66 inline CGALPointType
67 dealii_point_to_cgal_point(const dealii::Point<dim> &p)
68 {
69 constexpr int cdim = CGALPointType::Ambient_dimension::value;
70 static_assert(dim <= cdim, "Only dim <= cdim supported");
71 if constexpr (cdim == 1)
72 return CGALPointType(p[0]);
73 else if constexpr (cdim == 2)
74 return CGALPointType(p[0], dim > 1 ? p[1] : 0);
75 else if constexpr (cdim == 3)
76 return CGALPointType(p[0], dim > 1 ? p[1] : 0, dim > 2 ? p[2] : 0);
77 else
78 DEAL_II_NOT_IMPLEMENTED();
79 return CGALPointType();
80 }
81
82
83
84 template <int dim, typename CGALPointType>
85 inline dealii::Point<dim>
86 cgal_point_to_dealii_point(const CGALPointType &p)
87 {
88 constexpr int cdim = CGALPointType::Ambient_dimension::value;
89 if constexpr (dim == 1)
90 return dealii::Point<dim>(CGAL::to_double(p.x()));
91 else if constexpr (dim == 2)
92 return dealii::Point<dim>(CGAL::to_double(p.x()),
93 cdim > 1 ? CGAL::to_double(p.y()) : 0);
94 else if constexpr (dim == 3)
95 return dealii::Point<dim>(CGAL::to_double(p.x()),
96 cdim > 1 ? CGAL::to_double(p.y()) : 0,
97 cdim > 2 ? CGAL::to_double(p.z()) : 0);
98 else
99 DEAL_II_NOT_IMPLEMENTED();
100 }
101 } // namespace CGALWrappers
102
103 # endif
104
105 DEAL_II_NAMESPACE_CLOSE
106
107 #else
108
109 // Make sure the scripts that create the C++20 module input files have
110 // something to latch on if the preprocessor #ifdef above would
111 // otherwise lead to an empty content of the file.
112 DEAL_II_NAMESPACE_OPEN
113 DEAL_II_NAMESPACE_CLOSE
114
115 #endif
116 #endif