Partition_2: add Container template parameter to Partition_traits_2#9351
Partition_2: add Container template parameter to Partition_traits_2#9351RajdeepKushwaha5 wants to merge 1 commit intoCGAL:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Container template parameter to CGAL::Partition_traits_2 so users can choose the vertex container type (e.g., std::vector<Point_2>) for the output Polygon_2 produced by Partition_2 algorithms, while preserving the existing defaults for backward compatibility.
Changes:
- Extend
Partition_traits_2with a third template parameterContainer_(defaulting tostd::list<Point_2>-equivalent) and use it for theContainertypedef. - Update the reference documentation for
Partition_traits_2to document the new template parameter and updated typedef. - Update the package description class listing to reflect the new template signature.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
Partition_2/include/CGAL/Partition_traits_2.h |
Adds the Container_ template parameter and wires it into the Polygon_2 container type. |
Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h |
Documents the new container template parameter and updates the Container typedef description. |
Partition_2/doc/Partition_2/PackageDescription.txt |
Updates the class list to show Partition_traits_2<R,P,Container>. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| template <class Base_traits, | ||
| class PointPropertyMap = Identity_property_map<typename Base_traits::Point_2>, | ||
| class Container_ = std::list<typename boost::property_traits<PointPropertyMap>::key_type> > | ||
| class Partition_traits_2; |
There was a problem hiding this comment.
This change adds a new Container_ template parameter intended to let callers choose the output polygon vertex container, but there isn't a regression test exercising a non-default container (e.g., std::vector<Point_2>) with at least one partitioning function. Adding a small compile+run test would help ensure the new API works and stays supported.
| @@ -46,9 +51,11 @@ typedef boost::property_traits<PointPropertyMap>::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<Point_2>`. | |||
| */ | |||
| typedef std::list<Point_2> Container; | |||
| typedef Container Container; | |||
|
|
|||
There was a problem hiding this comment.
In the documentation header, the template parameter is named Container, and the nested typedef is written as typedef Container Container;. This effectively redefines the template parameter name in the same scope and does not document the actual container type alias (it should alias the template parameter type, not itself). Consider renaming the template parameter to Container_ (matching the implementation) and defining typedef Container_ Container; so the documented API matches the real one and parses cleanly.
|
Before pushing you should test locally. This would have revealed the |
| \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 `Point_2`. Defaults to `std::list<Point_2>`. |
There was a problem hiding this comment.
| value type `Point_2`. Defaults to `std::list<Point_2>`. | |
| value type `R::Point_2`. Defaults to `std::list<R::Point_2>`. |
Fixes CGAL#7545 The Container type used for the vertices of the output Polygon_2 was previously hardcoded to std::list<Point_2> inside Partition_traits_2. This prevented users from requesting a different container (e.g., std::vector<Point_2>) for the output polygons produced by all partitioning functions. Changes: * Partition_2/include/CGAL/Partition_traits_2.h - Add a third template parameter class Container_ = std::list<typename boost::property_traits<PointPropertyMap>::key_type> to both the forward declaration and the class definition. - Replace 'typedef ::std::list<Point_2> Container' with 'typedef Container_ Container', making the typedef an alias for the template argument. - Update the Self typedef to include all three template parameters. All existing uses of Partition_traits_2<K> or Partition_traits_2<K,PM> are fully backward-compatible since the new parameter defaults to std::list, preserving the previous behaviour. * Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h - Add \\tparam Container documentation. - Add Container to the class template declaration. - Document the Container typedef as reflecting the template parameter. * Partition_2/doc/Partition_2/PackageDescription.txt - Update the class listing to Partition_traits_2<R,P,Container>.
10a96a1 to
9391fb5
Compare
Fixes #7545
The
Containertype used for the vertices of the outputPolygon_2was hardcoded tostd::list<Point_2>insidePartition_traits_2. This prevented users from requesting a different container (e.g.,std::vector<Point_2>) for the output polygons produced by all partitioning functions (y_monotone_partition_2,approx_convex_partition_2,greene_approx_convex_partition_2,optimal_convex_partition_2).Root Cause
Partition_traits_2.hline 65 had:typedef ::std::list<Point_2> Container;
with no mechanism for users to change it.
Fix
Add a third template parameter to
Partition_traits_2:class Container_ = std::list<typename boost::property_traits::key_type>
The parameter defaults to
std::list<Point_2>, preserving full backwardcompatibility with all existing uses of
Partition_traits_2<K>andPartition_traits_2<K, PM>.Users can now write:
typedef CGAL::Partition_traits_2<K, CGAL::Identity_property_map<K::Point_2>,
std::vector<K::Point_2>> VecTraits;
std::listVecTraits::Polygon_2 parts;
CGAL::optimal_convex_partition_2(pts.begin(), pts.end(),
std::back_inserter(parts), VecTraits());
Files Changed
Partition_2/include/CGAL/Partition_traits_2.htypedef ::std::list<Point_2> Containerwithtypedef Container_ Container.Partition_2/doc/Partition_2/CGAL/Partition_traits_2.h\tparam Containerdocumentation.Partition_2/doc/Partition_2/PackageDescription.txtPartition_traits_2<R,P>toPartition_traits_2<R,P,Container>.