sphere-designer: Don't compute sqrt() unless absolutely necessary

This commit is contained in:
Mukund Sivaraman 2011-10-11 10:01:36 +05:30
parent 1558c3ffa5
commit 238736fb8f
1 changed files with 15 additions and 3 deletions

View File

@ -523,6 +523,18 @@ vdist (GimpVector4 *a, GimpVector4 *b)
return sqrt (x * x + y * y + z * z);
}
static inline gdouble
vdist2 (GimpVector4 *a, GimpVector4 *b)
{
gdouble x, y, z;
x = a->x - b->x;
y = a->y - b->y;
z = a->z - b->z;
return x * x + y * y + z * z;
}
static inline gdouble
vlen (GimpVector4 *a)
{
@ -716,7 +728,7 @@ static gdouble
checkdisc (ray * r, disc * disc)
{
GimpVector4 p, *v = &disc->a;
gdouble t, d;
gdouble t, d2;
gdouble i, j, k;
i = r->v2.x - r->v1.x;
@ -730,9 +742,9 @@ checkdisc (ray * r, disc * disc)
p.y = r->v1.y + j * t;
p.z = r->v1.z + k * t;
d = vdist (&p, v);
d2 = vdist2 (&p, v);
if (d > disc->r)
if (d2 > disc->r * disc->r)
t = 0.0;
return t;