Mercurial > hg > octave-image
changeset 879:43cd1c5e0955 stable
bwdist: fix endless loop in bwdist with quasi-euclidean method in x86 systems.
* bwdist.cc: in a 32-bit machine, use of float instead of double was somehow
causing an endless loop (this may be treating the symptoms instead of the real
cause) in specific matrices. Added a test that duplicated this bug. This was
a regression caused by cset 27d87f06dd99 when changing the output class from
double to single for Matlab compatibility.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sun, 09 Mar 2014 20:41:08 +0000 |
parents | 72930d024906 |
children | 4a96ec52e023 |
files | src/bwdist.cc |
diffstat | 1 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bwdist.cc +++ b/src/bwdist.cc @@ -65,7 +65,7 @@ } } - float olddist2, newdist2, newdistx, newdisty; + double olddist2, newdist2, newdistx, newdisty; bool changed; // Initialize index offsets for the current image width @@ -641,5 +641,29 @@ %! assert (dout, dist) %! assert (cout, c) +## The quasi-euclidean method is apparently sensitive to a machine precision +## error that happens in x86 systems only. This test will cause an endless +## loop in case of a regression. +%!test +%! bw = [ 0 1 1 0 0 0 1 0 +%! 0 0 0 0 0 0 0 0 +%! 1 1 0 0 0 0 0 0 +%! 0 0 0 0 0 0 1 0 +%! 0 0 0 0 1 0 0 1 +%! 0 0 0 0 0 0 0 0 +%! 1 0 0 0 0 0 0 0 +%! 0 0 1 0 0 1 1 0]; +%! out = single ([ +%! 1.00000 0.00000 0.00000 1.00000 2.00000 1.00000 0.00000 1.00000 +%! 1.00000 1.00000 1.00000 sqrt(2) sqrt(2)+1 sqrt(2) 1.00000 sqrt(2) +%! 0.00000 0.00000 1.00000 2.00000 2.00000 sqrt(2) 1.00000 sqrt(2) +%! 1.00000 1.00000 sqrt(2) sqrt(2) 1.00000 1.00000 0.00000 1.00000 +%! 2.00000 2.00000 2.00000 1.00000 0.00000 1.00000 1.00000 0.00000 +%! 1.00000 sqrt(2) 2.00000 sqrt(2) 1.00000 sqrt(2) sqrt(2) 1.00000 +%! 0.00000 1.00000 1.00000 sqrt(2) sqrt(2) 1.00000 1.00000 sqrt(2) +%! 1.00000 1.00000 0.00000 1.00000 1.00000 0.00000 0.00000 1.00000 +%! ]); +%! assert (bwdist (bw, "quasi-euclidean"), out); + %!error <unknown METHOD> bwdist (bw, "not a valid method"); */