- Re-instate the fully unconditional "snap-to-last" behaviour in

uniquify().  Mention that "snap-to-last" is a no-op when
    second-to-last point is more than <tolerance> apart from the last
    point.

  - Assert that the <tolerance> is a non-negative value.

  - For benefit of Emacs indenting, adjust license block.
This commit is contained in:
Bård Skaflestad 2009-08-14 16:42:03 +00:00
parent 6c6b1aa0c8
commit d1175bc038

View File

@ -32,6 +32,7 @@ You should have received a copy of the GNU General Public License
along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
@ -79,11 +80,13 @@ static int createSortedList(double *list, int n, int m,
/*-----------------------------------------------------------------
Remove points that are closer than tolerance in list
of increasing doubles
Remove points less than <tolerance> apart in <list> of increasing
doubles.
*/
static int uniquify(int n, double *list, double tolerance)
{
assert (!(tolerance < 0.0));
if (n<1) return 0;
int i;
int pos = 0;
@ -96,14 +99,19 @@ static int uniquify(int n, double *list, double tolerance)
}
}
/* Keep last value (one way or the other...) */
#if 0
if (val + tolerance < list[n-1]){
/*
Preserve outer z-boundary.
This operation is a no-op in the case
list[pos-2] + tolerance < list[n-1].
If, however, the second to last point is less than <tolerance>
away from the last point (list[n-1]), we remove this
second-to-last point as it cannot be distinguished from "final"
point.
*/
list[pos-1] = list[n-1];
}
#else
list[pos-1] = list[n-1];
#endif
return pos;
}