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> 2007-06-12 Sven Neumann <sven@gimp.org>
* plug-ins/common/psd-load.c: applied slightly modified patch from * plug-ins/common/psd-load.c: applied slightly modified patch from

View File

@ -888,10 +888,10 @@ simplify_subdivide (const BoundSeg *segs,
gint end_idx, gint end_idx,
GArray **ret_points) GArray **ret_points)
{ {
gint maxdist_idx; gint maxdist_idx;
gint dist, maxdist; gint maxdist;
gint i, dx, dy; gint threshold;
gdouble realdist; gint i, dx, dy;
if (end_idx - start_idx < 2) if (end_idx - start_idx < 2)
{ {
@ -909,8 +909,8 @@ simplify_subdivide (const BoundSeg *segs,
for (i = start_idx + 1; i < end_idx; i++) for (i = start_idx + 1; i < end_idx; i++)
{ {
/* compare the sqared distances */ /* 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)); SQR (segs[i].y1 - segs[start_idx].y1));
if (dist > maxdist) if (dist > maxdist)
{ {
@ -919,7 +919,7 @@ simplify_subdivide (const BoundSeg *segs,
} }
} }
realdist = sqrt ((gdouble) maxdist); threshold = 1;
} }
else else
{ {
@ -933,11 +933,8 @@ simplify_subdivide (const BoundSeg *segs,
* (for the real distance we'd have to divide by * (for the real distance we'd have to divide by
* (SQR(dx)+SQR(dy))) * (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)); dy * (segs[start_idx].x1 - segs[i].x1));
if (dist < 0)
dist *= -1;
if (dist > maxdist) if (dist > maxdist)
{ {
@ -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 (maxdist <= threshold)
if (realdist <= 1.0)
{ {
*ret_points = g_array_append_val (*ret_points, start_idx); *ret_points = g_array_append_val (*ret_points, start_idx);
return; return;