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:

committed by
Sven Neumann

parent
dfeaec0861
commit
345f007049
@ -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
|
||||||
|
@ -889,9 +889,9 @@ simplify_subdivide (const BoundSeg *segs,
|
|||||||
GArray **ret_points)
|
GArray **ret_points)
|
||||||
{
|
{
|
||||||
gint maxdist_idx;
|
gint maxdist_idx;
|
||||||
gint dist, maxdist;
|
gint maxdist;
|
||||||
|
gint threshold;
|
||||||
gint i, dx, dy;
|
gint i, dx, dy;
|
||||||
gdouble realdist;
|
|
||||||
|
|
||||||
if (end_idx - start_idx < 2)
|
if (end_idx - start_idx < 2)
|
||||||
{
|
{
|
||||||
@ -909,7 +909,7 @@ 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,12 +933,9 @@ 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)
|
||||||
{
|
{
|
||||||
maxdist = dist;
|
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 (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;
|
||||||
|
Reference in New Issue
Block a user