mirror of https://github.com/CGAL/cgal
Cleaned up
This commit is contained in:
parent
e6b72fc7c8
commit
0bf75c9062
|
|
@ -15,13 +15,11 @@
|
|||
#include <CGAL/license/Envelope_2.h>
|
||||
|
||||
|
||||
#include <CGAL/Arr_enums.h>
|
||||
#include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <CGAL/Arr_enums.h>
|
||||
#include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
|
|
@ -29,11 +27,9 @@ namespace CGAL {
|
|||
* A class implementing the divide-and-conquer algorithm for computing the
|
||||
* lower (or upper) envelope of a set of curves.
|
||||
*/
|
||||
template <class Traits_, class Diagram_>
|
||||
class Envelope_divide_and_conquer_2
|
||||
{
|
||||
template <typename Traits_, typename Diagram_>
|
||||
class Envelope_divide_and_conquer_2 {
|
||||
public:
|
||||
|
||||
typedef Traits_ Traits_2;
|
||||
typedef typename Traits_2::Point_2 Point_2;
|
||||
typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2;
|
||||
|
|
@ -42,11 +38,9 @@ public:
|
|||
typedef Diagram_ Envelope_diagram_1;
|
||||
|
||||
protected:
|
||||
|
||||
typedef Envelope_divide_and_conquer_2<Traits_2, Envelope_diagram_1> Self;
|
||||
|
||||
enum Envelope_type
|
||||
{
|
||||
enum Envelope_type {
|
||||
LOWER,
|
||||
UPPER
|
||||
};
|
||||
|
|
@ -71,131 +65,92 @@ protected:
|
|||
Self& operator=(const Self& );
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Constructor.
|
||||
/*! Constructor.
|
||||
*/
|
||||
Envelope_divide_and_conquer_2() :
|
||||
own_traits(true),
|
||||
env_type(LOWER)
|
||||
{
|
||||
traits = new Traits_adaptor_2;
|
||||
}
|
||||
{ traits = new Traits_adaptor_2; }
|
||||
|
||||
/*!
|
||||
* Constructor with a traits object.
|
||||
/*! Constructor with a traits object.
|
||||
* \param _traits The traits object.
|
||||
*/
|
||||
Envelope_divide_and_conquer_2(const Traits_2* _traits) :
|
||||
own_traits(false),
|
||||
env_type(LOWER)
|
||||
{
|
||||
traits = static_cast<const Traits_adaptor_2*> (_traits);
|
||||
}
|
||||
{ traits = static_cast<const Traits_adaptor_2*> (_traits); }
|
||||
|
||||
/*!
|
||||
* Destructor.
|
||||
/*! Destructor.
|
||||
*/
|
||||
~Envelope_divide_and_conquer_2()
|
||||
{
|
||||
if (own_traits)
|
||||
delete traits;
|
||||
}
|
||||
{ if (own_traits) delete traits; }
|
||||
|
||||
/*!
|
||||
* Construct the lower (or upper) envelope to the given range of curves.
|
||||
/*! Construct the lower (or upper) envelope to the given range of curves.
|
||||
* \param begin An iterator pointing at the beginning of the curves range.
|
||||
* \param end A past-the-end iterator for the curves range.
|
||||
* \param type The envelope type (true for lower, false of upper).
|
||||
* \param diagram Output: The minimization (or maximization) diagram.
|
||||
*/
|
||||
template <class CurvesIterator>
|
||||
void insert_curves (CurvesIterator begin, CurvesIterator end,
|
||||
bool type,
|
||||
Envelope_diagram_1& diagram)
|
||||
{
|
||||
template <typename CurvesIterator>
|
||||
void insert_curves(CurvesIterator begin, CurvesIterator end, bool type,
|
||||
Envelope_diagram_1& diagram) {
|
||||
// Subdivide the curves into x-monotone subcurves.
|
||||
CurvesIterator it;
|
||||
std::list<std::variant<Point_2, X_monotone_curve_2>> objects;
|
||||
std::list<X_monotone_curve_2> x_curves;
|
||||
|
||||
for (it = begin; it != end; it++)
|
||||
{
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
// Split the current curve to x-monotone subcurves.
|
||||
objects.clear();
|
||||
traits->make_x_monotone_2_object()(*it, std::back_inserter(objects));
|
||||
|
||||
for (auto obj_it = objects.begin(); obj_it != objects.end(); ++obj_it)
|
||||
{
|
||||
if(const X_monotone_curve_2* xcv_ptr = std::get_if<X_monotone_curve_2>(&(*obj_it)))
|
||||
for (auto obj_it = objects.begin(); obj_it != objects.end(); ++obj_it) {
|
||||
if (const auto* xcv_ptr = std::get_if<X_monotone_curve_2>(&(*obj_it)))
|
||||
x_curves.push_back (*xcv_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the envelope of the x-monotone curves.
|
||||
insert_x_monotone_curves (x_curves.begin(), x_curves.end(),
|
||||
type,
|
||||
diagram);
|
||||
return;
|
||||
insert_x_monotone_curves(x_curves.begin(), x_curves.end(), type, diagram);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Construct the lower (or upper) envelope to the given range of
|
||||
/*! Construct the lower (or upper) envelope to the given range of
|
||||
* x-monotone curves.
|
||||
* \param begin An iterator pointing at the beginning of the curves range.
|
||||
* \param end A past-the-end iterator for the curves range.
|
||||
* \param type The envelope type (true for lower, false for upper).
|
||||
* \param diagram Output: The minimization (or maximization) diagram.
|
||||
*/
|
||||
template <class XCurvesIterator>
|
||||
template <typename XCurvesIterator>
|
||||
void insert_x_monotone_curves(XCurvesIterator begin, XCurvesIterator end,
|
||||
bool type,
|
||||
Envelope_diagram_1& diagram)
|
||||
{
|
||||
bool type, Envelope_diagram_1& diagram) {
|
||||
// Set the envelope type.
|
||||
env_type = (type ? LOWER : UPPER);
|
||||
|
||||
// Separate the regular curves from the vertical ones.
|
||||
typename Traits_2::Is_vertical_2 is_vertical =
|
||||
traits->is_vertical_2_object();
|
||||
auto is_vertical = traits->is_vertical_2_object();
|
||||
|
||||
Curve_pointer_vector reg_vec;
|
||||
Curve_pointer_vector vert_vec;
|
||||
XCurvesIterator iter;
|
||||
|
||||
for (iter = begin; iter != end; ++iter)
|
||||
{
|
||||
if (is_vertical (*iter))
|
||||
vert_vec.push_back (&(*iter));
|
||||
else
|
||||
reg_vec.push_back (&(*iter));
|
||||
for (auto iter = begin; iter != end; ++iter) {
|
||||
if (is_vertical (*iter)) vert_vec.push_back (&(*iter));
|
||||
else reg_vec.push_back (&(*iter));
|
||||
}
|
||||
|
||||
// Construct the envelope for the non-vertical curves.
|
||||
_construct_envelope_non_vertical (reg_vec.begin(), reg_vec.end(),
|
||||
diagram);
|
||||
_construct_envelope_non_vertical(reg_vec.begin(), reg_vec.end(), diagram);
|
||||
|
||||
// Merge the vertical segments.
|
||||
if (vert_vec.size() > 0)
|
||||
_merge_vertical_segments (vert_vec,
|
||||
diagram);
|
||||
|
||||
return;
|
||||
if (vert_vec.size() > 0) _merge_vertical_segments(vert_vec, diagram);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Get the traits object.
|
||||
/*! Get the traits object.
|
||||
* \return A pointer to the traits object.
|
||||
*/
|
||||
Traits_2* get_traits () const
|
||||
{
|
||||
return (traits);
|
||||
}
|
||||
Traits_2* get_traits() const { return (traits); }
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* Construct the lower/upper envelope of the given list of non-vertical
|
||||
/*! Construct the lower/upper envelope of the given list of non-vertical
|
||||
* curves.
|
||||
* \param begin The first x-monotone curve.
|
||||
* \param end A past-the-end iterator for the curves.
|
||||
|
|
@ -205,16 +160,14 @@ protected:
|
|||
Curve_pointer_iterator end,
|
||||
Envelope_diagram_1& out_d);
|
||||
|
||||
/*!
|
||||
* Construct a singleton diagram, which matches a single curve.
|
||||
/*! Construct a singleton diagram, which matches a single curve.
|
||||
* \param cv The x-monotone curve.
|
||||
* \param out_d Output: The minimization (or maximization) diagram.
|
||||
*/
|
||||
void _construct_singleton_diagram (const X_monotone_curve_2& cv,
|
||||
Envelope_diagram_1& out_d);
|
||||
|
||||
/*
|
||||
* Merge two minimization (or maximization) diagrams.
|
||||
/* Merge two minimization (or maximization) diagrams.
|
||||
* \param d1 The first diagram,
|
||||
* representing the envelope of the curve set C1.
|
||||
* \param d1 The first diagram,
|
||||
|
|
@ -226,8 +179,7 @@ protected:
|
|||
const Envelope_diagram_1& d2,
|
||||
Envelope_diagram_1& out_d);
|
||||
|
||||
/*!
|
||||
* Compare two vertices.
|
||||
/*! Compare two vertices.
|
||||
* \param v1 The first vertex.
|
||||
* \param v2 The second vertex.
|
||||
* \param same_x Output parameter: TRUE iff x(v1) = x(v2).
|
||||
|
|
@ -243,9 +195,8 @@ protected:
|
|||
Vertex_const_handle v2,
|
||||
bool& same_x) const;
|
||||
|
||||
/*!
|
||||
* Deal with an interval which is non-empty in one of the merged diagrams and
|
||||
* empty in the other.
|
||||
/*! Deal with an interval which is non-empty in one of the merged diagrams
|
||||
* and empty in the other.
|
||||
* \param e The non-empty edge.
|
||||
* \param other_edge The empty edge.
|
||||
* \param v The next vertex to the right.
|
||||
|
|
@ -263,17 +214,17 @@ protected:
|
|||
Envelope_diagram_1& out_d);
|
||||
|
||||
|
||||
//! Compare the $y$-coordinates of two curves at their endpoints
|
||||
/*! The function compares the $y$ values of two curves with a joint
|
||||
range of $x$ values, at the end of the joint range.
|
||||
\param xcv1 The first curve
|
||||
\param xcv2 The second curve
|
||||
\param curve_end ARR_MIN_END - compare the $y$ value of the smaller
|
||||
endpoint, ARR_MAX_END - compare the $y$ value of the larger endpoint.
|
||||
\pre The two $x$-monotone curves need to have a partially overlapping
|
||||
$x$-ranges.
|
||||
\return
|
||||
\todo Move it to Arr_traits_adaptor ?
|
||||
/*! Compare the $y$-coordinates of two curves at their endpoints
|
||||
* The function compares the $y$ values of two curves with a joint
|
||||
* range of $x$ values, at the end of the joint range.
|
||||
* \param xcv1 The first curve
|
||||
* \param xcv2 The second curve
|
||||
* \param curve_end ARR_MIN_END - compare the $y$ value of the smaller
|
||||
* endpoint, ARR_MAX_END - compare the $y$ value of the larger endpoint.
|
||||
* \pre The two $x$-monotone curves need to have a partially overlapping
|
||||
* $x$-ranges.
|
||||
* \return
|
||||
* \todo Move it to Arr_traits_adaptor ?
|
||||
*/
|
||||
Comparison_result compare_y_at_end(const X_monotone_curve_2& xcv1,
|
||||
const X_monotone_curve_2& xcv2,
|
||||
|
|
@ -281,8 +232,7 @@ protected:
|
|||
|
||||
|
||||
|
||||
/*!
|
||||
* Merge two non-empty intervals into the merged diagram.
|
||||
/*! Merge two non-empty intervals into the merged diagram.
|
||||
* \param e1 The first non-empty edge.
|
||||
* \param is_leftmost1 Is it the leftmost edge in its diagram.
|
||||
* \param e2 The second non-empty edge.
|
||||
|
|
@ -301,8 +251,7 @@ protected:
|
|||
Comparison_result origin_of_v,
|
||||
Envelope_diagram_1& out_d);
|
||||
|
||||
/*!
|
||||
* Append a vertex to the given diagram: The new vertex that represents the
|
||||
/*! Append a vertex to the given diagram: The new vertex that represents the
|
||||
* given point as the new rightmost vertex of the diagram. The edge
|
||||
* between the current rightmost vertex and the new one contains the same
|
||||
* curves as the input edge.
|
||||
|
|
@ -317,15 +266,12 @@ protected:
|
|||
/*! \struct
|
||||
* A functor used to sort vertical segments by their x-coordinate.
|
||||
*/
|
||||
class Less_vertical_segment
|
||||
{
|
||||
class Less_vertical_segment {
|
||||
private:
|
||||
|
||||
typename Traits_2::Compare_x_2 comp_x;
|
||||
typename Traits_2::Construct_min_vertex_2 min_vertex;
|
||||
|
||||
public:
|
||||
|
||||
Less_vertical_segment(const Traits_2 *traits) :
|
||||
comp_x(traits->compare_x_2_object()),
|
||||
min_vertex(traits->construct_min_vertex_2_object())
|
||||
|
|
@ -333,14 +279,10 @@ protected:
|
|||
|
||||
bool operator()(const X_monotone_curve_2* cv1,
|
||||
const X_monotone_curve_2* cv2) const
|
||||
{
|
||||
return (comp_x (min_vertex (*cv1),
|
||||
min_vertex (*cv2)) == SMALLER);
|
||||
}
|
||||
{ return(comp_x(min_vertex(*cv1), min_vertex(*cv2)) == SMALLER); }
|
||||
};
|
||||
|
||||
/*!
|
||||
* Merge the vertical segments into the lower/upper envelope given as a
|
||||
/*! Merge the vertical segments into the lower/upper envelope given as a
|
||||
* minimization (or maximization) diagram.
|
||||
* \param vert_vec The list of vertical segments.
|
||||
* \param out_d The input minimization (or maximization) diagram.
|
||||
|
|
@ -349,8 +291,7 @@ protected:
|
|||
void _merge_vertical_segments(Curve_pointer_vector& vert_vec,
|
||||
Envelope_diagram_1& out_d);
|
||||
|
||||
/*!
|
||||
* Split a given diagram edge by inserting a vertex in its interior.
|
||||
/*! Split a given diagram edge by inserting a vertex in its interior.
|
||||
* \param diag The diagram.
|
||||
* \param p The point that the new vertex is associated with.
|
||||
* \param e The edge to split.
|
||||
|
|
|
|||
Loading…
Reference in New Issue