using Yw.Ahart;
|
|
namespace Yw.WinFrmUI
|
{
|
public static class PhartPoint2dListExtensions
|
{
|
public static double? GetX(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, double x)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_curve = GetFeatCurve(pt_list, feat_type);
|
if (feat_curve == null || feat_curve.IsInvalid())
|
return default;
|
return feat_curve.GetPointsX(x)?.FirstOrDefault() ?? null;
|
}
|
|
public static double GetY(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, double x)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_curve = GetFeatCurve(pt_list, feat_type);
|
if (feat_curve == null || feat_curve.IsInvalid())
|
return default;
|
return feat_curve.GetPointYUnlimited(x);
|
}
|
|
public static List<double> GetYList(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, int pt_count = 30)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_pt_list = GetPointList(pt_list, feat_type, pt_count);
|
if (feat_pt_list == null || !feat_pt_list.Any())
|
return default;
|
return feat_pt_list.Select(x => x.Y).ToList();
|
}
|
|
public static List<Yw.Geometry.Point2d> GetPointList(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, int pt_count = 30)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_curve = GetFeatCurve(pt_list, feat_type);
|
if (feat_curve == null || feat_curve.IsInvalid())
|
return default;
|
var feat_pt_list = feat_curve.GetPointList(pt_count);
|
return feat_pt_list;
|
}
|
|
public static List<Yw.Geometry.Point2d> GetExpandPointList(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type, double minXRatio = 0.9, double maxXRatio = 1.2, int pt_count = 30)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_curve = GetFeatCurve(pt_list, feat_type);
|
if (feat_curve == null || feat_curve.IsInvalid())
|
return default;
|
var feat_pt_list = feat_curve.GetPointListByXRatioRange(minXRatio, maxXRatio, pt_count);
|
return feat_pt_list;
|
}
|
|
public static IFeatCurve GetFeatCurve(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eFeatType feat_type)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
Yw.Ahart.IFeatCurve feat_curve = null;
|
switch (feat_type)
|
{
|
case Ahart.eFeatType.Polynomial: feat_curve = new Yw.Ahart.PolynomialCurve(pt_list); break;
|
case Ahart.eFeatType.Cubic: feat_curve = new Yw.Ahart.CubicCurve(pt_list); break;
|
case Ahart.eFeatType.Through: feat_curve = new Yw.Ahart.ThroughCurve(pt_list); break;
|
case Ahart.eFeatType.Quadratic: feat_curve = new Yw.Ahart.QuadraticCurve(pt_list); break;
|
case Ahart.eFeatType.Quartic: feat_curve = new Yw.Ahart.QuarticCurve(pt_list); break;
|
default: break;
|
}
|
|
return feat_curve;
|
}
|
|
public static Yw.Ahart.PerformCurveBase GetPerformCurve(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eCurveType curve_type, Yw.Ahart.eFeatType feat_type)
|
{
|
if (pt_list == null || !pt_list.Any())
|
return default;
|
var feat_curve = GetFeatCurve(pt_list, feat_type);
|
if (feat_curve == null || feat_curve.IsInvalid())
|
return default;
|
switch (curve_type)
|
{
|
case eCurveType.QH:
|
return new Yw.Ahart.CurveQH(feat_type, feat_curve);
|
case eCurveType.QP:
|
return new Yw.Ahart.CurveQP(feat_type, feat_curve);
|
case eCurveType.QE:
|
return new Yw.Ahart.CurveQE(feat_type, feat_curve);
|
case eCurveType.QNPSH:
|
return null;
|
case eCurveType.EqualE:
|
return new Yw.Ahart.CurveEqualE(feat_type, feat_curve);
|
case eCurveType.EqualP:
|
return new Yw.Ahart.CurveEqualP(feat_type, feat_curve);
|
case eCurveType.QL:
|
return new Yw.Ahart.CurveQL(feat_type, feat_curve);
|
case eCurveType.OL:
|
return new Yw.Ahart.CurveOL(feat_type, feat_curve);
|
case eCurveType.VOL:
|
return new Yw.Ahart.CurveVOL(feat_type, feat_curve);
|
default:
|
throw new Exception("曲线类型异常!");
|
}
|
|
}
|
|
|
|
/// <summary>
|
/// 计算总长度
|
/// </summary>
|
public static double TotalLength(this IEnumerable<Yw.Geometry.Point2d> pt_list)
|
{
|
if (pt_list == null || pt_list.Count() < 2)
|
return default;
|
var list = pt_list.ToList();
|
double length = 0;
|
for (int i = 1; i < list.Count(); i++)
|
{
|
double len = Math.Sqrt((list[i].X - list[i - 1].X) * (list[i].X - list[i - 1].X) + (list[i].Y - list[i - 1].Y) * (list[i].Y - list[i - 1].Y));
|
length += len;
|
}
|
return length;
|
}
|
|
/// <summary>
|
/// 根据周长度计算点位置,返回空表示超过总长
|
/// </summary>
|
/// <param name="length"></param>
|
/// <returns></returns>
|
public static Yw.Geometry.Point2d GetPosiByLength(this List<Yw.Geometry.Point2d> pt_list, double length_from_start)
|
{
|
if (pt_list == null)
|
return null;
|
if (length_from_start < 0.0001)
|
return pt_list.FirstOrDefault();
|
double length = 0;
|
for (int i = 1; i < pt_list.Count; i++)
|
{
|
double len_line = Math.Sqrt((pt_list[i].X - pt_list[i - 1].X) * (pt_list[i].X - pt_list[i - 1].X) + (pt_list[i].Y - pt_list[i - 1].Y) * (pt_list[i].Y - pt_list[i - 1].Y));
|
length += len_line;
|
if (length >= length_from_start)
|
{
|
Yw.Geometry.Point2d extPt = new Yw.Geometry.Point2d();
|
extPt.X = (pt_list[i - 1].X - pt_list[i].X) * (length - length_from_start) / len_line + pt_list[i].X;
|
extPt.Y = (pt_list[i - 1].Y - pt_list[i].Y) * (length - length_from_start) / len_line + pt_list[i].Y;
|
return extPt;
|
}
|
}
|
if (length >= length_from_start * 0.9999)
|
{
|
return pt_list.LastOrDefault();
|
}
|
return null;
|
}
|
|
/// <summary>
|
/// 获取Y最小的点的序号
|
/// </summary>
|
/// <returns></returns>
|
public static int GetPointIndexOfMinY(this List<Yw.Geometry.Point2d> pt_list)
|
{
|
if (pt_list == null)
|
return 0;
|
if (pt_list.Count == 0)
|
return 0;
|
if (pt_list.Count == 1)
|
return 0;
|
var minY = (from x in pt_list select x.Y).Min();
|
var pt = (from x in pt_list where x.Y == minY select x).FirstOrDefault();
|
if (pt == null)
|
return 0;
|
else
|
return pt_list.IndexOf(pt);
|
}
|
|
public static string ToDbString(this List<Yw.Geometry.Point2d> pt_list, Yw.Ahart.eCurveType curve_type, Yw.Ahart.eFeatType feat_type)
|
{
|
return PhartGraphHelper.ToDbString(curve_type, feat_type, pt_list);
|
}
|
|
}
|
|
|
|
}
|