Replace excessive exponentiation with simple x*x squaring in SphereIntersect.
This commit is contained in:
parent
8a0460b7fc
commit
6cfde41bc7
2 changed files with 28 additions and 10 deletions
|
|
@ -340,6 +340,24 @@ Class SWWMUtility
|
|||
}
|
||||
}
|
||||
|
||||
// "fast" exponentiation with integer exponents using loops
|
||||
static clearscope double IntPowF( double base, int exp )
|
||||
{
|
||||
if ( exp < 0 ) return 1./IntPowF(base,-exp);
|
||||
if ( exp == 0 ) return 1.;
|
||||
double rslt = base;
|
||||
for ( int i=0; i<exp; i++ ) rslt *= base;
|
||||
return rslt;
|
||||
}
|
||||
static clearscope int IntPow( int base, int exp )
|
||||
{
|
||||
if ( exp < 0 ) return int(1./IntPow(base,-exp));
|
||||
if ( exp == 0 ) return 1;
|
||||
int rslt = base;
|
||||
for ( int i=0; i<exp; i++ ) rslt *= base;
|
||||
return rslt;
|
||||
}
|
||||
|
||||
static clearscope String SuperscriptNum( int val )
|
||||
{
|
||||
// unicode is fun
|
||||
|
|
@ -348,7 +366,7 @@ Class SWWMUtility
|
|||
int digits = int(Log10(val));
|
||||
for ( int i=digits; i>=0; i-- )
|
||||
{
|
||||
int d = int(val/(10**i))%10;
|
||||
int d = int(val/IntPow(10,i))%10;
|
||||
str.AppendCharacter(digs[d]);
|
||||
}
|
||||
return str;
|
||||
|
|
@ -578,13 +596,13 @@ Class SWWMUtility
|
|||
Vector3 amin = ap+(-a.radius,-a.radius,0),
|
||||
amax = ap+(a.radius,a.radius,a.height);
|
||||
double distsq = 0.;
|
||||
if ( p.x < amin.x ) distsq += (amin.x-p.x)**2;
|
||||
if ( p.x > amax.x ) distsq += (p.x-amax.x)**2;
|
||||
if ( p.y < amin.y ) distsq += (amin.y-p.y)**2;
|
||||
if ( p.y > amax.y ) distsq += (p.y-amax.y)**2;
|
||||
if ( p.z < amin.z ) distsq += (amin.z-p.z)**2;
|
||||
if ( p.z > amax.z ) distsq += (p.z-amax.z)**2;
|
||||
return (distsq <= (radius**2));
|
||||
if ( p.x < amin.x ) distsq += (amin.x-p.x)*(amin.x-p.x);
|
||||
if ( p.x > amax.x ) distsq += (p.x-amax.x)*(p.x-amax.x);
|
||||
if ( p.y < amin.y ) distsq += (amin.y-p.y)*(amin.y-p.y);
|
||||
if ( p.y > amax.y ) distsq += (p.y-amax.y)*(p.y-amax.y);
|
||||
if ( p.z < amin.z ) distsq += (amin.z-p.z)*(amin.z-p.z);
|
||||
if ( p.z > amax.z ) distsq += (p.z-amax.z)*(p.z-amax.z);
|
||||
return (distsq <= (radius*radius));
|
||||
}
|
||||
|
||||
// Liang-Barsky line clipping
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue