DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Private Attributes
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction Class Reference

#include <LightSternBrocot.h>

Collaboration diagram for DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction:
Collaboration graph
[legend]

Public Types

typedef TInteger Integer
typedef TQuotient Quotient
typedef LightSternBrocot
< TInteger, TQuotient, TMap > 
SternBrocotTree
typedef SternBrocotTree::Fraction Self
typedef NumberTraits< Integer >
::UnsignedVersion 
UnsignedInteger
typedef std::pair< Quotient,
Quotient
Value
typedef std::vector< QuotientCFracSequence
typedef
InputIteratorWithRankOnSequence
< CFracSequence, Quotient
ConstIterator
typedef Value value_type
typedef ConstIterator const_iterator
typedef const value_typeconst_reference

Public Member Functions

 Fraction (Integer aP, Integer aQ, Fraction start=SternBrocotTree::zeroOverOne())
 Fraction (Node *sb_node=0, bool sup1=false)
 Fraction (const Self &other)
Selfoperator= (const Self &other)
bool null () const
Integer p () const
Integer q () const
Quotient u () const
Quotient k () const
bool isSup1 () const
Quotient trueK () const
Fraction left () const
Fraction right () const
bool even () const
bool odd () const
Fraction ancestor () const
bool isAncestorDirect () const
Fraction father () const
Fraction father (Quotient m) const
Fraction previousPartial () const
Fraction inverse () const
Fraction partial (Quotient kp) const
Fraction reduced (Quotient i) const
void push_back (const std::pair< Quotient, Quotient > &quotient)
void pushBack (const std::pair< Quotient, Quotient > &quotient)
void getSplit (Fraction &f1, Fraction &f2) const
void getSplitBerstel (Fraction &f1, Quotient &nb1, Fraction &f2, Quotient &nb2) const
void getCFrac (std::vector< Quotient > &quotients) const
bool equals (Integer p1, Integer q1) const
bool lessThan (Integer p1, Integer q1) const
bool moreThan (Integer p1, Integer q1) const
bool operator== (const Fraction &other) const
bool operator!= (const Fraction &other) const
bool operator< (const Fraction &other) const
bool operator> (const Fraction &other) const
void selfDisplay (std::ostream &out) const
ConstIterator begin () const
ConstIterator end () const

Protected Member Functions

Fraction next (Quotient v) const
Fraction next1 (Quotient v) const

Private Attributes

NodemyNode
bool mySup1

Detailed Description

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
class DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction

This fraction is a model of CPositiveIrreducibleFraction.

It represents a positive irreducible fraction, i.e. some p/q qith gcd(p,q)=1. It is an inner class of LightSternBrocot. This representation of a fraction is simply a pointer to the corresponding node in this tree, plus a boolean indicating if it is bigger than 1/1.

Definition at line 195 of file LightSternBrocot.h.


Member Typedef Documentation

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef std::vector<Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::CFracSequence

Definition at line 203 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef ConstIterator DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_iterator

Definition at line 208 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef const value_type& DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_reference

Definition at line 209 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef InputIteratorWithRankOnSequence<CFracSequence,Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ConstIterator

Definition at line 204 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef TInteger DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Integer

Definition at line 197 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef TQuotient DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Quotient

Definition at line 198 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef SternBrocotTree::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Self

Definition at line 200 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef LightSternBrocot<TInteger, TQuotient, TMap> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::SternBrocotTree

Definition at line 199 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef NumberTraits<Integer>::UnsignedVersion DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::UnsignedInteger

Definition at line 201 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef std::pair<Quotient, Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Value

Definition at line 202 of file LightSternBrocot.h.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
typedef Value DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::value_type

Definition at line 207 of file LightSternBrocot.h.


Constructor & Destructor Documentation

template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction ( Integer  aP,
Integer  aQ,
Fraction  start = SternBrocotTree::zeroOverOne() 
)
inline

Creates the fraction aP/aQ. Complexity is in O(n) where n is the depth of continued fraction of aP/aQ.

Parameters:
aPthe numerator (>=0)
aQthe denominator (>=0)
start(optional) unused in this representation.

Definition at line 65 of file LightSternBrocot.ih.

References DGtal::IntegerComputer< TInteger >::getEuclideanDiv(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::inverse(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::k(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next1(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::oneOverZero(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::operator=(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::zeroOverOne().

{
// special case 1/0
this->operator=( oneOverZero() );
else
{
bool sup1 = aP > aQ;
if ( sup1 ) std::swap( aP, aQ );
Integer _quot, _rem;
bool prec_was_one = false;
{
ic.getEuclideanDiv( _quot, _rem, aP, aQ );
if ( f.k() == j )
f = f.next( v );
else
f = f.next1( v );
if ( v != 0 ) ++j;
aP = aQ;
aQ = _rem;
}
if ( prec_was_one ) f = f.next( NumberTraits<Quotient>::ONE );
this->operator=( sup1 ? f.inverse() : f );
}
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction ( Node sb_node = 0,
bool  sup1 = false 
)
inline

Default constructor.

Parameters:
sb_nodethe associated node (or 0 for null fraction).
sup1when 'true', the fraction is greater than 1/1 and represents q/p.

Definition at line 101 of file LightSternBrocot.ih.

: myNode( sb_node ), mySup1( sup1 )
{
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction ( const Self other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 109 of file LightSternBrocot.ih.

: myNode( other.myNode ), mySup1( other.mySup1 )
{
}

Member Function Documentation

template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ancestor ( ) const
inline
Returns:
the ancestor of this fraction in O(1), ie [u0,...,u_{k-1},uk] => [u0,...,u_{k-1}] if u_{k-1} > 1, => [u0,...,u_{k-2}] otherwise.

Definition at line 405 of file LightSternBrocot.ih.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced().

{
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ConstIterator DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::begin ( ) const
inline
Returns:
a const iterator pointing on the beginning of the sequence of quotients of this fraction. NB: \( O(\sum_i u_i) \) operation.

Definition at line 581 of file LightSternBrocot.ih.

{
this->getCFrac( *seq );
return ConstIterator( seq, seq->begin() );
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ConstIterator DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::end ( ) const
inline
Returns:
a const iterator pointing after the end of the sequence of quotients of this fraction. NB: O(1) operation.

Definition at line 592 of file LightSternBrocot.ih.

{
static CFracSequence dummy;
return ConstIterator( 0, dummy.end() );
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::equals ( Integer  p1,
Integer  q1 
) const
inline
Parameters:
p1a numerator.
q1a denominator.
Returns:
'true' if this is the fraction p1/q1.

Definition at line 207 of file LightSternBrocot.ih.

{
return ( this->p() == p1 ) && ( this->q() == q1 );
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::even ( ) const
inline
Returns:
'true' if it is an even fraction, i.e. its depth k() is even.

Definition at line 387 of file LightSternBrocot.ih.

template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father ( ) const
inline
Returns:
the father of this fraction in O(1), ie [u0,...,uk] => [u0,...,uk - 1]

Definition at line 423 of file LightSternBrocot.ih.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced().

template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father ( Quotient  m) const
inline
Parameters:
ma quotient between 1 and uk-1.
Returns:
a given father of this fraction in O(uk - m), ie [u0,...,uk] => [u0,...,m]
Todo:
Do it in O(1)... but require to change the data structure.

Definition at line 435 of file LightSternBrocot.ih.

{
if ( m >= NumberTraits<Quotient>::ONE ) // >= 1
{
return isAncestorDirect()
? ancestor().next( m )
: ancestor().next1( m );
}
else // == 0
return reduced( 2 );
// isAncestorDirect()
// ? ancestor().ancestor()
// : ancestor();
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac ( std::vector< Quotient > &  quotients) const
inline
Parameters:
quotients(returns) the coefficients of the continued fraction of 'this'.

Definition at line 560 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ancestor(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::u().

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display().

{
if ( null() ) return;
if ( mySup1 && ( i > 0 ) ) --i;
quotients.resize( i + 1 );
Fraction f( *this );
while ( i >= 0 && ( f.myNode->k >= 0 ) )
{
quotients[ i ] = ( j == f.myNode->k ) ? f.u() : NumberTraits<Quotient>::ONE;
f = ( j == f.myNode->k ) ? f.ancestor() : f.father();
--i, --j;
}
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getSplit ( Fraction f1,
Fraction f2 
) const
inline

Splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = [f1] [f2].

Parameters:
f1(returns) the left part of the split.
f2(returns) the right part of the split.

Definition at line 518 of file LightSternBrocot.ih.

{
if ( odd() )
{
f1 = ancestor();
f2 = father();
}
else
{
f1 = father();
f2 = ancestor();
}
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getSplitBerstel ( Fraction f1,
Quotient nb1,
Fraction f2,
Quotient nb2 
) const
inline

Berstel splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = nb1*[f1] nb2*[f2]. Also, if 'this->k' is even then nb1=1, otherwise nb2=1.

Parameters:
f1(returns) the left part of the split (left pattern).
nb1(returns) the number of repetition of the left pattern
f2(returns) the right part of the split (right pattern).
nb2(returns) the number of repetition of the right pattern

Definition at line 536 of file LightSternBrocot.ih.

{
// TODO
if ( odd() )
{
f1 = ancestor();
f2 = reduced( 2 );
nb1 = this->u();
nb2 = 1;
}
else
{
f1 = reduced( 2 );
f2 = ancestor();
nb1 = 1;
nb2 = this->u();
}
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::inverse ( ) const
inline
Returns:
the inverse of this fraction in O(1), ie [u0,...,uk] => [0,u0,...,uk] or [0,u0,...,uk] => [u0,...,uk].

Definition at line 463 of file LightSternBrocot.ih.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().

{
return Fraction( myNode, ! mySup1 );
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::isAncestorDirect ( ) const
inline
Returns:
'true' if its ancestor has depth k-1, otherwise returns false.

Definition at line 414 of file LightSternBrocot.ih.

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::isSup1 ( ) const
inline
Attention:
Only for debug purposes.
Returns:
'true' iff the fraction is greater than 1/1.

Definition at line 267 of file LightSternBrocot.h.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.

{ return mySup1; }
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Quotient DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::k ( ) const
inline
Returns:
its depth (1+number of coefficients of its continued fraction).

Definition at line 169 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myOneOverOne, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myZeroOverOne.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().

{
ASSERT( myNode != 0 );
if ( mySup1 )
{
// if ( ( myNode->k == 0 )
// && ( myNode != instance().myZeroOverOne )
// && ( myNode != instance().myOneOverOne ) )
// {
// std::cerr << "****ERROR**** "
// << " sup1=" << mySup1
// << " p=" << myNode->p
// << " q=" << myNode->q
// << " k=" << myNode->k
// << " u=" << myNode->u;
// std::cerr << std::endl;
// }
ASSERT( ( myNode->k != 0 )
|| ( myNode == instance().myOneOverOne ) );
ASSERT( ( myNode->k != -1 )
|| ( myNode == instance().myOneOverZero ) );
else if ( myNode == instance().myOneOverOne )
else
}
return myNode->k;
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::left ( ) const
inline
Returns:
its left descendant (construct it if it does not exist yet).

Definition at line 361 of file LightSternBrocot.ih.

{
// Use the fact that [...,u_n,1] = [...,u_n + 1]
else
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::lessThan ( Integer  p1,
Integer  q1 
) const
inline
Parameters:
p1a numerator.
q1a denominator.
Returns:
'true' if this is < to the fraction p/q.

Definition at line 216 of file LightSternBrocot.ih.

{
Integer d = p() * q1 - q() * p1;
return d < NumberTraits<Integer>::ZERO;
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::moreThan ( Integer  p1,
Integer  q1 
) const
inline
Parameters:
p1a numerator.
q1a denominator.
Returns:
'true' if this is > to the fraction p1/q1.

Definition at line 226 of file LightSternBrocot.ih.

{
Integer d = p() * q1 - q() * p1;
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next ( Quotient  v) const
inlineprotected
Returns:
the fraction [u_0, ..., u_n, v] if [u_0, ..., u_n] is the current fraction. Construct it if it does not exist yet.

Definition at line 278 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::ascendant, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::descendant2, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myZeroOverOne, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::nbFractions.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().

{
typedef typename MapQuotientToNode::iterator Iterator;
ASSERT( ! this->null() );
return *this;
else if ( ( v == NumberTraits<Quotient>::ONE )
&& ( this->myNode != instance().myZeroOverOne ) )
{ // Specific case: same depth.
v += u();
bool anc_direct = isAncestorDirect();
Iterator itkey = anc_direct
? myNode->ascendant->descendant.find( v )
: myNode->ascendant->descendant2.find( v );
Iterator itend = anc_direct
if ( itkey != itend ) // found
return Fraction( itkey->second, mySup1 );
Node* new_node = new Node( myNode->p + myNode->ascendant->p,
if (anc_direct ) myNode->ascendant->descendant[ v ] = new_node;
else myNode->ascendant->descendant2[ v ] = new_node;
return Fraction( new_node, mySup1 );
}
else
{
Iterator itkey = myNode->descendant.find( v );
if ( itkey != myNode->descendant.end() ) // found
{
return Fraction( itkey->second, mySup1 );
}
Node* new_node =
new Node( myNode->p * v + myNode->ascendant->p,
v, myNode->k + 1, myNode );
myNode->descendant[ v ] = new_node;
return Fraction( new_node, mySup1 );
}
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next1 ( Quotient  v) const
inlineprotected
Returns:
the fraction [u_0, ..., u_n -1, 1, v] if [u_0, ..., u_n] is the current fraction. Construct it if it does not exist yet.

Definition at line 328 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::nbFractions.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().

{
typedef typename MapQuotientToNode::iterator Iterator;
ASSERT( ! this->null() );
return *this;
else if ( v == NumberTraits<Quotient>::ONE )
{ // Specific case: depth + 1. [u_0, ..., u_n] => [u_0, ..., u_n -1, 2]
if ( f.myNode->k == myNode->k )
return father().next( 2 );
else
return father().next1( 2 );
}
else
{ // Gen case: [u_0, ..., u_n] => [u_0, ..., u_n -1, 1, v]
Iterator itkey = myNode->descendant2.find( v );
if ( itkey != myNode->descendant2.end() ) // found
return Fraction( itkey->second, mySup1 );
Node* new_node
= new Node( myNode->p * v + myNode->p - myNode->ascendant->p,
myNode->q * v + myNode->q - myNode->ascendant->q,
v, myNode->k + 2, myNode );
myNode->descendant2[ v ] = new_node;
return Fraction( new_node, mySup1 );
}
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::null ( ) const
inline
Returns:
'true' iff it is the null fraction 0/0.

Definition at line 132 of file LightSternBrocot.ih.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display().

{
return myNode == 0;
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::odd ( ) const
inline
Returns:
'true' if it is an odd fraction, i.e. its depth k() is odd.

Definition at line 396 of file LightSternBrocot.ih.

{
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator!= ( const Fraction other) const
inline
Parameters:
otherany fraction.
Returns:
'true' iff this is different from other.

Definition at line 249 of file LightSternBrocot.ih.

References operator==().

{
return ! this->operator==( other );
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator< ( const Fraction other) const
inline
Parameters:
otherany fraction.
Returns:
'true' iff this is < to other.

Definition at line 258 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().

{
return this->lessThan( other.p(), other.q() );
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction & DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator= ( const Self other)
inline

Assignment

Parameters:
otherthe object to clone.
Returns:
a reference to 'this'.

Definition at line 118 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.

{
if ( this != &other )
{
myNode = other.myNode;
mySup1 = other.mySup1;
}
return *this;
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator== ( const Fraction other) const
inline
Parameters:
otherany fraction.
Returns:
'true' iff this is equal to other.

Definition at line 236 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::p, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::q.

{
if ( mySup1 == other.mySup1 )
return ( myNode == other.myNode );
else
return ( ( myNode->p == other.myNode->q )
&& ( myNode->q == other.myNode->p ) );
}
template<typename TInteger , typename TQuotient , typename TMap >
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator> ( const Fraction other) const
inline
Parameters:
otherany fraction.
Returns:
'true' iff this is > to other.

Definition at line 267 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().

{
return this->moreThan( other.p(), other.q() );
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Integer DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::p ( ) const
inline
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::partial ( Quotient  kp) const
inline
Parameters:
kpthe chosen depth of the partial fraction (kp <= k()).
Returns:
the partial fraction of depth kp, ie. [u0,...,uk] => [u0,...,ukp]

Definition at line 472 of file LightSternBrocot.ih.

{
ASSERT( ( ((Quotient)-2) <= kp ) && ( kp <= myNode->k ) );
return reduced( myNode->k - kp );
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::previousPartial ( ) const
inline
Returns:
the previous partial of this fraction in O(1), ie [u0,...,u{k-1},uk] => [u0,...,u{k-1}]. Otherwise said, it is its ascendant with a smaller depth.

Definition at line 454 of file LightSternBrocot.ih.

{
return ancestor();
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::push_back ( const std::pair< Quotient, Quotient > &  quotient)
inline
    Modifies this fraction \form#77 to obtain the
    fraction \form#147. The depth of the quotient
    must be given, since continued fractions have two writings

\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).

    Useful to create output iterators, for instance with

    @code 
    typedef ... Fraction; 
    Fraction f;
    std::back_insert_iterator<Fraction> itout = std::back_inserter( f );
    @endcode

    @param quotient the pair \form#76.

Definition at line 499 of file LightSternBrocot.ih.

{
pushBack( quotient );
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::pushBack ( const std::pair< Quotient, Quotient > &  quotient)
inline
    Modifies this fraction \form#77 to obtain the
    fraction \form#147. The depth of the quotient
    must be given, since continued fractions have two writings

\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).

    See push_back for creating output iterators.

    @param quotient the pair \form#76.

Definition at line 508 of file LightSternBrocot.ih.

{
ASSERT( false
&& "UNIMPLEMENTED. Use SternBrocot::Fraction or LighterSternBrocot::Fraction instead." );
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Integer DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::q ( ) const
inline
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced ( Quotient  i) const
inline
Parameters:
ia positive integer smaller or equal to k()+2.
Returns:
the partial fraction of depth k()-i, ie. [u0,...,uk] => [u0,...,u{k-i}]

Definition at line 482 of file LightSternBrocot.ih.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ancestor(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode.

{
ASSERT( ( ((Quotient)0) <= i ) && ( i <= ( myNode->k+((Quotient)2) ) ) );
Fraction f( *this );
for ( ; i != NumberTraits<Quotient>::ZERO; --i )
{
f = ( j == f.myNode->k ) ? f.ancestor() : f.father();
--j;
}
return f;
}
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::right ( ) const
inline
Returns:
its right descendant (construct it if it does not exist yet).

Definition at line 374 of file LightSternBrocot.ih.

{
if ( ! myNode->isSameDepthLeft() )
// Use the fact that [...,u_n,1] = [...,u_n + 1]
else
}
template<typename TInteger , typename TQuotient , typename TMap >
void DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the fraction on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 602 of file LightSternBrocot.ih.

{
if ( this->null() ) out << "[Fraction null]";
else
{
out << "[Fraction f=" << this->p()
<< "/" << this->q()
<< " u=" << this->u()
<< " k=" << this->k()
<< std::flush;
std::vector<Quotient> quotients;
if ( this->k() >= 0 )
{
this->getCFrac( quotients );
out << " [" << quotients[ 0 ];
for ( unsigned int i = 1; i < quotients.size(); ++i )
out << "," << quotients[ i ];
out << "]";
}
out << " ]";
}
}
template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
Quotient DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::trueK ( ) const
inline
Attention:
Only for debug purposes.
Returns:
the depth of the node.

Definition at line 269 of file LightSternBrocot.h.

References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode.

{ return myNode->k; }
template<typename TInteger , typename TQuotient , typename TMap >
DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Quotient DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::u ( ) const
inline
Returns:
its quotient (last coefficient of its continued fraction).

Definition at line 159 of file LightSternBrocot.ih.

Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac().

{
ASSERT( myNode != 0 );
return myNode->u;
}

Field Documentation

template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
Node* DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode
private
template<typename TInteger, typename TQuotient, typename TMap = StdMapRebinder>
bool DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1
private

The documentation for this class was generated from the following files: