
Perhaps you need this formula.
Here is a link to the wikipedia page for this formula.
This source is very thorough, but probably not the easiest to read. You can read the explanation on the wiki, but I'm going to explain it here in a different way, in the hope that I can help you and other readers visualize it.
x0 and y0 are the coordinates of the click point. x1 and y1 are the coordinates of the endpoint of your first line. x2 and y2 are the coordinates of your second endpoint on the same line.
This formula takes three sets of coordinates for three points as parameters.
The first two groups of coordinates form a line. The third parameter is your click point. It returns the distance.
Ok, now try to imagine what this formula does. So you take the click point and the two end points of the line, and you imagine a triangle. We have three points that we need to make a triangle.
therefore, to find the height of the triangle, you have a formula that is a permutation of the familiar A = (1/2) bh

So, when you find the height of the triangle like this, you find the distance between the click point and the line. (This is the shortest distance between the click point and the string, to be exact)
The higher distance formula above basically does this. The difference here, and why it looks more complicated, is that the part in which A is calculated is explicitly shown.
As for the tolerance you were talking about, just set a variable for the tolerance and compare the distance to that tolerance. If you want something a little more โfuzzyโ for the allowance for clicks next to the line, you will need to do more math, but I assume that you only want to know if the click was a certain distance from the line.
When you write this function, make sure that you do good bookkeeping and set the correct coordinates in the right place, otherwise you will get a distant distance, but not what you want. Since you mentioned that you use integers, you cannot get the perfect shape back from the distance formula, I mean, look at this square root, so if you don't get the perfect int back, donโt worry, just round up or down ,