Why does juce think the following two line segments intersect one another?

The following snippet of code returns true when the call to intersects is made:

    juce::Line<int> a(-5, -5, -5, -2); // vertical
    juce::Line<int> b(0, 0, 10, 0);    // horizontal

    DBG("intersects " << (a.intersects(b) ? "true" : "false"));
    auto p = a.getIntersection(b);
    DBG("getIntersection " << p.getX() << ", " << p.getY());

Here is the output:

intersects true
getIntersection -5, -2

Clearly these two line segments do not actually intersect, do they? What am I missing here?

This probably has to do with the fact you are using ints

Because these are lines, not segments?

I thought so too at first and I only skimmed through the docs and misread but it does specifically talk about line segment intersections JUCE: Line< ValueType > Class Template Reference

I see, but you are not reading the doc of the method you used.
The doc talks about line segments for the intersects method that takes a reference to an intersection point as an additional parameter.
The one you use talks about lines.
Just guessing here but worth trying the other method.

Yep, if you use Line<float>, it works fine. Thanks Intrets.

The docs are pretty clearly referring to segments, as is the underlying JUCE code in Line::intersects(). But it doesn’t seem work properly if you are using ints.

Oh I see. The doc is not clear about segments everywhere. But it indeed says:
“The ValueType template parameter should be a primitive type - float or double are what it’s designed for. Integer types will work in a basic way, but some methods that perform mathematical operations may not compile, or they may not produce sensible results.”

Thanks for pointing that out dimbouche, I totally overlooked that in the header for the Line docs.