~ubuntu-branches/debian/stretch/cgal/stretch

« back to all changes in this revision

Viewing changes to include/CGAL/Arr_segment_traits_2.h

  • Committer: Package Import Robot
  • Author(s): Joachim Reichel
  • Date: 2014-04-05 10:56:43 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140405105643-jgnrpu2thtx23zfs
Tags: 4.4-1
* New upstream release.
* Remove patches do-not-link-example-with-qt4-support-library.patch and
  fix_jet_fitting_3.patch (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
//
15
15
// $URL$
16
16
// $Id$
17
 
// 
 
17
//
18
18
//
19
19
// Author(s)     : Ron Wein          <wein@post.tau.ac.il>
20
20
//                 Efi Fogel         <efif@post.tau.ac.il>
30
30
#include <CGAL/intersections.h>
31
31
#include <CGAL/Arr_tags.h>
32
32
#include <CGAL/Arr_geometry_traits/Segment_assertions.h>
 
33
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
33
34
#include <fstream>
34
35
 
35
36
namespace CGAL {
36
37
 
37
 
template <class Kernel_> class Arr_segment_2;
 
38
template <class Kernel_ = Exact_predicates_exact_constructions_kernel>
 
39
class Arr_segment_2;
38
40
 
39
41
/*!
40
42
 * \class A traits class for maintaining an arrangement of segments, aoviding
46
48
 * Arrangement_2 type and require objects and operations supported by the
47
49
 * kernel, but not defined in this derived class.
48
50
 */
49
 
template <class Kernel_>
 
51
template <class Kernel_ = Exact_predicates_exact_constructions_kernel>
50
52
class Arr_segment_traits_2 : public Kernel_
51
53
{
52
54
  friend class Arr_segment_2<Kernel_>;
56
58
  typedef Kernel_                         Kernel;
57
59
  typedef typename Kernel::FT             FT;
58
60
 
59
 
  typedef typename Algebraic_structure_traits<FT>::Is_exact 
 
61
  typedef typename Algebraic_structure_traits<FT>::Is_exact
60
62
                                          Has_exact_division;
61
63
 
62
64
  // Category tags:
63
65
  typedef Tag_true                        Has_left_category;
64
66
  typedef Tag_true                        Has_merge_category;
65
67
  typedef Tag_false                       Has_do_intersect_category;
66
 
  
 
68
 
67
69
  typedef Arr_oblivious_side_tag          Left_side_category;
68
70
  typedef Arr_oblivious_side_tag          Bottom_side_category;
69
71
  typedef Arr_oblivious_side_tag          Top_side_category;
70
72
  typedef Arr_oblivious_side_tag          Right_side_category;
71
 
 
 
73
 
72
74
  typedef typename Kernel::Line_2         Line_2;
73
75
  typedef CGAL::Segment_assertions<Arr_segment_traits_2<Kernel> >
74
76
                                          Segment_assertions;
124
126
      is_pt_max = (res == SMALLER);
125
127
 
126
128
      CGAL_precondition_msg (! is_degen,
127
 
                             "Cannot contruct a degenerate segment.");
 
129
                             "Cannot construct a degenerate segment.");
128
130
 
129
131
      l = kernel.construct_line_2_object()(seg);
130
132
      is_vert = kernel.is_vertical_2_object()(seg);
147
149
      is_pt_max = (res == SMALLER);
148
150
 
149
151
      CGAL_precondition_msg (! is_degen,
150
 
                             "Cannot contruct a degenerate segment.");
 
152
                             "Cannot construct a degenerate segment.");
151
153
 
152
154
      l = kernel.construct_line_2_object()(source, target);
153
155
      is_vert = kernel.is_vertical_2_object()(l);
232
234
      CGAL_precondition_code (
233
235
        Kernel    kernel;
234
236
      );
235
 
      CGAL_precondition 
236
 
        (Segment_assertions::_assert_is_point_on (p, l, 
 
237
      CGAL_precondition
 
238
        (Segment_assertions::_assert_is_point_on (p, l,
237
239
                                                  Has_exact_division()) &&
238
240
         kernel.compare_xy_2_object() (p, right()) == SMALLER);
239
241
 
262
264
      CGAL_precondition_code (
263
265
        Kernel    kernel;
264
266
      );
265
 
      CGAL_precondition 
266
 
        (Segment_assertions::_assert_is_point_on (p, l, 
 
267
      CGAL_precondition
 
268
        (Segment_assertions::_assert_is_point_on (p, l,
267
269
                                                  Has_exact_division()) &&
268
270
         kernel.compare_xy_2_object() (p, left()) == LARGER);
269
271
 
538
540
      // Make sure that p lies on both curves, and that both are defined to its
539
541
      // left (so their left endpoint is lexicographically smaller than p).
540
542
      CGAL_precondition_code (
541
 
        typename Kernel::Compare_xy_2 compare_xy = 
 
543
        typename Kernel::Compare_xy_2 compare_xy =
542
544
                                                  kernel.compare_xy_2_object();
543
545
      );
544
546
 
545
 
      CGAL_precondition 
546
 
        (Segment_assertions::_assert_is_point_on (p, cv1, 
 
547
      CGAL_precondition
 
548
        (Segment_assertions::_assert_is_point_on (p, cv1,
547
549
                                                  Has_exact_division()) &&
548
550
         Segment_assertions::_assert_is_point_on (p, cv2,
549
551
                                                  Has_exact_division()));
589
591
      // Make sure that p lies on both curves, and that both are defined to its
590
592
      // right (so their right endpoint is lexicographically larger than p).
591
593
      CGAL_precondition_code (
592
 
        typename Kernel::Compare_xy_2 compare_xy = 
 
594
        typename Kernel::Compare_xy_2 compare_xy =
593
595
                                                 kernel.compare_xy_2_object();
594
596
      );
595
597
 
596
598
      CGAL_precondition
597
 
        (Segment_assertions::_assert_is_point_on (p, cv1, 
 
599
        (Segment_assertions::_assert_is_point_on (p, cv1,
598
600
                                                  Has_exact_division()) &&
599
601
         Segment_assertions::_assert_is_point_on (p, cv2,
600
602
                                                  Has_exact_division()));
701
703
      // Make sure that p lies on the interior of the curve.
702
704
      CGAL_precondition_code (
703
705
        Kernel                        kernel;
704
 
        typename Kernel::Compare_xy_2 compare_xy = 
 
706
        typename Kernel::Compare_xy_2 compare_xy =
705
707
                                                 kernel.compare_xy_2_object();
706
708
      );
707
709
 
757
759
 
758
760
      // Check if we have a single intersection point.
759
761
      const Point_2  *ip = object_cast<Point_2> (&obj);
760
 
      
 
762
 
761
763
      if (ip != NULL)
762
764
      {
763
765
        // Check if the intersection point ip lies on both segments.
856
858
 
857
859
    /*! The traits (in case it has state) */
858
860
    const Traits* m_traits;
859
 
    
 
861
 
860
862
    /*! Constructor
861
863
     * \param traits the traits (in case it has state)
862
864
     */
863
865
    Are_mergeable_2(const Traits* traits) : m_traits(traits) {}
864
866
 
865
867
    friend class Arr_segment_traits_2<Kernel>;
866
 
    
 
868
 
867
869
  public:
868
870
    /*!
869
871
     * Check whether it is possible to merge two given x-monotone curves.
879
881
      if (!m_traits->equal_2_object()(cv1.right(), cv2.left()) &&
880
882
          !m_traits->equal_2_object()(cv2.right(), cv1.left()))
881
883
        return false;
882
 
      
 
884
 
883
885
      // Check whether the two curves have the same supporting line.
884
886
      const Kernel* kernel = m_traits;
885
887
      typename Kernel::Equal_2 equal = kernel->equal_2_object();
886
 
      return (equal(cv1.line(), cv2.line()) || 
887
 
              equal(cv1.line(), 
 
888
      return (equal(cv1.line(), cv2.line()) ||
 
889
              equal(cv1.line(),
888
890
                    kernel->construct_opposite_line_2_object()(cv2.line())));
889
891
    }
890
892
  };
902
904
 
903
905
    /*! The traits (in case it has state) */
904
906
    const Traits* m_traits;
905
 
    
 
907
 
906
908
    /*! Constructor
907
909
     * \param traits the traits (in case it has state)
908
910
     */
909
911
    Merge_2(const Traits* traits) : m_traits(traits) {}
910
912
 
911
913
    friend class Arr_segment_traits_2<Kernel>;
912
 
    
 
914
 
913
915
  public:
914
916
    /*!
915
917
     * Merge two given x-monotone curves into a single curve (segment).
925
927
      CGAL_precondition(m_traits->are_mergeable_2_object()(cv1, cv2));
926
928
 
927
929
      Equal_2 equal = m_traits->equal_2_object();
928
 
      
 
930
 
929
931
      // Check which curve extends to the right of the other.
930
932
      if (equal(cv1.right(), cv2.left())) {
931
933
        // cv2 extends cv1 to the right.
959
961
     * \param p The exact point.
960
962
     * \param i The coordinate index (either 0 or 1).
961
963
     * \pre i is either 0 or 1.
962
 
     * \return An approximation of p's x-coordinate (if i == 0), or an 
 
964
     * \return An approximation of p's x-coordinate (if i == 0), or an
963
965
     *         approximation of p's y-coordinate (if i == 1).
964
966
     */
965
967
    Approximate_number_type operator() (const Point_2& p,
1004
1006
 
1005
1007
  /// \name Functor definitions for the Boolean set-operation traits.
1006
1008
  //@{
1007
 
 
 
1009
 
1008
1010
  class Compare_endpoints_xy_2
1009
1011
  {
1010
1012
  public:
1073
1075
  Arr_segment_2 () :
1074
1076
    Base()
1075
1077
  {}
1076
 
    
 
1078
 
1077
1079
  /*!
1078
1080
   * Constructor from a "kernel" segment.
1079
1081
   * \param seg The segment.
1130
1132
   * Get the segment source.
1131
1133
   */
1132
1134
  const Point_2& source() const
1133
 
  { 
 
1135
  {
1134
1136
    return (this->ps);
1135
1137
  }
1136
1138
 
1152
1154
    opp.is_pt_max = !(this->is_pt_max);
1153
1155
    opp.is_vert = this->is_vert;
1154
1156
    opp.is_degen = this->is_degen;
1155
 
    
 
1157
 
1156
1158
    return (opp);
1157
1159
  }
1158
1160
};