[BUG] D2D renderer does not draw purely horizontal/vertical paths

I found a small bug in the d2d renderer.

If a juce::Path is purely horizontal or vertical, the Direct2D renderer skips it completely. Such paths render correctly on macOS or when using the Software Renderer.

This happens because of this check in Direct2DGraphicsContext::strokePath():1438

 if(p.getBounds().isEmpty()) 
    return;

The bounds of a horizontal/vertical path have height/width zero and therefore getBounds().isEmpty() becomes true.

This could be fixed in multiple ways. I went for

if (auto b = p.getBounds(); b.getWidth() == 0.f && b.getHeight() == 0.f)
    return;

but it could also be if (p.isEmpty()) return;

It depends on the question whether a path that is just a point should still be drawn if a PathStrokeType is used that would convert that into something.

The fix could be cherry-picked from here:

1 Like

The current isEmpty() returns whether the area of the rectangle is 0 (i.e. at least one of the dimensions is 0).

I think this case shows that it would be helpful to also have a method that returns whether both the dimensions are 0

I proposed such addition a while ago, feel free to vote it:

1 Like

I agree that would be a nice 2-in-1 patch :).

This should be fixed on develop.

My report was about strokePath() and it was already fixed on develop.
For fillPath(), p.getBounds().isEmpty() would be enough as filling a path with height or width 0 should do nothing - unlike strokePath which adds volume to paths.