eliminate calls to sqrt().

2007-06-12  Sven Neumann  <sven@gimp.org>

	* app/base/boundary.c (simplify_subdivide): eliminate calls to sqrt().

svn path=/trunk/; revision=22764
This commit is contained in:
Sven Neumann 2007-06-12 10:20:36 +00:00 committed by Sven Neumann
parent dfeaec0861
commit 345f007049
2 changed files with 16 additions and 15 deletions

View File

@ -1,3 +1,7 @@
2007-06-12 Sven Neumann <sven@gimp.org>
* app/base/boundary.c (simplify_subdivide): eliminate calls to sqrt().
2007-06-12 Sven Neumann <sven@gimp.org>
* plug-ins/common/psd-load.c: applied slightly modified patch from

View File

@ -889,9 +889,9 @@ simplify_subdivide (const BoundSeg *segs,
GArray **ret_points)
{
gint maxdist_idx;
gint dist, maxdist;
gint maxdist;
gint threshold;
gint i, dx, dy;
gdouble realdist;
if (end_idx - start_idx < 2)
{
@ -909,7 +909,7 @@ simplify_subdivide (const BoundSeg *segs,
for (i = start_idx + 1; i < end_idx; i++)
{
/* compare the sqared distances */
dist = (SQR (segs[i].x1 - segs[start_idx].x1) +
gint dist = (SQR (segs[i].x1 - segs[start_idx].x1) +
SQR (segs[i].y1 - segs[start_idx].y1));
if (dist > maxdist)
@ -919,7 +919,7 @@ simplify_subdivide (const BoundSeg *segs,
}
}
realdist = sqrt ((gdouble) maxdist);
threshold = 1;
}
else
{
@ -933,12 +933,9 @@ simplify_subdivide (const BoundSeg *segs,
* (for the real distance we'd have to divide by
* (SQR(dx)+SQR(dy)))
*/
dist = (dx * (segs[start_idx].y1 - segs[i].y1) -
gint dist = abs (dx * (segs[start_idx].y1 - segs[i].y1) -
dy * (segs[start_idx].x1 - segs[i].x1));
if (dist < 0)
dist *= -1;
if (dist > maxdist)
{
maxdist = dist;
@ -946,11 +943,11 @@ simplify_subdivide (const BoundSeg *segs,
}
}
realdist = ((gdouble) maxdist) / sqrt ((gdouble) (SQR (dx) + SQR (dy)));
/* threshold is chosen to catch 45 degree stairs */
threshold = SQR (dx) + SQR (dy);
}
/* threshold is chosen to catch 45 degree stairs */
if (realdist <= 1.0)
if (maxdist <= threshold)
{
*ret_points = g_array_append_val (*ret_points, start_idx);
return;