linearindex(): Assert component indices in range.

While here, split a long line and sort includes.

Signed-off-by: Bård Skaflestad <Bard.Skaflestad@sintef.no>
This commit is contained in:
Bård Skaflestad
2012-06-20 13:25:11 +00:00
committed by Bård Skaflestad
parent 736b623d4b
commit adf266f077

View File

@@ -32,12 +32,13 @@
along with OpenRS. If not, see <http://www.gnu.org/licenses/>. along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <float.h> #include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "preprocess.h" #include "preprocess.h"
#include "uniquepoints.h" #include "uniquepoints.h"
#include "facetopology.h" #include "facetopology.h"
@@ -66,6 +67,14 @@ process_horizontal_faces(int **intersections,
static int static int
linearindex(const int dims[3], int i, int j, int k) linearindex(const int dims[3], int i, int j, int k)
{ {
assert (0 <= i);
assert (0 <= j);
assert (0 <= k);
assert (i < dims[0]);
assert (j < dims[1]);
assert (k < dims[2]);
return i + dims[0]*(j + dims[1]*k); return i + dims[0]*(j + dims[1]*k);
} }
@@ -75,9 +84,9 @@ linearindex(const int dims[3], int i, int j, int k)
faster than j, and Cartesian dimensions <dims>, find pointers to the faster than j, and Cartesian dimensions <dims>, find pointers to the
(i-1, j-1, 0), (i-1, j, 0), (i, j-1, 0) and (i, j, 0) elements of (i-1, j-1, 0), (i-1, j, 0), (i, j-1, 0) and (i, j, 0) elements of
field. */ field. */
static void igetvectors(int dims[3], int i, int j, int *field, int *v[]) static void
igetvectors(int dims[3], int i, int j, int *field, int *v[])
{ {
int im = max(1, i ) - 1; int im = max(1, i ) - 1;
int ip = min(dims[0], i+1) - 1; int ip = min(dims[0], i+1) - 1;
int jm = max(1, j ) - 1; int jm = max(1, j ) - 1;