sweep_curves_base_2.h

来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 1,701 行 · 第 1/5 页

H
1,701 行
字号
    less_point_xy(Traits *traits_) : traits(traits_) {}        inline  bool operator()(const Point& p1, const Point& p2) const    {       return (traits->compare_xy(p1,p2) == SMALLER);    }  private:    Traits *traits;  };  // A predicate ordering two Curve nodes.  template <class _Curve_node>  class less_curve_xy {  public:    typedef SweepLineTraits_2                       Traits;    typedef typename Traits::X_curve                X_curve;     typedef typename Traits::Point                  Point;        less_curve_xy(Traits *traits_) : traits(traits_) {}        /*!      Returns true if the first curve is "less" than the second curve.      If both curves are "the same", it returns the one with a smaller id.    */    inline  bool operator()(const _Curve_node& cv1,                             const _Curve_node& cv2) const    {      Comparison_result result;        const Point& ref_point = rightmost(cv1.get_rightmost_point().point(),                                         cv2.get_rightmost_point().point());        // if both curves are vartical, we look at the ids      if (traits->curve_is_vertical(cv2.get_curve()) &&        (traits->curve_is_vertical(cv1.get_curve())))        return ( cv1.get_curve().id() < cv2.get_curve().id() );        // if the rightmost points are different, we compare the curves relative      // to the righmost of the two      if ( cv1.get_rightmost_point() != cv2.get_rightmost_point() ) {        result = curve_node_compare_at_x(cv1, cv2, ref_point);      } else      {         // both curves enamting the same point.        if ( traits->curve_is_vertical(cv1.get_curve()) )            // if one of the curves enamating from the point is vertical          // then it will have larger value on the status.          return false;        else if ( traits->curve_is_vertical(cv2.get_curve()) )          return true;            result = _curves_compare_y_at_x_right (cv1.get_curve(), 					    cv2.get_curve(), 					    ref_point);        if (result == EQUAL)          result = traits->curves_compare_y_at_x (cv1.get_curve(),                                                cv2.get_curve(),                                                ref_point);      }        if (result == SMALLER){        return true;      }      else if (result == LARGER){        return false;      }      else { // equal - the curves are overlapping.        return ( cv1.get_curve().id() < cv2.get_curve().id() );        }    }        private:    Comparison_result curve_node_compare_at_x(const _Curve_node &cv1,                                               const _Curve_node &cv2,                                               const Point &q) const    {      Comparison_result result;      bool update_first_cv = false, update_second_cv = false;      X_curve_plus first_cv , second_cv;  // making an optimization.              // taking care the edge case of vertical segments: if one is      // vertical, then the order is set according the 'rightmost'      // point (so far) of the vertical curve comparing the point that      // a vertical line hits the other curve.      if ( traits->curve_is_vertical(cv1.get_curve()) ) {                // if the curve is vertical and the point is its target we        // refer that curve as a point.        if (traits->point_equal(traits->curve_target(cv1.get_curve()),                                   cv1.get_rightmost_point().point()))	{	  if (! traits->point_in_x_range	      (cv2.get_curve(), 	       traits->curve_target(cv1.get_curve())))	    return (EQUAL);	  	  Comparison_result cres = traits->curve_compare_y_at_x	    (traits->curve_target(cv1.get_curve()), cv2.get_curve());          if (cres == SMALLER || cres == EQUAL)            // if the target is on cv2 its means that it tangent to            // cv2 from below.            return  SMALLER;          else            return  LARGER;        }                  X_curve tmp_cv;        if (!traits->point_equal(traits->curve_source(cv1.get_curve()), q)) {          traits->curve_split(cv1.get_curve(), tmp_cv, first_cv, q);          update_first_cv = true;        }      }            if ( traits->curve_is_vertical(cv2.get_curve()) ){                // if the curve is vertical and the point is its target we        // refer that curve as a point.        if (traits->point_equal(traits->curve_target(cv2.get_curve()),                                  cv2.get_rightmost_point().point()))	{	  if (! traits->point_in_x_range	      (cv1.get_curve(), 	       traits->curve_target(cv2.get_curve())))	    return (EQUAL);          Comparison_result cres = traits->curve_compare_y_at_x	    (traits->curve_target(cv2.get_curve()), cv1.get_curve());          // if the target is on cv1 its means that it tangent to cv1           // from below.	  if (cres == SMALLER || cres == EQUAL)            return  LARGER;          else            return  SMALLER;        }                X_curve tmp_cv;        if (!traits->point_equal(traits->curve_source(cv2.get_curve()), q)) {          traits->curve_split(cv2.get_curve(), tmp_cv, second_cv, q);          update_second_cv = true;        }      }                // making this four cases in order to make an optimization for not       // copying to first_cv and second_cv the original curves is not needed.      if (!update_first_cv && !update_second_cv)         result =          _curves_compare_y_at_x_right	      (cv1.get_curve(), cv2.get_curve(),  	       // making an optimization attemp:	       rightmost(cv1.get_rightmost_point().point(),			 cv2.get_rightmost_point().point()));            else if (update_first_cv && !update_second_cv)        result =          _curves_compare_y_at_x_right             (first_cv, cv2.get_curve(), 	      rightmost(cv1.get_rightmost_point().point(),			cv2.get_rightmost_point().point()));      else if (!update_first_cv && update_second_cv)        result =          _curves_compare_y_at_x_right	      (cv1.get_curve(), second_cv, 	       rightmost(cv1.get_rightmost_point().point(),			 cv2.get_rightmost_point().point()));      else               // update_first_cv && update_second_cv is true.        result =          _curves_compare_y_at_x_right	      (first_cv, second_cv, 	       rightmost(cv1.get_rightmost_point().point(),			 cv2.get_rightmost_point().point()));            if (result == EQUAL){        if (!update_first_cv && !update_second_cv)          result =            traits->              curves_compare_y_at_x(cv1.get_curve(), cv2.get_curve(),                                 rightmost(cv1.get_rightmost_point().point(),                                            cv2.get_rightmost_point().point()));        else if (update_first_cv && !update_second_cv)          result =            traits->              curves_compare_y_at_x(first_cv, cv2.get_curve(),                                  rightmost(cv1.get_rightmost_point().point(),                                            cv2.get_rightmost_point().point()));        else if (!update_first_cv && update_second_cv)          result =            traits->              curves_compare_y_at_x(cv1.get_curve(),second_cv,                                  rightmost(cv1.get_rightmost_point().point(),                                            cv2.get_rightmost_point().point()));        else           // update_first_cv && update_second_cv is true.          result =            traits->              curves_compare_y_at_x(first_cv, second_cv,                                 rightmost(cv1.get_rightmost_point().point(),                                            cv2.get_rightmost_point().point()));      }                // if one of the curves is vertical - EQUAL means that the other curve       // is between the source and target point of the vertical curve, and       // for our definition - it means that the verical curve comes first.      if ( result == EQUAL &&          traits->curve_is_vertical(update_first_cv ? first_cv:                                    cv1.get_curve()) )      {	if (! traits->point_in_x_range	    (update_second_cv ? second_cv : cv2.get_curve(),	     traits->curve_source(update_first_cv ? 				  first_cv : cv1.get_curve())))	  result = SMALLER;        // if first_cv is vertical and its source tangent to second_cv -         // it means that first_cv is above second_cv.	else if (traits->curve_compare_y_at_x		 (traits->curve_source(update_first_cv ? 				       first_cv : cv1.get_curve()),                  update_second_cv ? second_cv : cv2.get_curve()) == EQUAL)          result = LARGER;        else          result = SMALLER;      }      else if (result == EQUAL &&                traits->curve_is_vertical(update_second_cv? second_cv:                                          cv2.get_curve()))      {	if (! traits->point_in_x_range	    (update_first_cv ? first_cv : cv1.get_curve(), 	     traits->curve_source(update_second_cv ? 				  second_cv : cv2.get_curve())))	  result = LARGER;        // if second_cv is vertical and its source tangent to first_cv -         // it means that second_cv is above first_cv.	else if (traits->curve_compare_y_at_x		 (traits->curve_source(update_second_cv ? 				       second_cv : cv2.get_curve()),                  update_first_cv ? first_cv: cv1.get_curve()) == EQUAL)          result = SMALLER;        else          result = LARGER;      }      return result;    }          const Point& rightmost(const Point &p1, const Point &p2) const    {       Comparison_result res = traits->compare_xy(p1,p2);            return ((res == SMALLER) ? p2 : p1);    }    // Imitate the previous behaviour of the function: that is, return    // EQUAL in undefined cases.    Comparison_result _curves_compare_y_at_x_right (const X_curve& cv1,						 const X_curve& cv2,						 const Point& p) const    {      // In case the point is not in the x-range of both curves or that      // one of the curves is not defined at p's right, return EQUAL.      Comparison_result res1 = traits->compare_x(traits->curve_source(cv1),						 traits->curve_target(cv1));      Comparison_result res2 = traits->compare_x(traits->curve_source(cv2),						 traits->curve_target(cv2));      const Point& left1 = (res1 == SMALLER) ? traits->curve_source(cv1) :	traits->curve_target(cv1);      const Point& right1 = (res1 == LARGER) ? traits->curve_source(cv1) :	traits->curve_target(cv1);      const Point& left2 = (res2 == SMALLER) ? traits->curve_source(cv2) :	traits->curve_target(cv2);      const Point& right2 = (res2 == LARGER) ? traits->curve_source(cv2) :	traits->curve_target(cv2);      if (traits->compare_x (right1, p) != LARGER)	return (EQUAL);      else if (traits->compare_x (left1, p) == LARGER)	return (EQUAL);      if (traits->compare_x (right2, p) != LARGER)	return (EQUAL);      else if (traits->compare_x (left2, p) == LARGER)	return (EQUAL);      // Compare using the traits function:      Comparison_result res = traits->curves_compare_y_at_x (cv1, cv2, p);      if (res != EQUAL)	return (res);      return (traits->curves_compare_y_at_x_right (cv1, cv2, p));    }          Traits  *traits;  };public:  typedef CurveInputIterator                    Curve_iterator;  typedef SweepLineTraits_2                     Traits;  typedef Point_plus_                           Point_plus;  typedef typename  Traits::Point               Point;    typedef X_curve_plus_                         X_curve_plus;  typedef typename Curve_node::Points_iterator  Points_iterator;    typedef typename Curve_node::Points_const_iterator     	                                        Points_const_iterator;  typedef typename Intersection_point_node::Curve_node_iterator                                                     Curve_node_iterator;  typedef typename Intersection_point_node::Curve_node_const_iterator                                                  Curve_node_const_iterator;protected:  typedef  std::pair<const Point,Point_plus>    pair_Point_Point_plus;  typedef  std::pair<const Point,Intersection_point_node>                                          pair_Point_Intersection_point_node;   typedef  std::pair<const Curve_node,X_curve_plus>                                                   pair_Curve_node_X_curve_plus;  typedef less_point_xy<Point>                  Less_xy;  typedef less_curve_xy<Curve_node>             Less_yx;  public:  typedef std::map<Point, Point_plus, Less_xy>  Vertices_points_plus;  typedef std::map<Point,Intersection_point_node, Less_xy>                                                Event_queue;  typedef std::set<Curve_node, Less_yx>         Status_line;     typedef std::list<X_curve>                    X_curve_list;  typedef typename X_curve_list::iterator       X_curve_list_iterator;  typedef typename Event_queue::value_type      Event_queue_value_type;  typedef typename Status_line::value_type      Status_line_value_type;  typedef typename Event_queue::iterator        Event_queue_iterator;  typedef typename Status_line::iterator        Status_line_iterator;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?