Kaydet (Commit) f0c03edd authored tarafından Michael Stahl's avatar Michael Stahl

sw: remove silly BigInt based SqRt

Change-Id: I0a23682998fcf23f917289a0137d137b240a9d92
üst 09af884e
...@@ -35,7 +35,6 @@ class SwRootFrm; ...@@ -35,7 +35,6 @@ class SwRootFrm;
class SwDoc; class SwDoc;
class SwAttrSet; class SwAttrSet;
class SdrObject; class SdrObject;
class BigInt;
class SvxBrushItem; class SvxBrushItem;
class XFillStyleItem; class XFillStyleItem;
class XFillGradientItem; class XFillGradientItem;
...@@ -82,8 +81,6 @@ void PaintCharacterBorder( ...@@ -82,8 +81,6 @@ void PaintCharacterBorder(
// Implementation in feshview.cxx // Implementation in feshview.cxx
SwFlyFrm *GetFlyFromMarked( const SdrMarkList *pLst, SwViewShell *pSh ); SwFlyFrm *GetFlyFromMarked( const SdrMarkList *pLst, SwViewShell *pSh );
sal_uLong SqRt( BigInt nX );
SwFrm *SaveCntnt( SwLayoutFrm *pLay, SwFrm *pStart = NULL ); SwFrm *SaveCntnt( SwLayoutFrm *pLay, SwFrm *pStart = NULL );
void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGrow ); void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGrow );
......
...@@ -877,7 +877,7 @@ static const SwFrm * lcl_CalcDownDist( SwDistance &rRet, ...@@ -877,7 +877,7 @@ static const SwFrm * lcl_CalcDownDist( SwDistance &rRet,
return 0; return 0;
} }
static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay, static sal_uInt64 lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
const SwCntntFrm *& rpCnt, const SwCntntFrm *& rpCnt,
const bool bBody, const sal_Bool bFtn ) const bool bBody, const sal_Bool bFtn )
{ {
...@@ -890,8 +890,8 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay, ...@@ -890,8 +890,8 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
#endif #endif
rpCnt = 0; rpCnt = 0;
sal_uLong nDistance = ULONG_MAX; sal_uInt64 nDistance = SAL_MAX_UINT64;
sal_uLong nNearest = ULONG_MAX; sal_uInt64 nNearest = SAL_MAX_UINT64;
const SwCntntFrm *pCnt = pLay->ContainsCntnt(); const SwCntntFrm *pCnt = pLay->ContainsCntnt();
while ( pCnt && (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn())) while ( pCnt && (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn()))
...@@ -907,13 +907,12 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay, ...@@ -907,13 +907,12 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
{ {
//Calculate the distance between those two points. //Calculate the distance between those two points.
//'delta' X^2 + 'delta' Y^2 = 'distance'^2 //'delta' X^2 + 'delta' Y^2 = 'distance'^2
sal_uInt32 dX = std::max( pCnt->Frm().Left(), rPt.X() ) - sal_uInt64 dX = std::max( pCnt->Frm().Left(), rPt.X() ) -
std::min( pCnt->Frm().Left(), rPt.X() ), std::min( pCnt->Frm().Left(), rPt.X() ),
dY = std::max( pCnt->Frm().Top(), rPt.Y() ) - dY = std::max( pCnt->Frm().Top(), rPt.Y() ) -
std::min( pCnt->Frm().Top(), rPt.Y() ); std::min( pCnt->Frm().Top(), rPt.Y() );
BigInt dX1( dX ), dY1( dY ); // square of the difference will do fine here
dX1 *= dX1; dY1 *= dY1; const sal_uInt64 nDiff = (dX * dX) + (dY * dY);
const sal_uLong nDiff = ::SqRt( dX1 + dY1 );
if ( pCnt->Frm().Top() <= rPt.Y() ) if ( pCnt->Frm().Top() <= rPt.Y() )
{ {
if ( nDiff < nDistance ) if ( nDiff < nDistance )
...@@ -935,7 +934,7 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay, ...@@ -935,7 +934,7 @@ static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
} while ( pCnt && pLay->IsAnLower( pCnt ) ); } while ( pCnt && pLay->IsAnLower( pCnt ) );
} }
if ( nDistance == ULONG_MAX ) if (nDistance == SAL_MAX_UINT64)
{ rpCnt = pNearest; { rpCnt = pNearest;
return nNearest; return nNearest;
} }
...@@ -955,26 +954,26 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt, ...@@ -955,26 +954,26 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt,
//above the point. //above the point.
const SwCntntFrm *pRet, *pNew; const SwCntntFrm *pRet, *pNew;
const SwLayoutFrm *pLay = pCnt->FindPageFrm(); const SwLayoutFrm *pLay = pCnt->FindPageFrm();
sal_uLong nDist; sal_uInt64 nDist; // not sure if a sal_Int32 would be enough?
nDist = ::lcl_FindCntDiff( rPt, pLay, pNew, bBody, bFtn ); nDist = ::lcl_FindCntDiff( rPt, pLay, pNew, bBody, bFtn );
if ( pNew ) if ( pNew )
pRet = pNew; pRet = pNew;
else else
{ pRet = pCnt; { pRet = pCnt;
nDist = ULONG_MAX; nDist = SAL_MAX_UINT64;
} }
const SwCntntFrm *pNearest = pRet; const SwCntntFrm *pNearest = pRet;
sal_uLong nNearest = nDist; sal_uInt64 nNearest = nDist;
if ( pLay ) if ( pLay )
{ {
const SwLayoutFrm *pPge = pLay; const SwLayoutFrm *pPge = pLay;
sal_uLong nOldNew = ULONG_MAX; sal_uInt64 nOldNew = SAL_MAX_UINT64;
for ( sal_uInt16 i = 0; pPge->GetPrev() && (i < 3); ++i ) for ( sal_uInt16 i = 0; pPge->GetPrev() && (i < 3); ++i )
{ {
pPge = (SwLayoutFrm*)pPge->GetPrev(); pPge = (SwLayoutFrm*)pPge->GetPrev();
const sal_uLong nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn ); const sal_uInt64 nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
if ( nNew < nDist ) if ( nNew < nDist )
{ {
if ( pNew->Frm().Top() <= rPt.Y() ) if ( pNew->Frm().Top() <= rPt.Y() )
...@@ -988,18 +987,18 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt, ...@@ -988,18 +987,18 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt,
nNearest = nNew; nNearest = nNew;
} }
} }
else if ( nOldNew != ULONG_MAX && nNew > nOldNew ) else if (nOldNew != SAL_MAX_UINT64 && nNew > nOldNew)
break; break;
else else
nOldNew = nNew; nOldNew = nNew;
} }
pPge = pLay; pPge = pLay;
nOldNew = ULONG_MAX; nOldNew = SAL_MAX_UINT64;
for ( sal_uInt16 j = 0; pPge->GetNext() && (j < 3); ++j ) for ( sal_uInt16 j = 0; pPge->GetNext() && (j < 3); ++j )
{ {
pPge = (SwLayoutFrm*)pPge->GetNext(); pPge = (SwLayoutFrm*)pPge->GetNext();
const sal_uLong nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn ); const sal_uInt64 nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
if ( nNew < nDist ) if ( nNew < nDist )
{ {
if ( pNew->Frm().Top() <= rPt.Y() ) if ( pNew->Frm().Top() <= rPt.Y() )
...@@ -1013,7 +1012,7 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt, ...@@ -1013,7 +1012,7 @@ static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt,
nNearest = nNew; nNearest = nNew;
} }
} }
else if ( nOldNew != ULONG_MAX && nNew > nOldNew ) else if (nOldNew != SAL_MAX_UINT64 && nNew > nOldNew)
break; break;
else else
nOldNew = nNew; nOldNew = nNew;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <tools/bigint.hxx>
#include <svx/svdmodel.hxx> #include <svx/svdmodel.hxx>
#include <svx/svdpage.hxx> #include <svx/svdpage.hxx>
#include <editeng/brushitem.hxx> #include <editeng/brushitem.hxx>
...@@ -2683,29 +2682,6 @@ void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGro ...@@ -2683,29 +2682,6 @@ void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGro
pParent->Grow( nGrowVal ); pParent->Grow( nGrowVal );
} }
/*************************************************************************
|*
|* SqRt() Berechnung der Quadratwurzel, damit die math.lib
|* nicht auch noch dazugelinkt werden muss.
|*
|*************************************************************************/
sal_uLong SqRt( BigInt nX )
{
BigInt nErg = 1;
if ( !nX.IsNeg() )
{
BigInt nOldErg = 1;
for ( int i = 0; i <= 5; i++ )
{
nErg = (nOldErg + (nX / nOldErg)) / BigInt(2);
nOldErg = nErg;
}
}
return nErg >= BigInt(SAL_MAX_UINT32) ? ULONG_MAX : (sal_uLong)nErg;
}
/*************************************************************************/ /*************************************************************************/
SwPageFrm * InsertNewPage( SwPageDesc &rDesc, SwFrm *pUpper, SwPageFrm * InsertNewPage( SwPageDesc &rDesc, SwFrm *pUpper,
......
...@@ -1142,17 +1142,15 @@ sal_Bool GetFrmInPage( const SwCntntFrm *pCnt, SwWhichPage fnWhichPage, ...@@ -1142,17 +1142,15 @@ sal_Bool GetFrmInPage( const SwCntntFrm *pCnt, SwWhichPage fnWhichPage,
} }
} }
sal_uLong CalcDiff( const Point &rPt1, const Point &rPt2 ) static sal_uInt64 CalcDiff(const Point &rPt1, const Point &rPt2)
{ {
//Calculate the distance between the two points. //Calculate the distance between the two points.
//'delta' X^2 + 'delta'Y^2 = 'distance'^2 //'delta' X^2 + 'delta'Y^2 = 'distance'^2
sal_uInt32 dX = std::max( rPt1.X(), rPt2.X() ) - sal_uInt64 dX = std::max( rPt1.X(), rPt2.X() ) -
std::min( rPt1.X(), rPt2.X() ), std::min( rPt1.X(), rPt2.X() ),
dY = std::max( rPt1.Y(), rPt2.Y() ) - dY = std::max( rPt1.Y(), rPt2.Y() ) -
std::min( rPt1.Y(), rPt2.Y() ); std::min( rPt1.Y(), rPt2.Y() );
BigInt dX1( dX ), dY1( dY ); return (dX * dX) + (dY * dY);
dX1 *= dX1; dY1 *= dY1;
return ::SqRt( dX1 + dY1 );
} }
/** Check if the point lies inside the page part in wich also the CntntFrame lies. /** Check if the point lies inside the page part in wich also the CntntFrame lies.
...@@ -1209,7 +1207,7 @@ const SwCntntFrm *SwLayoutFrm::GetCntntPos( Point& rPoint, ...@@ -1209,7 +1207,7 @@ const SwCntntFrm *SwLayoutFrm::GetCntntPos( Point& rPoint,
const SwLayoutFrm *pInside = NULL; const SwLayoutFrm *pInside = NULL;
sal_uInt16 nMaxPage = GetPhyPageNum() + (bDefaultExpand ? 1 : 0); sal_uInt16 nMaxPage = GetPhyPageNum() + (bDefaultExpand ? 1 : 0);
Point aPoint = rPoint; Point aPoint = rPoint;
sal_uLong nDistance = ULONG_MAX; sal_uInt64 nDistance = SAL_MAX_UINT64;
while ( true ) //A loop to be sure we always find one. while ( true ) //A loop to be sure we always find one.
{ {
...@@ -1262,7 +1260,7 @@ const SwCntntFrm *SwLayoutFrm::GetCntntPos( Point& rPoint, ...@@ -1262,7 +1260,7 @@ const SwCntntFrm *SwLayoutFrm::GetCntntPos( Point& rPoint,
if( !pInside || ( pInside->IsAnLower( pCntnt ) && if( !pInside || ( pInside->IsAnLower( pCntnt ) &&
( !pCntnt->IsInFtn() || pInside->IsFtnContFrm() ) ) ) ( !pCntnt->IsInFtn() || pInside->IsFtnContFrm() ) ) )
{ {
const sal_uLong nDiff = ::CalcDiff( aCntntPoint, rPoint ); const sal_uInt64 nDiff = ::CalcDiff(aCntntPoint, rPoint);
sal_Bool bBetter = nDiff < nDistance; // This one is nearer sal_Bool bBetter = nDiff < nDistance; // This one is nearer
if( !pInside ) if( !pInside )
{ {
...@@ -1406,7 +1404,7 @@ void SwPageFrm::GetCntntPosition( const Point &rPt, SwPosition &rPos ) const ...@@ -1406,7 +1404,7 @@ void SwPageFrm::GetCntntPosition( const Point &rPt, SwPosition &rPos ) const
const SwCntntFrm *pAct = pCntnt; const SwCntntFrm *pAct = pCntnt;
Point aAct = rPt; Point aAct = rPt;
sal_uLong nDist = ULONG_MAX; sal_uLong nDist = SAL_MAX_UINT64;
while ( pCntnt ) while ( pCntnt )
{ {
...@@ -1433,7 +1431,7 @@ void SwPageFrm::GetCntntPosition( const Point &rPt, SwPosition &rPos ) const ...@@ -1433,7 +1431,7 @@ void SwPageFrm::GetCntntPosition( const Point &rPt, SwPosition &rPos ) const
else if ( aCntFrm.Right() < rPt.X() ) else if ( aCntFrm.Right() < rPt.X() )
aPoint.X() = aCntFrm.Right(); aPoint.X() = aCntFrm.Right();
const sal_uLong nDiff = ::CalcDiff( aPoint, rPt ); const sal_uInt64 nDiff = ::CalcDiff( aPoint, rPt );
if ( nDiff < nDist ) if ( nDiff < nDist )
{ {
aAct = aPoint; aAct = aPoint;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment