We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › selecting points from an array
Page Index Toggle Pages: 1
selecting points from an array (Read 497 times)
selecting points from an array
Apr 19th, 2007, 6:56pm
 
Hello People,

i have a logic problem, which i can't get solved:

I have an array with ~500 entries (Coordinates)
Now i want to move the mouse and always when the
mouse koordinates are equal (or in a range) of one
or more coordinates from the array the programm should
return the position of the equal coordinate(s) in the array.

I thought to make it like this, but it needs too much performance
and i don't know if it is corrrect:

....
void draw(){

for(i = 0; i < array.length; i++){

if(mouseX == array[i].x && mouseY == array[i].y){

// equal xposition

}

}

}
....

i am struggling with this problem a lot now. I would
be VERY VERY happy if someone might have a idea etc.
to solve this.

Thank you very much!
Re: selecting points from an array
Reply #1 - Apr 19th, 2007, 7:49pm
 
does that make sense? say mouseXY is 5 and 10 .. now you are running thru the array to find two _equal_ values 5 and 10 and return them? what's wrong with the mouse-coords in the first place? what are you really trying to do, returning the array index? are you looking for collision with the mouse?

edit: if you are just trying to find out if the coords are in the array at all, then you can simplify this:
Code:

boolean arr = new boolean[width*height];
// to get or set a value at x,y use:
// arr[x+y* width] = ...
// let's assume you've set values in there, now you can just check:
if ( arr[mouseX+mouseY*width] ) { /*do something here ... */ };

F
Page Index Toggle Pages: 1