With this being said, your generic idea is correct. The question is can it now be optimized somehow?
There are many methods we can potentially employ here. The trick is all in the way you arrange your data. In your current case, you are doing a center point with your sensitivity variable being your span. One could imagine the first optimization being instead of using a sensitivity that moves left right up and down from a center point, you could implement instead a top-left point with a span that only moves right and down from the top-left point. Your if statement would then become:
if(x > cxy[z][0] && x < (cxy[z][0]+sensivity) && y > cxy[z][1] && y < (cxy[z][1]+sensivity))
So what does this do for you:
This above optimization allows you to hold the same overall amount of data but get rid of 2 math operations per check. Considering that your input parameters are both floating points, this can save quite a bit of time.
If you are doing all pixel based operations, then that brings me to the next optimization. Do ALL calculation using integers instead of floating point, this will also heavily speed up your overall algorithm time.
a further optimization could now be, if you are willing to spend more RAM for better performance, you could instead of having 1 point per region, you could have a top-left and a bottom-right point for each region. This would make your if statement look something like the following:
if(x > tlxy[z][0] && x < brxy[z][0] && y > tlxy[z][1] && y < brxy[z][1])
where tlxy is the array of top-left points, brxy is the array of bottom-right points
and z is still the "region" you are checking against
How does this aid:
As you can see in the above if statement, this now has absolutely no explicit math operations. To support this algorithm, you need to be willing to spend 2 times the memory as the array cxy originally was.
Now within your loop, you are going through ALL 24 region points. If you KNOW FOR CERTAIN that none of your regions overlap, then a point can truly only fall in 1 region at a time. You can save some time on most x y input points by breaking out of the for loop at the point you also increment points. That would look as follows:
public void checkCoordinate(float x, float y){
for(int z = 0; z < 24; z++){
if(x > tlxy[z][0] && x < brxy[z][0] && y > tlxy[z][1] && y < brxy[z][1]){
points += 1;
break;
}
}
}
The above will ONLY WORK IFF you know for certain there are no overlapping regions (not even edges.
On final optimization I can see might have potential. Depending on what your regions look like, you could pre-separate all regions into quadrants. This way you can test the x point to be on the left or right hand of the screen, then test the y point to be in the top or bottom. If your regions distribution is fairly even, this could have the potential to cut your test time down by 4 as you would not only need to test the regions within a quadrant (if the given statistical distribution is what I said). In the worst case, all regions lie in a single quadrant and all points you test are in that quadrant in which case the problem from a complexity standpoint is no worse than what it was before. It simply adds a setup test on your input x and y.
I hope this gives you enough info to at least get started on your way!!!