# Weirdness when drawing a path

**URL:** <https://forum.juce.com/t/weirdness-when-drawing-a-path/48972>\
**Category:** General JUCE discussion\
**Created:** [November 27, 2021, 4:03pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972 "2021-11-27T16:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbacklund](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nbacklund/32/2969_2.png) [@nbacklund](https://forum.juce.com/u/nbacklund)\
**Post date:** [November 27, 2021, 4:03pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/1 "2021-11-27T16:03:18Z")

</div>

I’m drawing a quite simple path in my plugin, It’s a closed path consisting of 5 points.  
But when I draw it, the diagonal lines come out much thicker than the rest, and I have no idea why:

![Screenshot 2021-11-27 at 16.56.03](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/a/ae84d4a58ddc760c7f14baefd41b9b600a6c2500.png)

For reference, here’s the code:

```
Path outline;
outline.startNewSubPath(0, 0);
outline.lineTo(20, 0);
outline.lineTo(20, 10);
outline.lineTo(10, 15);
outline.lineTo(0, 10);
outline.closeSubPath();

g.setColour(kDisplayBackgroundColour);
g.fillPath(outline);
g.setColour(Colours::black);
g.strokePath(outline, PathStrokeType(2));

```

Does anyone know what’s going on?  
I’m using JUCE 6.1.2 on macOS 12.0.1.

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [November 27, 2021, 4:25pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/2 "2021-11-27T16:25:00Z")

</div>

Your path is being clipped by the edge of the component because you’ve got points at X=0 and Y=0. When you stroke a path, each line segment goes through the _middle_ of each point, meaning if you’ve got a stroke width of 2px, 1px of the line is on the outside of the filled area, while 1px is on the inside of the filled area.

You’ll be able to see this more clearly if you stroke the path before you fill it, you’ll see the stroked segment ‘spilling’ out from behind the filled area.

The best solution (IME) is to simply reduce the path by 1/2 the stroke width. So in your case, with a stroke width of 2px, you want to bring the path inwards by 1px. You’d start at (1, 1), then go to (19, 1), etc.

---

<div class="post-metadata">

**Author:** ![nbacklund](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nbacklund/32/2969_2.png) [@nbacklund](https://forum.juce.com/u/nbacklund)\
**Post date:** [November 27, 2021, 5:54pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/3 "2021-11-27T17:54:53Z")

</div>

Ah, yes, of course, that’s it! 😃

Thank you so much, it was driving me crazy!

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [November 27, 2021, 7:16pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/4 "2021-11-27T19:16:49Z")

</div>

in my current main project i have a static constexpr for the thickness of everything, because i found it cool to be consistent across the project. also that lets me easily try different thicknesses by just changing one variable. now in every component that does something with its bounds i always start with

```auto
const auto bounds = getLocalBounds().toFloat().reducedBy(thickness);

```

because then if you use these bounds rather than the “real” bounds you always have bounds you can savely work with while also being right at the edge with everything.

now that i see this though… i consider deliberately clipping the bounds sometimes. kind of a cool 3d effect

---

<div class="post-metadata">

**Author:** ![bcsuganthan](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bcsuganthan](https://forum.juce.com/u/bcsuganthan)\
**Post date:** [November 30, 2021, 12:27pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/5 "2021-11-30T12:27:25Z")

</div>

A lazy quick dirty hack is to do `setPaintingIsUnclipped(true);` in the component’s constructor where the out of bounds painting is done.

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [November 30, 2021, 12:29pm UTC](https://forum.juce.com/t/weirdness-when-drawing-a-path/48972/6 "2021-11-30T12:29:58Z")

</div>

This would only work if your drawing is static - if the component in question moved, or the path changed in some way, the part of the path that was painted outside the component’s bounds won’t be repainted. You’d have to manually flag those external bounds to be painted in the parent.
