Line::getDistanceFromPoint broken with Line<int>


The Line::getDistanceFromPoint() method has the following calculation:

    auto prop = ((targetPoint.x - start.x) * delta.x
               + (targetPoint.y - start.y) * delta.y) / length;

The auto resolves to an int type when we have Line<int> and so the proportion is truncated to 0 or 1.

Looking at the git log I see this was changed from double to auto on April 24, 2017, with commit e0698daacabc90c791b33c0ec928091418e03feb. So, it’s probably recently broken, although Line<int> doesn’t seem to be used much.

Thanks for taking a look!



Note that in defense of the above mentioned commit, it looks like the above method would have already been broken prior to it due to this line as the prop proportion is cast to an int before the multiplication with delta:

pointOnLine = start + delta * static_cast<ValueType> (prop);

I think that this would probably be better:

pointOnLine = start + delta * prop;

Since delta is a Point<int> and it knows how to multiply by a floating point type.


Thanks Rob, I’ll sort that out!