It sounds like you're suggesting there would be multiple hits to the same block with this method but I don't see why.
However, I do see how you could trigger a collision with multiple blocks; there might be two that would have been within the range of movement if it didn't bounce. However, it's not hard to pick which collision happened first and only process that one.
Here's some pseudocode (Disclaimer: This is completely untested!):
bool collided = false;
double nearestHit = double.MaxValue;
BlockEdge nearestHitEdge;
foreach block in blocks {
foreach edge in block {
Vector2 intersection = lineIntersection(ballVelocityVector, edge);
double distance = distanceBetween(ballCoords, interesection);
if (distance < ballRadius + length(ballVelocityVector) && distance < nearestHit) {
collided = true;
nearestHitEdge = edge;
nearestHit = distance;
}
}
}
if (collided) {
nearestHitEdge.parentBlock.hit();
ball.bounceOff(nearestHitEdge);
}
/* End of pseudocode */
Also, for your convenience here's some actual C# code for finding the intersection of two lines given two points on the lines. It expects "points" to be a 4x2 multidimensional array where the first index specifies which point and the second index indicates X (0) or Y (1). The first two points define one line and the other two define the other line.
double nx, ny;
if (points[0, 0] == points[1, 0])
{
if (points[2, 0] == points[3, 0])
{
nx = double.MaxValue;
ny = double.MaxValue;
}
else
{
double slope2 =(points[3, 1] - points[2, 1]) / (points[3, 0] - points[2, 0]);
double b2 = points[2, 0] * -slope2 + points[2, 1];
nx = points[0, 0];
ny = slope2 * nx + b2;
}
}
else if (points[2, 0] == points[3, 0])
{
double slope1 = (points[1, 1] - points[0, 1]) / (points[1, 0] - points[0, 0]);
double b1 = points[0, 0] * -slope1 + points[0, 1];
nx = points[1, 0];
ny = slope1 * nx + b1;
}
else
{
double slope1 = (points[1, 1] - points[0, 1]) / (points[1, 0] - points[0, 0]);
double slope2 = (points[3, 1] - points[2, 1]) / (points[3, 0] - points[2, 0]);
double b1 = points[0, 0] * -slope1 + points[0, 1];
double b2 = points[2, 0] * -slope2 + points[2, 1];
nx = (b2 - b1) / (slope1 - slope2);
ny = slope1 * nx + b1;
}