summaryrefslogtreecommitdiff
path: root/svtools/source/misc/imap.cxx
diff options
context:
space:
mode:
authorJuan Picca <jumapico@gmail.com>2014-09-19 14:19:30 -0300
committerDavid Tardon <dtardon@redhat.com>2014-10-09 11:33:33 +0000
commit47a2d7642d249d70b5da0c330a73f3a0032e4bba (patch)
tree202b04810382ea87cf8015a7b4de29e931408948 /svtools/source/misc/imap.cxx
parentae77dc81c33ab0817264bcf5fc8bb71a55b78a73 (diff)
fdo#81356: convert Fraction to boost::rational<long> - wip
* Added rational util functions used by Fraction class not available in the boost::rational class. * Replaced usage of Fraction by boost::rational<long> * Removed code that relies on: 1. fraction.IsValid() -- rational only allow valid values, ie denominator() != 0 2. rational.denominator() == 0 -- always false 3. rational.denominator() < 0 -- always false but implementation detail: http://www.boost.org/doc/libs/release/libs/rational/rational.html#Internal%20representation * Simplified code that relies on: 1. rational.denominator() != 0 -- always true * BUGS EXIST because Fraction allows the creation of invalid values but boost::rational throws the exception boost::bad_rational Change-Id: I84970a4956afb3f91ac0c8f726547466319420f9 Reviewed-on: https://gerrit.libreoffice.org/11551 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'svtools/source/misc/imap.cxx')
-rw-r--r--svtools/source/misc/imap.cxx42
1 files changed, 15 insertions, 27 deletions
diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx
index 705021afe3fb..967724923ed8 100644
--- a/svtools/source/misc/imap.cxx
+++ b/svtools/source/misc/imap.cxx
@@ -35,8 +35,8 @@
#include <boost/scoped_ptr.hpp>
-#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \
- (aPT).Y()=((aPT).Y()*(aFracY).GetNumerator())/(aFracY).GetDenominator();
+#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).numerator())/(aFracX).denominator(); \
+ (aPT).Y()=((aPT).Y()*(aFracY).numerator())/(aFracY).denominator();
/******************************************************************************/
@@ -226,16 +226,13 @@ Rectangle IMapRectangleObject::GetRectangle( bool bPixelCoords ) const
return aNewRect;
}
-void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
+void IMapRectangleObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY )
{
Point aTL( aRect.TopLeft() );
Point aBR( aRect.BottomRight() );
- if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
- {
- SCALEPOINT( aTL, rFracX, rFracY );
- SCALEPOINT( aBR, rFracX, rFracY );
- }
+ SCALEPOINT( aTL, rFracX, rFracY );
+ SCALEPOINT( aBR, rFracX, rFracY );
aRect = Rectangle( aTL, aBR );
}
@@ -371,19 +368,16 @@ Rectangle IMapCircleObject::GetBoundRect() const
Size( nWidth, nWidth ) );
}
-void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
+void IMapCircleObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY )
{
- Fraction aAverage( rFracX );
+ boost::rational<long> aAverage( rFracX );
aAverage += rFracY;
- aAverage *= Fraction( 1, 2 );
+ aAverage *= boost::rational<long>( 1, 2 );
- if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
- {
- SCALEPOINT( aCenter, rFracX, rFracY );
- }
+ SCALEPOINT( aCenter, rFracX, rFracY );
- nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator();
+ nRadius = ( nRadius * aAverage.numerator() ) / aAverage.denominator();
}
bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj )
@@ -493,7 +487,7 @@ void IMapPolygonObject::SetExtraEllipse( const Rectangle& rEllipse )
}
}
-void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
+void IMapPolygonObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY )
{
sal_uInt16 nCount = aPoly.GetSize();
@@ -501,10 +495,7 @@ void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
{
Point aScaledPt( aPoly[ i ] );
- if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
- {
- SCALEPOINT( aScaledPt, rFracX, rFracY );
- }
+ SCALEPOINT( aScaledPt, rFracX, rFracY );
aPoly[ i ] = aScaledPt;
}
@@ -514,11 +505,8 @@ void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
Point aTL( aEllipse.TopLeft() );
Point aBR( aEllipse.BottomRight() );
- if ( rFracX.GetDenominator() && rFracY.GetDenominator() )
- {
- SCALEPOINT( aTL, rFracX, rFracY );
- SCALEPOINT( aBR, rFracX, rFracY );
- }
+ SCALEPOINT( aTL, rFracX, rFracY );
+ SCALEPOINT( aBR, rFracX, rFracY );
aEllipse = Rectangle( aTL, aBR );
}
@@ -824,7 +812,7 @@ IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize,
return( pObj ? ( pObj->IsActive() ? pObj : NULL ) : NULL );
}
-void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
+void ImageMap::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY )
{
size_t nCount = maList.size();