1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.2-branch/Arrangement_2/include/CGAL/Arr_non_caching_segment_basic_traits_2.h $
// $Id: Arr_non_caching_segment_basic_traits_2.h 29412 2006-03-12 09:38:57Z wein $
//
//
// Author(s) : Efi Fogel <efif@post.tau.ac.il>
// Ron Wein <wein@post.tau.ac.il>
// (based on old version by: Iddo Hanniel,
// Eyal Flato,
// Oren Nechushtan,
// Ester Ezra,
// Shai Hirsch,
// and Eugene Lipovetsky)
#ifndef CGAL_ARR_NON_CACHING_SEGMENT_BASIC_TRAITS_2_H
#define CGAL_ARR_NON_CACHING_SEGMENT_BASIC_TRAITS_2_H
/*! \file The basic non-caching segment traits-class for the arrangement
* package. This traits class handles x-monotone non-intersecting segments.
* It is a model of the ArrangementBasicTraits_2 concept. The class is
* templated by a kernel and inherits from it all the types and many of the
* functors required by the concept it models.
*/
#include <CGAL/tags.h>
#include <CGAL/representation_tags.h>
#include <CGAL/assertions.h>
#include <CGAL/Arr_traits_2/Segment_assertions.h>
#include <CGAL/Number_type_traits.h>
CGAL_BEGIN_NAMESPACE
/*! \class
* A model of the ArrangementBasicTraits_2 concept that handles x-monotone
* non-intersecting line segments.
*/
template <class T_Kernel>
class Arr_non_caching_segment_basic_traits_2 : public T_Kernel
{
public:
typedef T_Kernel Kernel;
typedef typename Kernel::FT FT;
typedef typename Number_type_traits<FT>::Has_exact_division
Has_exact_division;
typedef
CGAL::Segment_assertions<Arr_non_caching_segment_basic_traits_2<Kernel> >
Segment_assertions;
// Categories:
typedef Tag_true Has_left_category;
/*! Default Constructor */
Arr_non_caching_segment_basic_traits_2()
{}
/// \name Types and functor inherited from the kernel
//@{
// Traits types:
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Segment_2 X_monotone_curve_2;
/*! Compare the x-coordinates of two points */
typedef typename Kernel::Compare_x_2 Compare_x_2;
/*! Compare two points lexigoraphically; by x, then by y */
typedef typename Kernel::Compare_xy_2 Compare_xy_2;
/*! Obtain the left endpoint of a given segment */
typedef typename Kernel::Construct_min_vertex_2 Construct_min_vertex_2;
/*! Obtain the right endpoint of a given segment */
typedef typename Kernel::Construct_max_vertex_2 Construct_max_vertex_2;
/*! Check whether a given segment is vertical */
typedef typename Kernel::Is_vertical_2 Is_vertical_2;
/*! Return the location of a given point with respect to an input segment */
typedef typename Kernel::Compare_y_at_x_2 Compare_y_at_x_2;
/*! Check if two segments or if two points are identical */
typedef typename Kernel::Equal_2 Equal_2;
//@}
/// \name Functor introduced here (based on the kernel)
//@{
/*! \class
* A functor for comparing two segments to the left of a point
*/
class Compare_y_at_x_left_2 {
public:
/*
* Compare the y value of two segments immediately to the left of their
* intersection point.
* \param cv1 The first segment.
* \param cv2 The second segment.
* \param p The intersection point.
* \pre The point p lies on both segments, and both of them must be also be
* defined (lexicographically) to its left.
* \return The relative position of cv1 with respect to cv2 immdiately to
* the left of p: SMALLER, LARGER or EQUAL.
*/
Comparison_result operator()(const X_monotone_curve_2 & cv1,
const X_monotone_curve_2 & cv2,
const Point_2 & p) const
{
Kernel kernel;
// The two segments must be defined at q and also to its left.
CGAL_precondition_code(
Compare_y_at_x_2 compare_y_at_x = kernel.compare_y_at_x_2_object();
);
CGAL_precondition
(Segment_assertions::_assert_is_point_on(p, cv1, Has_exact_division())&&
Segment_assertions::_assert_is_point_on(p, cv2, Has_exact_division()));
CGAL_precondition_code(
Compare_xy_2 compare_xy = kernel.compare_xy_2_object();
typename Kernel::Construct_vertex_2 construct_vertex =
kernel.construct_vertex_2_object();
const Point_2 & source1 = construct_vertex(cv1, 0);
const Point_2 & target1 = construct_vertex(cv1, 1);
const Point_2 & left1 =
(kernel.less_xy_2_object()(source1, target1)) ? source1 : target1;
const Point_2 & source2 = construct_vertex(cv2, 0);
const Point_2 & target2 = construct_vertex(cv2, 1);
const Point_2 & left2 =
(kernel.less_xy_2_object()(source2, target2)) ? source2 : target2;
);
CGAL_precondition(compare_xy(left1, p) == SMALLER &&
compare_xy(left2, p) == SMALLER);
// Compare the slopes of the two segments to determine thir relative
// position immediately to the left of q.
// Notice that we swap the order of the curves in order to obtain the
// correct result to the left of p.
return kernel.compare_slope_2_object()(cv2, cv1);
}
};
/*! Obtain a Compare_y_at_x_left_2 functor object. */
Compare_y_at_x_left_2 compare_y_at_x_left_2_object() const
{
return Compare_y_at_x_left_2();
}
/*! \class
* A functor for comparing two segments to the right of a point.
*/
class Compare_y_at_x_right_2 {
public:
/*!
* Compare the y value of two segments immediately to the right of their
* intersection point.
* \param cv1 The first segment.
* \param cv2 The second segment.
* \param p The intersection point.
* \pre The point p lies on both segments, and both of them must be also be
* defined (lexicographically) to its right.
* \return The relative position of cv1 with respect to cv2 immdiately to
* the right of p: SMALLER, LARGER or EQUAL.
*/
Comparison_result operator()(const X_monotone_curve_2 & cv1,
const X_monotone_curve_2 & cv2,
const Point_2 & p) const
{
Kernel kernel;
// The two segments must be defined at q and also to its right.
CGAL_precondition_code(
Compare_y_at_x_2 compare_y_at_x = kernel.compare_y_at_x_2_object();
);
CGAL_precondition
(Segment_assertions::_assert_is_point_on(p, cv1, Has_exact_division())&&
Segment_assertions::_assert_is_point_on(p, cv2, Has_exact_division()));
CGAL_precondition_code(
Compare_xy_2 compare_xy = kernel.compare_xy_2_object();
typename Kernel::Construct_vertex_2 construct_vertex =
kernel.construct_vertex_2_object();
const Point_2 & source1 = construct_vertex(cv1, 0);
const Point_2 & target1 = construct_vertex(cv1, 1);
const Point_2 & right1 =
(kernel.less_xy_2_object()(source1, target1)) ? target1 : source1;
const Point_2 & source2 = construct_vertex(cv2, 0);
const Point_2 & target2 = construct_vertex(cv2, 1);
const Point_2 & right2 =
(kernel.less_xy_2_object()(source2, target2)) ? target2 : source2;
);
CGAL_precondition(compare_xy(right1, p) == LARGER &&
compare_xy(right2, p) == LARGER);
// Compare the slopes of the two segments to determine thir relative
// position immediately to the left of q.
return kernel.compare_slope_2_object()(cv1, cv2);
}
};
/*! Obtain a Compare_y_at_x_right_2 functor object. */
Compare_y_at_x_right_2 compare_y_at_x_right_2_object() const
{
return Compare_y_at_x_right_2();
}
//@}
/// \name Functor definitions for the landmarks point-location strategy.
//@{
typedef double Approximate_number_type;
class Approximate_2
{
public:
/*!
* Return an approximation of a point coordinate.
* \param p The exact point.
* \param i The coordinate index (either 0 or 1).
* \pre i is either 0 or 1.
* \return An approximation of p's x-coordinate (if i == 0), or an
* approximation of p's y-coordinate (if i == 1).
*/
Approximate_number_type operator() (const Point_2& p,
int i) const
{
CGAL_precondition (i == 0 || i == 1);
if (i == 0)
return (CGAL::to_double(p.x()));
else
return (CGAL::to_double(p.y()));
}
};
/*! Get an Approximate_2 functor object. */
Approximate_2 approximate_2_object () const
{
return Approximate_2();
}
typedef typename Kernel::Construct_segment_2 Construct_x_monotone_curve_2;
/*! Get a Construct_x_monotone_curve_2 functor object. */
Construct_x_monotone_curve_2 construct_x_monotone_curve_2_object () const
{
return (this->construct_segment_2_object());
}
//@}
};
CGAL_END_NAMESPACE
#endif
|