mirror of https://github.com/CGAL/cgal
Give public methods more descriptive names, default one defaults to reduced conv
This commit is contained in:
parent
6f609e7122
commit
55d0e7bf45
|
|
@ -30,20 +30,48 @@
|
||||||
|
|
||||||
namespace CGAL {
|
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 <class Kernel, class Container>
|
||||||
|
Polygon_with_holes_2<Kernel,Container>
|
||||||
|
minkowski_sum_by_reduced_convolution_2 (const Polygon_2<Kernel,Container>& pgn1,
|
||||||
|
const Polygon_2<Kernel,Container>& pgn2)
|
||||||
|
{
|
||||||
|
Minkowski_sum_by_reduced_convolution_2<Kernel, Container> mink_sum;
|
||||||
|
Polygon_2<Kernel,Container> sum_bound;
|
||||||
|
std::list<Polygon_2<Kernel,Container> > 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<Kernel,Container> (sum_bound,
|
||||||
|
sum_holes.begin(),
|
||||||
|
sum_holes.end()));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Compute the Minkowski sum of two simple polygons using the convolution
|
* Compute the Minkowski sum of two simple polygons using the convolution
|
||||||
* method.
|
* method.
|
||||||
* Note that as the input polygons may not be convex, their Minkowski sum may
|
* 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
|
* not be a simple polygon. The result is therefore represented as a polygon
|
||||||
* with holes.
|
* with holes.
|
||||||
* \param pgn1 The first polygon.
|
|
||||||
* \param pgn2 The second polygon.
|
|
||||||
* \return The resulting polygon with holes, representing the sum.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class Kernel, class Container>
|
template <class Kernel, class Container>
|
||||||
Polygon_with_holes_2<Kernel,Container>
|
Polygon_with_holes_2<Kernel,Container>
|
||||||
minkowski_sum_2 (const Polygon_2<Kernel,Container>& pgn1,
|
minkowski_sum_by_full_convolution_2 (const Polygon_2<Kernel,Container>& pgn1,
|
||||||
const Polygon_2<Kernel,Container>& pgn2)
|
const Polygon_2<Kernel,Container>& pgn2)
|
||||||
{
|
{
|
||||||
Minkowski_sum_by_convolution_2<Kernel, Container> mink_sum;
|
Minkowski_sum_by_convolution_2<Kernel, Container> mink_sum;
|
||||||
|
|
@ -60,23 +88,23 @@ minkowski_sum_2 (const Polygon_2<Kernel,Container>& pgn1,
|
||||||
sum_holes.end()));
|
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 <class Kernel, class Container>
|
template <class Kernel, class Container>
|
||||||
Polygon_with_holes_2<Kernel,Container>
|
Polygon_with_holes_2<Kernel,Container>
|
||||||
minkowski_sum_2_new (const Polygon_2<Kernel,Container>& pgn1,
|
minkowski_sum_2 (const Polygon_2<Kernel,Container>& pgn1,
|
||||||
const Polygon_2<Kernel,Container>& pgn2)
|
const Polygon_2<Kernel,Container>& pgn2)
|
||||||
{
|
{
|
||||||
Minkowski_sum_by_reduced_convolution_2<Kernel, Container> mink_sum;
|
return minkowski_sum_by_reduced_convolution_2(pgn1, pgn2);
|
||||||
Polygon_2<Kernel,Container> sum_bound;
|
|
||||||
std::list<Polygon_2<Kernel,Container> > 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<Kernel,Container> (sum_bound,
|
|
||||||
sum_holes.begin(),
|
|
||||||
sum_holes.end()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ int main (int argc, char **argv)
|
||||||
std::cout << "Using the reduced convolution method ... ";
|
std::cout << "Using the reduced convolution method ... ";
|
||||||
timer.reset();
|
timer.reset();
|
||||||
timer.start();
|
timer.start();
|
||||||
sum_conv_new = minkowski_sum_2_new (pgn1, pgn2);
|
sum_conv_new = minkowski_sum_by_reduced_convolution_2 (pgn1, pgn2);
|
||||||
timer.stop();
|
timer.stop();
|
||||||
std::cout << "Done (" << timer.time() << " s)" << std::endl;
|
std::cout << "Done (" << timer.time() << " s)" << std::endl;
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ int main (int argc, char **argv)
|
||||||
std::cout << "Using the convolution method ... ";
|
std::cout << "Using the convolution method ... ";
|
||||||
timer.reset();
|
timer.reset();
|
||||||
timer.start();
|
timer.start();
|
||||||
sum_conv = minkowski_sum_2 (pgn1, pgn2);
|
sum_conv = minkowski_sum_by_full_convolution_2 (pgn1, pgn2);
|
||||||
timer.stop();
|
timer.stop();
|
||||||
if (are_equal (result, sum_conv))
|
if (are_equal (result, sum_conv))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue