This commit is contained in:
2026-05-29 01:33:38 +07:00
parent ca673c737d
commit 7ebbeb7855
6 changed files with 3724 additions and 1635 deletions

View File

@@ -48,268 +48,284 @@ public static partial class Extensions
mimic.Size = count;
}
internal static U Protect<U>(this U? metric) where U : class, IMetric<U>, new() => metric ?? new();
internal static C Protect<C, U>(this C? collection)
where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new() => collection ?? new();
public static C MetricSelect<C, U>(this C? collection, Func<U, U>? selector)
where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static double QuickPow(this double baseValue, int exp)
{
var source = (collection ??= new());
var nColl = (C)source.CreateByInstanceU(source.Count);
if (selector is not null)
switch (exp)
{
for (int i = 0; i < nColl.Count; i++)
nColl[i] = selector(source[i]);
return nColl;
case 0: return 1.0;
case 1: return baseValue;
case 2: return baseValue * baseValue;
case 3: return baseValue * baseValue * baseValue;
case 4: { double x2 = baseValue * baseValue; return x2 * x2; }
case -1: return 1.0 / baseValue;
case -2: return 1.0 / (baseValue * baseValue);
default: return Math.Pow(baseValue, exp);
}
return new();
}
public static IEnumerable<double> MetricSelect<U>(this IMetricCollection<U> collection, Func<U, double> selector)
where U : class, IMetric<U>, new()
{
if (collection is not null)
{
if (selector is not null)
return collection.Select(selector);
return collection.Select(u => double.NaN);
}
else return [];
}
public static IMetricCollection<Uz> MetricSelect<Ux, Uz>(this IMetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
{
if (collection is not null && selector is not null)
{
var destCollection = collection.CreateByInstance<Uz>(collection.Count);
for (int i = 0; i < collection.Count; i++)
destCollection[i] = selector(collection[i]);
return destCollection;
}
return null!;
}
public static MetricCollection<Uz> MetricSelect<Ux, Uz>(this MetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
{
if (collection is not null && selector is not null)
{
var destCollection = collection.CreateByInstance<Uz>(collection.Count());
for (int i = 0; i < collection.Count(); i++)
destCollection[i] = selector(collection[i]);
return destCollection;
}
return null!;
}
public static MetricArray<Uz> MetricSelect<Ux, Uz>(this MetricArray<Ux>? collection, Func<Ux, Uz>? selector)
where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
{
var coll = collection?.ToArray();
if (coll is not null && selector is not null)
{
var destCollection = new MetricArray<Uz>(coll.Length);
for (int i = 0; i < coll.Length; i++)
destCollection[i] = selector(coll[i]);
return destCollection;
}
return null!;
}
public static MetricList<Uz> MetricSelect<Ux, Uz>(this MetricList<Ux>? collection, Func<Ux, Uz>? selector)
where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
{
if (collection is not null && selector is not null)
{
var destCollection = new MetricList<Uz>(collection.Count);
for (int i = 0; i < collection.Count; i++)
destCollection[i] = selector(collection[i]);
return destCollection;
}
return null!;
}
public static MetricObservableCollection<Uz> MetricSelect<Ux, Uz>(this MetricObservableCollection<Ux>? collection, Func<Ux, Uz>? selector)
where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
{
if (collection is not null && selector is not null)
{
var destCollection = new MetricObservableCollection<Uz>(collection.Count);
for (int i = 0; i < collection.Count; i++)
destCollection[i] = selector(collection[i]);
return destCollection;
}
return null!;
}
public static double[] MetricSelect<U>(this MetricArray<U> collection, Func<U, double> selector)
where U : class, IMetric<U>, new()
{
var coll = collection ?? [];
var arr = new double[coll.Length];
if (selector is not null)
for (int i = 0; i < arr.Length; i++)
arr[i] = selector(coll[i]);
return arr;
}
public static List<double> MetricSelect<U>(this MetricList<U> collection, Func<U, double> selector)
where U : class, IMetric<U>, new()
{
var coll = collection ?? [];
var list = new List<double>(coll.Count);
if (selector is not null)
for (int i = 0; i < list.Count; i++)
list[i] = selector(coll[i]);
return list;
}
public static ObservableCollection<double> MetricSelect<U>(this MetricObservableCollection<U> collection, Func<U, double> selector)
where U : class, IMetric<U>, new()
{
var coll = collection ?? [];
var list = new List<double>(coll.Count);
if (selector is not null)
for (int i = 0; i < list.Count; i++)
list[i] = selector(coll[i]);
return new(list);
}
internal static C ForEachC<C, U>(this C? collection, Func<U, U>? Set)
where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
{
var nColl = (C)(collection ??= new()).CreateByInstanceU(collection.Count);
if (Set is not null)
for (int i = 0; i < nColl.Count; i++)
nColl[i] = Set(nColl[i]);
return nColl;
}
internal static double ProtectValue(this IMetric? metric) => metric is null ? 0d : metric.Value;
public static U Min<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() < T2.ProtectValue() ? T1 : T2).Protect();
public static U Min<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Min((units ?? []).MaxBy(u => u.ProtectValue()));
public static U Max<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() > T2.ProtectValue() ? T1 : T2).Protect();
public static U Max<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Max((units ?? []).MaxBy(u => u.ProtectValue()));
//internal static double ToDouble(this double number) => number;
//internal static double ToDouble(this double? number) => number ?? 0d;
//internal static double ToDouble<N>(this N number) where N : INumber<N> => Convert.ToDouble(number);
//internal static double ToDouble<N>(this N? number) where N : struct, INumber<N> => number is not null ? Convert.ToDouble(number) : 0d;
internal static IEnumerable<U> MetricSelect<U>(this double[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
internal static IEnumerable<U> MetricSelect<U>(this double?[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
internal static IEnumerable<U> MetricSelect<U, N>(this N[] nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
internal static IEnumerable<U> MetricSelect<U, N>(this N?[] nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double?> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N> nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N?> nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
public static U Clone<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = metric.ProtectValue() };
public static U Abs<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = Math.Abs(metric.ProtectValue()) };
/// <summary>C^2 = A^2 + B^2</summary>
/// <returns>C = (A^2 + B^2).Sqrt(2)</returns>
public static U Hypotenuse<U>(this U? A, U? B) where U : class, IMetric<U>, new()
{
var a = A.ProtectValue();
var b = B.ProtectValue();
return new U() { Value = Math.Sqrt(a * a + b * b) };
}
/// <summary>C^2 = A^2 + B^2</summary>
/// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
public static U KatetFromHyp<U>(this U? A, U? C) where U : class, IMetric<U>, new()
{
var a = A.ProtectValue();
var c = C.ProtectValue();
return new U() { Value = Math.Sqrt(c * c - a * a) };
}
/// <summary>C^2 = A^2 + B^2</summary>
/// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
public static U KatetFromKatet<U>(this U? C, U? A) where U : class, IMetric<U>, new()
{
var a = A.ProtectValue();
var c = C.ProtectValue();
return new U() { Value = Math.Sqrt(c * c - a * a) };
}
public static Area Pow(this Length? metric, double? val = 2) => new() { Value = Math.Pow(metric.ProtectValue(), val ?? 2) };
public static Length Sqrt(this Area? metric) => new() { Value = Math.Sqrt(metric.ProtectValue()) };
//internal static U Protect<U>(this U? metric) where U : class, IMetric<U>, new() => metric ?? new();
//internal static C Protect<C, U>(this C? collection)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new() => collection ?? new();
public static U MetricSum<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Where(t => t is not null).Sum(m => m.ProtectValue()) ?? 0d };
public static U MetricAverage<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Average(m => m.ProtectValue()) ?? double.NaN };
public static U MetricMax<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Max(m => m.ProtectValue()) };
public static U MetricMin<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Min(m => m.ProtectValue()) };
//public static C MetricSelect<C, U>(this C? collection, Func<U, U>? selector)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var source = (collection ??= new());
// var nColl = (C)source.CreateByInstanceU(source.Count);
// if (selector is not null)
// {
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = selector(source[i]);
// return nColl;
// }
// return new();
//}
//public static IEnumerable<double> MetricSelect<U>(this IMetricCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// if (collection is not null)
// {
// if (selector is not null)
// return collection.Select(selector);
// return collection.Select(u => double.NaN);
// }
// else return [];
//}
public static C MetricSum<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
{
var cArr = collections.ToArray();
C accumulator = (C)cArr.FirstOrDefault(new C());
for (int i = 1; i < cArr.Length; i++)
accumulator = accumulator.FuncByPairOrOneToMany(cArr[i], (a, b) => a + b, out C _);
return accumulator;
}
public static C MetricAverage<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
=> collections.MetricSum() / collections.Count();
//public static IMetricCollection<Uz> MetricSelect<Ux, Uz>(this IMetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricCollection<Uz> MetricSelect<Ux, Uz>(this MetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count());
// for (int i = 0; i < collection.Count(); i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricArray<Uz> MetricSelect<Ux, Uz>(this MetricArray<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// var coll = collection?.ToArray();
// if (coll is not null && selector is not null)
// {
// var destCollection = new MetricArray<Uz>(coll.Length);
// for (int i = 0; i < coll.Length; i++)
// destCollection[i] = selector(coll[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricList<Uz> MetricSelect<Ux, Uz>(this MetricList<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricList<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricObservableCollection<Uz> MetricSelect<Ux, Uz>(this MetricObservableCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricObservableCollection<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static double[] MetricSelect<U>(this MetricArray<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var arr = new double[coll.Length];
// if (selector is not null)
// for (int i = 0; i < arr.Length; i++)
// arr[i] = selector(coll[i]);
// return arr;
//}
//public static List<double> MetricSelect<U>(this MetricList<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return list;
//}
//public static ObservableCollection<double> MetricSelect<U>(this MetricObservableCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return new(list);
//}
//internal static C ForEachC<C, U>(this C? collection, Func<U, U>? Set)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var nColl = (C)(collection ??= new()).CreateByInstanceU(collection.Count);
// if (Set is not null)
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = Set(nColl[i]);
// return nColl;
//}
//internal static double ProtectValue(this IMetric? metric) => metric is null ? 0d : metric.Value;
//public static U Min<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() < T2.ProtectValue() ? T1 : T2).Protect();
//public static U Min<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Min((units ?? []).MaxBy(u => u.ProtectValue()));
//public static U Max<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() > T2.ProtectValue() ? T1 : T2).Protect();
//public static U Max<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Max((units ?? []).MaxBy(u => u.ProtectValue()));
////internal static double ToDouble(this double number) => number;
////internal static double ToDouble(this double? number) => number ?? 0d;
////internal static double ToDouble<N>(this N number) where N : INumber<N> => Convert.ToDouble(number);
////internal static double ToDouble<N>(this N? number) where N : struct, INumber<N> => number is not null ? Convert.ToDouble(number) : 0d;
//internal static IEnumerable<U> MetricSelect<U>(this double[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this double?[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N[] nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N?[] nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double?> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N> nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N?> nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
public static U MetricSumBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
where U : class, IMetric<U>, new()
{
if (source is null) return new();
if (selector is null) throw new ArgumentNullException("selector is null");
return new() { Value = source.Select(selector).Where(t => t is not null).Sum(t => t.ProtectValue()) };
}
public static U MetricAverageBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
where U : class, IMetric<U>, new()
{
if (source is null) return new();
if (selector is null) throw new ArgumentNullException("selector is null");
//public static U Clone<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = metric.ProtectValue() };
//public static U Abs<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = Math.Abs(metric.ProtectValue()) };
return new() { Value = source.Select(selector).Average(t => t.ProtectValue()) };
}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>C = (A^2 + B^2).Sqrt(2)</returns>
//public static U Hypotenuse<U>(this U? A, U? B) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var b = B.ProtectValue();
// return new U() { Value = Math.Sqrt(a * a + b * b) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromHyp<U>(this U? A, U? C) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var c = C.ProtectValue();
// return new U() { Value = Math.Sqrt(c * c - a * a) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromKatet<U>(this U? C, U? A) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var c = C.ProtectValue();
// return new U() { Value = Math.Sqrt(c * c - a * a) };
//}
//public static Area Pow(this Length? metric, double? val = 2) => new() { Value = Math.Pow(metric.ProtectValue(), val ?? 2) };
//public static Length Sqrt(this Area? metric) => new() { Value = Math.Sqrt(metric.ProtectValue()) };
public static C MetricSumBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
{
if (source is null) return new();
if (selector is null) throw new ArgumentNullException("selector is null");
return source.Select(selector).MetricSum();
}
public static C MetricAverageBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
{
if (source is null) return new();
if (selector is null) throw new ArgumentNullException("selector is null");
return source.Select(selector).MetricAverage();
}
//public static U MetricSum<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Where(t => t is not null).Sum(m => m.ProtectValue()) ?? 0d };
//public static U MetricAverage<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Average(m => m.ProtectValue()) ?? double.NaN };
//public static U MetricMax<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Max(m => m.ProtectValue()) };
//public static U MetricMin<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Min(m => m.ProtectValue()) };
public static MetricArray<U> ToMetricArray<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
public static MetricList<U> ToMetricList<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
//public static C MetricSum<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// var cArr = collections.ToArray();
// C accumulator = (C)cArr.FirstOrDefault(new C());
// for (int i = 1; i < cArr.Length; i++)
// accumulator = accumulator.FuncByPairOrOneToMany(cArr[i], (a, b) => a + b, out C _);
// return accumulator;
//}
//public static C MetricAverage<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
// => collections.MetricSum() / collections.Count();
//public static U MetricSumBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { Value = source.Select(selector).Where(t => t is not null).Sum(t => t.ProtectValue()) };
//}
//public static U MetricAverageBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { Value = source.Select(selector).Average(t => t.ProtectValue()) };
//}
//public static C MetricSumBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricSum();
//}
//public static C MetricAverageBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricAverage();
//}
//public static MetricArray<U> ToMetricArray<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
//public static MetricList<U> ToMetricList<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
//namespace QWERTYkez.Mensura.Units;
///// <summary>
///// Base value is MilliMeters
///// </summary>
//[UnitOperatorsGenerator, DebuggerDisplay("mm = {_MilliMeters.ToString(\"0.###\")}, m = {Meters.ToString(\"0.###\")}")]
//public readonly partial record struct XXXXXXXXXXXXXX
//{
// public static XXXXXXXXXXXXXX MilliMeter { get; } = new(1);
//#pragma warning disable IDE1006 // _Подчеркивание для обозначения того, что это базовая единица
// [NotMapped, JsonIgnore] public double _MilliMeters { get => _Value; init => _Value = value; }
//#pragma warning restore IDE1006
// public static XXXXXXXXXXXXXX CentiMeter { get; } = new(XXXXXXXXXXXXXXConv.CentiMeters.To(1));
// [NotMapped, JsonIgnore] public double CentiMeters
// {
// get => XXXXXXXXXXXXXXConv.CentiMeters.From(_Value);
// init
// {
// XXXXXXXXXXXXXX aaa = new();
// XXXXXXXXXXXXXX bbb = new();
// if (aaa != bbb || aaa == bbb)
// {
// }
// _Value = XXXXXXXXXXXXXXConv.CentiMeters.To(value);
// }
// }
// public static XXXXXXXXXXXXXX DeciMeter { get; } = new(XXXXXXXXXXXXXXConv.DeciMeters.To(1));
// [NotMapped, JsonIgnore] public double DeciMeters
// {
// get => XXXXXXXXXXXXXXConv.DeciMeters.From(_Value);
// init => _Value = XXXXXXXXXXXXXXConv.DeciMeters.To(value);
// }
// public static XXXXXXXXXXXXXX Meter { get; } = new(XXXXXXXXXXXXXXConv.Meters.To(1));
// [NotMapped, JsonIgnore] public double Meters
// {
// get => XXXXXXXXXXXXXXConv.Meters.From(_Value);
// init => _Value = XXXXXXXXXXXXXXConv.Meters.To(value);
// }
// public static XXXXXXXXXXXXXX KiloMeter { get; } = new(XXXXXXXXXXXXXXConv.KiloMeters.To(1));
// [NotMapped, JsonIgnore] public double KiloMeters
// {
// get => XXXXXXXXXXXXXXConv.KiloMeters.From(_Value);
// init => _Value = XXXXXXXXXXXXXXConv.KiloMeters.To(value);
// }
// public XXXXXXXXXXXXXX AddMilliMeters(double value) => new(_Value + value);
// public XXXXXXXXXXXXXX AddCentiMeters(double value) => new(_Value + XXXXXXXXXXXXXXConv.CentiMeters.To(value));
// public XXXXXXXXXXXXXX AddDeciMeters(double value) => new(_Value + XXXXXXXXXXXXXXConv.DeciMeters.To(value));
// public XXXXXXXXXXXXXX AddMeters(double value) => new(_Value + XXXXXXXXXXXXXXConv.Meters.To(value));
// public XXXXXXXXXXXXXX AddKiloMeters(double value) => new(_Value + XXXXXXXXXXXXXXConv.KiloMeters.To(value));
//}
//internal readonly struct XXXXXXXXXXXXXXConv
//{
// private XXXXXXXXXXXXXXConv(double multiplicator) => this.Multiplicator = multiplicator;
// public double To(double value) => value * Multiplicator;
// public double From(double value) => value / Multiplicator;
// public double Multiplicator { get; init; }
// public static XXXXXXXXXXXXXXConv MilliMeters { get; } = new(1);
// public static XXXXXXXXXXXXXXConv CentiMeters { get; } = new(10);
// public static XXXXXXXXXXXXXXConv DeciMeters { get; } = new(100);
// public static XXXXXXXXXXXXXXConv Meters { get; } = new(1000);
// public static XXXXXXXXXXXXXXConv KiloMeters { get; } = new(1000000);
//}

View File

@@ -9,4 +9,5 @@ global using System.Numerics;
global using System.Runtime.CompilerServices;
global using System.Runtime.InteropServices;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Text.Json.Serialization;
global using QWERTYkez.Mensura;