diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs
new file mode 100644
index 00000000000..b3a91008502
--- /dev/null
+++ b/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs
@@ -0,0 +1,31 @@
+using System;
+using Avalonia.Media;
+using Avalonia.Utilities;
+
+namespace Avalonia.Rendering.SceneGraph;
+
+internal static class GeometryBoundsHelper
+{
+ ///
+ /// Calculates the bounds of a given geometry with respect to the pens
+ ///
+ /// The calculated bounds without s
+ /// The pen with information about the s
+ ///
+ public static Rect CalculateBoundsWithLineCaps(this Rect originalBounds, IPen? pen)
+ {
+ if (pen is null || MathUtilities.IsZero(pen.Thickness)) return originalBounds;
+
+ switch (pen.LineCap)
+ {
+ case PenLineCap.Flat:
+ return originalBounds;
+ case PenLineCap.Round:
+ return originalBounds.Inflate(pen.Thickness / 2);
+ case PenLineCap.Square:
+ return originalBounds.Inflate(pen.Thickness);
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+}
diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs
index 508ca0ad183..378a4cdd201 100644
--- a/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs
+++ b/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs
@@ -24,7 +24,7 @@ public GeometryNode(Matrix transform,
IPen pen,
IGeometryImpl geometry,
IDictionary childScenes = null)
- : base(geometry.GetRenderBounds(pen), transform)
+ : base(geometry.GetRenderBounds(pen).CalculateBoundsWithLineCaps(pen), transform)
{
Transform = transform;
Brush = brush?.ToImmutable();