forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AvaloniaUI#8699 from timunie/fix/backport_GH_7778
Backport PR 7778
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters