Fixed Arrangement_2 construction bug - made the geometry traits const

This commit is contained in:
Efi Fogel 2009-07-05 13:14:14 +00:00
parent 57ba5cc702
commit 4d94f715b9
7 changed files with 166 additions and 147 deletions

View File

@ -45,20 +45,21 @@ protected:
public:
Gps_agg_curve_data() : Base(),
m_arr(NULL),
m_bc(0),
m_twin_bc(0)
Gps_agg_curve_data() :
Base(),
m_arr(NULL),
m_bc(0),
m_twin_bc(0)
{}
Gps_agg_curve_data(const Arrangement* arr,
Halfedge_handle he,
unsigned int bc,
unsigned int twin_bc): Base(he),
m_arr(arr),
m_bc(bc),
m_twin_bc(twin_bc)
unsigned int twin_bc):
Base(he),
m_arr(arr),
m_bc(bc),
m_twin_bc(twin_bc)
{}
unsigned int bc() const
@ -181,7 +182,7 @@ class Gps_agg_meta_traits :
Gps_agg_meta_traits()
{}
Gps_agg_meta_traits(Traits& base_tr) : Base(base_tr)
Gps_agg_meta_traits(const Traits & base_tr) : Base(base_tr)
{}
@ -210,7 +211,7 @@ class Gps_agg_meta_traits :
template<class OutputIterator>
OutputIterator operator() (const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2,
OutputIterator oi)
OutputIterator oi) const
{
if (cv1.data().arr() == cv2.data().arr())
{
@ -269,7 +270,7 @@ class Gps_agg_meta_traits :
Curve_data cv_data(cv1.data().arr(),
Halfedge_handle(),
ov_bc, ov_twin_bc);
*oi = CGAL::make_object (X_monotone_curve_2 (*overlap_cv, cv_data));
*oi = CGAL::make_object (X_monotone_curve_2(*overlap_cv, cv_data));
}
}
}
@ -279,7 +280,7 @@ class Gps_agg_meta_traits :
};
/*! Get an Intersect_2 functor object. */
Intersect_2 intersect_2_object ()
Intersect_2 intersect_2_object () const
{
return Intersect_2(this->m_base_tr->intersect_2_object(),
this->m_base_tr->compare_endpoints_xy_2_object(),
@ -300,7 +301,7 @@ class Gps_agg_meta_traits :
{}
void operator() (const X_monotone_curve_2& cv, const Point_2 & p,
X_monotone_curve_2& c1, X_monotone_curve_2& c2)
X_monotone_curve_2& c1, X_monotone_curve_2& c2) const
{
m_base_split(cv.base(),
p.base(),
@ -320,7 +321,7 @@ class Gps_agg_meta_traits :
};
/*! Get a Split_2 functor object. */
Split_2 split_2_object ()
Split_2 split_2_object () const
{
return Split_2(this->m_base_tr->split_2_object());
}
@ -342,12 +343,13 @@ class Gps_agg_meta_traits :
* \param cv The curve.
* \return The left endpoint.
*/
Point_2 operator() (const X_monotone_curve_2 & cv)
Point_2 operator() (const X_monotone_curve_2 & cv) const
{
if(cv.data().halfedge() == Halfedge_handle())
return (Point_2 (m_base(cv.base())));
CGAL_assertion((Arr_halfedge_direction)cv.data().halfedge()->direction() == ARR_LEFT_TO_RIGHT);
CGAL_assertion((Arr_halfedge_direction)cv.data().halfedge()->direction() ==
ARR_LEFT_TO_RIGHT);
return Point_2 (m_base(cv.base()), cv.data().halfedge()->source());
}
};
@ -355,7 +357,8 @@ class Gps_agg_meta_traits :
/*! Get a Construct_min_vertex_2 functor object. */
Construct_min_vertex_2 construct_min_vertex_2_object () const
{
return Construct_min_vertex_2(this->m_base_tr->construct_min_vertex_2_object());
return Construct_min_vertex_2(this->m_base_tr->
construct_min_vertex_2_object());
}
@ -375,12 +378,13 @@ class Gps_agg_meta_traits :
* \param cv The curve.
* \return The right endpoint.
*/
Point_2 operator() (const X_monotone_curve_2 & cv)
Point_2 operator() (const X_monotone_curve_2 & cv) const
{
if(cv.data().halfedge() == Halfedge_handle())
return (Point_2 (m_base(cv.base())));
CGAL_assertion((Arr_halfedge_direction)cv.data().halfedge()->direction() == ARR_LEFT_TO_RIGHT);
CGAL_assertion((Arr_halfedge_direction)cv.data().halfedge()->direction() ==
ARR_LEFT_TO_RIGHT);
return Point_2 (m_base(cv.base()), cv.data().halfedge()->target());
}
};
@ -388,7 +392,8 @@ class Gps_agg_meta_traits :
/*! Get a Construct_min_vertex_2 functor object. */
Construct_max_vertex_2 construct_max_vertex_2_object () const
{
return Construct_max_vertex_2(this->m_base_tr->construct_max_vertex_2_object());
return Construct_max_vertex_2(this->m_base_tr->
construct_max_vertex_2_object());
}
@ -428,7 +433,7 @@ class Gps_agg_meta_traits :
/*! Get a Construct_min_vertex_2 functor object. */
Compare_xy_2 compare_xy_2_object ()
Compare_xy_2 compare_xy_2_object () const
{
return Compare_xy_2(this->m_base_tr->compare_xy_2_object());
}
@ -452,21 +457,21 @@ class Gps_agg_meta_traits :
/*! Obtains the parameter space at the end of a curve-end along the x-axis.
*/
Arr_parameter_space operator() (const X_monotone_curve_2 & cv,
const Arr_curve_end& end)
const Arr_curve_end& end) const
{
return m_base(cv.base(), end);
}
/*! Obtains the parameter space for a curve along the x-axis.
*/
Arr_parameter_space operator() (const X_monotone_curve_2 & cv)
Arr_parameter_space operator() (const X_monotone_curve_2 & cv) const
{
return m_base(cv.base());
}
/*! Obtains the parameter space for a point along the x-axis.
*/
Arr_parameter_space operator() (const Point_2 & pt)
Arr_parameter_space operator() (const Point_2 & pt) const
{
return m_base(pt.base());
}
@ -530,21 +535,21 @@ class Gps_agg_meta_traits :
/*! Obtains the parameter space at the end of a curve-end along the y-axis.
*/
Arr_parameter_space operator() (const X_monotone_curve_2 & cv,
const Arr_curve_end& end)
const Arr_curve_end& end) const
{
return m_base(cv.base(), end);
}
/*! Obtains the parameter space for a curve along the x-axis.
*/
Arr_parameter_space operator() (const X_monotone_curve_2 & cv)
Arr_parameter_space operator() (const X_monotone_curve_2 & cv) const
{
return m_base(cv.base());
}
/*! Obtains the parameter space for a point along the x-axis.
*/
Arr_parameter_space operator() (const Point_2 & pt)
Arr_parameter_space operator() (const Point_2 & pt) const
{
return m_base(pt.base());
}

View File

@ -108,7 +108,7 @@ public:
/*! Constructor. */
Gps_agg_op (Arrangement_2& arr, std::vector<Vertex_handle>& vert_vec,
Traits_2& tr) :
const Traits_2 & tr) :
m_arr (&arr),
m_traits(new Meta_traits(tr)),
m_visitor (&arr, &m_edges_hash, &vert_vec),
@ -118,7 +118,7 @@ public:
void sweep_arrangements(unsigned int lower,
unsigned int upper,
unsigned int jump,
std::vector<Arr_entry>& arr_vec)
std::vector<Arr_entry>& arr_vec)
{
std::list<Meta_X_monotone_curve_2> curves_list;

View File

@ -61,15 +61,13 @@ public:
if(i==j)
return;
typename Arrangement_2::Geometry_traits_2* tr =
const typename Arrangement_2::Geometry_traits_2 * tr =
arr_vec[i].first->geometry_traits();
Arrangement_2 *res = new Arrangement_2(tr);
std::vector<Vertex_handle> *verts = new std::vector<Vertex_handle>;
Gps_agg_op<Arrangement_2, Visitor>
agg_op(*res, *verts,
*(res->traits_adaptor())
);
agg_op(*res, *verts, *(res->traits_adaptor()));
agg_op.sweep_arrangements(i, j, jump, arr_vec);
for(unsigned int count=i; count<=j; count+=jump)

View File

@ -196,7 +196,7 @@ public:
template<class OutputIterator>
OutputIterator operator() (const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2,
OutputIterator oi)
OutputIterator oi) const
{
//// if the two curves are incident, do not intersect them
//if(m_self_tr->is_valid_index(cv1.data().index()) &&
@ -272,7 +272,7 @@ public:
};
/*! Get an Intersect_2 functor object. */
Intersect_2 intersect_2_object ()
Intersect_2 intersect_2_object () const
{
return Intersect_2(this->m_base_tr->intersect_2_object(),
this->m_base_tr->compare_endpoints_xy_2_object(),
@ -295,7 +295,7 @@ public:
{}
void operator() (const X_monotone_curve_2& cv, const Point_2 & p,
X_monotone_curve_2& c1, X_monotone_curve_2& c2)
X_monotone_curve_2& c1, X_monotone_curve_2& c2) const
{
m_base_split(cv.base(),
p.base(),
@ -313,10 +313,9 @@ public:
};
/*! Get a Split_2 functor object. */
Split_2 split_2_object ()
Split_2 split_2_object () const
{
return Split_2(this->m_base_tr->split_2_object(),
this);
return Split_2(this->m_base_tr->split_2_object(), this);
}
class Construct_min_vertex_2
@ -341,7 +340,7 @@ public:
* \param cv The curve.
* \return The left endpoint.
*/
Point_2 operator() (const X_monotone_curve_2 & cv)
Point_2 operator() (const X_monotone_curve_2 & cv) const
{
if(!m_self_tr->is_valid_index(cv.data().index()))
{
@ -395,7 +394,7 @@ public:
* \param cv The curve.
* \return The left endpoint.
*/
Point_2 operator() (const X_monotone_curve_2 & cv)
Point_2 operator() (const X_monotone_curve_2 & cv) const
{
if(!m_self_tr->is_valid_index(cv.data().index()))
{
@ -464,7 +463,7 @@ public:
/*! Get a Construct_min_vertex_2 functor object. */
Compare_xy_2 compare_xy_2_object ()
Compare_xy_2 compare_xy_2_object () const
{
return Compare_xy_2(this->m_base_tr->compare_xy_2_object(), this);
}

View File

@ -48,7 +48,7 @@ public:
class Construct_vertex_2
{
public:
Point_2 operator()(const X_monotone_curve_2& cv, int i)
Point_2 operator()(const X_monotone_curve_2& cv, int i) const
{
Base tr;
Compare_endpoints_xy_2 cmp_endpoints =

View File

@ -204,23 +204,24 @@ public:
protected:
//Data members
Base* m_base_tr;
bool m_traits_owner;
const Base * m_base_tr;
bool m_traits_owner;
public:
Gps_traits_decorator() : m_base_tr(new Base()),
m_traits_owner(true)
Gps_traits_decorator() :
m_base_tr(new Base()),
m_traits_owner(true)
{}
Gps_traits_decorator(Base& base_traits) :
Gps_traits_decorator(const Base & base_traits) :
m_base_tr(&base_traits),
m_traits_owner(false)
{}
~Gps_traits_decorator()
{
if(m_traits_owner)
if (m_traits_owner)
delete m_base_tr;
}
@ -231,7 +232,7 @@ public:
Base_Compare_x_2 m_base;
public:
Compare_x_2(Base_Compare_x_2& base) :m_base(base)
Compare_x_2(Base_Compare_x_2& base) : m_base(base)
{}
Comparison_result operator() (const Point_2& p1, const Point_2& p2) const
@ -254,7 +255,7 @@ public:
Base_Compare_xy_2 m_base;
public:
Compare_xy_2(const Base_Compare_xy_2& base) :m_base(base)
Compare_xy_2(const Base_Compare_xy_2& base) : m_base(base)
{}
Comparison_result operator() (const Point_2& p1, const Point_2& p2) const
@ -276,7 +277,8 @@ public:
Base_Construct_min_vertex_2 m_base;
public:
Construct_min_vertex_2(const Base_Construct_min_vertex_2& base) :m_base(base)
Construct_min_vertex_2(const Base_Construct_min_vertex_2& base) :
m_base(base)
{}
Point_2 operator() (const X_monotone_curve_2& cv) const
@ -298,7 +300,8 @@ public:
Base_Construct_max_vertex_2 m_base;
public:
Construct_max_vertex_2(const Base_Construct_max_vertex_2& base) :m_base(base)
Construct_max_vertex_2(const Base_Construct_max_vertex_2& base) :
m_base(base)
{}
Point_2 operator() (const X_monotone_curve_2& cv) const
@ -321,7 +324,7 @@ public:
Base_Is_vertical_2 m_base;
public:
Is_vertical_2(const Base_Is_vertical_2& base) :m_base(base)
Is_vertical_2(const Base_Is_vertical_2& base) : m_base(base)
{}
bool operator() (const X_monotone_curve_2& cv) const
@ -344,7 +347,7 @@ public:
Base_Compare_y_at_x_2 m_base;
public:
Compare_y_at_x_2(const Base_Compare_y_at_x_2& base) :m_base(base)
Compare_y_at_x_2(const Base_Compare_y_at_x_2& base) : m_base(base)
{}
Comparison_result operator() (const Point_2& p,
@ -368,7 +371,8 @@ public:
Base_Compare_y_at_x_right_2 m_base;
public:
Compare_y_at_x_right_2(const Base_Compare_y_at_x_right_2& base) :m_base(base)
Compare_y_at_x_right_2(const Base_Compare_y_at_x_right_2& base) :
m_base(base)
{}
Comparison_result operator() (const X_monotone_curve_2& cv1,
@ -393,7 +397,7 @@ public:
Base_Equal_2 m_base;
public:
Equal_2(const Base_Equal_2& base) :m_base(base)
Equal_2(const Base_Equal_2& base) : m_base(base)
{}
bool operator() (const Point_2& p1, const Point_2& p2) const
@ -416,7 +420,7 @@ public:
Base_Split_2 m_base;
public:
Split_2(const Base_Split_2& base) :m_base(base)
Split_2(const Base_Split_2& base) : m_base(base)
{}
void operator() (const X_monotone_curve_2& cv,
@ -506,10 +510,11 @@ public:
Base_Compare_endpoints_xy_2 m_base;
public:
Compare_endpoints_xy_2(const Base_Compare_endpoints_xy_2& base) :m_base(base)
Compare_endpoints_xy_2(const Base_Compare_endpoints_xy_2& base) :
m_base(base)
{}
Comparison_result operator()(const X_monotone_curve_2& cv)
Comparison_result operator()(const X_monotone_curve_2& cv) const
{
return (m_base(cv));
@ -533,7 +538,7 @@ public:
Construct_opposite_2(Base_Construct_opposite_2& base) :m_base(base)
{}
X_monotone_curve_2 operator()(const X_monotone_curve_2& cv)
X_monotone_curve_2 operator()(const X_monotone_curve_2& cv) const
{
return (X_monotone_curve_2(m_base(cv)));
}

View File

@ -46,25 +46,25 @@ public:
//Polygon_2 type is required by GeneralPolygonSetTraits Concept
typedef CGAL::Polygon_2<Kernel_, Container_> Polygon_2;
//Polygon_2 is a model of the GeneralPolygon2 concept.
typedef Polygon_2 General_polygon_2;
typedef Polygon_2 General_polygon_2;
//Polygon_with_holes_2 can be a simple polygon , with holes that are
//entirely inside him , or some vertices of the polygon and its holes
// may overlap.
//Polygon_with_holes_2 type required by GeneralPolygonSetTraits Concept.
//Polygon_with_holes_2 type required by GeneralPolygonSetTraits Concept.
typedef CGAL::Polygon_with_holes_2<Kernel_, Container_>
Polygon_with_holes_2;
Polygon_with_holes_2;
//Polygon_with_Holes_2 is a model of the GeneralPolygonWithHoles2 concept.
typedef Polygon_with_holes_2 General_polygon_with_holes_2;
typedef typename Base::X_monotone_curve_2 X_monotone_curve_2;
typedef Polygon_with_holes_2 General_polygon_with_holes_2;
typedef typename Base::X_monotone_curve_2 X_monotone_curve_2;
typedef Polygon_2_curve_iterator<X_monotone_curve_2,
Polygon_2> Curve_const_iterator;
typedef Polygon_2_curve_iterator<X_monotone_curve_2, Polygon_2>
Curve_const_iterator;
typedef typename Polygon_with_holes_2::Hole_const_iterator
Hole_const_iterator;
typedef typename Base::Point_2 Point_2;
Hole_const_iterator;
typedef typename Base::Point_2 Point_2;
/*!
@ -73,22 +73,21 @@ public:
class Construct_polygon_2
{
typedef Gps_segment_traits_2<Kernel_,
Container_,
Arr_seg_traits_> Self;
Container_,
Arr_seg_traits_> Self;
typedef Gps_traits_adaptor<Base> Traits_adaptor;
public:
template<class XCurveIterator>
void operator()(XCurveIterator begin,
XCurveIterator end,
Polygon_2& pgn)
void operator()(XCurveIterator begin, XCurveIterator end, Polygon_2& pgn)
const
{
Traits_adaptor tr;
typename Traits_adaptor::Construct_vertex_2 ctr_v =
tr.construct_vertex_2_object();
for(XCurveIterator itr = begin; itr != end; ++itr)
for (XCurveIterator itr = begin; itr != end; ++itr)
{
pgn.push_back(ctr_v(*itr, 1));
}
@ -109,6 +108,7 @@ public:
std::pair<Curve_const_iterator,
Curve_const_iterator> operator()(const General_polygon_2& pgn)
const
{
Curve_const_iterator c_begin(&pgn, pgn.edges_begin());
Curve_const_iterator c_end(&pgn, pgn.edges_end());
@ -117,7 +117,7 @@ public:
}
};
Construct_curves_2 construct_curves_2_object()
Construct_curves_2 construct_curves_2_object() const
{
return Construct_curves_2();
}
@ -128,85 +128,97 @@ public:
typedef Gps_traits_adaptor<Base> Traits_adaptor;
/* typedef CGAL::Is_valid_2<Self, Traits_adaptor> Is_valid_2;
Is_valid_2 is_valid_2_object()
{
Traits_adaptor tr_adp;
Is_valid_2 is_valid_2_object()
{
Traits_adaptor tr_adp;
return (Is_valid_2 (*this, tr_adp));
}*/
return (Is_valid_2 (*this, tr_adp));
}*/
//Added Functionality from GeneralPolygonWithHoles Concept to the traits.
/*A functor for constructing the outer boundary of a polygon with holes*/
//Added Functionality from GeneralPolygonWithHoles Concept to the traits.
/*A functor for constructing the outer boundary of a polygon with holes*/
class Construct_outer_boundary {
public:
General_polygon_2 operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.outer_boundary();
}
};
Construct_outer_boundary construct_outer_boundary_object() const {
return Construct_outer_boundary();
}
/*typedef from General_polygon_with_holes_2. Hole_const_iterator nested type is required by
GeneralPolygonWithHoles2 concept*/
/*A functor for constructing the container of holes of a polygon with holes. It returns ths
begin/end iterators for the holes*/
class Construct_holes {
public:
std::pair<Hole_const_iterator, Hole_const_iterator> operator()(const General_polygon_with_holes_2& pol_wh)
{
return std::make_pair(pol_wh.holes_begin(), pol_wh.holes_end());
}
};
Construct_holes construct_holes_object() const {
return Construct_holes();
}
/* A functor for constructing a General_polygon_with_holes from a General_Polygon
(and possibly a range of holes).*/
// constructs a general polygon with holes using a given general polygon outer
// as the outer boundary and a given range of holes. If outer is an empty general
// polygon, then an unbounded polygon with holes will be created. The holes must
// be contained inside the outer boundary, and the polygons representing the holes
// must be strictly simple and pairwise disjoint, except perhaps at the vertices.
class Construct_general_polygon_with_holes_2 {
public:
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary)
{
return General_polygon_with_holes_2(pgn_boundary);
}
template <class HolesInputIterator>
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary,
HolesInputIterator h_begin,
HolesInputIterator h_end)
{
return General_polygon_with_holes_2(pgn_boundary, h_begin,h_end);
}
public:
General_polygon_2 operator()(const General_polygon_with_holes_2& pol_wh)
const
{
return pol_wh.outer_boundary();
}
};
Construct_general_polygon_with_holes_2 construct_polygon_with_holes_2_object() const
Construct_outer_boundary construct_outer_boundary_object() const
{
return Construct_outer_boundary();
}
/* typedef from General_polygon_with_holes_2.
* Hole_const_iterator nested type is required by
* GeneralPolygonWithHoles2 concept
*/
/*A functor for constructing the container of holes of a polygon with holes.
* It returns ths begin/end iterators for the holes
*/
class Construct_holes {
public:
std::pair<Hole_const_iterator, Hole_const_iterator>
operator()(const General_polygon_with_holes_2& pol_wh) const
{
return std::make_pair(pol_wh.holes_begin(), pol_wh.holes_end());
}
};
Construct_holes construct_holes_object() const
{
return Construct_holes();
}
/* A functor for constructing a General_polygon_with_holes from a
* General_Polygon (and possibly a range of holes).
*
* constructs a general polygon with holes using a given general polygon
* outer as the outer boundary and a given range of holes. If outer is an
* empty general polygon, then an unbounded polygon with holes will be
* created. The holes must be contained inside the outer boundary, and the
* polygons representing the holes must be strictly simple and pairwise
* disjoint, except perhaps at the vertices.
*/
class Construct_general_polygon_with_holes_2 {
public:
General_polygon_with_holes_2 operator()(const General_polygon_2&
pgn_boundary) const
{
return General_polygon_with_holes_2(pgn_boundary);
}
template <class HolesInputIterator>
General_polygon_with_holes_2 operator()(const General_polygon_2&
pgn_boundary,
HolesInputIterator h_begin,
HolesInputIterator h_end) const
{
return General_polygon_with_holes_2(pgn_boundary, h_begin,h_end);
}
};
Construct_general_polygon_with_holes_2 construct_polygon_with_holes_2_object()
const
{
return Construct_general_polygon_with_holes_2();
}
//functor returns true if the outer boundary is unbounded, and false otherwise.
class Is_unbounded {
public:
bool operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.is_unbounded();
}
};
Is_unbounded construct_is_unbounded_object() {
return Is_unbounded();
}
};
//functor returns true if the outer boundary is unbounded, and false otherwise.
class Is_unbounded {
public:
bool operator()(const General_polygon_with_holes_2& pol_wh) const
{
return pol_wh.is_unbounded();
}
};
Is_unbounded construct_is_unbounded_object() const
{
return Is_unbounded();
}
};
CGAL_END_NAMESPACE