update AnimationPath
The PathLength can now be calculated automatically
This commit is contained in:
1 parent
5d8e4e566a
commit
904dae7e97
4 files changed
+83
-9
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Expression.Drawing;
|
||||
|
||||
namespace HandyControl.Tools.Extension
|
||||
{
|
||||
public static class GeometryExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取路径总长度
|
||||
/// </summary>
|
||||
/// <param name="geometry"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetTotalLength(this Geometry geometry)
|
||||
{
|
||||
if (geometry == null) return 0;
|
||||
|
||||
var pathGeometry = PathGeometry.CreateFromGeometry(geometry);
|
||||
pathGeometry.GetPointAtFractionLength(1e-4, out var point, out _);
|
||||
var length = (pathGeometry.Figures[0].StartPoint - point).Length * 1e+4;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取路径总长度
|
||||
/// </summary>
|
||||
/// <param name="geometry"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <param name="strokeThickness"></param>
|
||||
/// <returns></returns>
|
||||
public static double GetTotalLength(this Geometry geometry, Size size, double strokeThickness = 1)
|
||||
{
|
||||
if (geometry == null) return 0;
|
||||
|
||||
if (MathHelper.IsVerySmall(size.Width) || MathHelper.IsVerySmall(size.Height)) return 0;
|
||||
|
||||
var length = GetTotalLength(geometry);
|
||||
var sw = geometry.Bounds.Width / size.Width;
|
||||
var sh = geometry.Bounds.Height / size.Height;
|
||||
var min = Math.Min(sw, sh);
|
||||
|
||||
if (MathHelper.IsVerySmall(min) || MathHelper.IsVerySmall(strokeThickness)) return 0;
|
||||
|
||||
length /= min;
|
||||
return length / strokeThickness;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user