pogon...
This commit is contained in:
@@ -16,7 +16,7 @@ internal class CollectionsOperatorsGenerator : IIncrementalGenerator
|
||||
|
||||
private const string AttributeSource = @"namespace QWERTYkez.Mensura;
|
||||
|
||||
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
[System.AttributeUsage(System.AttributeTargets.Struct | System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
internal sealed class CollectionsOperatorsGeneratorAttribute : System.Attribute { }";
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
|
||||
@@ -91,16 +91,21 @@ namespace QWERTYkez.Mensura
|
||||
// Вы должны скопировать сюда всё содержимое вашего второго файла,
|
||||
// заменив XXXXXXXXXXXXXX на {typeName}.
|
||||
string skeleton = @"
|
||||
global using {typeName} = QWERTYkez.Mensura.Units.{typeName};
|
||||
global using {typeName}Extensions = QWERTYkez.Mensura.Units.{typeName}Extensions;
|
||||
global using {typeName}Converter = QWERTYkez.Mensura.Units.{typeName}Converter;
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
[JsonConverter(typeof({typeName}Converter))]
|
||||
public readonly partial record struct {typeName}
|
||||
public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEquatable<{typeName}>, IMensuraUnit
|
||||
{
|
||||
[JsonInclude, DataMember, JsonPropertyName(""v"")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||
internal double Value { get => _Value; init => _Value = value; }
|
||||
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
|
||||
internal readonly double _Value;
|
||||
internal {typeName}(double value) => _Value = value;
|
||||
|
||||
@@ -113,8 +118,13 @@ public readonly partial record struct {typeName}
|
||||
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNegative => _Value < 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsZero => _Value == 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNaN => double.IsNaN(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsFinite => double.IsFinite(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsInfinity => double.IsInfinity(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsPositiveInfinity => double.IsPositiveInfinity(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNegativeInfinity => double.IsNegativeInfinity(_Value);
|
||||
|
||||
|
||||
public static {typeName} Zero { get; } = new(0d);
|
||||
@@ -298,7 +308,7 @@ public readonly partial record struct {typeName}
|
||||
}
|
||||
}
|
||||
|
||||
public static class {typeName}Extension
|
||||
public static class {typeName}Extensions
|
||||
{
|
||||
internal static double ToDouble(this {typeName}? unit) => unit is null ? 0d : unit.Value._Value;
|
||||
|
||||
|
||||
@@ -49,18 +49,18 @@ public static partial class Extensions
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static double QuickPow(this double baseValue, int exp)
|
||||
internal static double QuickPow(this double base_Value, int exp)
|
||||
{
|
||||
switch (exp)
|
||||
{
|
||||
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);
|
||||
case 1: return base_Value;
|
||||
case 2: return base_Value * base_Value;
|
||||
case 3: return base_Value * base_Value * base_Value;
|
||||
case 4: { double x2 = base_Value * base_Value; return x2 * x2; }
|
||||
case -1: return 1.0 / base_Value;
|
||||
case -2: return 1.0 / (base_Value * base_Value);
|
||||
default: return Math.Pow(base_Value, exp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,261 +71,267 @@ public static partial class Extensions
|
||||
|
||||
|
||||
|
||||
//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()
|
||||
//{
|
||||
// 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 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 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();
|
||||
|
||||
|
||||
////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 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 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()) };
|
||||
//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 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 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 Protect_Value(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.Protect_Value() < T2.Protect_Value() ? 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.Protect_Value()));
|
||||
|
||||
//public static U Max<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.Protect_Value() > T2.Protect_Value() ? 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.Protect_Value()));
|
||||
|
||||
|
||||
////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 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 Clone<U>(this U? metric) where U : class, IMetric<U>, new() => new() { _Value = metric.Protect_Value() };
|
||||
//public static U Abs<U>(this U? metric) where U : class, IMetric<U>, new() => new() { _Value = Math.Abs(metric.Protect_Value()) };
|
||||
|
||||
///// <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.Protect_Value();
|
||||
// var b = B.Protect_Value();
|
||||
// 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.Protect_Value();
|
||||
// var c = C.Protect_Value();
|
||||
// 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.Protect_Value();
|
||||
// var c = C.Protect_Value();
|
||||
// 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.Protect_Value(), val ?? 2) };
|
||||
//public static Length Sqrt(this Area? metric) => new() { _Value = Math.Sqrt(metric.Protect_Value()) };
|
||||
|
||||
|
||||
//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.Protect_Value()) ?? 0d };
|
||||
//public static U MetricAverage<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args?.Average(m => m.Protect_Value()) ?? double.NaN };
|
||||
//public static U MetricMax<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args.Max(m => m.Protect_Value()) };
|
||||
//public static U MetricMin<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args.Min(m => m.Protect_Value()) };
|
||||
|
||||
|
||||
|
||||
//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 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 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 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.Protect_Value()) };
|
||||
//}
|
||||
//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.Protect_Value()) };
|
||||
//}
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
8
QWERTYkez.Mensura/IMensuraUnit.cs
Normal file
8
QWERTYkez.Mensura/IMensuraUnit.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace QWERTYkez.Mensura;
|
||||
|
||||
public interface IMensuraUnit
|
||||
{
|
||||
internal double Value { get; init; }
|
||||
}
|
||||
|
||||
public interface IMensuraUnit<U> where U : struct, IMensuraUnit, IEquatable<U> { }
|
||||
231
QWERTYkez.Mensura/Operators.cs
Normal file
231
QWERTYkez.Mensura/Operators.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
internal static class OperationsExtension
|
||||
{
|
||||
internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> new() { Value = t1.Value * t2.Value };
|
||||
|
||||
internal static TResult MultiplyProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> new() { Value = t1.Value * t2.Value * multiplicator };
|
||||
|
||||
internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> new() { Value = t1.Value / t2.Value };
|
||||
|
||||
internal static TResult DivideProtected<T1, T2, TResult>(this T1 t1, T2 t2, double multiplicator)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> new() { Value = t1.Value * multiplicator / t2.Value };
|
||||
}
|
||||
|
||||
internal static class Coefficients
|
||||
{
|
||||
internal static double MultiplyCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> r.Value / (a.Value * b.Value);
|
||||
|
||||
internal static double DivideCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
|
||||
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
||||
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
||||
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
||||
=> r.Value * b.Value / a.Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Length
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Area operator *(Length left, Length right)
|
||||
=> left.MultiplyProtected<Length, Length, Area>(right, Coeff1);
|
||||
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MilliMeter, MilliMeter, Area.MilliMeterSquared);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Volume operator *(Area left, Length right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Volume operator *(Length left, Area right)
|
||||
=> left.MultiplyProtected<Length, Area, Volume>(right, Coeff2);
|
||||
|
||||
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(MilliMeter, Area.MilliMeterSquared, Volume.MilliMeterCubic);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator *(Length left, UdelForce right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator *(UdelForce left, Length right) => left.MultiplyProtected<UdelForce, Length, Pressure>(right, Coeff3);
|
||||
static readonly double Coeff3 = Coefficients.MultiplyCoefficient(a => a.PerMeterCubic.Newtons = 1, Length.Meter, Pressure.NewtonPerMeterSquared);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(PogonForce left, Length right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(Length left, PogonForce right) => left.MultiplyProtected<Length, PogonForce, Force>(right, Coeff4);
|
||||
static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.Meter, b => b.PerMeter.Newtons = 1, Force.Newton);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(Force left, Length right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(Length left, Force right) => left.MultiplyProtected<Length, Force, Torque>(right, Coeff6);
|
||||
static readonly double Coeff6 = Coefficients.MultiplyCoefficient(Length.Meter, Force.Newton, Torque.Newton_Meter);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Mass // Grams
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Pressure // Pascals
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Length operator /(Pressure left, UdelForce right) => left.DivideProtected<Pressure, UdelForce, Length>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.DivideCoefficient(Pressure.Pascal, b => b.PerMeterCubic.Newtons = 1, Length.Meter);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(Pressure left, Area right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(Area left, Pressure right) => left.MultiplyProtected<Area, Pressure, Force>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure.Pascal, Force.Newton);
|
||||
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Length operator /(PogonForce left, Pressure right) => left.DivideProtected<PogonForce, Pressure, Length>(right, Coeff3);
|
||||
static readonly double Coeff3 = Coefficients.DivideCoefficient(a => a._PerMilliMeter.Newtons = 1, Pressure.NewtonPerMilliMeterSquared, Length.MilliMeter);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(Pressure left, Length right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(Length left, Pressure right) => left.MultiplyProtected<Length, Pressure, PogonForce>(right, Coeff4);
|
||||
static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length.MilliMeter, Pressure.NewtonPerMilliMeterSquared, r => r._PerMilliMeter.Newtons = 1);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Area // MilliMetersSquared
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(PogonForce left, Area right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(Area left, PogonForce right) => left.MultiplyProtected<Area, PogonForce, Torque>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, b => b.PerMeter.Newtons = 1, Torque.Newton_Meter);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Length operator /(Area left, Length right) => left.DivideProtected<Area, Length, Length>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.DivideCoefficient(Area.MilliMeterSquared, Length.MilliMeter, Length.MilliMeter);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Volume // MillimetersCubic
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Mass operator *(Density left, Volume right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Mass operator *(Volume left, Density right) => left.MultiplyProtected<Volume, Density, Mass>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Volume.MilliMeterCubic, b => b.PerMilliMeterCubic.Grams = 1, Time.Gram);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(Pressure left, Volume right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Torque operator *(Volume left, Pressure right) => left.MultiplyProtected<Volume, Pressure, Torque>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure.Pascal, Torque.Newton_Meter);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Area operator /(Volume left, Length right) => left.DivideProtected<Volume, Length, Area>(right);
|
||||
[CollectionsOperatorsGenerator] public static Length operator /(Volume left, Area right) => left.DivideProtected<Volume, Area, Length>(right, Coeff3);
|
||||
static readonly double Coeff3 = Coefficients.DivideCoefficient(Volume.MilliMeterCubic, Length.MilliMeter, Area.MilliMeterSquared);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Force // Newtons
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Area operator /(Force left, Pressure right) => left.DivideProtected<Force, Pressure, Area>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.DivideCoefficient(Force.Newton, Pressure.Pascal, Area.MeterSquared);
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator /(Force left, Area right) => left.DivideProtected<Force, Area, Pressure>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.DivideCoefficient(Force.Newton, Area.MeterSquared, Pressure.Pascal);
|
||||
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Torque // NewtonMeters
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Length operator /(Torque left, Force right) => left.DivideProtected<Torque, Force, Length>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Force.Newton, Length.Meter);
|
||||
[CollectionsOperatorsGenerator] public static Force operator /(Torque left, Length right) => left.DivideProtected<Torque, Length, Force>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Length.Meter, Force.Newton);
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator /(Torque left, Area right) => left.DivideProtected<Torque, Area, PogonForce>(right, Coeff3);
|
||||
static readonly double Coeff3 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Area.MilliMeterSquared, r => r.PerMilliMeter.KiloNewtons = 1);
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator /(Torque left, Volume right) => left.DivideProtected<Torque, Volume, Pressure>(right, Coeff4);
|
||||
static readonly double Coeff4 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Volume.MeterCubic, Pressure.Pascal);
|
||||
[CollectionsOperatorsGenerator] public static Volume operator /(Torque left, Pressure right) => left.DivideProtected<Torque, Pressure, Volume>(right, Coeff5);
|
||||
static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque.Newton_Meter, Pressure.Pascal, Volume.MeterCubic);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Frequency // Hertz
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Time
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Speed operator *(Boost left, Time right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Speed operator *(Time left, Boost right) => left.MultiplyProtected<Time, Boost, Speed>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost.MeterPerSecondSquared, Speed.MeterPerSecond);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Speed operator /(Length left, Time right) => left.DivideProtected<Length, Time, Speed>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Speed
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Length operator *(Speed left, Time right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Length operator *(Time left, Speed right) => left.MultiplyProtected<Time, Speed, Length>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Boost operator /(Speed left, Time right) => left.DivideProtected<Speed, Time, Boost>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost.MeterPerSecondSquared);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct Boost
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(Mass left, Boost right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Force operator *(Boost left, Mass right) => left.MultiplyProtected<Boost, Mass, Force>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, Time.KiloGram, Force.Newton);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(PogonMass left, Boost right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(Boost left, PogonMass right) => left.MultiplyProtected<Boost, PogonMass, PogonForce>(right, Coeff2);
|
||||
static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, b => b.PerMilliMeter.KiloGrams = 1, r => r.PerMilliMeter.Newtons = 1);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static UdelForce operator *(Density left, Boost right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static UdelForce operator *(Boost left, Density right) => left.MultiplyProtected<Boost, Density, UdelForce>(right, Coeff3);
|
||||
static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost.MeterPerSecondSquared, b => b.PerMilliMeterCubic.KiloGrams = 1, r => r.PerMilliMeterCubic.Newtons = 1);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static PogonMass operator /(PogonForce left, Boost right) => left.DivideProtected<PogonForce, Boost, PogonMass>(right, Coeff4);
|
||||
static readonly double Coeff4 = Coefficients.DivideCoefficient(a => a.PerMilliMeter.Newtons = 1, Boost.MeterPerSecondSquared, r => r.PerMilliMeter.KiloGrams = 1);
|
||||
|
||||
[CollectionsOperatorsGenerator] public static Density operator /(UdelForce left, Boost right) => left.DivideProtected<UdelForce, Boost, Density>(right, Coeff5);
|
||||
static readonly double Coeff5 = Coefficients.DivideCoefficient(a => a.PerMilliMeterCubic.Newtons = 1, Boost.MeterPerSecondSquared, r => r.PerMilliMeterCubic.KiloGrams = 1);
|
||||
|
||||
|
||||
[CollectionsOperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => left.DivideProtected<Pressure, Boost, MassPerSquare>(right, Coeff6);
|
||||
static readonly double Coeff6 = Coefficients.DivideCoefficient(Pressure.Pascal, Boost.MeterPerSecondSquared, MassPerSquare.KiloGramPerMeterSquared);
|
||||
}
|
||||
|
||||
[CollectionsOperatorsGenerator] public readonly partial record struct MassPerSquare
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator *(Boost left, MassPerSquare right) => right * left;
|
||||
[CollectionsOperatorsGenerator] public static Pressure operator *(MassPerSquare left, Boost right) => left.MultiplyProtected<MassPerSquare, Boost, Pressure>(right, Coeff1);
|
||||
static readonly double Coeff1 = Coefficients.MultiplyCoefficient(MassPerSquare.KiloGramPerMeterSquared, Boost.MeterPerSecondSquared, Pressure.Pascal);
|
||||
}
|
||||
|
||||
//[CollectionsOperatorsGenerator] public readonly partial record struct PogonForce : Pogon<PogonForce, Force>
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
|
||||
//[CollectionsOperatorsGenerator] public readonly partial record struct PogonMass : Pogon<PogonMass, Mass>
|
||||
//{
|
||||
// [CollectionsOperatorsGenerator] public static Boost operator /(PogonForce left, PogonMass right) => left.DivideProtected<PogonForce, PogonMass, Boost>(right, Coeff1);
|
||||
|
||||
// static readonly double Coeff1 = Coefficients.DivideCoefficient(a => a.PerMilliMeter.Newtons = 1, b => b.PerMilliMeter.KiloGrams = 1, Boost.MeterPerSecondSquared);
|
||||
//}
|
||||
|
||||
//[CollectionsOperatorsGenerator] public readonly partial record struct UdelForce : Udel<UdelForce, Force>
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
|
||||
//[CollectionsOperatorsGenerator] public readonly partial record struct Density : Udel<Density, Mass>
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
@@ -10,6 +10,46 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net10.0|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QWERTYkez.Mensura.Generator\QWERTYkez.Mensura.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
11
QWERTYkez.Mensura/Units/.Constants.cs
Normal file
11
QWERTYkez.Mensura/Units/.Constants.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
internal class Constants
|
||||
{
|
||||
/// <summary>
|
||||
/// Ускоре́ние свобо́дного паде́ния (ускорение силы тяжести) [м/с2]
|
||||
/// </summary>
|
||||
public const double g = 9.81;
|
||||
|
||||
public const double Pi = Math.PI;
|
||||
}
|
||||
126
QWERTYkez.Mensura/Units/Angle.cs
Normal file
126
QWERTYkez.Mensura/Units/Angle.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Seconds
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("Radians = {Radians.ToString(\"0.###\")}, Degrees = {Degrees.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Angle
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Seconds { get => Seconds; init => Seconds = value; }
|
||||
|
||||
public static Angle Second { get; } = new() { Seconds = 1 };
|
||||
[NotMapped, JsonIgnore] public double Seconds
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Angle Minute { get; } = new() { Minutes = 1 };
|
||||
[NotMapped, JsonIgnore] public double Minutes
|
||||
{
|
||||
get => AngleConv.Minutes.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AngleConv.Minutes.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Angle Degree { get; } = new() { Degrees = 1 };
|
||||
[NotMapped, JsonIgnore] public double Degrees
|
||||
{
|
||||
get => AngleConv.Degrees.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AngleConv.Degrees.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Angle Radian { get; } = new() { Radians = 1 };
|
||||
[NotMapped, JsonIgnore] public double Radians
|
||||
{
|
||||
get => AngleConv.Radians.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AngleConv.Radians.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Angle AddSeconds(double value) => new(_Value + value);
|
||||
public Angle AddMinutes(double value) => new(_Value + AngleConv.Minutes.To(value));
|
||||
public Angle AddGrads(double value) => new(_Value + AngleConv.Grads.To(value));
|
||||
public Angle AddDegrees(double value) => new(_Value + AngleConv.Degrees.To(value));
|
||||
public Angle AddRadians(double value) => new(_Value + AngleConv.Radians.To(value));
|
||||
|
||||
|
||||
public static Angle Degs___0 { get; } = new() { Degrees = 0 };
|
||||
public static Angle Degs__15 { get; } = new() { Degrees = 15 };
|
||||
public static Angle Degs__30 { get; } = new() { Degrees = 30 };
|
||||
public static Angle Degs__45 { get; } = new() { Degrees = 45 };
|
||||
public static Angle Degs__60 { get; } = new() { Degrees = 60 };
|
||||
public static Angle Degs__75 { get; } = new() { Degrees = 75 };
|
||||
public static Angle Degs__90 { get; } = new() { Degrees = 90 };
|
||||
public static Angle Degs_105 { get; } = new() { Degrees = 105 };
|
||||
public static Angle Degs_120 { get; } = new() { Degrees = 120 };
|
||||
public static Angle Degs_135 { get; } = new() { Degrees = 135 };
|
||||
public static Angle Degs_150 { get; } = new() { Degrees = 150 };
|
||||
public static Angle Degs_165 { get; } = new() { Degrees = 165 };
|
||||
public static Angle Degs_180 { get; } = new() { Degrees = 180 };
|
||||
public static Angle Degs_195 { get; } = new() { Degrees = 195 };
|
||||
public static Angle Degs_210 { get; } = new() { Degrees = 210 };
|
||||
public static Angle Degs_225 { get; } = new() { Degrees = 225 };
|
||||
public static Angle Degs_240 { get; } = new() { Degrees = 240 };
|
||||
public static Angle Degs_255 { get; } = new() { Degrees = 255 };
|
||||
public static Angle Degs_270 { get; } = new() { Degrees = 270 };
|
||||
public static Angle Degs_285 { get; } = new() { Degrees = 285 };
|
||||
public static Angle Degs_300 { get; } = new() { Degrees = 300 };
|
||||
public static Angle Degs_315 { get; } = new() { Degrees = 315 };
|
||||
public static Angle Degs_330 { get; } = new() { Degrees = 330 };
|
||||
public static Angle Degs_345 { get; } = new() { Degrees = 345 };
|
||||
public static Angle Degs_360 { get; } = new() { Degrees = 360 };
|
||||
|
||||
public static Angle Pi { get; } = new(Constants.Pi);
|
||||
|
||||
public static double Cos__0 { get; } = 1;
|
||||
public static double Cos_45 { get; } = Math.Cos(45 * Math.PI / 180);
|
||||
public static double Cos_90 { get; } = 0;
|
||||
public static double Sin__0 { get; } = 0;
|
||||
public static double Sin_45 { get; } = Math.Sin(45 * Math.PI / 180);
|
||||
public static double Sin_90 { get; } = 1;
|
||||
|
||||
|
||||
public static Angle Acos(double d) => new() { Radians = Math.Acos(d) };
|
||||
public static Angle Acosh(double d) => new() { Radians = Math.Acosh(d) };
|
||||
public static Angle Asin(double d) => new() { Radians = Math.Asin(d) };
|
||||
public static Angle Asinh(double d) => new() { Radians = Math.Asinh(d) };
|
||||
public static Angle Atan(double d) => new() { Radians = Math.Atan(d) };
|
||||
public static Angle Atanh(double d) => new() { Radians = Math.Atanh(d) };
|
||||
|
||||
public double Cos() => Math.Cos(AngleConv.Radians.From(_Value));
|
||||
public double Cosh() => Math.Cosh(AngleConv.Radians.From(_Value));
|
||||
public double Sin() => Math.Sin(AngleConv.Radians.From(_Value));
|
||||
public (double Sin, double Cos) SinCos() => Math.SinCos(AngleConv.Radians.From(_Value));
|
||||
public double Sinh() => Math.Sinh(AngleConv.Radians.From(_Value));
|
||||
public double Tan() => Math.Tan(AngleConv.Radians.From(_Value));
|
||||
public double Tanh() => Math.Tanh(AngleConv.Radians.From(_Value));
|
||||
|
||||
|
||||
internal const double PiDiv2 = Math.PI / 2;
|
||||
public double Ctg() => Math.Tan(PiDiv2 - AngleConv.Radians.From(_Value));
|
||||
}
|
||||
|
||||
internal readonly struct AngleConv
|
||||
{
|
||||
private AngleConv(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 AngleConv Seconds { get; } = new(1);
|
||||
public static AngleConv Minutes { get; } = new(60);
|
||||
public static AngleConv Grads { get; } = new(3240);
|
||||
public static AngleConv Degrees { get; } = new(3600);
|
||||
public static AngleConv Radians { get; } = new((180 * 60 * 60) / Math.PI);
|
||||
}
|
||||
78
QWERTYkez.Mensura/Units/Area.cs
Normal file
78
QWERTYkez.Mensura/Units/Area.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is MilliMetersSquared
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("mm2 = {_MilliMetersSquared.ToString(\"0.###\")}, m2 = {MetersSquared.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Area
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _MilliMetersSquared { get => MilliMetersSquared; init => MilliMetersSquared = value; }
|
||||
|
||||
public static Area MilliMeterSquared { get; } = new() { MilliMetersSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double MilliMetersSquared
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
public static Area CentiMeterSquared { get; } = new() { CentiMetersSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double CentiMetersSquared
|
||||
{
|
||||
get => AreaConv.CentiMetersSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AreaConv.CentiMetersSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Area MeterSquared { get; } = new() { MetersSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double MetersSquared
|
||||
{
|
||||
get => AreaConv.MetersSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AreaConv.MetersSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Area Hector { get; } = new() { Hectors = 1 };
|
||||
[NotMapped, JsonIgnore] public double Hectors
|
||||
{
|
||||
get => AreaConv.Hectors.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AreaConv.Hectors.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Area KiloMeterSquared { get; } = new() { KiloMetersSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloMetersSquared
|
||||
{
|
||||
get => AreaConv.KiloMetersSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = AreaConv.KiloMetersSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Area AddMilliMetersSquared(double value) => new(_Value + value);
|
||||
public Area AddCentiMetersSquared(double value) => new(_Value + AreaConv.CentiMetersSquared.To(value));
|
||||
public Area AddMetersSquared(double value) => new(_Value + AreaConv.MetersSquared.To(value));
|
||||
public Area AddHectors(double value) => new(_Value + AreaConv.Hectors.To(value));
|
||||
public Area AddKiloMetersSquared(double value) => new(_Value + AreaConv.KiloMetersSquared.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct AreaConv
|
||||
{
|
||||
private AreaConv(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 AreaConv MilliMetersSquared { get; } = new(1);
|
||||
public static AreaConv CentiMetersSquared { get; } = new(100);
|
||||
public static AreaConv MetersSquared { get; } = new(1000000);
|
||||
public static AreaConv Hectors { get; } = new(10000000000);
|
||||
public static AreaConv KiloMetersSquared { get; } = new(1000000000000);
|
||||
}
|
||||
45
QWERTYkez.Mensura/Units/Boost.cs
Normal file
45
QWERTYkez.Mensura/Units/Boost.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is MetersPerSecondSquared
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("m/s2 = {_MetersPerSecondSquared.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Boost
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _MetersPerSecondSquared { get => MetersPerSecondSquared; init => MetersPerSecondSquared = value; }
|
||||
|
||||
public static Boost MeterPerSecondSquared { get; } = new() { MetersPerSecondSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double MetersPerSecondSquared
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boost KiloMeterPerSecondSquared { get; } = new() { KiloMetersPerSecondSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloMetersPerSecondSquared
|
||||
{
|
||||
get => BoostConv.KiloMetersPerSecondSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = BoostConv.KiloMetersPerSecondSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Boost G { get; } = new() { MetersPerSecondSquared = Constants.g };
|
||||
|
||||
public Boost AddMetersPerSecondSquared(double value) => new(_Value + value);
|
||||
public Boost AddKiloMetersPerSecondSquared(double value) => new(_Value + BoostConv.KiloMetersPerSecondSquared.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct BoostConv
|
||||
{
|
||||
private BoostConv(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 BoostConv MetersPerSecondSquared { get; } = new(1);
|
||||
public static BoostConv KiloMetersPerSecondSquared { get; } = new(1000);
|
||||
}
|
||||
67
QWERTYkez.Mensura/Units/Force.cs
Normal file
67
QWERTYkez.Mensura/Units/Force.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Newtons
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("N = {_Newtons.ToString(\"0.###\")}, kgf = {KiloGramForces.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Force
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Newtons { get => Newtons; init => Newtons = value; }
|
||||
|
||||
public static Force Newton { get; } = new() { Newtons = 1 };
|
||||
[NotMapped, JsonIgnore] public double Newtons
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Force KiloGramForce { get; } = new() { KiloGramForces = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramForces
|
||||
{
|
||||
get => ForceConv.KiloGramForces.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = ForceConv.KiloGramForces.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Force KiloNewton { get; } = new() { KiloNewtons = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloNewtons
|
||||
{
|
||||
get => ForceConv.KiloNewtons.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = ForceConv.KiloNewtons.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Force TonForce { get; } = new() { TonForces = 1 };
|
||||
[NotMapped, JsonIgnore] public double TonForces
|
||||
{
|
||||
get => ForceConv.TonForces.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = ForceConv.TonForces.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Force AddNewtons(double value) => new(_Value + value);
|
||||
public Force AddKiloGramForces(double value) => new(_Value + ForceConv.KiloGramForces.To(value));
|
||||
public Force AddKiloNewtons(double value) => new(_Value + ForceConv.KiloNewtons.To(value));
|
||||
public Force AddTonForces(double value) => new(_Value + ForceConv.TonForces.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct ForceConv
|
||||
{
|
||||
private ForceConv(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 ForceConv Newtons { get; } = new(1);
|
||||
public static ForceConv KiloGramForces { get; } = new(Constants.g);
|
||||
public static ForceConv KiloNewtons { get; } = new(1000);
|
||||
public static ForceConv TonForces { get; } = new(Constants.g * 1000);
|
||||
}
|
||||
57
QWERTYkez.Mensura/Units/Frequency.cs
Normal file
57
QWERTYkez.Mensura/Units/Frequency.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Hertz
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("Hz = {_Hertz.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Frequency
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Hertz { get => Hertz; init => Hertz = value; }
|
||||
|
||||
public static Frequency OneHertz { get; } = new() { Hertz = 1 };
|
||||
[NotMapped, JsonIgnore] public double Hertz
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Frequency OneKiloHertz { get; } = new() { KiloHertz = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloHertz
|
||||
{
|
||||
get => FrequencyConv.KiloHertz.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = FrequencyConv.KiloHertz.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Frequency OneMegaHertz { get; } = new() { MegaHertz = 1 };
|
||||
[NotMapped, JsonIgnore] public double MegaHertz
|
||||
{
|
||||
get => FrequencyConv.MegaHertz.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = FrequencyConv.MegaHertz.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Time ToTime() => new() { Seconds = 1 / _Hertz };
|
||||
|
||||
public Frequency AddHertz(double value) => new(_Value + value);
|
||||
public Frequency AddKiloHertz(double value) => new(_Value + FrequencyConv.KiloHertz.To(value));
|
||||
public Frequency AddMegaHertz(double value) => new(_Value + FrequencyConv.MegaHertz.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct FrequencyConv
|
||||
{
|
||||
private FrequencyConv(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 FrequencyConv Hertz { get; } = new(1);
|
||||
public static FrequencyConv KiloHertz { get; } = new(1000);
|
||||
public static FrequencyConv MegaHertz { get; } = new(1000000);
|
||||
}
|
||||
@@ -7,9 +7,7 @@
|
||||
public readonly partial record struct Length
|
||||
{
|
||||
public static Length MilliMeter { get; } = new(1);
|
||||
#pragma warning disable IDE1006 // _Подчеркивание для обозначения того, что это базовая единица
|
||||
[NotMapped, JsonIgnore] public double _MilliMeters { get => _Value; init => _Value = value; }
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
|
||||
public static Length CentiMeter { get; } = new(LengthConv.CentiMeters.To(1));
|
||||
|
||||
66
QWERTYkez.Mensura/Units/Mass.cs
Normal file
66
QWERTYkez.Mensura/Units/Mass.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Grams
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("gr = {_Grams.ToString(\"0.###\")}, kg = {KiloGrams.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Mass
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Grams { get => Grams; init => Grams = value; }
|
||||
|
||||
public static Mass Gram { get; } = new() { Grams = 1 };
|
||||
[NotMapped, JsonIgnore] public double Grams
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Mass KiloGram { get; } = new() { KiloGrams = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGrams
|
||||
{
|
||||
get => MassConv.KiloGrams.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = MassConv.KiloGrams.To(value);
|
||||
}
|
||||
}
|
||||
public static Mass Centner { get; } = new() { Centners = 1 };
|
||||
[NotMapped, JsonIgnore] public double Centners
|
||||
{
|
||||
get => MassConv.Centners.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = MassConv.Centners.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mass Ton { get; } = new() { Tons = 1 };
|
||||
[NotMapped, JsonIgnore] public double Tons
|
||||
{
|
||||
get => MassConv.Tons.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = MassConv.Tons.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Mass AddGrams(double value) => new(_Value + value);
|
||||
public Mass AddKiloGrams(double value) => new(_Value + MassConv.KiloGrams.To(value));
|
||||
public Mass AddCentners(double value) => new(_Value + MassConv.Centners.To(value));
|
||||
public Mass AddTons(double value) => new(_Value + MassConv.Tons.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct MassConv
|
||||
{
|
||||
private MassConv(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 MassConv Grams { get; } = new(1);
|
||||
public static MassConv KiloGrams { get; } = new(1000);
|
||||
public static MassConv Centners { get; } = new(100000);
|
||||
public static MassConv Tons { get; } = new(1000000);
|
||||
}
|
||||
43
QWERTYkez.Mensura/Units/MassPerSquare.cs
Normal file
43
QWERTYkez.Mensura/Units/MassPerSquare.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is KiloGramsPerMeterSquared
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("kg/m2 = {_KiloGramsPerMeterSquared.ToString(\"0.###\")}, kg/mm2 = {KiloGramsPerMilliMeterSquared.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct MassPerSquare
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _KiloGramsPerMeterSquared { get => KiloGramsPerMeterSquared; init => KiloGramsPerMeterSquared = value; }
|
||||
|
||||
public static MassPerSquare KiloGramPerMeterSquared { get; } = new() { KiloGramsPerMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramsPerMeterSquared
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static MassPerSquare KiloGramPerMilliMeterSquared { get; } = new() { KiloGramsPerMilliMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramsPerMilliMeterSquared
|
||||
{
|
||||
get => MassPerSquareConv.KiloGramsPerMilliMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = MassPerSquareConv.KiloGramsPerMilliMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public MassPerSquare AddKiloGramsPerMeterSquared(double value) => new(_Value + value);
|
||||
public MassPerSquare AddKiloGramsPerMilliMeterSquared(double value) => new(_Value + MassPerSquareConv.KiloGramsPerMilliMeterSquared.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct MassPerSquareConv
|
||||
{
|
||||
private MassPerSquareConv(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 MassPerSquareConv KiloGramsPerMeterSquared { get; } = new(1);
|
||||
public static MassPerSquareConv KiloGramsPerMilliMeterSquared { get; } = new(1000000);
|
||||
}
|
||||
149
QWERTYkez.Mensura/Units/Pogon/.Pogon.cs
Normal file
149
QWERTYkez.Mensura/Units/Pogon/.Pogon.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is PerMilliMeter
|
||||
/// </summary>
|
||||
public abstract class Pogon<T>
|
||||
{
|
||||
|
||||
|
||||
internal T PerValue { get; init; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[NotMapped, JsonIgnore] internal T PerValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T _PerMilliMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[NotMapped, JsonIgnore] public T PerMilliMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerCentiMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * LengthConv.CentiMeters.Multiplicator,
|
||||
BaseContainerMultiplicator = LengthConv.CentiMeters.Multiplicator,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / LengthConv.CentiMeters.Multiplicator;
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerDeciMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * LengthConv.DeciMeters.Multiplicator,
|
||||
BaseContainerMultiplicator = LengthConv.DeciMeters.Multiplicator,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / LengthConv.DeciMeters.Multiplicator;
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * LengthConv.Meters.Multiplicator,
|
||||
BaseContainerMultiplicator = LengthConv.Meters.Multiplicator,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / LengthConv.Meters.Multiplicator;
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerKiloMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * LengthConv.KiloMeters.Multiplicator,
|
||||
BaseContainerMultiplicator = LengthConv.KiloMeters.Multiplicator,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / LengthConv.KiloMeters.Multiplicator;
|
||||
}
|
||||
}
|
||||
|
||||
public static T operator *(Pogon<U, T> left, Length right) => ((U)left).Protect()._PerMilliMeter * right.Protect()._MilliMeters;
|
||||
public static MetricCollection<T> operator *(Pogon<U, T> left, MetricCollection<Length> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricArray<T> operator *(Pogon<U, T> left, MetricArray<Length> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricList<T> operator *(Pogon<U, T> left, MetricList<Length> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricObservableCollection<T> operator *(Pogon<U, T> left, MetricObservableCollection<Length> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
|
||||
|
||||
public static T operator *(Length left, Pogon<U, T> right) => ((U)right).Protect()._PerMilliMeter * left.Protect()._MilliMeters;
|
||||
public static MetricCollection<T> operator *(MetricCollection<Length> left, Pogon<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricArray<T> operator *(MetricArray<Length> left, Pogon<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricList<T> operator *(MetricList<Length> left, Pogon<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricObservableCollection<T> operator *(MetricObservableCollection<Length> left, Pogon<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
|
||||
|
||||
public static Length operator /(T left, Pogon<U, T> right) => new() { _MilliMeters = left.Protect() / ((U)right).Protect()._PerMilliMeter };
|
||||
public static MetricCollection<Length> operator *(MetricCollection<T> left, Pogon<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricArray<Length> operator *(MetricArray<T> left, Pogon<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricList<Length> operator *(MetricList<T> left, Pogon<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricObservableCollection<Length> operator *(MetricObservableCollection<T> left, Pogon<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
}
|
||||
14
QWERTYkez.Mensura/Units/Pogon/PogonForce.cs
Normal file
14
QWERTYkez.Mensura/Units/Pogon/PogonForce.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
[DebuggerDisplay("N/m = {PerMeter._Newtons.ToString(\"0.###\")}, kgf/m = {PerMeter.KiloGramXXXXXXXXs.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct PogonXXXXXXXX
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public partial class Length : Metric<Length, Length>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static PogonXXXXXXXX operator /(XXXXXXXX left, Length right) => left.DivideProtected<XXXXXXXX, Length, PogonXXXXXXXX>(right, PogonXXXXXXXXCoeff);
|
||||
static readonly double PogonXXXXXXXXCoeff = Coefficients.DivideCoefficient<XXXXXXXX, Length, PogonXXXXXXXX>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
|
||||
}
|
||||
14
QWERTYkez.Mensura/Units/Pogon/PogonMass.cs
Normal file
14
QWERTYkez.Mensura/Units/Pogon/PogonMass.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
[Owned, JsonConverter(typeof(MetricFormatter<PogonMass>)), DebuggerDisplay("gr/m = {PerMeter._Grams.ToString(\"0.###\")}, kg/m = {PerMeter.KiloGrams.ToString(\"0.###\")}")]
|
||||
public partial class PogonMass : Pogon<PogonMass, Mass>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Density operator /(PogonMass left, Area right) => left.DivideProtected<PogonMass, Area, Density>(right, UdelMassCoeff);
|
||||
static readonly double UdelMassCoeff = Coefficients.DivideCoefficient<PogonMass, Area, Density>(a => a._PerMilliMeter.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeterCubic.Value = 1);
|
||||
}
|
||||
|
||||
public partial class Length : Metric<Length, Length>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static PogonMass operator /(Mass left, Length right) => left.DivideProtected<Mass, Length, PogonMass>(right, PogonMassCoeff);
|
||||
static readonly double PogonMassCoeff = Coefficients.DivideCoefficient<Mass, Length, PogonMass>(a => a.Value = 1, b => b._MilliMeters = 1, r => r._PerMilliMeter.Value = 1);
|
||||
}
|
||||
568
QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Gen.cs
Normal file
568
QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Gen.cs
Normal file
@@ -0,0 +1,568 @@
|
||||
global using PogonMass = QWERTYkez.Mensura.Units.Pogon.PogonMass;
|
||||
global using PogonMassExtensions = QWERTYkez.Mensura.Units.Pogon.PogonMassExtensions;
|
||||
global using PogonMassConverter = QWERTYkez.Mensura.Units.Pogon.PogonMassConverter;
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace QWERTYkez.Mensura.Units
|
||||
{
|
||||
public readonly partial record struct Length
|
||||
{
|
||||
// ==========================================
|
||||
// === MULTIPLY ===
|
||||
// ==========================================
|
||||
|
||||
public static Mass[] operator *(PogonMass[] left, Length right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(PogonMass[] left, Length? right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(Length left, PogonMass[] right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(Length? left, PogonMass[] right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
// === ReadOnlySpan ===
|
||||
|
||||
public static Span<Mass> operator *(Length left, ReadOnlySpan<PogonMass> right)
|
||||
{
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(Length? left, ReadOnlySpan<PogonMass> right)
|
||||
{
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(ReadOnlySpan<PogonMass> left, Length right)
|
||||
{
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(ReadOnlySpan<PogonMass> left, Length? right)
|
||||
{
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
// === List ===
|
||||
|
||||
public static List<Mass> operator *(Length left, List<PogonMass> right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(Length? left, List<PogonMass> right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(List<PogonMass> left, Length right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(List<PogonMass> left, Length? right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace QWERTYkez.Mensura.Units.Pogon
|
||||
{
|
||||
[JsonConverter(typeof(PogonMassConverter))]
|
||||
public readonly partial record struct PogonMass : IMensuraUnit<PogonMass>, IEquatable<PogonMass>, IMensuraUnit
|
||||
{
|
||||
|
||||
[JsonInclude, DataMember, JsonPropertyName("v")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||
internal double Value { get => _Value; init => _Value = value; }
|
||||
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
|
||||
internal readonly double _Value;
|
||||
internal PogonMass(double value) => _Value = value;
|
||||
|
||||
|
||||
[NotMapped, JsonIgnore]
|
||||
internal Mass PerValue
|
||||
{ get => (Mass)_Value; init => _Value = (double)value; }
|
||||
|
||||
|
||||
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsZero => _Value == 0;
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNaN => double.IsNaN(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsFinite => double.IsFinite(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsInfinity => double.IsInfinity(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsPositiveInfinity => double.IsPositiveInfinity(_Value);
|
||||
[JsonIgnore, IgnoreDataMember] public bool IsNegativeInfinity => double.IsNegativeInfinity(_Value);
|
||||
|
||||
|
||||
public static Mass operator *(PogonMass left, Length right) => left.PerValue * right._Value;
|
||||
public static Mass operator *(PogonMass? left, Length right) => (left ?? default).PerValue * right._Value;
|
||||
public static Mass operator *(PogonMass left, Length? right) => left.PerValue * (right ?? default)._Value;
|
||||
public static Mass operator *(PogonMass? left, Length? right) => (left ?? default).PerValue * (right ?? default)._Value;
|
||||
|
||||
public static Mass operator *(Length left, PogonMass right) => right.PerValue * left._Value;
|
||||
public static Mass operator *(Length? left, PogonMass right) => right.PerValue * (left ?? default)._Value;
|
||||
public static Mass operator *(Length left, PogonMass? right) => (right ?? default).PerValue * left._Value;
|
||||
public static Mass operator *(Length? left, PogonMass? right) => (right ?? default).PerValue * (left ?? default)._Value;
|
||||
|
||||
public static Length operator /(Mass left, PogonMass right) => new(left / right.PerValue);
|
||||
public static Length operator /(Mass? left, PogonMass right) => new((left ?? default) / right.PerValue);
|
||||
public static Length operator /(Mass left, PogonMass? right) => new(left / (right ?? default).PerValue);
|
||||
public static Length operator /(Mass? left, PogonMass? right) => new((left ?? default) / (right ?? default).PerValue);
|
||||
|
||||
|
||||
// ==========================================
|
||||
// === MULTIPLY ===
|
||||
// ==========================================
|
||||
|
||||
public static Mass[] operator *(PogonMass left, Length[] right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(PogonMass? left, Length[] right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(Length[] left, PogonMass right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static Mass[] operator *(Length[] left, PogonMass? right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new Mass[len];
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
// === ReadOnlySpan ===
|
||||
|
||||
public static Span<Mass> operator *(PogonMass left, ReadOnlySpan<Length> right)
|
||||
{
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(PogonMass? left, ReadOnlySpan<Length> right)
|
||||
{
|
||||
int len = right.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(ReadOnlySpan<Length> left, PogonMass right)
|
||||
{
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static Span<Mass> operator *(ReadOnlySpan<Length> left, PogonMass? right)
|
||||
{
|
||||
int len = left.Length;
|
||||
if (len == 0) return [];
|
||||
|
||||
Span<Mass> result = new Mass[len];
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
// === List ===
|
||||
|
||||
public static List<Mass> operator *(PogonMass left, List<Length> right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = left * right[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(PogonMass? left, List<Length> right)
|
||||
{
|
||||
if (right is null) return null!;
|
||||
int len = right.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
if (left is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * right[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(List<Length> left, PogonMass right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = right * left[i];
|
||||
return result;
|
||||
}
|
||||
public static List<Mass> operator *(List<Length> left, PogonMass? right)
|
||||
{
|
||||
if (left is null) return null!;
|
||||
int len = left.Count;
|
||||
if (len == 0) return [];
|
||||
|
||||
var result = new List<Mass>(len);
|
||||
if (right is { } val)
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = val * left[i];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class PogonMassExtensions
|
||||
{
|
||||
internal static Mass Protect(this Mass? unit) => unit ?? default;
|
||||
internal static double ToDouble(this PogonMass? unit) => unit?._Value ?? 0d;
|
||||
|
||||
|
||||
public static PogonMass MetricSum(this IEnumerable<PogonMass> units) => new(units?.Sum(m => m._Value) ?? 0d);
|
||||
public static PogonMass MetricAverage(this IEnumerable<PogonMass> units) => new(units?.Average(m => m._Value) ?? double.NaN);
|
||||
public static PogonMass MetricMax(this IEnumerable<PogonMass> units) => new(units?.Max(m => m._Value) ?? double.MinValue);
|
||||
public static PogonMass MetricMin(this IEnumerable<PogonMass> units) => new(units?.Min(m => m._Value) ?? double.MaxValue);
|
||||
|
||||
public static PogonMass MetricSum(this IEnumerable<PogonMass?> units) => new(units?.Sum(m => m.ToDouble()) ?? 0d);
|
||||
public static PogonMass MetricAverage(this IEnumerable<PogonMass?> units) => new(units?.Average(m => m.ToDouble()) ?? double.NaN);
|
||||
public static PogonMass MetricMax(this IEnumerable<PogonMass?> units) => new(units?.Max(m => m.ToDouble()) ?? double.MinValue);
|
||||
public static PogonMass MetricMin(this IEnumerable<PogonMass?> units) => new(units?.Min(m => m.ToDouble()) ?? double.MaxValue);
|
||||
|
||||
|
||||
|
||||
internal static void MultiplyCore(ReadOnlySpan<PogonMass> source, Length value, Span<Mass> destination)
|
||||
{
|
||||
var dVal = value._Value;
|
||||
int len = source.Length;
|
||||
ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<PogonMass, double>(source);
|
||||
Span<double> dstDouble = MemoryMarshal.Cast<Mass, double>(destination);
|
||||
|
||||
var vectorized_Value = new Vector<double>(dVal);
|
||||
int vectorSize = Vector<double>.Count;
|
||||
int i = 0;
|
||||
|
||||
ref double srcRef = ref MemoryMarshal.GetReference(srcDouble);
|
||||
ref double dstRef = ref MemoryMarshal.GetReference(dstDouble);
|
||||
|
||||
int SIMDEnd = len - (len % vectorSize);
|
||||
for (; i < SIMDEnd; i += vectorSize)
|
||||
{
|
||||
ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
var vector = new Vector<double>(srcWindow);
|
||||
var multiplied = vector * vectorized_Value;
|
||||
ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
multiplied.CopyTo(dstWindow);
|
||||
}
|
||||
|
||||
for (; i < len; i++)
|
||||
{
|
||||
Unsafe.Add(ref dstRef, i) = Unsafe.Add(ref srcRef, i) * dVal;
|
||||
}
|
||||
}
|
||||
internal static void MultiplyCore(ReadOnlySpan<Length> source, PogonMass value, Span<Mass> destination)
|
||||
{
|
||||
var dVal = value._Value;
|
||||
int len = source.Length;
|
||||
ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<Length, double>(source);
|
||||
Span<double> dstDouble = MemoryMarshal.Cast<Mass, double>(destination);
|
||||
|
||||
var vectorized_Value = new Vector<double>(dVal);
|
||||
int vectorSize = Vector<double>.Count;
|
||||
int i = 0;
|
||||
|
||||
ref double srcRef = ref MemoryMarshal.GetReference(srcDouble);
|
||||
ref double dstRef = ref MemoryMarshal.GetReference(dstDouble);
|
||||
|
||||
int SIMDEnd = len - (len % vectorSize);
|
||||
for (; i < SIMDEnd; i += vectorSize)
|
||||
{
|
||||
ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
var vector = new Vector<double>(srcWindow);
|
||||
var multiplied = vector * vectorized_Value;
|
||||
ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
multiplied.CopyTo(dstWindow);
|
||||
}
|
||||
|
||||
for (; i < len; i++)
|
||||
{
|
||||
Unsafe.Add(ref dstRef, i) = Unsafe.Add(ref srcRef, i) * dVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static void DivideCore(ReadOnlySpan<Mass> source, PogonMass divisor, Span<Length> destination)
|
||||
{
|
||||
// 1. Проверка на ноль
|
||||
if (divisor.IsZero || divisor.IsNaN)
|
||||
throw new DivideByZeroException("Делитель не может быть равен нулю.");
|
||||
|
||||
var dVal = divisor._Value;
|
||||
int len = source.Length;
|
||||
ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<Mass, double>(source);
|
||||
Span<double> dstDouble = MemoryMarshal.Cast<Length, double>(destination);
|
||||
|
||||
var vectorized_Value = new Vector<double>(dVal);
|
||||
int vectorSize = Vector<double>.Count;
|
||||
int i = 0;
|
||||
|
||||
ref double srcRef = ref MemoryMarshal.GetReference(srcDouble);
|
||||
ref double dstRef = ref MemoryMarshal.GetReference(dstDouble);
|
||||
|
||||
int SIMDEnd = len - (len % vectorSize);
|
||||
for (; i < SIMDEnd; i += vectorSize)
|
||||
{
|
||||
ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
var vector = new Vector<double>(srcWindow);
|
||||
var multiplied = vector / vectorized_Value;
|
||||
ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
multiplied.CopyTo(dstWindow);
|
||||
}
|
||||
|
||||
for (; i < len; i++)
|
||||
{
|
||||
Unsafe.Add(ref dstRef, i) = Unsafe.Add(ref srcRef, i) / dVal;
|
||||
}
|
||||
}
|
||||
internal static void DivideCore(Mass dividend, ReadOnlySpan<PogonMass> source, Span<Length> destination)
|
||||
{
|
||||
var dVal = dividend._Value;
|
||||
int len = source.Length;
|
||||
ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<PogonMass, double>(source);
|
||||
Span<double> dstDouble = MemoryMarshal.Cast<Length, double>(destination);
|
||||
|
||||
var vectorized_Value = new Vector<double>(dVal);
|
||||
var zeroVector = Vector<double>.Zero; // Вектор из нулей для сравнения
|
||||
int vectorSize = Vector<double>.Count;
|
||||
int i = 0;
|
||||
|
||||
ref double srcRef = ref MemoryMarshal.GetReference(srcDouble);
|
||||
ref double dstRef = ref MemoryMarshal.GetReference(dstDouble);
|
||||
|
||||
int SIMDEnd = len - (len % vectorSize);
|
||||
for (; i < SIMDEnd; i += vectorSize)
|
||||
{
|
||||
ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
var vector = new Vector<double>(srcWindow);
|
||||
|
||||
// БЫСТРАЯ ПРОВЕРКА: Есть ли хотя бы один 0.0 в текущем векторе?
|
||||
if (Vector.EqualsAny(vector, zeroVector))
|
||||
{
|
||||
throw new DivideByZeroException($"Обнаружен делитель, равный нулю, в районе индексов {i}..{i + vectorSize - 1}.");
|
||||
}
|
||||
|
||||
var multiplied = vectorized_Value / vector;
|
||||
ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
multiplied.CopyTo(dstWindow);
|
||||
}
|
||||
|
||||
// Хвостовой цикл
|
||||
for (; i < len; i++)
|
||||
{
|
||||
double divisor = Unsafe.Add(ref srcRef, i);
|
||||
if (divisor == 0.0)
|
||||
{
|
||||
throw new DivideByZeroException($"Обнаружен делитель, равный нулю, в индексе {i}.");
|
||||
}
|
||||
Unsafe.Add(ref dstRef, i) = dVal / divisor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PogonMassConverter : JsonConverter<PogonMass>
|
||||
{
|
||||
// Используем инвариантную культуру, чтобы разделителем всегда была точка (10.5, а не 10,5)
|
||||
private static readonly CultureInfo Culture = CultureInfo.InvariantCulture;
|
||||
|
||||
public override PogonMass Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
double double_Value;
|
||||
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
// Безопасно парсим double из строки с поддержкой точки как разделителя
|
||||
if (!double.TryParse(reader.GetString(), NumberStyles.Float, Culture, out double_Value))
|
||||
{
|
||||
throw new JsonException($"Не удалось преобразовать строковое значение в double для метрики {nameof(PogonMass)}.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Прямое быстрое чтение числа из JSON
|
||||
double_Value = reader.GetDouble();
|
||||
}
|
||||
|
||||
return new(double_Value);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, PogonMass value, JsonSerializerOptions options)
|
||||
{
|
||||
// Записываем число напрямую в байтовый буфер без выделения памяти под строки
|
||||
writer.WriteNumberValue(value._Value);
|
||||
}
|
||||
|
||||
public override void WriteAsPropertyName(Utf8JsonWriter writer, PogonMass value, JsonSerializerOptions options)
|
||||
{
|
||||
// Ключи JSON-объектов всегда должны быть строками.
|
||||
// Форматируем double в строку с точкой, чтобы другие сервисы экосистемы прочитали её корректно.
|
||||
// Формат "R" (Round-trip) гарантирует, что число не потеряет точность при обратном парсинге.
|
||||
writer.WritePropertyName(value._Value.ToString("R", Culture));
|
||||
}
|
||||
|
||||
public override PogonMass ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
string propertyName = reader.GetString()!;
|
||||
|
||||
if (!double.TryParse(propertyName, NumberStyles.Float, Culture, out double double_Value))
|
||||
{
|
||||
throw new JsonException($"Невалидное числовое значение в ключе свойства JSON: '{propertyName}' для метрики {nameof(PogonMass)}.");
|
||||
}
|
||||
|
||||
return new(double_Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Ref.cs
Normal file
33
QWERTYkez.Mensura/Units/Pogon/PogonXXXXXXXX.Ref.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace QWERTYkez.Mensura.Units.Pogon;
|
||||
|
||||
public readonly partial record struct PogonMass
|
||||
{
|
||||
|
||||
[NotMapped, JsonIgnore] public Mass _PerMilliMeter
|
||||
{ get => (Mass)_Value; init => _Value = (double)value; }
|
||||
|
||||
[NotMapped, JsonIgnore] public Mass PerCentiMeter
|
||||
{
|
||||
get => new(_Value * LengthConv.CentiMeters.Multiplicator);
|
||||
init => _Value = value._Value / LengthConv.CentiMeters.Multiplicator;
|
||||
}
|
||||
|
||||
[NotMapped, JsonIgnore] public Mass PerDeciMeter
|
||||
{
|
||||
get => new(_Value * LengthConv.DeciMeters.Multiplicator);
|
||||
init => _Value = value._Value / LengthConv.DeciMeters.Multiplicator;
|
||||
}
|
||||
|
||||
[NotMapped, JsonIgnore] public Mass PerMeter
|
||||
{
|
||||
get => new(_Value * LengthConv.Meters.Multiplicator);
|
||||
init => _Value = value._Value / LengthConv.Meters.Multiplicator;
|
||||
}
|
||||
|
||||
[NotMapped, JsonIgnore] public Mass PerKiloMeter
|
||||
{
|
||||
get => new(_Value * LengthConv.KiloMeters.Multiplicator);
|
||||
init => _Value = value._Value / LengthConv.KiloMeters.Multiplicator;
|
||||
}
|
||||
|
||||
}
|
||||
150
QWERTYkez.Mensura/Units/Pressure.cs
Normal file
150
QWERTYkez.Mensura/Units/Pressure.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Pascals or NewtonsPerMeterSquared
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("Pa, N/m2 = {NewtonsPerMeterSquared.ToString(\"0.###\")}, kgf/mm2 = {KiloGramForcesPerMilliMeterSquared.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Pressure
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Pascals { get => Pascals; init => Pascals = value; }
|
||||
|
||||
public static Pressure Pascal { get; } = new() { Pascals = 1 };
|
||||
[NotMapped, JsonIgnore] public double Pascals
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure NewtonPerMeterSquared { get; } = new() { NewtonsPerMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double NewtonsPerMeterSquared
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure KiloPascal { get; } = new() { KiloPascals = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloPascals
|
||||
{
|
||||
get => PressureConv.KiloPascals.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.KiloPascals.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure MegaPascal { get; } = new() { MegaPascals = 1 };
|
||||
[NotMapped, JsonIgnore] public double MegaPascals
|
||||
{
|
||||
get => PressureConv.MegaPascals.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.MegaPascals.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure NewtonPerMilliMeterSquared { get; } = new() { NewtonsPerMilliMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double NewtonsPerMilliMeterSquared
|
||||
{
|
||||
get => PressureConv.NewtonsPerMilliMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.NewtonsPerMilliMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure KiloGramForcePerMilliMeterSquared { get; } = new() { KiloGramForcesPerMilliMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramForcesPerMilliMeterSquared
|
||||
{
|
||||
get => PressureConv.KiloGramForcesPerMilliMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.KiloGramForcesPerMilliMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure KiloGramForcePerMeterSquared { get; } = new() { KiloGramForcesPerMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramForcesPerMeterSquared
|
||||
{
|
||||
get => PressureConv.KiloGramForcesPerMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.KiloGramForcesPerMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure KiloNewtonPerMilliMeterSquared { get; } = new() { KiloNewtonsPerMilliMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloNewtonsPerMilliMeterSquared
|
||||
{
|
||||
get => PressureConv.KiloNewtonsPerMilliMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.KiloNewtonsPerMilliMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure KiloNewtonPerMeterSquared { get; } = new() { KiloNewtonsPerMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloNewtonsPerMeterSquared
|
||||
{
|
||||
get => PressureConv.KiloNewtonsPerMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.KiloNewtonsPerMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure TonForcePerMilliMeterSquared { get; } = new() { TonForcesPerMilliMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double TonForcesPerMilliMeterSquared
|
||||
{
|
||||
get => PressureConv.TonForcesPerMilliMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.TonForcesPerMilliMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pressure TonForcePerMeterSquared { get; } = new() { TonForcesPerMeterSquared = 1 };
|
||||
[NotMapped, JsonIgnore] public double TonForcesPerMeterSquared
|
||||
{
|
||||
get => PressureConv.TonForcesPerMeterSquared.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = PressureConv.TonForcesPerMeterSquared.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Pressure AddPascals(double value) => new(_Value + value);
|
||||
public Pressure AddNewtonsPerMeterSquared(double value) => new(_Value + value);
|
||||
public Pressure AddKiloPascals(double value) => new(_Value + PressureConv.KiloPascals.To(value));
|
||||
public Pressure AddMegaPascals(double value) => new(_Value + PressureConv.MegaPascals.To(value));
|
||||
public Pressure AddKiloGramForcesPerMeterSquared(double value) => new(_Value + PressureConv.KiloGramForcesPerMeterSquared.To(value));
|
||||
public Pressure AddTonsPerMeterSquared(double value) => new(_Value + PressureConv.TonForcesPerMeterSquared.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct PressureConv
|
||||
{
|
||||
private PressureConv(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 PressureConv Pascals { get; } = new(1);
|
||||
public static PressureConv NewtonsPerMeterSquared { get; } = new(1);
|
||||
public static PressureConv KiloPascals { get; } = new(1000);
|
||||
public static PressureConv MegaPascals { get; } = new(1000000);
|
||||
public static PressureConv NewtonsPerMilliMeterSquared { get; } = new(1000000);
|
||||
|
||||
public static PressureConv KiloGramForcesPerMeterSquared { get; } = new(Constants.g);
|
||||
public static PressureConv KiloGramForcesPerMilliMeterSquared { get; } = new(Constants.g * 1000000);
|
||||
|
||||
public static PressureConv KiloNewtonsPerMeterSquared { get; } = new(1000);
|
||||
public static PressureConv KiloNewtonsPerMilliMeterSquared { get; } = new(1000000000);
|
||||
|
||||
public static PressureConv TonForcesPerMeterSquared { get; } = new(Constants.g * 1000);
|
||||
public static PressureConv TonForcesPerMilliMeterSquared { get; } = new(Constants.g * 1000000000000);
|
||||
}
|
||||
43
QWERTYkez.Mensura/Units/Speed.cs
Normal file
43
QWERTYkez.Mensura/Units/Speed.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is KiloMetersPerHour
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("km/h = {_KiloMetersPerHour.ToString(\"0.###\")}, m/s = {MetersPerSecond.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Speed
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _KiloMetersPerHour { get => KiloMetersPerHour; init => KiloMetersPerHour = value; }
|
||||
|
||||
public static Speed KiloMeterPerHour { get; } = new() { KiloMetersPerHour = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloMetersPerHour
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Speed MeterPerSecond { get; } = new() { MetersPerSecond = 1 };
|
||||
[NotMapped, JsonIgnore] public double MetersPerSecond
|
||||
{
|
||||
get => SpeedConv.MetersPerSecond.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = SpeedConv.MetersPerSecond.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Speed AddKiloMetersPerHour(double value) => new(_Value + value);
|
||||
public Speed AddMetersPerSecond(double value) => new(_Value + SpeedConv.MetersPerSecond.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct SpeedConv
|
||||
{
|
||||
private SpeedConv(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 SpeedConv KiloMetersPerHour { get; } = new(1);
|
||||
public static SpeedConv MetersPerSecond { get; } = new(3.6);
|
||||
}
|
||||
69
QWERTYkez.Mensura/Units/Time.cs
Normal file
69
QWERTYkez.Mensura/Units/Time.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is MilliSeconds
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("ms = {_MilliSeconds.ToString(\"0.###\")}, s = {Seconds.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Time
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _MilliSeconds { get => MilliSeconds; init => MilliSeconds = value; }
|
||||
|
||||
public static Time MilliSecond { get; } = new() { MilliSeconds = 1 };
|
||||
[NotMapped, JsonIgnore] public double MilliSeconds
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Time Second { get; } = new() { Seconds = 1 };
|
||||
[NotMapped, JsonIgnore] public double Seconds
|
||||
{
|
||||
get => TimeConv.Seconds.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = TimeConv.Seconds.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Time Minute { get; } = new() { Minutes = 1 };
|
||||
[NotMapped, JsonIgnore] public double Minutes
|
||||
{
|
||||
get => TimeConv.Minutes.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = TimeConv.Minutes.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Time Hour { get; } = new() { Hours = 1 };
|
||||
[NotMapped, JsonIgnore] public double Hours
|
||||
{
|
||||
get => TimeConv.Hours.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = TimeConv.Hours.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Frequency ToFrequency() => new() { _Hertz = 1 / Seconds };
|
||||
|
||||
public Time AddMilliSeconds(double value) => new(_Value + value);
|
||||
public Time AddSeconds(double value) => new(_Value + TimeConv.Seconds.To(value));
|
||||
public Time AddMinutes(double value) => new(_Value + TimeConv.Minutes.To(value));
|
||||
public Time AddHours(double value) => new(_Value + TimeConv.Hours.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct TimeConv
|
||||
{
|
||||
private TimeConv(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 TimeConv MilliSeconds { get; } = new(1);
|
||||
public static TimeConv Seconds { get; } = new(1000);
|
||||
public static TimeConv Minutes { get; } = new(60000);
|
||||
public static TimeConv Hours { get; } = new(3600000);
|
||||
}
|
||||
55
QWERTYkez.Mensura/Units/Torque.cs
Normal file
55
QWERTYkez.Mensura/Units/Torque.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Newton_Meters
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("N*m = {_Newton_Meters.ToString(\"0.###\")}, kgf*m = {KiloGramForce_Meters.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Torque
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Newton_Meters { get => Newton_Meters; init => Newton_Meters = value; }
|
||||
|
||||
public static Torque Newton_Meter { get; } = new() { Newton_Meters = 1 };
|
||||
[NotMapped, JsonIgnore] public double Newton_Meters
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Torque KiloGramForce_Meter { get; } = new() { KiloGramForce_Meters = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloGramForce_Meters
|
||||
{
|
||||
get => TorqueConv.KiloGramForce_Meters.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = TorqueConv.KiloGramForce_Meters.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Torque TonnForce_Meter { get; } = new() { TonnForce_Meters = 1 };
|
||||
[NotMapped, JsonIgnore] public double TonnForce_Meters
|
||||
{
|
||||
get => TorqueConv.TonnForce_Meters.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = TorqueConv.TonnForce_Meters.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Torque AddNewton_Meters(double value) => new(_Value + value);
|
||||
public Torque AddKiloGramForce_Meters(double value) => new(_Value + TorqueConv.KiloGramForce_Meters.To(value));
|
||||
public Torque AddTonnForce_Meters(double value) => new(_Value + TorqueConv.TonnForce_Meters.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct TorqueConv
|
||||
{
|
||||
private TorqueConv(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 TorqueConv Newton_Meters { get; } = new(1);
|
||||
public static TorqueConv KiloGramForce_Meters { get; } = new(Constants.g);
|
||||
public static TorqueConv TonnForce_Meters { get; } = new(Constants.g * 1000);
|
||||
}
|
||||
175
QWERTYkez.Mensura/Units/Udel/.Udel.cs
Normal file
175
QWERTYkez.Mensura/Units/Udel/.Udel.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is PerMilliMeterCubic
|
||||
/// </summary>
|
||||
[Owned]
|
||||
public abstract class Udel<U, T> : Metric<U, Udel<U, T>>
|
||||
where U : Udel<U, T>, new()
|
||||
where T : Metric<T, T>, new()
|
||||
{
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(PerMeter_PerMilliMeterSquared));
|
||||
OnPropertyChanged(nameof(PerMilliMeterCubic));
|
||||
OnPropertyChanged(nameof(PerCentiMeterCubic));
|
||||
OnPropertyChanged(nameof(PerDeciMeterCubic));
|
||||
OnPropertyChanged(nameof(PerMeterCubic));
|
||||
OnPropertyChanged(nameof(PerKiloMeterCubic));
|
||||
}
|
||||
|
||||
[NotMapped, JsonIgnore] internal T PerValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
OnPropertyChanged(nameof(PerValue));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T _PerMilliMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
OnPropertyChanged(nameof(_PerMilliMeterCubic));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[NotMapped, JsonIgnore] public T PerMilliMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value,
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value;
|
||||
OnPropertyChanged(nameof(PerMilliMeterCubic));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerMeter_PerMilliMeterSquared
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2),
|
||||
BaseContainerMultiplicator = LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2),
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / (LengthConv.Meters.Multiplicator * Math.Pow(LengthConv.MilliMeters.Multiplicator, 2));
|
||||
OnPropertyChanged(nameof(PerMeter_PerMilliMeterSquared));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerCentiMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * Math.Pow(LengthConv.CentiMeters.Multiplicator, 3),
|
||||
BaseContainerMultiplicator = Math.Pow(LengthConv.CentiMeters.Multiplicator, 3),
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / Math.Pow(LengthConv.CentiMeters.Multiplicator, 3);
|
||||
OnPropertyChanged(nameof(PerCentiMeterCubic));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerDeciMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * Math.Pow(LengthConv.DeciMeters.Multiplicator, 3),
|
||||
BaseContainerMultiplicator = Math.Pow(LengthConv.DeciMeters.Multiplicator, 3),
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / Math.Pow(LengthConv.DeciMeters.Multiplicator, 3);
|
||||
OnPropertyChanged(nameof(PerDeciMeterCubic));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * Math.Pow(LengthConv.Meters.Multiplicator, 3),
|
||||
BaseContainerMultiplicator = Math.Pow(LengthConv.Meters.Multiplicator, 3),
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / Math.Pow(LengthConv.Meters.Multiplicator, 3);
|
||||
OnPropertyChanged(nameof(PerMeterCubic));
|
||||
}
|
||||
}
|
||||
[NotMapped, JsonIgnore] public T PerKiloMeterCubic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new()
|
||||
{
|
||||
BaseContainer = this,
|
||||
SilentValueSetter = Value * Math.Pow(LengthConv.KiloMeters.Multiplicator, 3),
|
||||
BaseContainerMultiplicator = Math.Pow(LengthConv.KiloMeters.Multiplicator, 3),
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
Value = value.Value / Math.Pow(LengthConv.KiloMeters.Multiplicator, 3);
|
||||
OnPropertyChanged(nameof(PerKiloMeterCubic));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static T operator *(Udel<U, T> left, Volume right) => ((U)left).Protect()._PerMilliMeterCubic * right.Protect()._MilliMetersCubic;
|
||||
public static MetricCollection<T> operator *(Udel<U, T> left, MetricCollection<Volume> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricArray<T> operator *(Udel<U, T> left, MetricArray<Volume> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricList<T> operator *(Udel<U, T> left, MetricList<Volume> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
public static MetricObservableCollection<T> operator *(Udel<U, T> left, MetricObservableCollection<Volume> right) => right.MetricSelect(r => ((U)left).Protect() * r.Protect());
|
||||
|
||||
public static T operator *(Volume left, Udel<U, T> right) => ((U)right).Protect()._PerMilliMeterCubic * left.Protect()._MilliMetersCubic;
|
||||
public static MetricCollection<T> operator *(MetricCollection<Volume> left, Udel<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricArray<T> operator *(MetricArray<Volume> left, Udel<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricList<T> operator *(MetricList<Volume> left, Udel<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
public static MetricObservableCollection<T> operator *(MetricObservableCollection<Volume> left, Udel<U, T> right) => left.MetricSelect(r => ((U)right).Protect() * r.Protect());
|
||||
|
||||
public static Volume operator /(T left, Udel<U, T> right) => new() { _MilliMetersCubic = left.Protect() / ((U)right).Protect()._PerMilliMeterCubic };
|
||||
public static MetricCollection<Volume> operator *(MetricCollection<T> left, Udel<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricArray<Volume> operator *(MetricArray<T> left, Udel<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricList<Volume> operator *(MetricList<T> left, Udel<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
public static MetricObservableCollection<Volume> operator *(MetricObservableCollection<T> left, Udel<U, T> right) => left.MetricSelect(l => l.Protect() / ((U)right).Protect());
|
||||
}
|
||||
16
QWERTYkez.Mensura/Units/Udel/UdelForce.cs
Normal file
16
QWERTYkez.Mensura/Units/Udel/UdelForce.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
[Owned, JsonConverter(typeof(MetricFormatter<UdelForce>)), DebuggerDisplay("N/(m*mm2) = {PerMeter_PerMilliMeterSquared._Newtons.ToString(\"0.###\")}, kgf/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGramForces.ToString(\"0.###\")}")]
|
||||
public partial class UdelForce : Udel<UdelForce, Force>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(Area left, UdelForce right) => right * left;
|
||||
|
||||
[CollectionsOperatorsGenerator] public static PogonForce operator *(UdelForce left, Area right) => left.MultiplyProtected<UdelForce, Area, PogonForce>(right, PogonForceCoeff);
|
||||
static readonly double PogonForceCoeff = Coefficients.MultiplyCoefficient<UdelForce, Area, PogonForce>(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1);
|
||||
}
|
||||
|
||||
public partial class Volume : Metric<Volume, Volume>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static UdelForce operator /(Force left, Volume right) => left.DivideProtected<Force, Volume, UdelForce>(right, UdelForceCoeff);
|
||||
static readonly double UdelForceCoeff = Coefficients.DivideCoefficient<Force, Volume, UdelForce>(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1);
|
||||
}
|
||||
16
QWERTYkez.Mensura/Units/Udel/UdelMass (Density).cs
Normal file
16
QWERTYkez.Mensura/Units/Udel/UdelMass (Density).cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace MetricSystem;
|
||||
|
||||
[Owned, JsonConverter(typeof(MetricFormatter<Density>)), DebuggerDisplay("gr/(m*mm2) = {PerMeter_PerMilliMeterSquared._Grams.ToString(\"0.###\")}, kg/(m*mm2) = {PerMeter_PerMilliMeterSquared.KiloGrams.ToString(\"0.###\")}")]
|
||||
public partial class Density : Udel<Density, Mass>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static PogonMass operator *(Area left, Density right) => right * left;
|
||||
|
||||
[CollectionsOperatorsGenerator] public static PogonMass operator *(Density left, Area right) => left.MultiplyProtected<Density, Area, PogonMass>(right, PogonMassCoeff);
|
||||
static readonly double PogonMassCoeff = Coefficients.MultiplyCoefficient<Density, Area, PogonMass>(a => a._PerMilliMeterCubic.Value = 1, b => b._MilliMetersSquared = 1, r => r._PerMilliMeter.Value = 1);
|
||||
}
|
||||
|
||||
public partial class Volume : Metric<Volume, Volume>
|
||||
{
|
||||
[CollectionsOperatorsGenerator] public static Density operator /(Mass left, Volume right) => left.DivideProtected<Mass, Volume, Density>(right, DensityCoeff);
|
||||
static readonly double DensityCoeff = Coefficients.DivideCoefficient<Mass, Volume, Density>(a => a.Value = 1, b => b._MilliMetersCubic = 1, r => r._PerMilliMeterCubic.Value = 1);
|
||||
}
|
||||
55
QWERTYkez.Mensura/Units/Voltage.cs
Normal file
55
QWERTYkez.Mensura/Units/Voltage.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is Volts
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("V = {_Volts.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Voltage
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _Volts { get => Volts; init => Volts = value; }
|
||||
|
||||
public static Voltage Volt { get; } = new() { Volts = 1 };
|
||||
[NotMapped, JsonIgnore] public double Volts
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Voltage KiloVolt { get; } = new() { KiloVolts = 1 };
|
||||
[NotMapped, JsonIgnore] public double KiloVolts
|
||||
{
|
||||
get => VoltageConv.KiloVolts.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = VoltageConv.KiloVolts.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Voltage MegaVolt { get; } = new() { MegaVolts = 1 };
|
||||
[NotMapped, JsonIgnore] public double MegaVolts
|
||||
{
|
||||
get => VoltageConv.MegaVolts.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = VoltageConv.MegaVolts.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Voltage AddVolts(double value) => new(_Value + value);
|
||||
public Voltage AddKiloVolts(double value) => new(_Value + VoltageConv.KiloVolts.To(value));
|
||||
public Voltage AddMegaVolts(double value) => new(_Value + VoltageConv.MegaVolts.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct VoltageConv
|
||||
{
|
||||
private VoltageConv(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 VoltageConv Volts { get; } = new(1);
|
||||
public static VoltageConv KiloVolts { get; } = new(1000);
|
||||
public static VoltageConv MegaVolts { get; } = new(1000000);
|
||||
}
|
||||
55
QWERTYkez.Mensura/Units/Volume.cs
Normal file
55
QWERTYkez.Mensura/Units/Volume.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace QWERTYkez.Mensura.Units;
|
||||
|
||||
/// <summary>
|
||||
/// Base value is MilliMetersCubic
|
||||
/// </summary>
|
||||
[UnitOperatorsGenerator, DebuggerDisplay("mm3 = {_MilliMetersCubic.ToString(\"0.###\")}, m3 = {MetersCubic.ToString(\"0.###\")}")]
|
||||
public readonly partial record struct Volume
|
||||
{
|
||||
[NotMapped, JsonIgnore] public double _MilliMetersCubic { get => MilliMetersCubic; init => MilliMetersCubic = value; }
|
||||
|
||||
public static Volume MilliMeterCubic { get; } = new() { MilliMetersCubic = 1 };
|
||||
[NotMapped, JsonIgnore] public double MilliMetersCubic
|
||||
{
|
||||
get => _Value;
|
||||
init
|
||||
{
|
||||
_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Volume CentiMeterCubic { get; } = new() { CentiMetersCubic = 1 };
|
||||
[NotMapped, JsonIgnore] public double CentiMetersCubic
|
||||
{
|
||||
get => VolumeConv.CentiMetersCubic.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = VolumeConv.CentiMetersCubic.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Volume MeterCubic { get; } = new() { MetersCubic = 1 };
|
||||
[NotMapped, JsonIgnore] public double MetersCubic
|
||||
{
|
||||
get => VolumeConv.MetersCubic.From(_Value);
|
||||
init
|
||||
{
|
||||
_Value = VolumeConv.MetersCubic.To(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Volume AddMilliMetersCubic(double value) => new(_Value + value);
|
||||
public Volume AddCentiMetersCubic(double value) => new(_Value + VolumeConv.CentiMetersCubic.To(value));
|
||||
public Volume AddMetersCubic(double value) => new(_Value + VolumeConv.MetersCubic.To(value));
|
||||
}
|
||||
|
||||
internal readonly struct VolumeConv
|
||||
{
|
||||
private VolumeConv(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 VolumeConv MilliMetersCubic { get; } = new(1);
|
||||
public static VolumeConv CentiMetersCubic { get; } = new(1000);
|
||||
public static VolumeConv MetersCubic { get; } = new(1000000000);
|
||||
}
|
||||
@@ -7,12 +7,12 @@
|
||||
//public readonly partial record struct XXXXXXXXXXXXXX
|
||||
//{
|
||||
// [JsonInclude, DataMember, JsonPropertyName("v")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||
// internal double Value { get => _Value; init => _Value = value; }
|
||||
// internal double _Value { get => _Value; init => _Value = value; }
|
||||
// internal readonly double _Value;
|
||||
// internal XXXXXXXXXXXXXX(double value) => _Value = value;
|
||||
|
||||
// public override int GetHashCode() => _Value.GetHashCode();
|
||||
// public int CompareTo(XXXXXXXXXXXXXX? other) => _Value.CompareTo(other is null ? 0d : other.Value._Value);
|
||||
// public int CompareTo(XXXXXXXXXXXXXX? other) => _Value.CompareTo(other is null ? 0d : other._Value._Value);
|
||||
// public int CompareTo(XXXXXXXXXXXXXX other) => _Value.CompareTo(other._Value);
|
||||
|
||||
// public bool Equals(XXXXXXXXXXXXXX? other) => _Value.Equals(other?._Value);
|
||||
@@ -31,13 +31,13 @@
|
||||
// public static XXXXXXXXXXXXXX PositiveInfinity { get; } = new(double.PositiveInfinity);
|
||||
|
||||
|
||||
// public static bool operator ==(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) == (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator !=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) != (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator ==(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) == (T2 is null ? 0d : T2._Value._Value);
|
||||
// public static bool operator !=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) != (T2 is null ? 0d : T2._Value._Value);
|
||||
|
||||
// public static bool operator <(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) < (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator <=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) <= (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator >(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) > (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator >=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1.Value._Value) >= (T2 is null ? 0d : T2.Value._Value);
|
||||
// public static bool operator <(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) < (T2 is null ? 0d : T2._Value._Value);
|
||||
// public static bool operator <=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) <= (T2 is null ? 0d : T2._Value._Value);
|
||||
// public static bool operator >(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) > (T2 is null ? 0d : T2._Value._Value);
|
||||
// public static bool operator >=(XXXXXXXXXXXXXX? T1, XXXXXXXXXXXXXX? T2) => (T1 is null ? 0d : T1._Value._Value) >= (T2 is null ? 0d : T2._Value._Value);
|
||||
|
||||
|
||||
// public static XXXXXXXXXXXXXX operator +(XXXXXXXXXXXXXX T2) => new(+T2._Value);
|
||||
@@ -180,7 +180,7 @@
|
||||
// /// <summary>C^2 = this^2 + B^2</summary> <returns>C = (this^2 + B^2).Sqrt(2)</returns>
|
||||
// public XXXXXXXXXXXXXX HypFromLeg(XXXXXXXXXXXXXX? B)
|
||||
// {
|
||||
// double b = B is null ? 0d : B.Value._Value;
|
||||
// double b = B is null ? 0d : B._Value._Value;
|
||||
// return new(Math.Sqrt(_Value * _Value + b * b));
|
||||
// }
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
// /// <summary>C^2 = this^2 + B^2</summary> <returns>B = (C^2 - this^2).Sqrt(2)</returns>
|
||||
// public XXXXXXXXXXXXXX LegFromHyp(XXXXXXXXXXXXXX? C)
|
||||
// {
|
||||
// double c = C is null ? 0d : C.Value._Value;
|
||||
// double c = C is null ? 0d : C._Value._Value;
|
||||
// return new(Math.Sqrt(c * c - _Value * _Value));
|
||||
// }
|
||||
|
||||
@@ -200,24 +200,24 @@
|
||||
// /// <summary>this^2 = A^2 + B^2</summary> <returns>B = (this^2 - A^2).Sqrt(2)</returns>
|
||||
// public XXXXXXXXXXXXXX LegFromLeg(XXXXXXXXXXXXXX? A)
|
||||
// {
|
||||
// double a = A is null ? 0d : A.Value._Value;
|
||||
// double a = A is null ? 0d : A._Value._Value;
|
||||
// return new(Math.Sqrt(_Value * _Value - a * a));
|
||||
// }
|
||||
//}
|
||||
|
||||
//public static class XXXXXXXXXXXXXXExtension
|
||||
//{
|
||||
// internal static double ToDouble(this XXXXXXXXXXXXXX? unit) => unit is null ? 0d : unit.Value._Value;
|
||||
// internal static double ToDouble(this XXXXXXXXXXXXXX? unit) => unit is null ? 0d : unit._Value._Value;
|
||||
|
||||
// public static XXXXXXXXXXXXXX MetricSum(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { Value = units?.Sum(m => m._Value) ?? 0d };
|
||||
// public static XXXXXXXXXXXXXX MetricAverage(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { Value = units?.Average(m => m._Value) ?? double.NaN };
|
||||
// public static XXXXXXXXXXXXXX MetricMax(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { Value = units?.Max(m => m._Value) ?? double.MinValue };
|
||||
// public static XXXXXXXXXXXXXX MetricMin(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { Value = units?.Min(m => m._Value) ?? double.MaxValue };
|
||||
// public static XXXXXXXXXXXXXX MetricSum(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { _Value = units?.Sum(m => m._Value) ?? 0d };
|
||||
// public static XXXXXXXXXXXXXX MetricAverage(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { _Value = units?.Average(m => m._Value) ?? double.NaN };
|
||||
// public static XXXXXXXXXXXXXX MetricMax(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { _Value = units?.Max(m => m._Value) ?? double.MinValue };
|
||||
// public static XXXXXXXXXXXXXX MetricMin(this IEnumerable<XXXXXXXXXXXXXX> units) => new() { _Value = units?.Min(m => m._Value) ?? double.MaxValue };
|
||||
|
||||
// public static XXXXXXXXXXXXXX MetricSum(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { Value = units?.Sum(m => m.ToDouble()) ?? 0d };
|
||||
// public static XXXXXXXXXXXXXX MetricAverage(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { Value = units?.Average(m => m.ToDouble()) ?? double.NaN };
|
||||
// public static XXXXXXXXXXXXXX MetricMax(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { Value = units?.Max(m => m.ToDouble()) ?? double.MinValue };
|
||||
// public static XXXXXXXXXXXXXX MetricMin(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { Value = units?.Min(m => m.ToDouble()) ?? double.MaxValue };
|
||||
// public static XXXXXXXXXXXXXX MetricSum(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { _Value = units?.Sum(m => m.ToDouble()) ?? 0d };
|
||||
// public static XXXXXXXXXXXXXX MetricAverage(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { _Value = units?.Average(m => m.ToDouble()) ?? double.NaN };
|
||||
// public static XXXXXXXXXXXXXX MetricMax(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { _Value = units?.Max(m => m.ToDouble()) ?? double.MinValue };
|
||||
// public static XXXXXXXXXXXXXX MetricMin(this IEnumerable<XXXXXXXXXXXXXX?> units) => new() { _Value = units?.Min(m => m.ToDouble()) ?? double.MaxValue };
|
||||
|
||||
|
||||
// internal static void MultiplyCore(ReadOnlySpan<XXXXXXXXXXXXXX> source, double value, Span<XXXXXXXXXXXXXX> destination)
|
||||
@@ -226,7 +226,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(value);
|
||||
// var vectorized_Value = new Vector<double>(value);
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
// ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
// ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
// var vector = new Vector<double>(srcWindow);
|
||||
// var multiplied = vector * vectorizedValue;
|
||||
// var multiplied = vector * vectorized_Value;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -260,7 +260,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(divisor);
|
||||
// var vectorized_Value = new Vector<double>(divisor);
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
|
||||
@@ -273,7 +273,7 @@
|
||||
// ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
// ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
// var vector = new Vector<double>(srcWindow);
|
||||
// var multiplied = vector / vectorizedValue;
|
||||
// var multiplied = vector / vectorized_Value;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -290,7 +290,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(dividend);
|
||||
// var vectorized_Value = new Vector<double>(dividend);
|
||||
// var zeroVector = Vector<double>.Zero; // Вектор из нулей для сравнения
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
@@ -311,7 +311,7 @@
|
||||
// throw new DivideByZeroException($"Обнаружен делитель, равный нулю, в районе индексов {i}..{i + vectorSize - 1}.");
|
||||
// }
|
||||
|
||||
// var multiplied = vectorizedValue / vector;
|
||||
// var multiplied = vectorized_Value / vector;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -334,7 +334,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(summand);
|
||||
// var vectorized_Value = new Vector<double>(summand);
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
|
||||
@@ -347,7 +347,7 @@
|
||||
// ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
// ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
// var vector = new Vector<double>(srcWindow);
|
||||
// var multiplied = vector + vectorizedValue;
|
||||
// var multiplied = vector + vectorized_Value;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -364,7 +364,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(subtrahend);
|
||||
// var vectorized_Value = new Vector<double>(subtrahend);
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
|
||||
@@ -377,7 +377,7 @@
|
||||
// ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
// ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
// var vector = new Vector<double>(srcWindow);
|
||||
// var multiplied = vector - vectorizedValue;
|
||||
// var multiplied = vector - vectorized_Value;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -394,7 +394,7 @@
|
||||
// ReadOnlySpan<double> srcDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(source);
|
||||
// Span<double> dstDouble = MemoryMarshal.Cast<XXXXXXXXXXXXXX, double>(destination);
|
||||
|
||||
// var vectorizedValue = new Vector<double>(minuend);
|
||||
// var vectorized_Value = new Vector<double>(minuend);
|
||||
// int vectorSize = Vector<double>.Count;
|
||||
// int i = 0;
|
||||
|
||||
@@ -407,7 +407,7 @@
|
||||
// ref double currentSrc = ref Unsafe.Add(ref srcRef, i);
|
||||
// ReadOnlySpan<double> srcWindow = MemoryMarshal.CreateReadOnlySpan(ref currentSrc, vectorSize);
|
||||
// var vector = new Vector<double>(srcWindow);
|
||||
// var multiplied = vectorizedValue - vector;
|
||||
// var multiplied = vectorized_Value - vector;
|
||||
// ref double currentDst = ref Unsafe.Add(ref dstRef, i);
|
||||
// Span<double> dstWindow = MemoryMarshal.CreateSpan(ref currentDst, vectorSize);
|
||||
// multiplied.CopyTo(dstWindow);
|
||||
@@ -447,7 +447,7 @@
|
||||
// if (exp < 0)
|
||||
// {
|
||||
// baseVector = Vector<double>.One / baseVector;
|
||||
// exp = -exp; // Внимание: может переполниться при int.MinValue, но для степеней это редчайший кейс
|
||||
// exp = -exp; // Внимание: может переполниться при int.Min_Value, но для степеней это редчайший кейс
|
||||
// }
|
||||
|
||||
// var result = Vector<double>.One;
|
||||
@@ -558,7 +558,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value * multiplicator);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value * multiplicator);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -585,7 +585,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value * multiplicator);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value * multiplicator);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -617,7 +617,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value * multiplicator);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value * multiplicator);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -646,7 +646,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? item.Value._Value * multiplicator : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? item._Value._Value * multiplicator : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
// public static Tcoll Multiply<Tcoll>(this double multiplicator, ICollection<XXXXXXXXXXXXXX?> units)
|
||||
@@ -665,8 +665,8 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(item.Value._Value * multiplicator) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(item._Value._Value * multiplicator) : null;
|
||||
// }
|
||||
// public static IEnumerable<XXXXXXXXXXXXXX?> Multiply(this double multiplicator, IEnumerable<XXXXXXXXXXXXXX?> units)
|
||||
// => units.Multiply(multiplicator);
|
||||
@@ -706,7 +706,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value / divisor);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value / divisor);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -720,7 +720,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(dividend / item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(dividend / item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -754,7 +754,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value / divisor);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value / divisor);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -768,7 +768,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(dividend / item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(dividend / item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -809,7 +809,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value / divisor);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value / divisor);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -824,7 +824,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(dividend / item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(dividend / item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -860,7 +860,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? item.Value._Value / divisor : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? item._Value._Value / divisor : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
// public static Tcoll Divide<Tcoll>(this double dividend, ICollection<XXXXXXXXXXXXXX?> units)
|
||||
@@ -871,7 +871,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? dividend / item.Value._Value : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? dividend / item._Value._Value : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
|
||||
@@ -892,15 +892,15 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(item.Value._Value * divisor) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(item._Value._Value * divisor) : null;
|
||||
// }
|
||||
// public static IEnumerable<XXXXXXXXXXXXXX?> Divide(this double dividend, IEnumerable<XXXXXXXXXXXXXX?> units)
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(dividend / item.Value._Value) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(dividend / item._Value._Value) : null;
|
||||
// }
|
||||
|
||||
// // ==========================================
|
||||
@@ -928,7 +928,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value + summand);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value + summand);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -955,7 +955,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value + summand);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value + summand);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -987,7 +987,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value + summand);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value + summand);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1016,7 +1016,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? item.Value._Value + summand : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? item._Value._Value + summand : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
// public static Tcoll Plus<Tcoll>(this double summand, ICollection<XXXXXXXXXXXXXX?> units)
|
||||
@@ -1035,8 +1035,8 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(item.Value._Value + summand) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(item._Value._Value + summand) : null;
|
||||
// }
|
||||
// public static IEnumerable<XXXXXXXXXXXXXX?> Plus(this double summand, IEnumerable<XXXXXXXXXXXXXX?> units)
|
||||
// => units.Plus(summand);
|
||||
@@ -1073,7 +1073,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value - subtrahend);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value - subtrahend);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1087,7 +1087,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(minuend - item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(minuend - item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1117,7 +1117,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value - subtrahend);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value - subtrahend);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1131,7 +1131,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(minuend - item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(minuend - item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1170,7 +1170,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value - subtrahend);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value - subtrahend);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1185,7 +1185,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(minuend - item.Value._Value);
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(minuend - item._Value._Value);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1221,7 +1221,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? item.Value._Value - subtrahend : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? item._Value._Value - subtrahend : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
// public static Tcoll Minus<Tcoll>(this double minuend, ICollection<XXXXXXXXXXXXXX?> units)
|
||||
@@ -1232,7 +1232,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? minuend - item.Value._Value : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? minuend - item._Value._Value : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
|
||||
@@ -1253,15 +1253,15 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(item.Value._Value - subtrahend) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(item._Value._Value - subtrahend) : null;
|
||||
// }
|
||||
// public static IEnumerable<XXXXXXXXXXXXXX?> Minus(this double minuend, IEnumerable<XXXXXXXXXXXXXX?> units)
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(minuend - item.Value._Value) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(minuend - item._Value._Value) : null;
|
||||
// }
|
||||
|
||||
// // ==========================================
|
||||
@@ -1287,10 +1287,10 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue)
|
||||
// if (item.Has_Value)
|
||||
// {
|
||||
// // Используем тот же быстрый QuickPow, что и в ядре, чтобы не вызывать тяжелый Math.Pow
|
||||
// item = new XXXXXXXXXXXXXX(item.Value._Value.QuickPow(power));
|
||||
// item = new XXXXXXXXXXXXXX(item._Value._Value.QuickPow(power));
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
@@ -1313,7 +1313,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value.QuickPow(power));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value.QuickPow(power));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1341,7 +1341,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(item.Value._Value.QuickPow(power));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(item._Value._Value.QuickPow(power));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1366,7 +1366,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? item.Value._Value.QuickPow(power) : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? item._Value._Value.QuickPow(power) : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
|
||||
@@ -1381,8 +1381,8 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(item.Value._Value.QuickPow(power)) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(item._Value._Value.QuickPow(power)) : null;
|
||||
// }
|
||||
|
||||
// // ==========================================
|
||||
@@ -1408,9 +1408,9 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue)
|
||||
// if (item.Has_Value)
|
||||
// {
|
||||
// item = new XXXXXXXXXXXXXX(Math.Pow(item.Value._Value, power));
|
||||
// item = new XXXXXXXXXXXXXX(Math.Pow(item._Value._Value, power));
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
@@ -1433,7 +1433,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(Math.Pow(item.Value._Value, power));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(Math.Pow(item._Value._Value, power));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1461,7 +1461,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(Math.Pow(item.Value._Value, power));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(Math.Pow(item._Value._Value, power));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1486,7 +1486,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? Math.Pow(item.Value._Value, power) : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? Math.Pow(item._Value._Value, power) : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
|
||||
@@ -1501,8 +1501,8 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(Math.Pow(item.Value._Value, power)) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(Math.Pow(item._Value._Value, power)) : null;
|
||||
// }
|
||||
|
||||
|
||||
@@ -1529,9 +1529,9 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue)
|
||||
// if (item.Has_Value)
|
||||
// {
|
||||
// item = new XXXXXXXXXXXXXX(Math.Sqrt(item.Value._Value));
|
||||
// item = new XXXXXXXXXXXXXX(Math.Sqrt(item._Value._Value));
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
@@ -1554,7 +1554,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref result[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(Math.Sqrt(item.Value._Value));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(Math.Sqrt(item._Value._Value));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1582,7 +1582,7 @@
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// ref var item = ref dstSpan[i];
|
||||
// if (item.HasValue) item = new XXXXXXXXXXXXXX(Math.Sqrt(item.Value._Value));
|
||||
// if (item.Has_Value) item = new XXXXXXXXXXXXXX(Math.Sqrt(item._Value._Value));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@@ -1607,7 +1607,7 @@
|
||||
// if (tColl is List<XXXXXXXXXXXXXX> list)
|
||||
// list.Capacity = units.Count;
|
||||
// foreach (var item in units)
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.HasValue ? Math.Sqrt(item.Value._Value) : 0d));
|
||||
// tColl.Add(new XXXXXXXXXXXXXX(item.Has_Value ? Math.Sqrt(item._Value._Value) : 0d));
|
||||
// return tColl;
|
||||
// }
|
||||
|
||||
@@ -1622,8 +1622,8 @@
|
||||
// {
|
||||
// ArgumentNullException.ThrowIfNull(units);
|
||||
// foreach (var item in units)
|
||||
// yield return item.HasValue
|
||||
// ? new XXXXXXXXXXXXXX(Math.Sqrt(item.Value._Value)) : null;
|
||||
// yield return item.Has_Value
|
||||
// ? new XXXXXXXXXXXXXX(Math.Sqrt(item._Value._Value)) : null;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1634,12 +1634,12 @@
|
||||
|
||||
// public override XXXXXXXXXXXXXX Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
// {
|
||||
// double doubleValue;
|
||||
// double double_Value;
|
||||
|
||||
// if (reader.TokenType == JsonTokenType.String)
|
||||
// {
|
||||
// // Безопасно парсим double из строки с поддержкой точки как разделителя
|
||||
// if (!double.TryParse(reader.GetString(), NumberStyles.Float, Culture, out doubleValue))
|
||||
// if (!double.TryParse(reader.GetString(), NumberStyles.Float, Culture, out double_Value))
|
||||
// {
|
||||
// throw new JsonException($"Не удалось преобразовать строковое значение в double для метрики {nameof(XXXXXXXXXXXXXX)}.");
|
||||
// }
|
||||
@@ -1647,10 +1647,10 @@
|
||||
// else
|
||||
// {
|
||||
// // Прямое быстрое чтение числа из JSON
|
||||
// doubleValue = reader.GetDouble();
|
||||
// double_Value = reader.GetDouble();
|
||||
// }
|
||||
|
||||
// return new(doubleValue);
|
||||
// return new(double_Value);
|
||||
// }
|
||||
|
||||
// public override void Write(Utf8JsonWriter writer, XXXXXXXXXXXXXX value, JsonSerializerOptions options)
|
||||
@@ -1671,11 +1671,11 @@
|
||||
// {
|
||||
// string propertyName = reader.GetString()!;
|
||||
|
||||
// if (!double.TryParse(propertyName, NumberStyles.Float, Culture, out double doubleValue))
|
||||
// if (!double.TryParse(propertyName, NumberStyles.Float, Culture, out double double_Value))
|
||||
// {
|
||||
// throw new JsonException($"Невалидное числовое значение в ключе свойства JSON: '{propertyName}' для метрики {nameof(XXXXXXXXXXXXXX)}.");
|
||||
// }
|
||||
|
||||
// return new(doubleValue);
|
||||
// return new(double_Value);
|
||||
// }
|
||||
//}
|
||||
@@ -10,4 +10,5 @@ global using System.Runtime.CompilerServices;
|
||||
global using System.Runtime.InteropServices;
|
||||
global using System.Text.Json;
|
||||
global using System.Text.Json.Serialization;
|
||||
global using QWERTYkez.Mensura;
|
||||
global using QWERTYkez.Mensura;
|
||||
global using QWERTYkez.Mensura.Units;
|
||||
Reference in New Issue
Block a user