Home »
Public Forums »
archive »
Best way to deal with checking array indices are within bounds
Best way to deal with checking array indices are within bounds [message #75639] |
Tue, 15 March 2011 08:23 |
Robin Wilson
Messages: 40 Registered: August 2010
|
Member |
|
|
Hi all,
I was wondering what people generally do about checking that array
indices are within bounds when working with images - as I assume it is a
problem many people have. For example, in the following code:
x_index = 49
y_index = 42
x_index += 3
x_index += 3
Trying to index a 50x50 array with x_index and y_index will give an
error because the x_index is outside the bounds. I frequently run into
this issue as I do a lot of image processing.
How do people generally deal with it? I often end up using a lot of IF
statements (like below), which gets very messy and is error-prone - does
anyone have a better way to do this?
IF x_index GT 50 THEN x_index = 50
IF x_index LT 0 THEN x_index = 0
...
Any views/ideas?
Cheers,
Robin
------------------
Robin Wilson
A PhD student studying complexity in remote sensing
www.rtwilson.com/academic
|
|
|
Current Time: Wed Oct 08 15:10:32 PDT 2025
Total time taken to generate the page: 0.00591 seconds