diff --git a/Minkowski_sum_2/include/CGAL/minkowski_sum_2.h b/Minkowski_sum_2/include/CGAL/minkowski_sum_2.h index 52551454373..497d9dcb2a2 100644 --- a/Minkowski_sum_2/include/CGAL/minkowski_sum_2.h +++ b/Minkowski_sum_2/include/CGAL/minkowski_sum_2.h @@ -30,21 +30,49 @@ namespace CGAL { +/*! + * Computes the Minkowski sum \f$ P \oplus Q\f$ of the two given polygons. + * The function computes the reduced convolution of the two polygons and + * extracts those loops of the convolution which are part of the Minkowsi + * sum. This method works very efficiently, regardless of whether `P` and + * `Q` are convex or non-convex. + * Note that as the input polygons may not be convex, their Minkowski + * sum may not be a simple polygon. The result is therefore represented + * as a polygon with holes. + * \pre Both `P` and `Q` are simple, counterclockwise-oriented polygons. +*/ + +template +Polygon_with_holes_2 +minkowski_sum_by_reduced_convolution_2 (const Polygon_2& pgn1, + const Polygon_2& pgn2) +{ + Minkowski_sum_by_reduced_convolution_2 mink_sum; + Polygon_2 sum_bound; + std::list > sum_holes; + + if (pgn1.size() > pgn2.size()) + mink_sum (pgn1, pgn2, sum_bound, std::back_inserter(sum_holes)); + else + mink_sum (pgn2, pgn1, sum_bound, std::back_inserter(sum_holes)); + + return (Polygon_with_holes_2 (sum_bound, + sum_holes.begin(), + sum_holes.end())); +} + /*! * Compute the Minkowski sum of two simple polygons using the convolution * method. * Note that as the input polygons may not be convex, their Minkowski sum may * not be a simple polygon. The result is therefore represented as a polygon * with holes. - * \param pgn1 The first polygon. - * \param pgn2 The second polygon. - * \return The resulting polygon with holes, representing the sum. */ template Polygon_with_holes_2 -minkowski_sum_2 (const Polygon_2& pgn1, - const Polygon_2& pgn2) +minkowski_sum_by_full_convolution_2 (const Polygon_2& pgn1, + const Polygon_2& pgn2) { Minkowski_sum_by_convolution_2 mink_sum; Polygon_2 sum_bound; @@ -60,23 +88,23 @@ minkowski_sum_2 (const Polygon_2& pgn1, sum_holes.end())); } +/*! + * Compute the Minkowski sum of two simple polygons using the reduced + * convolution method. + * Note that as the input polygons may not be convex, their Minkowski sum may + * not be a simple polygon. The result is therefore represented as a polygon + * with holes. + * + * \sa `CGAL::minkowski_sum_by_reduced_convolution_2()` + * \sa `CGAL::minkowski_sum_by_full_convolution_2()` + */ + template Polygon_with_holes_2 -minkowski_sum_2_new (const Polygon_2& pgn1, - const Polygon_2& pgn2) +minkowski_sum_2 (const Polygon_2& pgn1, + const Polygon_2& pgn2) { - Minkowski_sum_by_reduced_convolution_2 mink_sum; - Polygon_2 sum_bound; - std::list > sum_holes; - - if (pgn1.size() > pgn2.size()) - mink_sum (pgn1, pgn2, sum_bound, std::back_inserter(sum_holes)); - else - mink_sum (pgn2, pgn1, sum_bound, std::back_inserter(sum_holes)); - - return (Polygon_with_holes_2 (sum_bound, - sum_holes.begin(), - sum_holes.end())); + return minkowski_sum_by_reduced_convolution_2(pgn1, pgn2); } /*! diff --git a/Minkowski_sum_2/test/Minkowski_sum_2/test_Minkowski_sum.cpp b/Minkowski_sum_2/test/Minkowski_sum_2/test_Minkowski_sum.cpp index 1b32c75dcca..6cc34ffafb5 100644 --- a/Minkowski_sum_2/test/Minkowski_sum_2/test_Minkowski_sum.cpp +++ b/Minkowski_sum_2/test/Minkowski_sum_2/test_Minkowski_sum.cpp @@ -95,7 +95,7 @@ int main (int argc, char **argv) std::cout << "Using the reduced convolution method ... "; timer.reset(); timer.start(); - sum_conv_new = minkowski_sum_2_new (pgn1, pgn2); + sum_conv_new = minkowski_sum_by_reduced_convolution_2 (pgn1, pgn2); timer.stop(); std::cout << "Done (" << timer.time() << " s)" << std::endl; @@ -120,7 +120,7 @@ int main (int argc, char **argv) std::cout << "Using the convolution method ... "; timer.reset(); timer.start(); - sum_conv = minkowski_sum_2 (pgn1, pgn2); + sum_conv = minkowski_sum_by_full_convolution_2 (pgn1, pgn2); timer.stop(); if (are_equal (result, sum_conv)) {