Problem with line intersection with grid.

Yes, poorly named thread I'm sorry. One problem I'm having is that I have absolutely no idea what this is called, or even what area of math this falls under. To the best of my knowledge it falls under Trig because it deals with angles.

Anyway, I'm a computer programmer working on something and I'm given a 3d grid. This space is infinite in two dimensions, but finite in the third. Then, I have a point in this space and a direction. One thing I kept in my mind while trying to solve this problem is that this line thing will only stop if the direction is not parallel to the dimension that is finite. Yes, wrong terminology. Chances are that the direction isn't parallel though.

What I'm looing for is the first cube (that is, closest to the point I'm given) that this resulting line (it might be called a ray) occupies that matches a certain criteria that I'm given. To do that I'll need to check each cube to see if it matches my criteria. The only problem is that I can't figure out how to get which cubes this line occupies.

My current method is to increment a certain distance (currently I'm using 1/10th of the size of a cube, it works well) away from the point and test if the occupied cube matches the criteria. If it doesn't increment again and repeat. The problem with this method is that if the line/ray just clips a corner of a cube, I may miss it. I know for certain there is a way to solve this without missing any cubes.

Also, if at all possible, could i have the name of my method and the correct method so that I know what to call them?