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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
// Copyright (c) 2006-2009 Max-Planck-Institute Saarbruecken (Germany).
// 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 Lesser 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/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_d/Event_line_builder.h $
// $Id: Event_line_builder.h 67262 2012-01-18 11:56:04Z hemmer $
//
//
// Author(s) : Michael Kerber <mkerber@mpi-inf.mpg.de>
//
// ============================================================================
#ifndef CGAL_ACK_EVENT_LINE_BUILDER
#define CGAL_ACK_EVENT_LINE_BUILDER 1
#include <CGAL/basic.h>
#include <CGAL/Algebraic_structure_traits.h>
#include <CGAL/Algebraic_kernel_d/algebraic_curve_kernel_2_tools.h>
#include <CGAL/Algebraic_kernel_d/Bitstream_descartes.h>
#include <CGAL/Algebraic_kernel_d/exceptions.h>
#include <boost/numeric/interval.hpp>
#include <vector>
#include <algorithm>
#include <utility>
// Constant for the interval test in \c compute_mk
#define CGAL_ACK_COMPUTE_MK_PRECISION 64
#if defined(BOOST_MSVC)
# pragma warning(push)
# pragma warning(disable:4290)
#endif
namespace CGAL {
namespace internal {
/*!
* \brief Constructs Vert_line-objects for an algebraic curve.
*
*
* The method \ref create_event_line builds such a vert-line
* for critical x-values. See the
* documentation of this routines for further information.
*
*/
template<typename AlgebraicKernelWithAnalysis_2>
class Event_line_builder {
public:
typedef AlgebraicKernelWithAnalysis_2 Algebraic_kernel_with_analysis_2;
// \brief The curve class.
typedef typename Algebraic_kernel_with_analysis_2::Curve_analysis_2 Curve_analysis_2;
// \brief Type of the coefficients of the input polynomial
typedef typename Algebraic_kernel_with_analysis_2::Coefficient Coefficient;
// \brief The type for rational x-coordinates and for interval boundaries
typedef typename Algebraic_kernel_with_analysis_2::Bound Bound;
// \brief Univariate polynomials
typedef typename Algebraic_kernel_with_analysis_2::Polynomial_1
Polynomial_1;
// \brief Bivariate polynomials
typedef typename Algebraic_kernel_with_analysis_2::Polynomial_2
Polynomial_2;
// \brief Rational polynomials
typedef typename
CGAL::Polynomial_traits_d<Polynomial_2>
::template Rebind<Bound,1>::Other::Type Poly_rat_1;
// \brief Type for x-values
typedef typename Curve_analysis_2::Algebraic_real_1 Algebraic_real_1;
//! \brief \c Vert_line specification for critical x-values
typedef typename Curve_analysis_2::Status_line_1 Status_line_1;
// \brief Type for Polynomial traits
typedef CGAL::Polynomial_traits_d<Polynomial_2> Polynomial_traits_2;
//! Default Constructor
Event_line_builder() {}
/*!
* \brief Constructs the builder for the \c curve object.
*
* Apart from the curve itself a polynomial is passed which is expected
* to be the primitive part of the curve.
* If the flag \c compute_sturm_habicht is set, the principal and
* coprincipal Sturm-Habicht coefficients of \c polynomial are computed.
* These coefficients provide information about properties of the curve
* at certain <tt>x</tt>-coordinates. Some methods of this class are only
* possible if they are computed.
*
* See \c NiX_resultant_matrix for
* more details about Sturm-Habicht sequences.
*/
Event_line_builder(Algebraic_kernel_with_analysis_2* kernel,
Curve_analysis_2 curve,
Polynomial_2 polynomial)
throw(internal::Zero_resultant_exception<Polynomial_2>)
: _m_kernel(kernel), curve(curve), polynomial(polynomial)
{}
/*!
* \brief Creates an event line at position \c alpha for the specified
* curve.
*
* Additionally, the \c id of the event line to be created has to be
* specfied, and
* the number of arcs that are entering from the left and leaving to the
* right are needed. Furthermore, the flag \c root_of_resultant tells
* whether \c alpha is a root of the resultant of the specified curve, and
* \c root_of_content indicates whether \c alpha is a root of the content,
* which is equivalent to the existence of a vertical line component.
*
* The function tries to apply the Bitstream Descartes method to isolate
* the real roots and create the Vert_line accordingly. For that purpose,
* symbolic precomputations are mostly necessary, using the Sturm-Habicht
* coefficients. It is necessary that they were computed beforehand.
* However, such symbolic computations need not be done if alpha is a
* simple root of the resultant, so if \c mult equals 1.
*
* The method will succeed, if the curve has only one multiple root
* at \c alpha over the complex numbers. It will never succeed, if there is
* more than one real root at \c alpha. In other cases, the outcome is not
* clear. In cases where the functions fails, a
* CGAL::internal::Non_generic_position_exception is thrown, otherwise, a
* fixed AcX::Vert_line object is returned.
*/
Status_line_1
create_event_line(int id,Algebraic_real_1 alpha,int arcs_left,int arcs_right,
bool root_of_resultant, bool root_of_content,int mult)
throw(CGAL::internal::Non_generic_position_exception) {
try {
int k;
Bitstream_descartes bit_des
= construct_bitstream_descartes(alpha,k,root_of_resultant,mult,
arcs_left,arcs_right);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "bitstream descartes constructed"
<< std::endl;
#endif
*/
int n = bit_des.number_of_real_roots();
int c = this->get_index_of_multiple_root(bit_des);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "n and c: " << n << " " << c << std::endl;
#endif
*/
int arcs_to_candidate_left=arcs_left-n+1;
int arcs_to_candidate_right=arcs_right-n+1;
//flag seems to be not used for now, but caused warnings (M.Hemmer)
//bool event_flag;
//if(false) {
if(arcs_to_candidate_left!=1 || arcs_to_candidate_right!= 1) {
//event_flag=true;
}
else {
// Need this flag to decide the event flag correctly,
// we don't care about it for now!
#if !CGAL_ACK_CHECK_CANDIDATE_FOR_SINGULARITY
//event_flag=false;
#else
Polynomial_2& f = polynomial;
if(c==-1 || k==0) {
//event_flag=false;
} else {
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Ev check..." << std::flush;
#endif
typename Polynomial_traits_2::Differentiate diff;
Polynomial_2 fx diff(f,0);
Polynomial_2 fy diff(f,1);
//event_flag=
event_point_checker(bit_des,f,alpha,k,fx,fy);
}
#endif
}
int root_number=bit_des.number_of_real_roots();
typename Status_line_1::Arc_container arc_container;
for(int i=0;i<root_number;i++) {
if(i != c ) {
arc_container.push_back(std::make_pair(1,1));
}
else {
arc_container.push_back
(std::make_pair(arcs_to_candidate_left,
arcs_to_candidate_right));
}
}
Status_line_1 vl(alpha, id, curve, arcs_left, arcs_right,
arc_container);
vl.set_isolator(bit_des);
vl._set_number_of_branches_approaching_infinity
(std::make_pair(0,0),std::make_pair(0,0));
#if !CGAL_ACK_SHEAR_ALL_NOT_Y_REGULAR_CURVES
if(kernel()->is_zero_at_1_object()
(CGAL::leading_coefficient(polynomial),alpha)) {
int n = CGAL::degree(polynomial,1);
CGAL_assertion(! kernel()->is_zero_at_1_object()
(CGAL::get_coefficient(polynomial,n-1),
alpha));
CGAL::Sign asym_sign
= kernel()->sign_at_1_object()
(CGAL::get_coefficient(polynomial,n-1),alpha)
* kernel()->sign_at_1_object()
(CGAL::differentiate
(CGAL::get_coefficient(polynomial,n)),alpha);
CGAL_assertion(asym_sign!=CGAL::ZERO);
if(asym_sign==CGAL::SMALLER) {
vl._set_number_of_branches_approaching_infinity
(std::make_pair(1,0),std::make_pair(0,1));
} else {
vl._set_number_of_branches_approaching_infinity
(std::make_pair(0,1),std::make_pair(1,0));
}
}
#endif
if(root_of_content) {
vl._set_v_line();
}
return vl;
}
catch(CGAL::internal::Non_generic_position_exception /* err */) {
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Detected non-generic position for alpha="
<< CGAL::to_double(alpha) << std::endl;
#endif
throw CGAL::internal::Non_generic_position_exception();
}
}
protected:
Algebraic_kernel_with_analysis_2* kernel() const {
return this->_m_kernel;
}
/*!
* Typedef for the Interval type
*/
typedef boost::numeric::interval<Bound> Interval;
// \brief Refinement type from the curve class.
typedef typename Curve_analysis_2::Bitstream_descartes
Bitstream_descartes;
typedef typename Curve_analysis_2::Bitstream_coefficient_kernel
Bitstream_coefficient_kernel;
typedef typename Curve_analysis_2::Bitstream_traits
Bitstream_traits;
Algebraic_kernel_with_analysis_2* _m_kernel;
//! The curve whose Status_line_1s are built.
Curve_analysis_2 curve;
//! The content free part of the curve's polynomial
Polynomial_2 polynomial;
/*!
* \brief Exact information about <tt>f<sub>x=alpha</sub></tt>.
*
* Returns a pair <tt>(m,k)</tt> with the following meaning. Let
* \c seq be a sequence <tt>g<sub>0</sub>,...,g<sub>n</sub></tt>.
* Then, \c k is the first index for which <tt>g<sub>i</sub>(alpha)</tt>
* is not zero. The number <tt>m</tt> is the result of the function
* <tt>C (g<sub>0</sub>(alpha),...,g<sub>n</sub>(alpha))</tt>, where
* <tt>C</tt> is defined as in L.Gonzalez-Vega, I.Necula: Efficient
* topology determination of implicitly defined algebraic plane curves.
* <i>Computer Aided Geometric Design</i> <b>19</b> (2002) 719-743.
* If \c seq is the sequence of principal Sturm-Habicht coefficients,
* \c m is the number of real roots of <tt>f<sub>x=alpha</sub></tt>,
* counted without multiplicity.
*
* If the first elements in the sequence are known to be zero,
* \c first_elements_zero can be set accordingly. The zero test is then
* ommitted for that leading elements.
*/
template<typename InputIterator>
std::pair<int,int> compute_mk(Algebraic_real_1 alpha,
InputIterator seq_begin,
InputIterator seq_end,
int first_elements_zero=0) {
typedef InputIterator Input_iterator;
Algebraic_real_1& alpha_ref=alpha;
int m,k=-1; // Initialize to prevent compiler warning
bool k_fixed=false;
int seq_size = std::distance(seq_begin,seq_end);
typedef int VT;
typedef std::vector<VT> A_vector;
A_vector spec_stha(0);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << seq_size << std::endl;
#endif
*/
CGAL_assertion(spec_stha.size()==0);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << seq_size << " elements to consider"
<< std::endl;
#endif
*/
int start_i=first_elements_zero;
for(int i=0;i<start_i;i++) {
spec_stha.push_back(VT(0));
}
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "mk.." << std::flush;
#endif
Input_iterator seq_it = seq_begin;
std::advance(seq_it,start_i);
for(int i=start_i;i< seq_size ;i++,seq_it++ ) {
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << spec_stha.size() << " " << i << std::endl;
CGAL_ACK_DEBUG_PRINT << "Now: " << i << "th stha" << std::flush;
CGAL_ACK_DEBUG_PRINT << "\nTry interval arithmetic.." << std::endl;
#endif
*/
CGAL::Sign ia_try
=kernel()->sign_at_1_object()(*seq_it,
alpha_ref,
CGAL_ACK_COMPUTE_MK_PRECISION);
//CGAL::Sign ia_try=CGAL::ZERO;
if(ia_try!=CGAL::ZERO) {
if(! k_fixed) {
k=i;
k_fixed=true;
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "m.." << std::flush;
#endif
}
spec_stha.push_back(ia_try);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "successful" << std::endl;
#endif
*/
continue;
}
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "no success" << std::endl;
CGAL_ACK_DEBUG_PRINT << "Is root of..." << std::flush;
CGAL_ACK_DEBUG_PRINT << "s." << std::endl;
CGAL_ACK_DEBUG_PRINT << "pol=" << *seq_it << std::endl;
CGAL_ACK_DEBUG_PRINT << "alpha=" << alpha.polynomial() << std::endl;
#endif
*/
bool root_of = kernel()->is_zero_at_1_object()(*seq_it,alpha);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "done "
<< ((root_of) ? "true" : "false")
<< std::endl;
#endif
*/
if(root_of) {
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Is zero" << std::endl;
#endif
*/
spec_stha.push_back(VT(0));
}
else {
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "is nonzero.." << std::flush;
#endif
*/
if(! k_fixed) {
k=i;
k_fixed=true;
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "m.." << std::flush;
#endif
*/
}
/*
#if CGAL_ACK_DEBUG_FLAG
::CGAL::set_ascii_mode(CGAL_ACK_DEBUG_PRINT);
CGAL_ACK_DEBUG_PRINT << "Stha: " << (*seq_it) << std::endl;
#endif
*/
VT beta
=kernel()->sign_at_1_object() (*seq_it,alpha_ref);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Value: " << beta << std::endl;
#endif
*/
spec_stha.push_back(beta);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << " " << spec_stha.size() << std::endl;
#endif
*/
}
}
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "--------" << std::endl;
CGAL_ACK_DEBUG_PRINT << " " << spec_stha.size() << std::endl;
for(int j=0;j<(int)spec_stha.size();j++) {
CGAL_ACK_DEBUG_PRINT << j << ": " << spec_stha[j] << std::endl;
}
CGAL_ACK_DEBUG_PRINT << "--------" << std::endl;
#endif
*/
typename A_vector::iterator it=spec_stha.begin() + k;
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "k=" << k << ", Compute m..." << std::flush;
#endif
*/
m = CGAL::number_of_real_roots(it,spec_stha.end());
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "done" << std::endl;
#endif
*/
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "k=" << k << " m=" << m << ".."<< std::flush;
#endif
return std::make_pair(m,k);
}
Poly_rat_1 mod(Poly_rat_1 a,Poly_rat_1 b) const {
Poly_rat_1 ret=CGAL::mod(a,b);
return ret;
}
/*!
* \brief Constructs a Bitstream Descartes object for
* <tt>f<sub>x=alpha</sub></tt>
*
* Tries to isolate the roots of <tt>f<sub>x=alpha</sub></tt> with the
* Bitstream m-k-Descartes method. As additional information, the value
* \c k is returned which is the greatest common divisor of \c f with its
* derivative. The flag \c root_of_resultant denotes whether alpha is
* a root of the resultant of \c f with its derivative.
* Also, the multiplicity of \c alpha as root of the resultant is given
* It his multiplcity is 1, one can avoid the computations with the
* Sturm-Habicht coefficient by looking at \c arcs_left and \c arcs_right.
*
* This method requires the Sturm-Habicht coefficients of \c f to be
* computed beforehand.
* On failure, the error CGAL::internal::Non_generic_position_exception
* is thrown.
*/
Bitstream_descartes construct_bitstream_descartes(const Algebraic_real_1&
alpha,
int& k,
bool root_of_resultant,
int mult,
int arcs_left,
int arcs_right)
throw(CGAL::internal::Non_generic_position_exception) {
Bitstream_traits traits(Bitstream_coefficient_kernel(kernel(),alpha));
if(root_of_resultant) {
#if !CGAL_ACK_SHEAR_ALL_NOT_Y_REGULAR_CURVES
if(kernel()->is_zero_at_1_object()
(CGAL::leading_coefficient(polynomial),alpha)) {
Polynomial_2 trunc_pol =
CGAL::internal::poly_non_vanish_leading_term
(kernel(),polynomial,alpha);
CGAL_assertion(CGAL::degree(trunc_pol,1)+1 ==
CGAL::degree(polynomial,1));
CGAL::internal::Square_free_descartes_tag t;
Bitstream_descartes bit_des(t,trunc_pol,traits);
return bit_des;
}
#endif
int m;
CGAL_assertion(mult>0);
if(mult==1) {
m=(arcs_left+arcs_right) / 2;
k=1;
}
else {
std::pair<int,int> mk
= compute_mk(alpha,
curve.principal_sturm_habicht_begin(),
curve.principal_sturm_habicht_end(),
1);
m = mk.first;
k = mk.second;
}
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Bit Des..." << std::flush;
#endif
CGAL::internal::M_k_descartes_tag t;
Bitstream_descartes bit_des(t,polynomial,m,k,traits);
return bit_des;
}
else {
CGAL::internal::Square_free_descartes_tag t;
Bitstream_descartes bit_des(t,polynomial,traits);
return bit_des;
}
}
/*!
* \brief Checks whether a point is a singularity or not.
*
* This routine is applied in situations where a potential event point
* has one incident arc to the left and to the right. To distinguish
* singularities from other points, this method checks whether the two
* linearly independent partial derivatives \c der_1 and \c der_2 vansh
* at the point \c (alpha,beta). Here, \c beta is implicitly defined as
* \f[\beta=\frac{-costha[k-1]}{k\cdot stha[k]}\f]
* and it is verified first that \c beta is indeed the y-value that
* corresponds to the multiple root in the <tt>bit_des</tt>-instance.
* If it is not, a Non_generic_position_exception is thrown.
*
* If no exception is thrown, the function returns true if and only if
* there is a singularity at <tt>(alpha,beta)</tt>.
*/
bool event_point_checker(Bitstream_descartes& bit_des,
const Polynomial_2& polynomial,
const Algebraic_real_1& alpha,
int k,
const Polynomial_2& der_1,
const Polynomial_2& der_2)
throw(CGAL::internal::Non_generic_position_exception) {
//Guess the right expression for y
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << costha.size() << " "
<< stha.size() << std::endl;
CGAL_ACK_DEBUG_PRINT << k << std::endl;
CGAL_ACK_DEBUG_PRINT << "Costha: " << costha[k-1]
<< " Stha: " << stha[k] << std::endl;
#endif
*/
Polynomial_1 p = -curve.coprincipal_sturm_habicht_of_primitive(k);
Polynomial_1 q
= Coefficient(k)*curve.principal_sturm_habicht_of_primitive(k);
/*
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << k << " " << CGAL::to_double(alpha)
<< std::endl);
CGAL_ACK_DEBUG_PRINT << p << " " << q << std::endl
<< polynomial << std::endl;
Bound a_d = alpha.low();
CGAL_ACK_DEBUG_PRINT << CGAL::to_double(p.evaluate(a_d)/
q.evaluate(a_d))
<< std::endl;
#endif
*/
// Check whether it lies in the candidates interval
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "iv-test..." << std::flush;
#endif
typedef typename CGAL::Get_arithmetic_kernel<Algebraic_real_1>
::Arithmetic_kernel::Bigfloat_interval BFI;
CGAL::internal::Bitstream_coefficient_kernel_at_alpha
<Algebraic_kernel_with_analysis_2>
alpha_kernel(kernel(),alpha);
int c = this->get_index_of_multiple_root(bit_des);
long old_prec = CGAL::get_precision(BFI());
//std::cout << "p=" << p << std::endl;
//std::cout << "q=" << q << std::endl;
long prec=16;
while(true) {
CGAL::set_precision(BFI(),prec);
//std::cout << "Increased to " << prec << std::endl;
BFI isol_iv
= CGAL::hull(CGAL::convert_to_bfi(bit_des.left_bound(c)),
CGAL::convert_to_bfi(bit_des.right_bound(c)));
BFI q_iv = alpha_kernel.convert_to_bfi_object()(q);
if(! CGAL::in_zero(q_iv)) {
BFI p_iv = alpha_kernel.convert_to_bfi_object()(p);
BFI approx_iv = p_iv/q_iv;
//std::cout << "p_iv=[" << CGAL::lower(p_iv) << "," << CGAL::upper(p_iv) << "]" << std::endl;
//std::cout << "q_iv=[" << CGAL::lower(q_iv) << "," << CGAL::upper(q_iv) << "]" << std::endl;
//std::cout << "isol_iv=[" << CGAL::lower(isol_iv) << "," << CGAL::upper(isol_iv) << "]" << std::endl;
//std::cout << "approx_iv=[" << CGAL::lower(approx_iv) << "," << CGAL::upper(approx_iv) << "]" << std::endl;
if(CGAL::subset(approx_iv,isol_iv)) {
break;
}
if(! CGAL::overlap(approx_iv,isol_iv)) {
throw CGAL::internal::Non_generic_position_exception();
}
}
prec*=2;
}
CGAL::set_precision(BFI(),old_prec);
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "on f..." << std::flush;
#endif
if(! CGAL::internal::zero_test_bivariate
<Algebraic_kernel_with_analysis_2>
(kernel(),alpha,polynomial,p,q)) {
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "Detected non-generic position for alpha="
<< CGAL::to_double(alpha) << std::endl;
#endif
throw CGAL::internal::Non_generic_position_exception();
}
// Check whether the two partial derivatives vanish
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "on fx..." << std::flush;
#endif
bool is_singularity
= CGAL::internal::zero_test_bivariate
<Algebraic_kernel_with_analysis_2>
(kernel(),alpha,der_1,p,q);
if(is_singularity) {
#if CGAL_ACK_DEBUG_FLAG
CGAL_ACK_DEBUG_PRINT << "on fy..." << std::flush;
#endif
return CGAL::internal::zero_test_bivariate
<Algebraic_kernel_with_analysis_2>
(kernel(),alpha,der_2,p,q);
} else {
return false;
}
}
protected:
int get_index_of_multiple_root(const Bitstream_descartes& bit_des) const {
int n = bit_des.number_of_real_roots();
for(int i=0;i<n;i++) {
if(! bit_des.is_certainly_simple_root(i)) {
return i;
}
}
return -1;
}
}; //class Event_line_builder
} // namespace internal
} //namespace CGAL
#if defined(BOOST_MSVC)
# pragma warning(pop)
#endif
#endif //CGAL_ACK_VERT_EVENT_BUILDER
|