diff --git a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs
index d04e2b3110..81c21c8648 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs
@@ -1,3 +1,4 @@
+using Avalonia.Logging;
using Avalonia.Platform;
using SharpDX.Direct2D1;
@@ -8,6 +9,8 @@ namespace Avalonia.Direct2D1.Media
///
public abstract class GeometryImpl : IGeometryImpl
{
+ private const float ContourApproximation = 0.0001f;
+
public GeometryImpl(Geometry geometry)
{
Geometry = geometry;
@@ -16,6 +19,9 @@ namespace Avalonia.Direct2D1.Media
///
public Rect Bounds => Geometry.GetWidenedBounds(0).ToAvalonia();
+ ///
+ public double ContourLength => Geometry.ComputeLength(null, ContourApproximation);
+
public Geometry Geometry { get; }
///
@@ -57,6 +63,24 @@ namespace Avalonia.Direct2D1.Media
transform.ToDirect2D()),
this);
}
+
+ ///
+ public bool TryGetPointAtDistance(double distance, out Point point)
+ {
+ Geometry.ComputePointAtLength((float)distance, ContourApproximation, out var tangentVector);
+ point = new Point(tangentVector.X, tangentVector.Y);
+ return true;
+ }
+
+ ///
+ public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent)
+ {
+ // Direct2D doesnt have this sadly.
+ Logger.TryGet(LogEventLevel.Warning, LogArea.Visual)?.Log(this, "TryGetPointAndTangentAtDistance is not available in Direct2D.");
+ point = new Point();
+ tangent = new Point();
+ return false;
+ }
protected virtual Geometry GetSourceGeometry() => Geometry;
}