Browse Source

Merge pull request #7778 from timunie/fix/RenderArtifactsOnLineEnds

Implement GeometryBoundsHelper
pull/7787/head
Jumar Macato 5 years ago
committed by GitHub
parent
commit
86923dcc9f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/Avalonia.Visuals/Rendering/SceneGraph/GeometryBoundsHelper.cs
  2. 2
      src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs

31
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
{
/// <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
src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs

@ -24,7 +24,7 @@ namespace Avalonia.Rendering.SceneGraph
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();

Loading…
Cancel
Save