From c11ce6c33a5f79d7cbc65b835c6a244836aae500 Mon Sep 17 00:00:00 2001 From: Dmitry Anisimov Date: Thu, 20 May 2021 13:25:59 +0200 Subject: [PATCH] updated cmakelists, refactored free functions for non eigen coordinates, fixed several warnings --- .../Barycentric_coordinates_2/CMakeLists.txt | 38 +- .../Barycentric_coordinates_2/CMakeLists.txt | 45 +- .../Terrain_height_modeling.cpp | 3 +- .../Wachspress_coordinates.cpp | 2 +- .../discrete_harmonic_coordinates.cpp | 11 +- .../mean_value_coordinates.cpp | 2 +- .../segment_coordinates.cpp | 2 +- .../triangle_coordinates.cpp | 2 +- .../include/CGAL/Barycentric_coordinates_2.h | 957 +----------------- .../Delaunay_domain_2.h | 6 +- .../Deprecated_headers_2.h | 5 +- .../Discrete_harmonic_coordinates_2.h | 174 ++++ .../Harmonic_coordinates_2.h | 3 +- .../Mean_value_coordinates_2.h | 172 ++++ .../Wachspress_coordinates_2.h | 174 ++++ .../boundary_coordinates_2.h | 170 ++++ .../internal/utils_2.h | 2 +- .../segment_coordinates_2.h | 181 ++++ .../triangle_coordinates_2.h | 191 ++++ .../Barycentric_coordinates_2/CMakeLists.txt | 98 +- 20 files changed, 1157 insertions(+), 1081 deletions(-) create mode 100644 Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/boundary_coordinates_2.h create mode 100644 Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/segment_coordinates_2.h create mode 100644 Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h diff --git a/Barycentric_coordinates_2/benchmark/Barycentric_coordinates_2/CMakeLists.txt b/Barycentric_coordinates_2/benchmark/Barycentric_coordinates_2/CMakeLists.txt index 78e12ef0193..24b160fb70f 100644 --- a/Barycentric_coordinates_2/benchmark/Barycentric_coordinates_2/CMakeLists.txt +++ b/Barycentric_coordinates_2/benchmark/Barycentric_coordinates_2/CMakeLists.txt @@ -3,7 +3,7 @@ project(Barycentric_coordinates_2_Benchmarks) -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.1...3.15) set(CMAKE_CXX_STANDARD 14) find_package(CGAL QUIET COMPONENTS Core) @@ -12,33 +12,25 @@ if(CGAL_FOUND) include(${CGAL_USE_FILE}) include(CGAL_CreateSingleSourceCGALProgram) - create_single_source_cgal_program( - "benchmark_segment_coordinates.cpp") - create_single_source_cgal_program( - "benchmark_triangle_coordinates.cpp") - create_single_source_cgal_program( - "benchmark_polygon_4_vertices.cpp") - create_single_source_cgal_program( - "benchmark_polygon_16_vertices.cpp") - create_single_source_cgal_program( - "benchmark_polygon_100_vertices.cpp") - create_single_source_cgal_program( - "benchmark_mv_34_vertices.cpp") + create_single_source_cgal_program("benchmark_segment_coordinates.cpp") + create_single_source_cgal_program("benchmark_triangle_coordinates.cpp") + create_single_source_cgal_program("benchmark_polygon_4_vertices.cpp") + create_single_source_cgal_program("benchmark_polygon_16_vertices.cpp") + create_single_source_cgal_program("benchmark_polygon_100_vertices.cpp") + create_single_source_cgal_program("benchmark_mv_34_vertices.cpp") find_package(Eigen3 REQUIRED) - if(EIGEN3_FOUND) - include(${EIGEN3_USE_FILE}) + include(CGAL_Eigen3_support) + if(TARGET CGAL::Eigen3_support) - create_single_source_cgal_program( - "benchmark_hm_4_vertices.cpp") - create_single_source_cgal_program( - "benchmark_hm_n_vertices.cpp") + create_single_source_cgal_program("benchmark_hm_4_vertices.cpp") + target_link_libraries(benchmark_hm_4_vertices PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("benchmark_hm_n_vertices.cpp") + target_link_libraries(benchmark_hm_n_vertices PUBLIC CGAL::Eigen3_support) else() - message(WARNING - "Harmonic coordinates require the Eigen library, and will not be compiled.") + message(WARNING "Several coordinates require the Eigen library, and will not be compiled.") endif() else() - message(WARNING - "This program requires the CGAL library, and will not be compiled.") + message(WARNING "This program requires the CGAL library, and will not be compiled.") endif() diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/CMakeLists.txt b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/CMakeLists.txt index b3dd19f81c9..6c6214920c1 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/CMakeLists.txt +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/CMakeLists.txt @@ -3,7 +3,7 @@ project(Barycentric_coordinates_2_Examples) -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.1...3.15) set(CMAKE_CXX_STANDARD 14) find_package(CGAL QUIET COMPONENTS Core) @@ -12,43 +12,34 @@ if(CGAL_FOUND) include(${CGAL_USE_FILE}) include(CGAL_CreateSingleSourceCGALProgram) - create_single_source_cgal_program( - "segment_coordinates.cpp") - create_single_source_cgal_program( - "triangle_coordinates.cpp") - create_single_source_cgal_program( - "wachspress_coordinates.cpp") - create_single_source_cgal_program( - "mean_value_coordinates.cpp") - create_single_source_cgal_program( - "discrete_harmonic_coordinates.cpp") + create_single_source_cgal_program("segment_coordinates.cpp") + create_single_source_cgal_program("triangle_coordinates.cpp") + create_single_source_cgal_program("wachspress_coordinates.cpp") + create_single_source_cgal_program("mean_value_coordinates.cpp") + create_single_source_cgal_program("discrete_harmonic_coordinates.cpp") # missing: # construct_centroid_2 # in projection traits - # create_single_source_cgal_program( - # "terrain_height_modeling.cpp") + # create_single_source_cgal_program("terrain_height_modeling.cpp") # this code is deprecated: - # create_single_source_cgal_program( - # "deprecated_coordinates.cpp") + # create_single_source_cgal_program("deprecated_coordinates.cpp") find_package(Eigen3 REQUIRED) - if(EIGEN3_FOUND) - include(${EIGEN3_USE_FILE}) + include(CGAL_Eigen3_support) + if(TARGET CGAL::Eigen3_support) - create_single_source_cgal_program( - "affine_coordinates.cpp") - create_single_source_cgal_program( - "harmonic_coordinates.cpp") - create_single_source_cgal_program( - "shape_deformation.cpp") + create_single_source_cgal_program("affine_coordinates.cpp") + target_link_libraries(affine_coordinates PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("harmonic_coordinates.cpp") + target_link_libraries(harmonic_coordinates PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("shape_deformation.cpp") + target_link_libraries(shape_deformation PUBLIC CGAL::Eigen3_support) else() - message(WARNING - "Harmonic/Affine coordinates require the Eigen library, and will not be compiled.") + message(WARNING "Several coordinates require the Eigen library, and will not be compiled.") endif() else() - message(WARNING - "This program requires the CGAL library, and will not be compiled.") + message(WARNING "This program requires the CGAL library, and will not be compiled.") endif() diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Terrain_height_modeling.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Terrain_height_modeling.cpp index 8a1902c0268..a187411e429 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Terrain_height_modeling.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Terrain_height_modeling.cpp @@ -1,7 +1,8 @@ #include #include #include -#include +#include +#include // Typedefs. using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Wachspress_coordinates.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Wachspress_coordinates.cpp index b2ce6d2b146..7bcec559009 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Wachspress_coordinates.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/Wachspress_coordinates.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include // Typedefs. using Kernel = CGAL::Simple_cartesian; diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/discrete_harmonic_coordinates.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/discrete_harmonic_coordinates.cpp index cb4471ddcfd..61987784e41 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/discrete_harmonic_coordinates.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/discrete_harmonic_coordinates.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include // Typedefs. using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; @@ -48,7 +49,7 @@ int main() { discrete_harmonic_2.weights(center, std::back_inserter(weights)); std::cout << std::endl << "discrete harmonic weights (center): "; - for (const FT weight : weights) + for (const FT& weight : weights) std::cout << weight << " "; std::cout << std::endl; @@ -57,7 +58,7 @@ int main() { discrete_harmonic_2(center, std::back_inserter(coordinates)); std::cout << std::endl << "discrete harmonic coordinates (center): "; - for (const FT coordinate : coordinates) + for (const FT& coordinate : coordinates) std::cout << coordinate << " "; std::cout << std::endl; @@ -105,7 +106,7 @@ int main() { square, e4, std::back_inserter(coordinates), kernel, point_map); std::cout << std::endl << "boundary coordinates (edge 2 and edge 4): "; - for (const FT coordinate : coordinates) + for (const FT& coordinate : coordinates) std::cout << coordinate << " "; std::cout << std::endl; @@ -144,7 +145,7 @@ int main() { discrete_harmonic_2(r, std::back_inserter(coordinates)); std::cout << std::endl << "discrete harmonic coordinates (exterior): "; - for (const FT coordinate : coordinates) + for (const FT& coordinate : coordinates) std::cout << coordinate << " "; std::cout << std::endl << std::endl; diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/mean_value_coordinates.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/mean_value_coordinates.cpp index 0b7c39ecf92..fe11349ec78 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/mean_value_coordinates.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/mean_value_coordinates.cpp @@ -1,5 +1,5 @@ #include -#include +#include // Typedefs. using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/segment_coordinates.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/segment_coordinates.cpp index e59881ad177..039757be950 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/segment_coordinates.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/segment_coordinates.cpp @@ -1,5 +1,5 @@ #include -#include +#include // Typedefs. using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; diff --git a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/triangle_coordinates.cpp b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/triangle_coordinates.cpp index fed50863368..6a30e9bf5ef 100644 --- a/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/triangle_coordinates.cpp +++ b/Barycentric_coordinates_2/examples/Barycentric_coordinates_2/triangle_coordinates.cpp @@ -1,5 +1,5 @@ #include -#include +#include // Typedefs. using Kernel = CGAL::Simple_cartesian; diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2.h index 2d571ed5a25..69f9b2c2f88 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2.h @@ -29,6 +29,10 @@ // #include // Internal includes. +#include +#include +#include + #include #include #include @@ -38,957 +42,6 @@ namespace CGAL { namespace Barycentric_coordinates { - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes segment coordinates. - - This function computes barycentric coordinates at a given `query` point - with respect to the end points `p0` and `p1` of a segment that is one - coordinate per end point. The coordinates are stored in a destination range - beginning at `c_begin`. - - After the coordinates \f$b_0\f$ and \f$b_1\f$ are computed, the query point \f$q\f$ can be - obtained as \f$q = b_0p_0 + b_1p_1\f$. If \f$q\f$ does not belong to the line through \f$p_0\f$ - and \f$p_1\f$, it is projected onto this line, and only then the coordinates are - computed. See more details in the user manual \ref compute_seg_coord "here". - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param p0 - the first vertex of a segment - - \param p1 - the second vertex of a segment - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \return an output iterator to the element in the destination range, - one past the last coordinate stored - - \pre p0 != p1 - */ - template< - typename OutIterator, - typename GeomTraits> - OutIterator segment_coordinates_2( - const typename GeomTraits::Point_2& p0, - const typename GeomTraits::Point_2& p1, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits) { - - return internal::linear_coordinates_2( - p0, p1, query, c_begin, traits); - } - - /// \cond SKIP_IN_MANUAL - template< - typename Point_2, - typename OutIterator> - OutIterator segment_coordinates_2( - const Point_2& p0, - const Point_2& p1, - const Point_2& query, - OutIterator c_begin) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return segment_coordinates_2( - p0, p1, query, c_begin, traits); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes segment coordinates. - - This function computes barycentric coordinates at a given `query` point - with respect to the end points `p0` and `p1` of a segment that is one - coordinate per end point. The coordinates are returned in a pair. - - After the coordinates \f$b_0\f$ and \f$b_1\f$ are computed, the query point \f$q\f$ can be - obtained as \f$q = b_0p_0 + b_1p_1\f$. If \f$q\f$ does not belong to the line through \f$p_0\f$ - and \f$p_1\f$, it is projected onto this line, and only then the coordinates are - computed. See more details in the user manual \ref compute_seg_coord "here". - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param p0 - the first vertex of a segment - - \param p1 - the second vertex of a segment - - \param query - a query point - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \return a pair `std::pair` - with the computed coordinates - - \pre p0 != p1 - */ - template - std::pair< - typename GeomTraits::FT, - typename GeomTraits::FT> - segment_coordinates_in_pair_2( - const typename GeomTraits::Point_2& p0, - const typename GeomTraits::Point_2& p1, - const typename GeomTraits::Point_2& query, - const GeomTraits& traits) { - - using FT = typename GeomTraits::FT; - std::vector coordinates; - coordinates.reserve(2); - internal::linear_coordinates_2( - p0, p1, query, std::back_inserter(coordinates), traits); - CGAL_assertion(coordinates.size() == 2); - return std::make_pair(coordinates[0], coordinates[1]); - } - - /// \cond SKIP_IN_MANUAL - template - std::pair< - typename Kernel_traits::Kernel::FT, - typename Kernel_traits::Kernel::FT> - segment_coordinates_in_pair_2( - const Point_2& p0, - const Point_2& p1, - const Point_2& query) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return segment_coordinates_in_pair_2( - p0, p1, query, traits); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes triangle coordinates. - - This function computes barycentric coordinates at a given `query` point - with respect to the points `p0`, `p1`, and `p2`, which form a triangle, that is one - coordinate per point. The coordinates are stored in a destination range - beginning at `c_begin`. - - After the coordinates \f$b_0\f$, \f$b_1\f$, and \f$b_2\f$ are computed, the query - point \f$q\f$ can be obtained as \f$q = b_0p_0 + b_1p_1 + b_2p_2\f$. See more details - in the user manual \ref compute_tri_coord "here". - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param p0 - the first vertex of a triangle - - \param p1 - the second vertex of a triangle - - \param p2 - the third vertex of a triangle - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \return an output iterator to the element in the destination range, - one past the last coordinate stored - - \pre area_2(p0, p1, p2) != 0 - */ - template< - typename OutIterator, - typename GeomTraits> - OutIterator triangle_coordinates_2( - const typename GeomTraits::Point_2& p0, - const typename GeomTraits::Point_2& p1, - const typename GeomTraits::Point_2& p2, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits) { - - return internal::planar_coordinates_2( - p0, p1, p2, query, c_begin, traits); - } - - /// \cond SKIP_IN_MANUAL - template< - typename Point_2, - typename OutIterator> - OutIterator triangle_coordinates_2( - const Point_2& p0, - const Point_2& p1, - const Point_2& p2, - const Point_2& query, - OutIterator c_begin) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return triangle_coordinates_2( - p0, p1, p2, query, c_begin, traits); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes triangle coordinates. - - This function computes barycentric coordinates at a given `query` point - with respect to the points `p0`, `p1`, and `p2`, which form a triangle, that is one - coordinate per point. The coordinates are returned in a tuple. - - After the coordinates \f$b_0\f$, \f$b_1\f$, and \f$b_2\f$ are computed, the query - point \f$q\f$ can be obtained as \f$q = b_0p_0 + b_1p_1 + b_2p_2\f$. See more details - in the user manual \ref compute_tri_coord "here". - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param p0 - the first vertex of a triangle - - \param p1 - the second vertex of a triangle - - \param p2 - the third vertex of a triangle - - \param query - a query point - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \return a tuple `std::tuple` - with the computed coordinates - - \pre area_2(p0, p1, p2) != 0 - */ - template - std::tuple< - typename GeomTraits::FT, - typename GeomTraits::FT, - typename GeomTraits::FT> - triangle_coordinates_in_tuple_2( - const typename GeomTraits::Point_2& p0, - const typename GeomTraits::Point_2& p1, - const typename GeomTraits::Point_2& p2, - const typename GeomTraits::Point_2& query, - const GeomTraits& traits) { - - using FT = typename GeomTraits::FT; - std::vector coordinates; - coordinates.reserve(3); - internal::planar_coordinates_2( - p0, p1, p2, query, std::back_inserter(coordinates), traits); - CGAL_assertion(coordinates.size() == 3); - return std::make_tuple(coordinates[0], coordinates[1], coordinates[2]); - } - - /// \cond SKIP_IN_MANUAL - template - std::tuple< - typename Kernel_traits::Kernel::FT, - typename Kernel_traits::Kernel::FT, - typename Kernel_traits::Kernel::FT> - triangle_coordinates_in_tuple_2( - const Point_2& p0, - const Point_2& p1, - const Point_2& p2, - const Point_2& query) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return triangle_coordinates_in_tuple_2( - p0, p1, p2, query, traits); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D boundary coordinates. - - This function computes boundary barycentric coordinates at a given `query` point - with respect to the vertices of a simple `polygon`, that is one - coordinate per vertex. The coordinates are stored in a destination range - beginning at `c_begin`. - - If `query` is at the vertex, the corresponding coordinate is set to one, while - all other coordinates are zero. If `query` is on the edge, the two corresponding - coordinates are segment coordinates, while all other coordinates are set to zero. - If `query` is not on the boundary, all the coordinates are set to zero. - - Internally, `segment_coordinates_2()` are used. - - \tparam VertexRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \tparam PointMap - a model of `ReadablePropertyMap` whose key type is `VertexRange::value_type` and - value type is `GeomTraits::Point_2` - - \param polygon - an instance of `VertexRange` with 2D points, which form a simple polygon - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param point_map - an instance of `PointMap` that maps a vertex from `polygon` to `Point_2` - - \return an output iterator to the element in the destination range, - one past the last coordinate stored + the flag indicating whether the - query point belongs to the polygon boundary - - \pre polygon.size() >= 3 - */ - template< - typename VertexRange, - typename OutIterator, - typename GeomTraits, - typename PointMap> - std::pair boundary_coordinates_2( - const VertexRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits, - const PointMap point_map) { - - const auto result = - internal::locate_wrt_polygon_2(polygon, query, traits, point_map); - auto location = (*result).first; - auto index = (*result).second; - - if (!result) { - index = std::size_t(-1); - location = internal::Query_point_location::UNSPECIFIED; - } - return internal::boundary_coordinates_2( - polygon, query, location, index, c_begin, traits, point_map); - } - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D boundary coordinates. - - This is an overload of the function `boundary_coordinates_2`. - - \tparam VertexRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - - \tparam Query_2 - a model of `Kernel::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam PointMap - a model of `ReadablePropertyMap` whose key type is `VertexRange::value_type` and - value type is `Query_2`. The default is `CGAL::Identity_property_map`. - - \param polygon - an instance of `VertexRange` with 2D points, which form a simple polygon - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param point_map - an instance of `PointMap` that maps a vertex from `polygon` to `Query_2`; - the default initialization is provided - - \return an output iterator to the element in the destination range, - one past the last coordinate stored + the flag indicating whether the - query point belongs to the polygon boundary - - \pre polygon.size() >= 3 - */ - template< - typename VertexRange, - typename Query_2, - typename OutIterator, - typename PointMap = CGAL::Identity_property_map > - std::pair boundary_coordinates_2( - const VertexRange& polygon, - const Query_2& query, - OutIterator c_begin, - const PointMap point_map = PointMap()) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return boundary_coordinates_2( - polygon, query, c_begin, traits, point_map); - } - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D Wachspress weights. - - This function computes 2D Wachspress weights at a given `query` point - with respect to the vertices of a strictly convex `polygon`, that is one - weight per vertex. The weights are stored in a destination range - beginning at `w_begin`. - - Internally, the class `Wachspress_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a strictly convex polygon - - \param query - a query point - - \param w_begin - the beginning of the destination range with the computed weights - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last weight stored - - \pre polygon.size() >= 3 - \pre polygon is simple - \pre polygon is strictly convex - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator wachspress_weights_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator w_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - Wachspress_coordinates_2 wachspress( - polygon, policy, traits); - return wachspress.weights(query, w_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator wachspress_weights_2( - const PointRange& polygon, - const Point_2& query, - OutIterator w_begin, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return wachspress_weights_2( - polygon, query, w_begin, traits, policy); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D Wachspress coordinates. - - This function computes 2D Wachspress coordinates at a given `query` point - with respect to the vertices of a strictly convex `polygon`, that is one - coordinate per vertex. The coordinates are stored in a destination range - beginning at `c_begin`. - - Internally, the class `Wachspress_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a strictly convex polygon - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last coordinate stored - - \pre polygon.size() >= 3 - \pre polygon is simple - \pre polygon is strictly convex - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator wachspress_coordinates_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - Wachspress_coordinates_2 wachspress( - polygon, policy, traits); - return wachspress(query, c_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator wachspress_coordinates_2( - const PointRange& polygon, - const Point_2& query, - OutIterator c_begin, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return wachspress_coordinates_2( - polygon, query, c_begin, traits, policy); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D discrete harmonic weights. - - This function computes 2D discrete harmonic weights at a given `query` point - with respect to the vertices of a strictly convex `polygon`, that is one - weight per vertex. The weights are stored in a destination range - beginning at `w_begin`. - - Internally, the class `Discrete_harmonic_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a strictly convex polygon - - \param query - a query point - - \param w_begin - the beginning of the destination range with the computed weights - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last weight stored - - \pre polygon.size() >= 3 - \pre polygon is simple - \pre polygon is strictly convex - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator discrete_harmonic_weights_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator w_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - Discrete_harmonic_coordinates_2 discrete_harmonic( - polygon, policy, traits); - return discrete_harmonic.weights(query, w_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator discrete_harmonic_weights_2( - const PointRange& polygon, - const Point_2& query, - OutIterator w_begin, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return discrete_harmonic_weights_2( - polygon, query, w_begin, traits, policy); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D discrete harmonic coordinates. - - This function computes 2D discrete harmonic coordinates at a given `query` point - with respect to the vertices of a strictly convex `polygon`, that is one - coordinate per vertex. The coordinates are stored in a destination range - beginning at `c_begin`. - - Internally, the class `Discrete_harmonic_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a strictly convex polygon - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last coordinate stored - - \pre polygon.size() >= 3 - \pre polygon is simple - \pre polygon is strictly convex - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator discrete_harmonic_coordinates_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - Discrete_harmonic_coordinates_2 discrete_harmonic( - polygon, policy, traits); - return discrete_harmonic(query, c_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator discrete_harmonic_coordinates_2( - const PointRange& polygon, - const Point_2& query, - OutIterator c_begin, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return discrete_harmonic_coordinates_2( - polygon, query, c_begin, traits, policy); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D mean value weights. - - This function computes 2D mean value weights at a given `query` point - with respect to the vertices of a simple `polygon`, that is one - weight per vertex. The weights are stored in a destination range - beginning at `w_begin`. - - Internally, the class `Mean_value_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a simple polygon - - \param query - a query point - - \param w_begin - the beginning of the destination range with the computed weights - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last weight stored - - \pre polygon.size() >= 3 - \pre polygon is simple - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator mean_value_weights_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator w_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - Mean_value_coordinates_2 mean_value( - polygon, policy, traits); - return mean_value.weights(query, w_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator mean_value_weights_2( - const PointRange& polygon, - const Point_2& query, - OutIterator w_begin, - const Computation_policy_2 policy = - Computation_policy_2::FAST_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return mean_value_weights_2( - polygon, query, w_begin, traits, policy); - } - /// \endcond - - /*! - \ingroup PkgBarycentricCoordinates2RefFunctions - - \brief computes 2D mean value coordinates. - - This function computes 2D mean value coordinates at a given `query` point - with respect to the vertices of a simple `polygon`, that is one - coordinate per vertex. The coordinates are stored in a destination range - beginning at `c_begin`. - - Internally, the class `Mean_value_coordinates_2` is used. If one wants to process - multiple query points, it is better to use that class. When using the free function, - internal memory is allocated for each query point, while when using the class, - it is allocated only once, which is much more efficient. However, for a few query - points, it is easier to use this function. It can also be used when the processing - time is not a concern. - - \tparam PointRange - a model of `ConstRange` whose iterator type is `RandomAccessIterator` - and value type is `GeomTraits::Point_2` - - \tparam OutIterator - a model of `OutputIterator` that accepts values of type `GeomTraits::FT` - - \tparam GeomTraits - a model of `BarycentricTraits_2` - - \param polygon - an instance of `PointRange` with 2D points, which form a simple polygon - - \param query - a query point - - \param c_begin - the beginning of the destination range with the computed coordinates - - \param traits - a traits class with geometric objects, predicates, and constructions; - this parameter can be omitted if the traits class can be deduced from the point type - - \param policy - one of the `Computation_policy_2`; - the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` - - \return an output iterator to the element in the destination range, - one past the last coordinate stored - - \pre polygon.size() >= 3 - \pre polygon is simple - */ - template< - typename PointRange, - typename OutIterator, - typename GeomTraits> - OutIterator mean_value_coordinates_2( - const PointRange& polygon, - const typename GeomTraits::Point_2& query, - OutIterator c_begin, - const GeomTraits& traits, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - Mean_value_coordinates_2 mean_value( - polygon, policy, traits); - return mean_value(query, c_begin); - } - - /// \cond SKIP_IN_MANUAL - template< - typename PointRange, - typename Point_2, - typename OutIterator> - OutIterator mean_value_coordinates_2( - const PointRange& polygon, - const Point_2& query, - OutIterator c_begin, - const Computation_policy_2 policy = - Computation_policy_2::PRECISE_WITH_EDGE_CASES) { - - using GeomTraits = typename Kernel_traits::Kernel; - const GeomTraits traits; - return mean_value_coordinates_2( - polygon, query, c_begin, traits, policy); - } - /// \endcond - /*! \ingroup PkgBarycentricCoordinates2RefFunctions @@ -1048,7 +101,7 @@ namespace Barycentric_coordinates { const PointRange& polygon, const PointRange& seeds, OutIterator c_begin, - const GeomTraits& traits, + const GeomTraits& /* traits */, // TODO: we should involve it in the code! const typename GeomTraits::FT max_edge_length = typename GeomTraits::FT(1) / typename GeomTraits::FT(100)) { diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Delaunay_domain_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Delaunay_domain_2.h index 03ac66738bf..9b37152b68d 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Delaunay_domain_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Delaunay_domain_2.h @@ -214,7 +214,7 @@ namespace Barycentric_coordinates { This function implements `DiscretizedDomain_2::number_of_vertices()`. */ - const std::size_t number_of_vertices() const { + std::size_t number_of_vertices() const { CGAL_assertion( m_vhs.size() == m_cdt.number_of_vertices()); @@ -251,7 +251,7 @@ namespace Barycentric_coordinates { \pre query_index >= 0 && query_index < number_of_vertices() */ - const bool is_on_boundary( + bool is_on_boundary( const std::size_t query_index) const { CGAL_precondition( @@ -515,7 +515,7 @@ namespace Barycentric_coordinates { } } - const std::size_t get_number_of_faces() const { + std::size_t get_number_of_faces() const { std::size_t num_faces = 0; for (auto fh = m_cdt.finite_faces_begin(); diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Deprecated_headers_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Deprecated_headers_2.h index d06289a0228..5a299833b17 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Deprecated_headers_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Deprecated_headers_2.h @@ -26,11 +26,12 @@ #include #include +#include +#include + #include #include #include -#include -#include #include #endif // CGAL_BARYCENTRIC_DEPRECATED_HEADERS_2_H diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Discrete_harmonic_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Discrete_harmonic_coordinates_2.h index f0bccddd099..8c8d09b8490 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Discrete_harmonic_coordinates_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Discrete_harmonic_coordinates_2.h @@ -382,6 +382,180 @@ namespace Barycentric_coordinates { } }; + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D discrete harmonic weights. + + This function computes 2D discrete harmonic weights at a given `query` point + with respect to the vertices of a strictly convex `polygon`, that is one + weight per vertex. The weights are stored in a destination range + beginning at `w_begin`. + + Internally, the class `Discrete_harmonic_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a strictly convex polygon + + \param query + a query point + + \param w_begin + the beginning of the destination range with the computed weights + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last weight stored + + \pre polygon.size() >= 3 + \pre polygon is simple + \pre polygon is strictly convex + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator discrete_harmonic_weights_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator w_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + Discrete_harmonic_coordinates_2 discrete_harmonic( + polygon, policy, traits); + return discrete_harmonic.weights(query, w_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator discrete_harmonic_weights_2( + const PointRange& polygon, + const Point_2& query, + OutIterator w_begin, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return discrete_harmonic_weights_2( + polygon, query, w_begin, traits, policy); + } + /// \endcond + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D discrete harmonic coordinates. + + This function computes 2D discrete harmonic coordinates at a given `query` point + with respect to the vertices of a strictly convex `polygon`, that is one + coordinate per vertex. The coordinates are stored in a destination range + beginning at `c_begin`. + + Internally, the class `Discrete_harmonic_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a strictly convex polygon + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + + \pre polygon.size() >= 3 + \pre polygon is simple + \pre polygon is strictly convex + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator discrete_harmonic_coordinates_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + Discrete_harmonic_coordinates_2 discrete_harmonic( + polygon, policy, traits); + return discrete_harmonic(query, c_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator discrete_harmonic_coordinates_2( + const PointRange& polygon, + const Point_2& query, + OutIterator c_begin, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return discrete_harmonic_coordinates_2( + polygon, query, c_begin, traits, policy); + } + /// \endcond + } // namespace Barycentric_coordinates } // namespace CGAL diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Harmonic_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Harmonic_coordinates_2.h index 13b2059b503..55eb4624c28 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Harmonic_coordinates_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Harmonic_coordinates_2.h @@ -350,7 +350,6 @@ namespace Barycentric_coordinates { if (m_setup_is_called) return; const std::size_t n = m_polygon.size(); - const std::size_t N = m_domain.number_of_vertices(); // Create an index map. It splits interior and boundary vertices. const auto pair = create_indices(m_indices); @@ -488,7 +487,7 @@ namespace Barycentric_coordinates { } void set_boundary_vector( - const std::size_t numB, + const std::size_t /* numB */, // this is not used here but the number of elements is numB! const std::vector& indices, VectorFT& boundary) const { diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_coordinates_2.h index 8f9eab93e32..05916485d83 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_coordinates_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_coordinates_2.h @@ -425,6 +425,178 @@ namespace Barycentric_coordinates { } }; + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D mean value weights. + + This function computes 2D mean value weights at a given `query` point + with respect to the vertices of a simple `polygon`, that is one + weight per vertex. The weights are stored in a destination range + beginning at `w_begin`. + + Internally, the class `Mean_value_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a simple polygon + + \param query + a query point + + \param w_begin + the beginning of the destination range with the computed weights + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last weight stored + + \pre polygon.size() >= 3 + \pre polygon is simple + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator mean_value_weights_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator w_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + Mean_value_coordinates_2 mean_value( + polygon, policy, traits); + return mean_value.weights(query, w_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator mean_value_weights_2( + const PointRange& polygon, + const Point_2& query, + OutIterator w_begin, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return mean_value_weights_2( + polygon, query, w_begin, traits, policy); + } + /// \endcond + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D mean value coordinates. + + This function computes 2D mean value coordinates at a given `query` point + with respect to the vertices of a simple `polygon`, that is one + coordinate per vertex. The coordinates are stored in a destination range + beginning at `c_begin`. + + Internally, the class `Mean_value_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a simple polygon + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + + \pre polygon.size() >= 3 + \pre polygon is simple + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator mean_value_coordinates_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + Mean_value_coordinates_2 mean_value( + polygon, policy, traits); + return mean_value(query, c_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator mean_value_coordinates_2( + const PointRange& polygon, + const Point_2& query, + OutIterator c_begin, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return mean_value_coordinates_2( + polygon, query, c_begin, traits, policy); + } + /// \endcond + } // namespace Barycentric_coordinates } // namespace CGAL diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Wachspress_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Wachspress_coordinates_2.h index 5202950a608..4e9ff6c8f0c 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Wachspress_coordinates_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Wachspress_coordinates_2.h @@ -370,6 +370,180 @@ namespace Barycentric_coordinates { } }; + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D Wachspress weights. + + This function computes 2D Wachspress weights at a given `query` point + with respect to the vertices of a strictly convex `polygon`, that is one + weight per vertex. The weights are stored in a destination range + beginning at `w_begin`. + + Internally, the class `Wachspress_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a strictly convex polygon + + \param query + a query point + + \param w_begin + the beginning of the destination range with the computed weights + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::FAST_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last weight stored + + \pre polygon.size() >= 3 + \pre polygon is simple + \pre polygon is strictly convex + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator wachspress_weights_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator w_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + Wachspress_coordinates_2 wachspress( + polygon, policy, traits); + return wachspress.weights(query, w_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator wachspress_weights_2( + const PointRange& polygon, + const Point_2& query, + OutIterator w_begin, + const Computation_policy_2 policy = + Computation_policy_2::FAST_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return wachspress_weights_2( + polygon, query, w_begin, traits, policy); + } + /// \endcond + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D Wachspress coordinates. + + This function computes 2D Wachspress coordinates at a given `query` point + with respect to the vertices of a strictly convex `polygon`, that is one + coordinate per vertex. The coordinates are stored in a destination range + beginning at `c_begin`. + + Internally, the class `Wachspress_coordinates_2` is used. If one wants to process + multiple query points, it is better to use that class. When using the free function, + internal memory is allocated for each query point, while when using the class, + it is allocated only once, which is much more efficient. However, for a few query + points, it is easier to use this function. It can also be used when the processing + time is not a concern. + + \tparam PointRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + and value type is `GeomTraits::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param polygon + an instance of `PointRange` with 2D points, which form a strictly convex polygon + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param policy + one of the `Computation_policy_2`; + the default is `Computation_policy_2::PRECISE_WITH_EDGE_CASES` + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + + \pre polygon.size() >= 3 + \pre polygon is simple + \pre polygon is strictly convex + */ + template< + typename PointRange, + typename OutIterator, + typename GeomTraits> + OutIterator wachspress_coordinates_2( + const PointRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + Wachspress_coordinates_2 wachspress( + polygon, policy, traits); + return wachspress(query, c_begin); + } + + /// \cond SKIP_IN_MANUAL + template< + typename PointRange, + typename Point_2, + typename OutIterator> + OutIterator wachspress_coordinates_2( + const PointRange& polygon, + const Point_2& query, + OutIterator c_begin, + const Computation_policy_2 policy = + Computation_policy_2::PRECISE_WITH_EDGE_CASES) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return wachspress_coordinates_2( + polygon, query, c_begin, traits, policy); + } + /// \endcond + } // namespace Barycentric_coordinates } // namespace CGAL diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/boundary_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/boundary_coordinates_2.h new file mode 100644 index 00000000000..1d0cd396088 --- /dev/null +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/boundary_coordinates_2.h @@ -0,0 +1,170 @@ +// Copyright (c) 2014 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Dmitry Anisimov, David Bommes, Kai Hormann, Pierre Alliez +// + +#ifndef CGAL_BARYCENTRIC_BOUNDARY_COORDINATES_2_H +#define CGAL_BARYCENTRIC_BOUNDARY_COORDINATES_2_H + +#include + +// Internal includes. +#include + +namespace CGAL { +namespace Barycentric_coordinates { + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D boundary coordinates. + + This function computes boundary barycentric coordinates at a given `query` point + with respect to the vertices of a simple `polygon`, that is one + coordinate per vertex. The coordinates are stored in a destination range + beginning at `c_begin`. + + If `query` is at the vertex, the corresponding coordinate is set to one, while + all other coordinates are zero. If `query` is on the edge, the two corresponding + coordinates are segment coordinates, while all other coordinates are set to zero. + If `query` is not on the boundary, all the coordinates are set to zero. + + Internally, `segment_coordinates_2()` are used. + + \tparam VertexRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \tparam PointMap + a model of `ReadablePropertyMap` whose key type is `VertexRange::value_type` and + value type is `GeomTraits::Point_2` + + \param polygon + an instance of `VertexRange` with 2D points, which form a simple polygon + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \param point_map + an instance of `PointMap` that maps a vertex from `polygon` to `Point_2` + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + the flag indicating whether the + query point belongs to the polygon boundary + + \pre polygon.size() >= 3 + */ + template< + typename VertexRange, + typename OutIterator, + typename GeomTraits, + typename PointMap> + std::pair boundary_coordinates_2( + const VertexRange& polygon, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits, + const PointMap point_map) { + + const auto result = + internal::locate_wrt_polygon_2(polygon, query, traits, point_map); + auto location = (*result).first; + auto index = (*result).second; + + if (!result) { + index = std::size_t(-1); + location = internal::Query_point_location::UNSPECIFIED; + } + return internal::boundary_coordinates_2( + polygon, query, location, index, c_begin, traits, point_map); + } + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes 2D boundary coordinates. + + This is an overload of the function `boundary_coordinates_2`. + + \tparam VertexRange + a model of `ConstRange` whose iterator type is `RandomAccessIterator` + + \tparam Query_2 + a model of `Kernel::Point_2` + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam PointMap + a model of `ReadablePropertyMap` whose key type is `VertexRange::value_type` and + value type is `Query_2`. The default is `CGAL::Identity_property_map`. + + \param polygon + an instance of `VertexRange` with 2D points, which form a simple polygon + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param point_map + an instance of `PointMap` that maps a vertex from `polygon` to `Query_2`; + the default initialization is provided + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + the flag indicating whether the + query point belongs to the polygon boundary + + \pre polygon.size() >= 3 + */ + template< + typename VertexRange, + typename Query_2, + typename OutIterator, + typename PointMap = CGAL::Identity_property_map > + std::pair boundary_coordinates_2( + const VertexRange& polygon, + const Query_2& query, + OutIterator c_begin, + const PointMap point_map = PointMap()) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return boundary_coordinates_2( + polygon, query, c_begin, traits, point_map); + } + +} // namespace Barycentric_coordinates +} // namespace CGAL + +#endif // CGAL_BARYCENTRIC_BOUNDARY_COORDINATES_2_H diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/internal/utils_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/internal/utils_2.h index 15bb0090fd9..45e14397b2f 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/internal/utils_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/internal/utils_2.h @@ -122,7 +122,7 @@ namespace internal { void normalize(std::vector& values) { FT sum = FT(0); - for (const FT value : values) + for (const FT& value : values) sum += value; CGAL_assertion(sum != FT(0)); diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/segment_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/segment_coordinates_2.h new file mode 100644 index 00000000000..2ffe5a97fce --- /dev/null +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/segment_coordinates_2.h @@ -0,0 +1,181 @@ +// Copyright (c) 2014 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Dmitry Anisimov, David Bommes, Kai Hormann, Pierre Alliez +// + +#ifndef CGAL_BARYCENTRIC_SEGMENT_COORDINATES_2_H +#define CGAL_BARYCENTRIC_SEGMENT_COORDINATES_2_H + +#include + +// Internal includes. +#include + +namespace CGAL { +namespace Barycentric_coordinates { + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes segment coordinates. + + This function computes barycentric coordinates at a given `query` point + with respect to the end points `p0` and `p1` of a segment that is one + coordinate per end point. The coordinates are stored in a destination range + beginning at `c_begin`. + + After the coordinates \f$b_0\f$ and \f$b_1\f$ are computed, the query point \f$q\f$ can be + obtained as \f$q = b_0p_0 + b_1p_1\f$. If \f$q\f$ does not belong to the line through \f$p_0\f$ + and \f$p_1\f$, it is projected onto this line, and only then the coordinates are + computed. See more details in the user manual \ref compute_seg_coord "here". + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param p0 + the first vertex of a segment + + \param p1 + the second vertex of a segment + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + + \pre p0 != p1 + */ + template< + typename OutIterator, + typename GeomTraits> + OutIterator segment_coordinates_2( + const typename GeomTraits::Point_2& p0, + const typename GeomTraits::Point_2& p1, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits) { + + return internal::linear_coordinates_2( + p0, p1, query, c_begin, traits); + } + + /// \cond SKIP_IN_MANUAL + template< + typename Point_2, + typename OutIterator> + OutIterator segment_coordinates_2( + const Point_2& p0, + const Point_2& p1, + const Point_2& query, + OutIterator c_begin) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return segment_coordinates_2( + p0, p1, query, c_begin, traits); + } + /// \endcond + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes segment coordinates. + + This function computes barycentric coordinates at a given `query` point + with respect to the end points `p0` and `p1` of a segment that is one + coordinate per end point. The coordinates are returned in a pair. + + After the coordinates \f$b_0\f$ and \f$b_1\f$ are computed, the query point \f$q\f$ can be + obtained as \f$q = b_0p_0 + b_1p_1\f$. If \f$q\f$ does not belong to the line through \f$p_0\f$ + and \f$p_1\f$, it is projected onto this line, and only then the coordinates are + computed. See more details in the user manual \ref compute_seg_coord "here". + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param p0 + the first vertex of a segment + + \param p1 + the second vertex of a segment + + \param query + a query point + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \return a pair `std::pair` + with the computed coordinates + + \pre p0 != p1 + */ + template + std::pair< + typename GeomTraits::FT, + typename GeomTraits::FT> + segment_coordinates_in_pair_2( + const typename GeomTraits::Point_2& p0, + const typename GeomTraits::Point_2& p1, + const typename GeomTraits::Point_2& query, + const GeomTraits& traits) { + + using FT = typename GeomTraits::FT; + std::vector coordinates; + coordinates.reserve(2); + internal::linear_coordinates_2( + p0, p1, query, std::back_inserter(coordinates), traits); + CGAL_assertion(coordinates.size() == 2); + return std::make_pair(coordinates[0], coordinates[1]); + } + + /// \cond SKIP_IN_MANUAL + template + std::pair< + typename Kernel_traits::Kernel::FT, + typename Kernel_traits::Kernel::FT> + segment_coordinates_in_pair_2( + const Point_2& p0, + const Point_2& p1, + const Point_2& query) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return segment_coordinates_in_pair_2( + p0, p1, query, traits); + } + /// \endcond + +} // namespace Barycentric_coordinates +} // namespace CGAL + +#endif // CGAL_BARYCENTRIC_SEGMENT_COORDINATES_2_H diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h new file mode 100644 index 00000000000..c51c5628ac1 --- /dev/null +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h @@ -0,0 +1,191 @@ +// Copyright (c) 2014 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Dmitry Anisimov, David Bommes, Kai Hormann, Pierre Alliez +// + +#ifndef CGAL_BARYCENTRIC_TRIANGLE_COORDINATES_2_H +#define CGAL_BARYCENTRIC_TRIANGLE_COORDINATES_2_H + +#include + +// Internal includes. +#include + +namespace CGAL { +namespace Barycentric_coordinates { + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes triangle coordinates. + + This function computes barycentric coordinates at a given `query` point + with respect to the points `p0`, `p1`, and `p2`, which form a triangle, that is one + coordinate per point. The coordinates are stored in a destination range + beginning at `c_begin`. + + After the coordinates \f$b_0\f$, \f$b_1\f$, and \f$b_2\f$ are computed, the query + point \f$q\f$ can be obtained as \f$q = b_0p_0 + b_1p_1 + b_2p_2\f$. See more details + in the user manual \ref compute_tri_coord "here". + + \tparam OutIterator + a model of `OutputIterator` that accepts values of type `GeomTraits::FT` + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param p0 + the first vertex of a triangle + + \param p1 + the second vertex of a triangle + + \param p2 + the third vertex of a triangle + + \param query + a query point + + \param c_begin + the beginning of the destination range with the computed coordinates + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \return an output iterator to the element in the destination range, + one past the last coordinate stored + + \pre area_2(p0, p1, p2) != 0 + */ + template< + typename OutIterator, + typename GeomTraits> + OutIterator triangle_coordinates_2( + const typename GeomTraits::Point_2& p0, + const typename GeomTraits::Point_2& p1, + const typename GeomTraits::Point_2& p2, + const typename GeomTraits::Point_2& query, + OutIterator c_begin, + const GeomTraits& traits) { + + return internal::planar_coordinates_2( + p0, p1, p2, query, c_begin, traits); + } + + /// \cond SKIP_IN_MANUAL + template< + typename Point_2, + typename OutIterator> + OutIterator triangle_coordinates_2( + const Point_2& p0, + const Point_2& p1, + const Point_2& p2, + const Point_2& query, + OutIterator c_begin) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return triangle_coordinates_2( + p0, p1, p2, query, c_begin, traits); + } + /// \endcond + + /*! + \ingroup PkgBarycentricCoordinates2RefFunctions + + \brief computes triangle coordinates. + + This function computes barycentric coordinates at a given `query` point + with respect to the points `p0`, `p1`, and `p2`, which form a triangle, that is one + coordinate per point. The coordinates are returned in a tuple. + + After the coordinates \f$b_0\f$, \f$b_1\f$, and \f$b_2\f$ are computed, the query + point \f$q\f$ can be obtained as \f$q = b_0p_0 + b_1p_1 + b_2p_2\f$. See more details + in the user manual \ref compute_tri_coord "here". + + \tparam GeomTraits + a model of `BarycentricTraits_2` + + \param p0 + the first vertex of a triangle + + \param p1 + the second vertex of a triangle + + \param p2 + the third vertex of a triangle + + \param query + a query point + + \param traits + a traits class with geometric objects, predicates, and constructions; + this parameter can be omitted if the traits class can be deduced from the point type + + \return a tuple `std::tuple` + with the computed coordinates + + \pre area_2(p0, p1, p2) != 0 + */ + template + std::tuple< + typename GeomTraits::FT, + typename GeomTraits::FT, + typename GeomTraits::FT> + triangle_coordinates_in_tuple_2( + const typename GeomTraits::Point_2& p0, + const typename GeomTraits::Point_2& p1, + const typename GeomTraits::Point_2& p2, + const typename GeomTraits::Point_2& query, + const GeomTraits& traits) { + + using FT = typename GeomTraits::FT; + std::vector coordinates; + coordinates.reserve(3); + internal::planar_coordinates_2( + p0, p1, p2, query, std::back_inserter(coordinates), traits); + CGAL_assertion(coordinates.size() == 3); + return std::make_tuple(coordinates[0], coordinates[1], coordinates[2]); + } + + /// \cond SKIP_IN_MANUAL + template + std::tuple< + typename Kernel_traits::Kernel::FT, + typename Kernel_traits::Kernel::FT, + typename Kernel_traits::Kernel::FT> + triangle_coordinates_in_tuple_2( + const Point_2& p0, + const Point_2& p1, + const Point_2& p2, + const Point_2& query) { + + using GeomTraits = typename Kernel_traits::Kernel; + const GeomTraits traits; + return triangle_coordinates_in_tuple_2( + p0, p1, p2, query, traits); + } + /// \endcond + +} // namespace Barycentric_coordinates +} // namespace CGAL + +#endif // CGAL_BARYCENTRIC_TRIANGLE_COORDINATES_2_H diff --git a/Barycentric_coordinates_2/test/Barycentric_coordinates_2/CMakeLists.txt b/Barycentric_coordinates_2/test/Barycentric_coordinates_2/CMakeLists.txt index 96b1fc6be93..f46581f136c 100644 --- a/Barycentric_coordinates_2/test/Barycentric_coordinates_2/CMakeLists.txt +++ b/Barycentric_coordinates_2/test/Barycentric_coordinates_2/CMakeLists.txt @@ -3,7 +3,7 @@ project(Barycentric_coordinates_2_Tests) -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.1...3.15) set(CMAKE_CXX_STANDARD 14) find_package(CGAL QUIET COMPONENTS Core) @@ -12,84 +12,60 @@ if(CGAL_FOUND) include(${CGAL_USE_FILE}) include(CGAL_CreateSingleSourceCGALProgram) - create_single_source_cgal_program( - "test_almost_degenerate_segment.cpp") - create_single_source_cgal_program( - "test_segment_coordinates.cpp") - create_single_source_cgal_program( - "test_segment_coordinates_with_offset.cpp") + create_single_source_cgal_program("test_almost_degenerate_segment.cpp") + create_single_source_cgal_program("test_segment_coordinates.cpp") + create_single_source_cgal_program("test_segment_coordinates_with_offset.cpp") - create_single_source_cgal_program( - "test_almost_degenerate_triangle.cpp") - create_single_source_cgal_program( - "test_triangle_coordinates.cpp") + create_single_source_cgal_program("test_almost_degenerate_triangle.cpp") + create_single_source_cgal_program("test_triangle_coordinates.cpp") - create_single_source_cgal_program( - "test_boundary_coordinates_at_vertices.cpp") - create_single_source_cgal_program( - "test_boundary_coordinates_on_edges.cpp") + create_single_source_cgal_program("test_boundary_coordinates_at_vertices.cpp") + create_single_source_cgal_program("test_boundary_coordinates_on_edges.cpp") - create_single_source_cgal_program( - "test_wp_dh_unit_square.cpp") - create_single_source_cgal_program( - "test_wp_almost_degenerate_polygon.cpp") - create_single_source_cgal_program( - "test_wp_const_linear_precision.cpp") - create_single_source_cgal_program( - "test_wp_triangle.cpp") - create_single_source_cgal_program( - "test_wp_weights.cpp") + create_single_source_cgal_program("test_wp_dh_unit_square.cpp") + create_single_source_cgal_program("test_wp_almost_degenerate_polygon.cpp") + create_single_source_cgal_program("test_wp_const_linear_precision.cpp") + create_single_source_cgal_program("test_wp_triangle.cpp") + create_single_source_cgal_program("test_wp_weights.cpp") - create_single_source_cgal_program( - "test_mv_special_points.cpp") - create_single_source_cgal_program( - "test_mv_weakly_convex_polygon.cpp") - create_single_source_cgal_program( - "test_mv_const_linear_precision.cpp") - create_single_source_cgal_program( - "test_mv_triangle.cpp") - create_single_source_cgal_program( - "test_mv_weights.cpp") + create_single_source_cgal_program("test_mv_special_points.cpp") + create_single_source_cgal_program("test_mv_weakly_convex_polygon.cpp") + create_single_source_cgal_program("test_mv_const_linear_precision.cpp") + create_single_source_cgal_program("test_mv_triangle.cpp") + create_single_source_cgal_program("test_mv_weights.cpp") - create_single_source_cgal_program( - "test_dh_almost_degenerate_polygon.cpp") - create_single_source_cgal_program( - "test_dh_const_linear_precision.cpp") - create_single_source_cgal_program( - "test_dh_triangle.cpp") - create_single_source_cgal_program( - "test_dh_weights.cpp") + create_single_source_cgal_program("test_dh_almost_degenerate_polygon.cpp") + create_single_source_cgal_program("test_dh_const_linear_precision.cpp") + create_single_source_cgal_program("test_dh_triangle.cpp") + create_single_source_cgal_program("test_dh_weights.cpp") # missing begin() and end() in CGAL 4.14 - # create_single_source_cgal_program( - # "test_cgal_polygons.cpp") + # create_single_source_cgal_program("test_cgal_polygons.cpp") find_package(Eigen3 REQUIRED) - if(EIGEN3_FOUND) - include(${EIGEN3_USE_FILE}) + include(CGAL_Eigen3_support) + if(TARGET CGAL::Eigen3_support) - create_single_source_cgal_program( - "test_hm_unit_square.cpp") - create_single_source_cgal_program( - "test_hm_const_linear_precision.cpp") - create_single_source_cgal_program( - "test_hm_triangle.cpp") + create_single_source_cgal_program("test_hm_unit_square.cpp") + target_link_libraries(test_hm_unit_square PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("test_hm_const_linear_precision.cpp") + target_link_libraries(test_hm_const_linear_precision PUBLIC CGAL::Eigen3_support) + create_single_source_cgal_program("test_hm_triangle.cpp") + target_link_libraries(test_hm_triangle PUBLIC CGAL::Eigen3_support) # missing: # construct_centroid_2, # compute_determinant_2 # in projection traits - # create_single_source_cgal_program( - # "test_projection_traits.cpp") + # create_single_source_cgal_program("test_projection_traits.cpp") + # target_link_libraries(test_projection_traits PUBLIC CGAL::Eigen3_support) - create_single_source_cgal_program( - "test_all_coordinates.cpp") + create_single_source_cgal_program("test_all_coordinates.cpp") + target_link_libraries(test_all_coordinates PUBLIC CGAL::Eigen3_support) else() - message(WARNING - "Harmonic coordinates require the Eigen library, and will not be compiled.") + message(WARNING "Several coordinates require the Eigen library, and will not be compiled.") endif() else() - message(WARNING - "This program requires the CGAL library, and will not be compiled.") + message(WARNING "This program requires the CGAL library, and will not be compiled.") endif()