updated bug in algebraic point

This commit is contained in:
Oren Salzman 2011-05-22 14:01:40 +00:00
parent 6efcbaaee4
commit c42ee37a48
5 changed files with 181 additions and 207 deletions

View File

@ -30,8 +30,8 @@
#include <vector>
#include "boost/variant.hpp"
//#include <CGAL/Arr_ver_support/Rational_arc_with_ver_d_1.h>
#include "Rational_arc_with_ver_d_1.h"
#include <CGAL/Arr_ver_support/Rational_arc_with_ver_d_1.h>
//#include "Rational_arc_with_ver_d_1.h"
namespace CGAL {
@ -133,24 +133,23 @@ public:
class Construct_vertical_x_curve_2
{
private:
typename Traits::Construct_vertical_segment construct_vertical_segment;
Traits& _traits;
public:
Construct_vertical_x_curve_2(Traits& traits)
:_traits(traits),
construct_vertical_segment(_traits.construct_vertical_segment_object()) {}
:_traits(traits)
{}
X_monotone_curve_2 operator() (const Point_2& p1,const Point_2& p2) const
{
return construct_vertical_segment (p1,p2);
return _traits.construct_vertical_segment_object() (p1,p2);
}
X_monotone_curve_2 operator() (const Point_2& p) const
{
return construct_vertical_segment (p);
return _traits.construct_vertical_segment_object() (p);
}
X_monotone_curve_2 operator() (const Point_2& p, bool is_directed_up) const
{
return construct_vertical_segment (p,is_directed_up);
return _traits.construct_vertical_segment_object() (p,is_directed_up);
}
}; //Construct_vertical_x_curve_2
@ -162,24 +161,22 @@ public:
class Construct_vertical_curve_2
{
private:
typename Traits::Construct_vertical_segment construct_vertical_segment;
Traits& _traits;
public:
Construct_vertical_curve_2 (Traits& traits)
:_traits(traits),
construct_vertical_segment(_traits.construct_vertical_segment_object())
:_traits(traits)
{}
Curve_2 operator() (const Point_2& p1,const Point_2& p2) const
{
return construct_vertical_segment (p1,p2);
return _traits.construct_vertical_segment_object()(p1,p2);
}
Curve_2 operator() (const Point_2& p) const
{
return construct_vertical_segment (p);
return _traits.construct_vertical_segment_object()(p);
}
Curve_2 operator() (const Point_2& p, bool is_directed_up) const
{
return construct_vertical_segment (p,is_directed_up);
return _traits.construct_vertical_segment_object()(p,is_directed_up);
}
}; //Construct_vertical_curve_2
@ -193,48 +190,46 @@ public:
{
private:
typedef typename Traits::Algebraic_real_1 Algebraic_real_1;
typename Traits::Construct_curve_2 construct_curve_2;
Traits& _traits;
public:
Construct_curve_2 (Traits& traits)
:_traits(traits),
construct_curve_2(_traits.construct_curve_2_object())
:_traits(traits)
{}
template <class InputIterator>
Curve_2 operator() (InputIterator begin, InputIterator end) const
{
return construct_curve_2 (begin,end);
return _traits.construct_curve_2_object()(begin,end);
}
template <class InputIterator>
Curve_2 operator() (InputIterator begin, InputIterator end,const Algebraic_real_1& x_s, bool dir_right) const
{
return construct_curve_2 (begin,end,x_s,dir_right);
return _traits.construct_curve_2_object()(begin,end,x_s,dir_right);
}
template <class InputIterator>
Curve_2 operator() (InputIterator begin, InputIterator end,
const Algebraic_real_1& x_s, const Algebraic_real_1& x_t) const
{
return construct_curve_2 (begin,end,x_s,x_t);
return _traits.construct_curve_2_object()(begin,end,x_s,x_t);
}
template <class InputIterator>
Curve_2 operator() (InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom) const
{
return construct_curve_2 (begin_numer, end_numer,begin_denom,end_denom);
return _traits.construct_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom);
}
template <class InputIterator>
Curve_2 operator() (InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom,
const Algebraic_real_1& x_s, bool dir_right) const
{
return construct_curve_2 (begin_numer, end_numer,begin_denom,end_denom,x_s,dir_right);
return _traits.construct_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom,x_s,dir_right);
}
template <class InputIterator>
Curve_2 operator() (InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom,
const Algebraic_real_1& x_s, const Algebraic_real_1& x_t) const
{
return construct_curve_2 (begin_numer, end_numer,begin_denom,end_denom,x_s,x_t);
return _traits.construct_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom,x_s,x_t);
}
}; //Construct_rational_curve_2
@ -246,49 +241,47 @@ public:
{
private:
typedef typename Traits::Algebraic_real_1 Algebraic_real_1;
typename Traits::Construct_x_monotone_curve_2 construct_x_monotone_curve_2;
Traits& _traits;
public:
Construct_x_monotone_curve_2 (Traits& traits)
:_traits(traits),
construct_x_monotone_curve_2(_traits.construct_x_monotone_curve_2_object())
:_traits(traits)
{}
template <class InputIterator>
X_monotone_curve_2 operator() (InputIterator begin, InputIterator end) const
{
return construct_x_monotone_curve_2 (begin,end);
return _traits.construct_x_monotone_curve_2_object()(begin,end);
}
template <class InputIterator>
X_monotone_curve_2 operator() ( InputIterator begin, InputIterator end,
const Algebraic_real_1& x_s, bool dir_right) const
{
return construct_x_monotone_curve_2 (begin,end,x_s,dir_right);
return _traits.construct_x_monotone_curve_2_object()(begin,end,x_s,dir_right);
}
template <class InputIterator>
X_monotone_curve_2 operator() (InputIterator begin, InputIterator end,
const Algebraic_real_1& x_s, const Algebraic_real_1& x_t) const
{
return construct_x_monotone_curve_2 (begin,end,x_s,x_t);
return _traits.construct_x_monotone_curve_2_object()(begin,end,x_s,x_t);
}
template <class InputIterator>
X_monotone_curve_2 operator() ( InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom) const
{
return construct_x_monotone_curve_2 (begin_numer, end_numer,begin_denom,end_denom);
return _traits.construct_x_monotone_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom);
}
template <class InputIterator>
X_monotone_curve_2 operator() ( InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom,
const Algebraic_real_1& x_s, bool dir_right) const
{
return construct_x_monotone_curve_2 (begin_numer, end_numer,begin_denom,end_denom,x_s,dir_right);
return _traits.construct_x_monotone_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom,x_s,dir_right);
}
template <class InputIterator>
X_monotone_curve_2 operator() ( InputIterator begin_numer, InputIterator end_numer,
InputIterator begin_denom, InputIterator end_denom,
const Algebraic_real_1& x_s, const Algebraic_real_1& x_t) const
{
return construct_x_monotone_curve_2 (begin_numer, end_numer,begin_denom,end_denom,x_s,x_t);
return _traits.construct_x_monotone_curve_2_object()(begin_numer, end_numer,begin_denom,end_denom,x_s,x_t);
}
}; //Construct_rational_x_curve_2
@ -498,9 +491,10 @@ public:
}
Comparison_result operator() (const Vertical_segment & cv) const
{
typename Traits::Compare_xy_2 compare_xy_2 = _traits.compare_xy_2_object();
CGAL_precondition(compare_xy_2(_p,cv.max()) == CGAL::EQUAL);
CGAL_precondition(_traits.compare_x_2_object()(_p,cv.max()) == CGAL::EQUAL);
typename Traits::Compare_xy_2 compare_xy_2 = _traits.compare_xy_2_object();
if (Is_line(cv))
return CGAL::EQUAL;
if ((Max_bounded(cv)) && (!Min_bounded(cv)) )
@ -642,7 +636,23 @@ public:
if (&cv1 == &cv2)
return (true);
return (cv1==cv2);
if (CGAL::compare(cv1.x(),cv2.x()) != CGAL::EQUAL)
return false;
if (Is_line(cv1) && Is_line(cv2))
return true;
if (Is_segment(cv1) && Is_segment(cv2))
return (_traits.equal_2_object() (cv1.min(),cv2.min()) &&
_traits.equal_2_object() (cv1.max(),cv2.max()) );
if (Max_bounded(cv1) && Max_bounded(cv2))
return (_traits.equal_2_object() (cv1.max(),cv2.max() ));
if (Min_bounded(cv1) && Min_bounded(cv2))
return (_traits.equal_2_object() (cv1.min(),cv2.min() ));
return false;
}
}; //Equal_2_visitor
}; //Equal_2
@ -1083,23 +1093,23 @@ public:
//try to merge at common maximum
if ((Max_bounded(cv1)) && (Max_bounded(cv2)))
{
if (cv1.max() == cv2.max())
if (_traits.equal_2_object()(cv1.max(),cv2.max()))
return true;
}
//try to merge at common minimum
if ((Min_bounded(cv1)) && (Min_bounded(cv2)))
{
if (cv1.min() == cv2.min())
if (_traits.equal_2_object()(cv1.min(),cv2.min()))
return true;
}
//try to merge at minimum and maximum
if ((Max_bounded(cv1)) && (Min_bounded(cv2)))
{
res = (cv1.max() == cv2.min());
res = (_traits.equal_2_object()(cv1.max(),cv2.min()));
}
if ((Min_bounded(cv1)) && (Max_bounded(cv2)))
{
res = (res || (cv1.min() == cv2.max()));
res = (res || (_traits.equal_2_object()(cv1.min(),cv2.max())));
}
return res;
}
@ -1171,7 +1181,7 @@ public:
Vertical_segment _c;
if ((Max_bounded(cv1)) &&
(Max_bounded(cv2)) &&
(cv1.max() == cv2.max()))
(compare_xy_2(cv1.max() , cv2.max()) == CGAL::EQUAL))
{
//merge at cv1.max() and cv2.max()
if ((Min_bounded(cv1) == false) || (Min_bounded(cv2) == false))
@ -1184,7 +1194,7 @@ public:
if ((Min_bounded(cv1)) &&
(Min_bounded(cv2)) &&
(cv1.min() == cv2.min()))
(compare_xy_2(cv1.min() , cv2.min()) == CGAL::EQUAL))
{
//merge at cv1.min() and cv2.min()
if ((Max_bounded(cv1) == false) || (Max_bounded(cv2) == false))
@ -1197,7 +1207,7 @@ public:
if ((Max_bounded(cv1)) &&
(Min_bounded(cv2)) &&
(cv1.max() == cv2.min()))
(compare_xy_2(cv1.max() , cv2.min()) == CGAL::EQUAL))
{
//merge at cv1.max() and cv2.min
if ((Min_bounded(cv1) == false) && (Max_bounded(cv2) == false))

View File

@ -78,12 +78,6 @@ public:
other.rational_function());
return rat_func_pair.compare_f_g_at(_x_coordinate);
}
bool operator == (const Algebraic_point_2_rep & other) const
{
return ( (this->_x_coordinate == other.x()) &&
(this->_rational_function == other.rational_function()) );
}
Algebraic_real_1& x()
{
return _x_coordinate;
@ -138,8 +132,8 @@ public:
std::pair<double,double> to_double() const
{
double x = CGAL::to_double(_x_coordinate);
double numer_val = evaluate_at(_rational_function.numer(),_x_coordinate);
double denom_val = evaluate_at(_rational_function.denom(),_x_coordinate);
double numer_val = evaluate_at(_rational_function.numer(),x);
double denom_val = evaluate_at(_rational_function.denom(),x);
return std::make_pair(x,numer_val/denom_val);
}
std::pair<Bound,Bound> approximate_absolute_x( int a) const
@ -230,13 +224,13 @@ private:
typedef CGAL::Coercion_traits<NTX,BFI> CT;
return typename CT::Cast()(x);
}
double evaluate_at(const Polynomial_1& poly, double x)
double evaluate_at(const Polynomial_1& poly,const double x) const
{
x_val = 1;
double x_val = 1;
double ret_val(0);
for (int i(0); i <= poly.degree(); ++i)
{
ret_val = ret_val + x_val*CGAL::to_double(poly()[i]);
ret_val = ret_val + x_val*CGAL::to_double(poly[i]);
x_val = x_val*x;
}
return ret_val;
@ -299,12 +293,6 @@ public:
return CGAL::EQUAL;
return this->ptr()->compare_xy_2(*other.ptr(),cache);
}
bool operator == (const Self & other) const
{
if (this->is_identical (other))
return true;
return this->ptr() == other.ptr();
}
Algebraic_real_1& x()
{
if (this->is_shared())

View File

@ -1175,7 +1175,7 @@ public:
if (! _has_same_base (arc))
return (false);
// Check that the arc endpoints are the same.
// Check that the arc left endpoints are the same.
Arr_parameter_space inf1 = left_infinite_in_x();
Arr_parameter_space inf2 = arc.left_infinite_in_x();
@ -1183,20 +1183,21 @@ public:
return (false);
if (inf1 == ARR_INTERIOR)
{
inf1 = left_infinite_in_y();
inf2 = arc.left_infinite_in_y();
{
inf1 = left_infinite_in_y();
inf2 = arc.left_infinite_in_y();
if (inf1 != inf2)
return (false);
}
if (inf1 != inf2)
return (false);
}
if (inf1 == ARR_INTERIOR &&
CGAL::compare(left().x(), arc.left().x()) != EQUAL)
{
return (false);
}
{
return (false);
}
// Check that the arc right endpoints are the same.
inf1 = right_infinite_in_x();
inf2 = arc.right_infinite_in_x();
@ -1204,13 +1205,13 @@ public:
return (false);
if (inf1 == ARR_INTERIOR)
{
{
inf1 = right_infinite_in_y();
inf2 = arc.right_infinite_in_y();
if (inf1 != inf2)
return (false);
}
}
if (inf1 == ARR_INTERIOR &&
CGAL::compare(right().x(), arc.right().x()) != EQUAL)
@ -1464,24 +1465,24 @@ protected:
{
return (this->_f == arc._f);
}
bool operator == (const Self& arc) const
{
if (this == &arc)
return true;
if ((_info ==arc._info) &&(_has_same_base(arc) ))
{
bool same_source(true);
bool same_target(true);
if ( (this->source_infinite_in_x () == ARR_INTERIOR) &&
(this->source_infinite_in_y () == ARR_INTERIOR) )
same_source = (this->source() == arc.source());
if ( (this->target_infinite_in_x () == ARR_INTERIOR) &&
(this->target_infinite_in_y () == ARR_INTERIOR) )
same_target = (this->target() == arc.target());
return (same_source && same_target);
}
return false;
}
//bool operator == (const Self& arc) const
//{
// if (this == &arc)
// return true;
// if ((_info ==arc._info) &&(_has_same_base(arc) ))
// {
// bool same_source(true);
// bool same_target(true);
// if ( (this->source_infinite_in_x () == ARR_INTERIOR) &&
// (this->source_infinite_in_y () == ARR_INTERIOR) )
// same_source = (this->source() == arc.source());
// if ( (this->target_infinite_in_x () == ARR_INTERIOR) &&
// (this->target_infinite_in_y () == ARR_INTERIOR) )
// same_target = (this->target() == arc.target());
// return (same_source && same_target);
// }
// return false;
//}
//---------------------------------------------------------------------
//Compute infinity type of the rational function P(x)/Q(x) at x = -oo.
@ -1852,17 +1853,16 @@ public:
CGAL_precondition (this->is_valid() && this->is_continuous());
CGAL_precondition (arc.is_valid() && arc.is_continuous());
if (*this == arc)
{
Self overlap_arc (*this);
*oi = make_object (overlap_arc);
++oi;
return (oi);
}
if (this->equals(arc))
{
Self overlap_arc (*this);
*oi = make_object (overlap_arc);
++oi;
return (oi);
}
if (this->_has_same_base (arc))
{
{
// Get the left and right endpoints of (*this) and their information
// bits.
const Algebraic_point_2& left1 = (this->is_directed_right() ?
@ -1872,15 +1872,15 @@ public:
int info_left1, info_right1;
if (this->is_directed_right())
{
info_left1 = (this->_info & this->SRC_INFO_BITS);
info_right1 = ((this->_info & this->TRG_INFO_BITS) >> 4);
}
{
info_left1 = (this->_info & this->SRC_INFO_BITS);
info_right1 = ((this->_info & this->TRG_INFO_BITS) >> 4);
}
else
{
info_right1 = (this->_info & this->SRC_INFO_BITS);
info_left1 = ((this->_info & this->TRG_INFO_BITS) >> 4);
}
{
info_right1 = (this->_info & this->SRC_INFO_BITS);
info_left1 = ((this->_info & this->TRG_INFO_BITS) >> 4);
}
// Get the left and right endpoints of the other arc and their
// information bits.
@ -1889,15 +1889,15 @@ public:
int info_left2, info_right2;
if (arc.is_directed_right())
{
info_left2 = (arc._info & this->SRC_INFO_BITS);
info_right2 = ((arc._info & this->TRG_INFO_BITS) >> 4);
}
{
info_left2 = (arc._info & this->SRC_INFO_BITS);
info_right2 = ((arc._info & this->TRG_INFO_BITS) >> 4);
}
else
{
info_right2 = (arc._info & this->SRC_INFO_BITS);
info_left2 = ((arc._info & this->TRG_INFO_BITS) >> 4);
}
{
info_right2 = (arc._info & this->SRC_INFO_BITS);
info_left2 = ((arc._info & this->TRG_INFO_BITS) >> 4);
}
// Locate the left curve-end with larger x-coordinate.
bool at_minus_infinity = false;
@ -1907,37 +1907,37 @@ public:
int info_left;
if (inf_l1 == ARR_INTERIOR && inf_l2 == ARR_INTERIOR)
{
// Let p_left be the rightmost of the two left endpoints.
if (left1.x() > left2.x())
{
// Let p_left be the rightmost of the two left endpoints.
if (left1.x() > left2.x())
{
p_left = left1;
info_left = info_left1;
}
else
{
p_left = left2;
info_left = info_left2;
}
}
else if (inf_l1 == ARR_INTERIOR)
{
// Let p_left be the left endpoint of (*this).
p_left = left1;
info_left = info_left1;
}
else if (inf_l2 == ARR_INTERIOR)
else
{
// Let p_left be the left endpoint of the other arc.
p_left = left2;
info_left = info_left2;
}
}
else if (inf_l1 == ARR_INTERIOR)
{
// Let p_left be the left endpoint of (*this).
p_left = left1;
info_left = info_left1;
}
else if (inf_l2 == ARR_INTERIOR)
{
// Let p_left be the left endpoint of the other arc.
p_left = left2;
info_left = info_left2;
}
else
{
// Both arcs are defined at x = -oo.
at_minus_infinity = true;
info_left = info_left1;
}
{
// Both arcs are defined at x = -oo.
at_minus_infinity = true;
info_left = info_left1;
}
// Locate the right curve-end with smaller x-coordinate.
bool at_plus_infinity = false;
@ -1947,66 +1947,65 @@ public:
int info_right;
if (inf_r1 == ARR_INTERIOR && inf_r2 == ARR_INTERIOR)
{
// Let p_right be the rightmost of the two right endpoints.
if (right1.x() < right2.x())
{
// Let p_right be the rightmost of the two right endpoints.
if (right1.x() < right2.x())
{
p_right = right1;
info_right = info_right1;
}
else
{
p_right = right2;
info_right = info_right2;
}
}
else if (inf_r1 == ARR_INTERIOR)
{
// Let p_right be the right endpoint of (*this).
p_right = right1;
info_right = info_right1;
}
else if (inf_r2 == ARR_INTERIOR)
else
{
// Let p_right be the right endpoint of the other arc.
p_right = right2;
info_right = info_right2;
}
}
else if (inf_r1 == ARR_INTERIOR)
{
// Let p_right be the right endpoint of (*this).
p_right = right1;
info_right = info_right1;
}
else if (inf_r2 == ARR_INTERIOR)
{
// Let p_right be the right endpoint of the other arc.
p_right = right2;
info_right = info_right2;
}
else
{
// Both arcs are defined at x = +oo.
at_plus_infinity = true;
info_right = info_right2;
}
{
// Both arcs are defined at x = +oo.
at_plus_infinity = true;
info_right = info_right2;
}
// Check the case of two bounded (in x) ends.
if (! at_minus_infinity && ! at_plus_infinity)
{
Comparison_result res = CGAL::compare(p_left.x(), p_right.x());
if (res == LARGER)
{
Comparison_result res = CGAL::compare(p_left.x(), p_right.x());
if (res == LARGER)
{
// The x-range of the overlap is empty, so there is no overlap.
return (oi);
}
else if (res == EQUAL)
{
// We have a single overlapping point. Just make sure this point
// is not at y = -/+ oo.
if (info_left &&
(this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0 &&
info_right &&
(this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0)
{
Intersection_point_2 ip (p_left, 0);
*oi = make_object (ip);
++oi;
}
return (oi);
}
// The x-range of the overlap is empty, so there is no overlap.
return (oi);
}
else if (res == EQUAL)
{
// We have a single overlapping point. Just make sure this point
// is not at y = -/+ oo.
if (info_left &&
(this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0 &&
info_right &&
(this->SRC_AT_Y_MINUS_INFTY | this->SRC_AT_Y_PLUS_INFTY) == 0)
{
Intersection_point_2 ip (p_left, 0);
*oi = make_object (ip);
++oi;
}
return (oi);
}
}
// Create the overlapping portion of the rational arc by properly setting
// the source (left) and target (right) endpoints and their information

View File

@ -94,13 +94,6 @@ public:
{
return (_min.x() == other.x()) ;
}
bool operator== (const Self& other) const
{
if ((has_same_min(other))&&
(has_same_max(other)))
return true;
return false;
}
Self& operator= (const Self & other)
{
if (this != &other) // protect against invalid self-assignment
@ -171,22 +164,6 @@ public:
private:
bool has_same_min(const Self& other) const
{
if (this->_min_parameter_space != other._min_parameter_space)
return false;
if (this->_min_parameter_space == CGAL:: ARR_BOTTOM_BOUNDARY)
return true;
return (_min == other.min());
}
bool has_same_max(const Self& other) const
{
if (this->_max_parameter_space != other._max_parameter_space)
return false;
if (this->_min_parameter_space == CGAL::ARR_TOP_BOUNDARY)
return true;
return (_max == other.max());
}
bool is_line() const
{
return ((_max_parameter_space == ARR_TOP_BOUNDARY ) &&

View File

@ -25,8 +25,8 @@
#include <CGAL/Arr_tags.h>
#include "boost/variant.hpp"
//#include <CGAL/Arr_ver_support/Visitors_d_1.h>
#include "Visitors_d_1.h"
#include <CGAL/Arr_ver_support/Visitors_d_1.h>
//#include "Visitors_d_1.h"
namespace CGAL {
namespace Arr_vertical_rational_arc {