diff --git a/Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h b/Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h index 577eccd5d4f2..aafc6362f7a8 100644 --- a/Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h +++ b/Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h @@ -9,6 +9,9 @@ Traits class that can be used with all the \tparam R a representation class \tparam PointPropertyMap a property map that maps to points of type `R::Point_2` +\tparam Container_ the container type used to store the vertices of the output + polygon. It must be a model of the `SequenceContainer` concept with + value type `R::Point_2`. Defaults to `std::list`. \cgalModels{ConvexPartitionIsValidTraits_2,IsYMonotoneTraits_2,OptimalConvexPartitionTraits_2,PartitionTraits_2,YMonotonePartitionIsValidTraits_2} @@ -22,7 +25,9 @@ Traits class that can be used with all the \sa `CGAL::y_monotone_partition_is_valid_2()` */ - template< typename R, typename PointPropertyMap = Identity_property_map > + template< typename R, + typename PointPropertyMap = Identity_property_map, + typename Container_ = std::list::key_type> > class Partition_traits_2 { public: @@ -46,9 +51,11 @@ typedef boost::property_traits::key_type Point_2; /*! - +The sequence container used to store the vertices of the output polygon. +This is determined by the `Container_` template parameter. +The default is `std::list`. */ -typedef std::list Container; +typedef Container_ Container; /*! diff --git a/Partition_2/doc/Partition_2/PackageDescription.txt b/Partition_2/doc/Partition_2/PackageDescription.txt index c97c815c64d1..ef100b88d322 100644 --- a/Partition_2/doc/Partition_2/PackageDescription.txt +++ b/Partition_2/doc/Partition_2/PackageDescription.txt @@ -77,7 +77,7 @@ original polygon). \cgalCRPSection{Classes} - `CGAL::Partition_is_valid_traits_2` -- `CGAL::Partition_traits_2` +- `CGAL::Partition_traits_2` \cgalCRPSection{Function Object Classes} diff --git a/Partition_2/include/CGAL/Partition_traits_2.h b/Partition_2/include/CGAL/Partition_traits_2.h index 389e64bcf33d..15c8e64d8925 100644 --- a/Partition_2/include/CGAL/Partition_traits_2.h +++ b/Partition_2/include/CGAL/Partition_traits_2.h @@ -25,7 +25,9 @@ namespace CGAL { - template > + template , + class Container_ = std::list::key_type> > class Partition_traits_2; template @@ -38,12 +40,12 @@ class Partition_traits_2; typedef BT type; }; -template +template class Partition_traits_2 : public Base_traits { private: typedef Base_traits Kernel; - typedef Partition_traits_2 Self; + typedef Partition_traits_2 Self; PointPropertyMap ppmap; @@ -62,7 +64,7 @@ class Partition_traits_2 : public Base_traits typedef typename boost::property_traits::key_type Point_2; typedef typename boost::call_traits::param_type Arg_type; - typedef ::std::list Container; + typedef Container_ Container; typedef typename Polygon_traits_getter::type PolygonTraits; typedef CGAL::Polygon_2 Polygon_2; diff --git a/Partition_2/test/Partition_2/partition_traits_2_vector_container_test.cpp b/Partition_2/test/Partition_2/partition_traits_2_vector_container_test.cpp new file mode 100644 index 000000000000..2049a04ace5b --- /dev/null +++ b/Partition_2/test/Partition_2/partition_traits_2_vector_container_test.cpp @@ -0,0 +1,64 @@ +// Regression test for the Container_ template parameter of Partition_traits_2. +// Verifies that a user-specified container type (std::vector) can be used in +// place of the default std::list for the output Polygon_2 vertex storage. +// Fixes: https://github.com/CGAL/cgal/issues/7545 + +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_2 Point_2; + +// Traits that stores polygon vertices in a std::vector instead of std::list. +typedef CGAL::Partition_traits_2, + std::vector> VecTraits; +typedef VecTraits::Polygon_2 VecPolygon_2; +typedef std::list VecPolygon_list; + +int main() +{ + // Build a simple non-convex CCW input polygon (same as the standard + // Partition_2 test suite polygon — proven to exercise all partitioners). + VecPolygon_2 polygon; + polygon.push_back(Point_2(227,423)); + polygon.push_back(Point_2(123,364)); + polygon.push_back(Point_2(129,254)); + polygon.push_back(Point_2(230,285)); + polygon.push_back(Point_2(231,128)); + polygon.push_back(Point_2(387,205)); + polygon.push_back(Point_2(417,331)); + polygon.push_back(Point_2(319,225)); + polygon.push_back(Point_2(268,293)); + polygon.push_back(Point_2(367,399)); + polygon.push_back(Point_2(298,418)); + polygon.push_back(Point_2(196,326)); + + // Partition using y_monotone — output polygons use std::vector vertices. + VecPolygon_list partition_polys; + CGAL::y_monotone_partition_2(polygon.vertices_begin(), + polygon.vertices_end(), + std::back_inserter(partition_polys), + VecTraits()); + + assert(!partition_polys.empty()); + + // Verify the vertex container is indeed std::vector. + static_assert( + std::is_same>::value, + "Container typedef must alias the Container_ template parameter"); + + // Partition using approx_convex. + partition_polys.clear(); + CGAL::approx_convex_partition_2(polygon.vertices_begin(), + polygon.vertices_end(), + std::back_inserter(partition_polys), + VecTraits()); + assert(!partition_polys.empty()); + + return 0; +}