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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
// Copyright (c) 2003-2008 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// 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/next/Circular_kernel_2/include/CGAL/Circular_kernel_2/Line_arc_2.h $
// $Id: Line_arc_2.h 67117 2012-01-13 18:14:48Z lrineau $
//
// Author(s) : Monique Teillaud, Sylvain Pion, Pedro Machado
// Partially supported by the IST Programme of the EU as a Shared-cost
// RTD (FET Open) Project under Contract No IST-2000-26473
// (ECG - Effective Computational Geometry for Curves and Surfaces)
// and a STREP (FET Open) Project under Contract No IST-006413
// (ACS -- Algorithms for Complex Shapes)
#ifndef CGAL_CIRCULAR_KERNEL_LINE_ARC_2_H
#define CGAL_CIRCULAR_KERNEL_LINE_ARC_2_H
#include <CGAL/global_functions_circular_kernel_2.h>
#include <CGAL/intersections.h>
#include <CGAL/Algebraic_kernel_for_circles/internal_functions_on_roots_and_polynomial_1_2_and_2_2.h>
#include <CGAL/Circular_kernel_2/internal_functions_on_line_2.h>
#include <CGAL/Circular_kernel_2/internal_functions_on_line_arc_2.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Circular_kernel_2/Circular_arc_2.h>
namespace CGAL {
namespace internal {
template <class CK >
class Line_arc_2_base
{
public:
typedef typename CK::FT FT;
typedef typename CK::RT RT;
typedef typename CK::Point_2 Point_2;
typedef typename CK::Line_2 Line_2;
typedef typename CK::Circle_2 Circle_2;
typedef typename CK::Circular_arc_2 Circular_arc_2;
typedef typename CK::Circular_arc_point_2 Circular_arc_point_2;
typedef typename CK::Root_of_2 Root_of_2;
typedef typename CK::Segment_2 Segment_2;
private:
typedef struct bit_field {
unsigned char begin_less_xy_than_end:2;
} bit_field;
// set flags to 0
// when 1 bit -> 0 = false, 1 = true
// when 2 bits -> 0 = don_know, 1 = false
// 2 = true
void reset_flags() const {
flags.begin_less_xy_than_end = 0;
}
public:
//typedef typename CGAL::Simple_cartesian<Root_of_2>::Point_2
// Numeric_point_2;
typedef typename CK::Root_for_circles_2_2
Root_for_circles_2_2;
static
Circular_arc_point_2
intersect(const Line_2 & l, const Circle_2 & c, const bool b)
{
typedef std::vector<CGAL::Object >
solutions_container;
solutions_container solutions;
CGAL::CircularFunctors::intersect_2<CK>
( l, c, std::back_inserter(solutions) );
typename solutions_container::iterator it = solutions.begin();
CGAL_kernel_precondition( it != solutions.end() );
// the circles intersect
const std::pair<typename CK::Circular_arc_point_2, unsigned> *result;
result = CGAL::object_cast<
std::pair<typename CK::Circular_arc_point_2, unsigned> >(&(*it));
if ( result->second == 2 ) // double solution
return result->first;
if (b) return result->first;
++it;
result = CGAL::object_cast<
std::pair<typename CK::Circular_arc_point_2, unsigned> >(&(*it));
return result->first;
}
public:
Line_arc_2_base()
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
: id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{}
Line_arc_2_base(const Line_2 &support,
const Circle_2 &c1,const bool b1,
const Circle_2 &c2,const bool b2)
:_support(support)
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
,id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{
_begin = intersect(support, c1, b1);
_end = intersect(support, c2, b2);
reset_flags();
}
Line_arc_2_base(const Line_2 &support,
const Line_2 &l1,
const Line_2 &l2)
:_support(support)
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
,id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{
CGAL_kernel_precondition(do_intersect(support, l1));
CGAL_kernel_precondition(do_intersect(support, l2));
//typedef typename Root_of_2::RT RT_2;
//Voir pour mettre une assertion au assign
Object obj = intersection(support, l1);
const Point_2 *pt = CGAL::object_cast<Point_2>(&obj);
_begin = Circular_arc_point_2(*pt);
obj = intersection(support, l2);
const Point_2 *pt2 = CGAL::object_cast<Point_2>(&obj);
_end = Circular_arc_point_2(*pt2);
reset_flags();
}
Line_arc_2_base(const Line_2 &support,
const Circular_arc_point_2 &p1,
const Circular_arc_point_2 &p2)
:_support(support)
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
,id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{
//Verifier si p1 et p2 sont sur la line
_begin = p1;
_end = p2;
reset_flags();
}
Line_arc_2_base(const Segment_2 &s)
:_support(s.supporting_line())
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
,id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{
_begin = Circular_arc_point_2(s.source());
_end = Circular_arc_point_2(s.target());
reset_flags();
}
Line_arc_2_base(const Point_2 &p1,
const Point_2 &p2)
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
: id_of_my_supporting_line(Circular_arc_2::circle_table.get_new_id())
#endif
{
_support = Line_2(p1, p2);
_begin = Circular_arc_point_2(p1);
_end = Circular_arc_point_2(p2);
reset_flags();
}
private:
Line_2 _support;
Circular_arc_point_2 _begin, _end;
mutable bit_field flags;
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
mutable unsigned int id_of_my_supporting_line;
unsigned int line_number() const {
return id_of_my_supporting_line;
}
void set_line_number(unsigned int i) const {
id_of_my_supporting_line = i;
}
#endif
private: //(some useful functions)
bool begin_less_xy_than_end() const {
if(flags.begin_less_xy_than_end == 0) {
if(compare_xy(_begin, _end) < 0)
flags.begin_less_xy_than_end = 2;
else flags.begin_less_xy_than_end = 1;
} return flags.begin_less_xy_than_end == 2;
}
public :
#ifdef CGAL_INTERSECTION_MAP_FOR_SUPPORTING_CIRCLES
template < class T >
static bool find_intersection_circle_line(
const Circular_arc_2& c,
const Line_arc_2_base& l,
T& res) {
if(c.id_of_my_supporting_circle == 0) return false;
return Circular_arc_2::circle_table.template find<T>(c.id_of_my_supporting_circle,
l.id_of_my_supporting_line,
res);
}
template < class T >
static void put_intersection_circle_line(const Circular_arc_2& c,
const Line_arc_2_base& l,
const T& res) {
Circular_arc_2::circle_table.template put<T>(c.circle_number(),
l.line_number(),
res);
}
#endif
const Line_2 & supporting_line() const
{
return _support;
}
const Circular_arc_point_2 & left() const
{
return begin_less_xy_than_end() ? _begin : _end;
}
const Circular_arc_point_2 & right() const
{
return begin_less_xy_than_end() ? _end : _begin;
}
const Circular_arc_point_2 & source() const
{
return _begin;
}
const Circular_arc_point_2 & target() const
{
return _end;
}
bool is_vertical() const
{
return supporting_line().is_vertical();
}
CGAL::Bbox_2 bbox() const
{
return _begin.bbox() + _end.bbox();
}
}; // end class Line_arc_2_base
template <class CB, typename Base_CK>
class Filtered_bbox_line_arc_2_base : public Base_CK::Line_arc_2 {
typedef Filtered_bbox_line_arc_2_base<CB,Base_CK> Self;
typedef typename Base_CK::Line_arc_2 P_arc;
public:
typedef typename CB::Point_2 Point_2;
typedef typename CB::Line_2 Line_2;
typedef typename CB::Segment_2 Segment_2;
typedef typename CB::Circle_2 Circle_2;
typedef typename CB::Circular_arc_point_2 Circular_arc_point_2;
Filtered_bbox_line_arc_2_base() : P_arc(), bb(NULL) {}
Filtered_bbox_line_arc_2_base(const P_arc& arc) : P_arc(arc), bb(NULL) {}
Filtered_bbox_line_arc_2_base(const Line_2 &support,
const Circle_2 &l1, const bool b_l1,
const Circle_2 &l2, const bool b_l2)
: P_arc(support,l1,b_l1,l2,b_l2), bb(NULL)
{}
Filtered_bbox_line_arc_2_base(const Line_2 &support,
const Line_2 &l1,
const Line_2 &l2)
: P_arc(support,l1,l2), bb(NULL)
{}
Filtered_bbox_line_arc_2_base(const Line_2 &support,
const Circular_arc_point_2 &begin,
const Circular_arc_point_2 &end)
: P_arc(support, begin, end) , bb(NULL)
{}
Filtered_bbox_line_arc_2_base(const Segment_2 &s)
: P_arc(s) , bb(NULL)
{}
Filtered_bbox_line_arc_2_base(const Point_2 &p1,
const Point_2 &p2)
: P_arc(p1,p2) , bb(NULL)
{}
Filtered_bbox_line_arc_2_base(const Filtered_bbox_line_arc_2_base &c)
: P_arc(c), bb(c.bb ? new Bbox_2(*(c.bb)) : NULL)
{}
Filtered_bbox_line_arc_2_base& operator=(const Self& c)
{
if(this != &c)
{
this->P_arc::operator=(c);
bb = c.bb ? new Bbox_2(*(c.bb)) : NULL;
}
return *this;
}
~Filtered_bbox_line_arc_2_base() { if(bb) delete bb; }
Bbox_2 bbox() const
{
if(bb==NULL)
bb=new Bbox_2(P_arc::bbox());
return *bb;
}
bool has_no_bbox() const
{ return (bb==NULL);}
private:
mutable Bbox_2 *bb;
}; // end class Filtered_bbox_line_arc_2_base
/* template < typename CK > */
/* std::ostream & */
/* operator<<(std::ostream & os, const Line_arc_2_base<CK> &a) */
/* { */
/* return os << a.supporting_line() << " " */
/* << a.source() << " " */
/* << a.target() << " "; */
/* } */
/* template < typename CK > */
/* std::istream & */
/* operator>>(std::istream & is, Line_arc_2_base<CK> &a) */
/* { */
/* typename CK::Line_2 l; */
/* typename CK::Circular_arc_point_2 p1; */
/* typename CK::Circular_arc_point_2 p2; */
/* is >> l >> p1 >> p2 ; */
/* if (is) */
/* a = Line_arc_2_base<CK>(l, p1, p2); */
/* return is; */
/* } */
} // namespace internal
} // namespace CGAL
#endif // CGAL_CIRCULAR_KERNEL_LINE_ARC_2_H
|