Jumar Macato
6 years ago
No known key found for this signature in database
GPG Key ID: B19884DAC3A5BF3F
1 changed files with
24 additions and
0 deletions
-
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 |
|
|
|
/// </summary>
|
|
|
|
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 |
|
|
|
/// <inheritdoc/>
|
|
|
|
public Rect Bounds => Geometry.GetWidenedBounds(0).ToAvalonia(); |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public double ContourLength => Geometry.ComputeLength(null, ContourApproximation); |
|
|
|
|
|
|
|
public Geometry Geometry { get; } |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -57,6 +63,24 @@ namespace Avalonia.Direct2D1.Media |
|
|
|
transform.ToDirect2D()), |
|
|
|
this); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
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; |
|
|
|
} |
|
|
|
|