Skip to content

Commit

Permalink
Merge pull request #8699 from timunie/fix/backport_GH_7778
Browse files Browse the repository at this point in the history
Backport PR 7778
  • Loading branch information
maxkatz6 authored Aug 9, 2022
2 parents 765c4d7 + 7b33526 commit d758481
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Avalonia.Media;
using Avalonia.Utilities;

namespace Avalonia.Rendering.SceneGraph;

internal static class GeometryBoundsHelper
{
/// <summary>
/// Calculates the bounds of a given geometry with respect to the pens <see cref="IPen.LineCap"/>
/// </summary>
/// <param name="originalBounds">The calculated bounds without <see cref="IPen.LineCap"/>s</param>
/// <param name="pen">The pen with information about the <see cref="IPen.LineCap"/>s</param>
/// <returns></returns>
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();
}
}
}
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GeometryNode(Matrix transform,
IPen pen,
IGeometryImpl geometry,
IDictionary<IVisual, Scene> childScenes = null)
: base(geometry.GetRenderBounds(pen), transform)
: base(geometry.GetRenderBounds(pen).CalculateBoundsWithLineCaps(pen), transform)
{
Transform = transform;
Brush = brush?.ToImmutable();
Expand Down

0 comments on commit d758481

Please sign in to comment.