42 template <
typename TFraction>
49 template <
typename TFraction>
57 template <
typename TFraction>
61 : myPattern( other.myPattern ), myMu( other.myMu )
65 template <
typename TFraction>
76 template <
typename TFraction>
80 : myPattern( aSlope ), myMu( aMu )
84 template <
typename TFraction>
88 : myPattern( a1, b1 ), myMu( mu1 )
92 template <
typename TFraction>
98 if ( slope().null() )
return false;
100 return ( mu() <= _r ) && ( _r < ( mu() + pattern().length() ) );
103 template <
typename TFraction>
109 ASSERT( ! slope().null() );
110 return a() * p[ 0 ] - b() * p[ 1 ];
113 template <
typename TFraction>
119 return pattern().
slope();
122 template <
typename TFraction>
131 template <
typename TFraction>
140 template <
typename TFraction>
149 template <
typename TFraction>
158 template <
typename TFraction>
167 template <
typename TFraction>
173 return pattern().
v();
176 template <
typename TFraction>
183 Integer c = ( mu() * u[ 0 ] ) / b();
185 ? v() * ( c + 1 ) - u * mu()
186 : u * mu() - v() * c );
189 template <
typename TFraction>
198 template <
typename TFraction>
205 return Point( x, ic.ceilDiv( q, b() ) );
208 template <
typename TFraction>
215 return Point( x, ic.floorDiv( q, b() ) );
218 template <
typename TFraction>
225 return Point( ic.ceilDiv( q, a() ), y );
228 template <
typename TFraction>
235 return Point( ic.floorDiv( q, a() ), y );
238 template <
typename TFraction>
244 return ( p1[ 0 ] < p2[ 0 ] )
245 || ( ( p1[ 0 ] == p2[ 0 ] ) && ( p1[ 1 ] < p2[ 1 ] ) );
248 template <
typename TFraction>
254 return ( p1[ 0 ] < p2[ 0 ] )
255 || ( ( p1[ 0 ] == p2[ 0 ] ) && ( p1[ 1 ] <= p2[ 1 ] ) );
258 template <
typename TFraction>
266 template <
typename TFraction>
276 template <
typename TFraction>
282 Integer cA = ic.floorDiv( A[ 0 ] - _U[ 0 ], v()[ 0 ] );
283 Point U1 = _U + v() * cA;
284 Integer cB = ic.ceilDiv( B[ 0 ] - _U[ 0 ], v()[ 0 ] );
285 Point U2 = _U + v() * cB;
286 if ( before( A, U1 ) ) U1 -= v();
287 if ( before( U2, B ) ) U2 += v();
288 return reversedSmartDSS( U1, U2, A, B );
292 template <
typename TFraction>
299 std::cerr <<
"[reversedSmartDSS] " << (*this)
300 <<
" " << pattern().rE() << std::endl
301 <<
" +- U1=" << U1 <<
" A=" << A
302 <<
" B=" << B <<
" U2=" << U2 << std::endl
303 <<
" v()=" << pattern().
v()
304 <<
" u()=" << pattern().bezout()
305 <<
" r(U())=" << r(U())
306 <<
" mu=" << mu() <<
" r(U1)=" << r(U1)
307 <<
" r(U2)=" << r(U2)
311 <<
" DSS(A)=" << this->operator()( A )
312 <<
" DSS(B)=" << this->operator()( B ) << std::endl;
314 ASSERT( ! slope().null() );
315 ASSERT( r( U1 ) == mu() && r( U2 ) == mu()
316 && this->
operator()( A ) && this->
operator()( B ) );
317 ASSERT( beforeOrEqual( U1, A ) );
318 ASSERT( before( A, B ) );
319 ASSERT( beforeOrEqual( B, U2 ) );
320 if ( A[ 0 ] == B[ 0 ] )
return Self( 1, 0, A[ 0 ] );
321 if ( A[ 1 ] == B[ 1 ] )
return Self( 0, 1, -A[ 1 ] );
322 Integer dU = U2[ 0 ] - U1[ 0 ];
325 std::cerr <<
" +- dU=" << dU << std::endl;
327 if ( ( dU >= (3*b()) )
328 || ( ( dU == (2*b()) ) && ( A == U1 || B == U2 ) )
329 || ( A == U1 && B == U2 ) )
332 std::cerr <<
"[reversedSmartDSS] 3 patterns || ..." << std::endl;
340 std::cerr <<
"[reversedSmartDSS] 2 patterns" << std::endl;
342 return DSSWithinTwoPatterns( U1, U2, A, B );
348 Integer posA = ( A - U1 ).norm1();
349 Integer posB = ( B - U1 ).norm1();
351 std::cerr <<
"[reversedSmartDSS] 1 pattern" << std::endl;
354 ( subpattern, nb, startPos, posA, posB );
356 std::cerr <<
" - smallest:" << subpattern.
rE() <<
" at " << startPos << endl;
360 bool n = pattern().getGreatestIncludedSubpattern
361 ( subpattern, nb, startPos, posA, posB );
363 std::cerr <<
" - greatest:" << subpattern.
rE() <<
" at " << startPos << endl;
366 Point NU( U1 + startPos );
368 - subpattern.
slope().q() * NU[ 1 ];
372 Point NU1( U1 + startPos );
373 Point NU2( NU1 + subpattern.
v()*nb );
375 - subpattern.
slope().q() * NU1[ 1 ];
380 template <
typename TFraction>
387 Point Um = U1 + pattern().
v();
388 ASSERT( Um + pattern().v() == U2 );
389 ASSERT( before( A, B ) );
390 ASSERT( before( A, Um ) );
391 ASSERT( before( Um, B ) );
392 ASSERT( r( U1 ) == mu() && r( U2 ) == mu() );
393 bool readyLU =
false;
394 bool readyRU =
false;
396 Point L1 = U1 + pattern().L( 0 );
397 Point L2 = L1 + pattern().v();
406 std::cerr <<
"[DSSWithinTwoPatterns] " << (*this)
407 <<
" " << pattern().rE() << std::endl
408 <<
" +- U1=" << U1 <<
" A=" << A
409 <<
" B=" << B <<
" U2=" << U2
410 <<
" L1=" << L1 << std::endl;
417 ( subpattern, nb, startPos,
418 ( A - U1 ).norm1(), ( Um - U1 ).norm1(),
false );
419 if ( ! mLU || nb > 1 )
422 ( subpattern, nb, startPos,
423 ( A - U1 ).norm1(), ( Um - U1 ).norm1(),
false );
433 ( subpattern, nb, startPos,
434 0, ( B - Um ).norm1(),
false );
435 if ( ! mRU || nb > 1 )
438 ( subpattern, nb, startPos,
439 0, ( B - Um ).norm1(),
false );
444 ASSERT( ! patRU.
slope().null() );
445 U2 = Um + patRU.
v() * nb;
449 posA = L1[ 0 ] <= A[ 0 ] ? ( A - L1 ).norm1() : 0;
450 posB = L2[ 0 ] > B[ 0 ] ? ( B - L1 ).norm1() : patL.
length();
452 ( subpattern, nb, startPos, posA, posB,
true );
456 ( subpattern, nb, startPos, posA, posB,
true );
465 L2 = Um + patL.
L( 0 );
473 std::cerr <<
" (*) " << (readyLU ?
'*' :
'-')
474 <<
"LU=" << patLU.
rE() <<
" at " << U1 << std::endl;
475 std::cerr <<
" (*) " << (readyRU ?
'*' :
'-')
476 <<
"RU=" << patRU.
rE() <<
" til " << U2 << std::endl;
477 std::cerr <<
" (*) " << (readyL ?
'*' :
'-')
478 <<
"L =" << patL.
rE() <<
" at " << L1 << std::endl;
480 if ( readyLU || readyRU || readyL )
484 std::cerr <<
" => deepest is " << patDeepest.
rE() << std::endl;
487 if ( ( readyLU && patDeepest.
slope().q() == patLU.
slope().q() )
488 || ( readyRU && patDeepest.
slope().q() == patRU.
slope().q() )
489 || ( readyL && patDeepest.
slope().q() == patL.
slope().q() ) )
493 - patDeepest.
slope().q() * Um[ 1 ];
497 template <
typename TFraction>
503 std::cerr <<
"[smartDSS] " << (*this)
504 <<
" " << pattern().rE() << std::endl
505 <<
" A=" << A <<
" B=" << B << std::endl;
507 ASSERT( ! slope().null() );
508 ASSERT( this->
operator()( A ) && this->
operator()( B ) );
509 ASSERT( before( A, B ) );
518 Point2I _Lp = _L + Point2I(1,-1);
520 while ( ( (_Up - A).norm1() <= AB1 )
521 && this->operator()( _Up ) )
524 std::cerr <<
"Vertical" << std::endl;
537 while ( p.
slope() != this->slope() )
540 std::cerr <<
"[smartDSS] v=" << p.
v()
542 <<
" U=(" << _U[0] <<
"," << _U[1] <<
")"
543 <<
" L=(" << _L[0] <<
"," << _L[1] <<
")"
544 <<
" Up=(" << _Up[0] <<
"," << _Up[1] <<
")"
545 <<
" Lp=(" << _Lp[0] <<
"," << _Lp[1] <<
")"
549 if ( ( (_Up - A).norm1() > AB1 ) && ( (_Lp - A).norm1() > AB1 ) )
break;
550 else if ( _Up[ 1 ] <= B[ 1 ] && this->
operator()( _Up ) )
553 for (
Quotient i = 1; i < delta; ++i )
556 if ( ! lul ) _L -= p.
v();
560 _Lp = _L + p.
v() + p.
v() - p.
bezout();
561 delta = 1; ulu =
true; lul =
false;
563 else if ( _Lp[ 0 ] <= B[ 0 ] && this->
operator()( _Lp ) )
566 for (
Quotient i = 1; i < delta; ++i )
568 _U = p.
slope() == f10 ? _Up - Point2I( 0,1 ) : _Up - p.
bezout();
569 if ( ! ulu ) _U -= p.
v();
573 _Lp = _L + p.
v() + p.
v() - p.
bezout();
574 delta = 1; ulu =
false; lul =
true;
588 template <
typename TFraction>
594 return deepest( f1, deepest( f2, f3 ) );
597 template <
typename TFraction>
603 return ( ( f1.k() > f2.k() )
604 || ( ( f1.k() == f2.k() ) && ( f1.u() >= f2.u() ) ) )
615 template <
typename TFraction>
620 out <<
"[StandardDSLQ0"
621 <<
" a=" << a() <<
", b=" << b() <<
", mu=" << mu() <<
"]";
628 template <
typename TFraction>
641 template <
typename TFraction>
647 object.selfDisplay( out );