26.06.04
This commit is contained in:
@@ -103,9 +103,8 @@ public class {typeName}Converter : UnitJsonConverter<{typeName}> { }
|
|||||||
[JsonConverter(typeof({typeName}Converter))]
|
[JsonConverter(typeof({typeName}Converter))]
|
||||||
public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEquatable<{typeName}>, IMensuraUnit
|
public readonly partial record struct {typeName} : IMensuraUnit<{typeName}>, IEquatable<{typeName}>, IMensuraUnit
|
||||||
{
|
{
|
||||||
[JsonInclude, DataMember, JsonPropertyName(""v"")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
[JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||||
internal double Value { get => _Value; init => _Value = value; }
|
internal double Value { get => _Value; init => _Value = value; }
|
||||||
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
|
|
||||||
internal readonly double _Value;
|
internal readonly double _Value;
|
||||||
internal {typeName}(double value) => _Value = value;
|
internal {typeName}(double value) => _Value = value;
|
||||||
|
|
||||||
|
|||||||
@@ -53,4 +53,36 @@ public static partial class CastExtensions
|
|||||||
{
|
{
|
||||||
return Unsafe.As<T[], R[]>(ref array).WrapAsList();
|
return Unsafe.As<T[], R[]>(ref array).WrapAsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R> ReCast<T, R>(this List<T> list)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
return Unsafe.As<List<T>, List<R>>(ref list);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R?> ReCast<T, R>(this List<T?> list)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
return Unsafe.As<List<T?>, List<R?>>(ref list);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R[] ReCast<T, R>(this T[] array)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
return Unsafe.As<T[], R[]>(ref array);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R?[] ReCast<T, R>(this T?[] array)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
return Unsafe.As<T?[], R?[]>(ref array);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +164,378 @@ public static partial class CollectionsDivideExtensions
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// === Array ===
|
||||||
|
internal static R[] Divide<T, R>(this T[] units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
units.DivideCore(divisor, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Divide<T, R>(this T?[] units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
units.DivideCore(divisor, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R[] Divide<T, R>(this double dividend, T[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
dividend.DivideCore(units, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Divide<T, R>(this double dividend, T?[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
dividend.DivideCore(units, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === List<T> ===
|
||||||
|
internal static List<R> Divide<T, R>(this List<T> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
DivideCore(CollectionsMarshal.AsSpan(units), divisor, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Divide<T, R>(this List<T?> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
DivideCore(CollectionsMarshal.AsSpan(units), divisor, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R> Divide<T, R>(this double dividend, List<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
DivideCore(dividend, CollectionsMarshal.AsSpan(units), count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Divide<T, R>(this double dividend, List<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
DivideCore(dividend, CollectionsMarshal.AsSpan(units), count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === ICollection<T> ===
|
||||||
|
internal static void Divide<T, R>(this ICollection<T> units, double divisor, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { DivideCore(array, divisor, count, destination); return; }
|
||||||
|
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).DivideCore(divisor, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() * invDivisor).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this ICollection<T?> units, double divisor, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { array.DivideCore(divisor, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).DivideCore(divisor, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() * invDivisor).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this double dividend, ICollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { dividend.DivideCore(array, count, destination); return; }
|
||||||
|
if (units is List<T> list) { dividend.DivideCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (dividend / item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this double dividend, ICollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { dividend.DivideCore(array, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { dividend.DivideCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (dividend / item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IReadOnlyCollection<T> ===
|
||||||
|
internal static void Divide<T, R>(this IReadOnlyCollection<T> units, double divisor, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { array.DivideCore(divisor, count, destination); return; }
|
||||||
|
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).DivideCore(divisor, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() * invDivisor).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this IReadOnlyCollection<T?> units, double divisor, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { array.DivideCore(divisor, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).DivideCore(divisor, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() * invDivisor).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this double dividend, IReadOnlyCollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { dividend.DivideCore(array, count, destination); return; }
|
||||||
|
if (units is List<T> list) { dividend.DivideCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (dividend / item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Divide<T, R>(this double dividend, IReadOnlyCollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { dividend.DivideCore(array, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { dividend.DivideCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (dividend / item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> + yeild ===
|
||||||
|
static IEnumerable<R> DivideIterator<T, R>(IEnumerable<T> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (item.ToDouble() * invDivisor).ToUnit<R>();
|
||||||
|
}
|
||||||
|
static IEnumerable<R?> DivideNullableIterator<T, R>(IEnumerable<T?> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
double invDivisor = 1.0 / divisor;
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (item.Value.ToDouble() * invDivisor).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
static IEnumerable<R> DivideIterator<T, R>(double dividend, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (dividend / item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
static IEnumerable<R?> DivideNullableIterator<T, R>(double dividend, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (dividend / item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> ===
|
||||||
|
internal static IEnumerable<R> Divide<T, R>(this IEnumerable<T> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return array.Divide<T, R>(divisor);
|
||||||
|
if (units is List<T> list) return list.Divide<T, R>(divisor);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Divide(divisor, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Divide(divisor, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return DivideIterator<T, R>(units, divisor);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Divide<T, R>(this IEnumerable<T?> units, double divisor)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return array.Divide<T, R>(divisor);
|
||||||
|
if (units is List<T?> list) return list.Divide<T, R>(divisor);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Divide(divisor, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Divide(divisor, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return DivideNullableIterator<T, R>(units, divisor);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R> Divide<T, R>(this double dividend, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return dividend.Divide<T, R>(array);
|
||||||
|
if (units is List<T> list) return dividend.Divide<T, R>(list);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
dividend.Divide(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
dividend.Divide(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return DivideIterator<T, R>(dividend, units);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Divide<T, R>(this double dividend, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return dividend.Divide<T, R>(array);
|
||||||
|
if (units is List<T?> list) return dividend.Divide<T, R>(list);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
dividend.Divide(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
dividend.Divide(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return DivideNullableIterator<T, R>(dividend, units);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// === ReadOnlySpan
|
// === ReadOnlySpan
|
||||||
public static void Divide<T>(this ReadOnlySpan<T> units, double divisor, Span<T> destination)
|
public static void Divide<T>(this ReadOnlySpan<T> units, double divisor, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
@@ -477,14 +849,14 @@ public static partial class CollectionsDivideExtensions
|
|||||||
if (units is List<T> list) return list.Divide(divisor);
|
if (units is List<T> list) return list.Divide(divisor);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Divide(divisor, arr);
|
arr.Divide(divisor, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Divide(divisor, arr);
|
arr.Divide(divisor, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return DivideIterator(units, divisor);
|
return DivideIterator(units, divisor);
|
||||||
@@ -497,14 +869,14 @@ public static partial class CollectionsDivideExtensions
|
|||||||
if (units is List<T?> list) return list.Divide(divisor);
|
if (units is List<T?> list) return list.Divide(divisor);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Divide(divisor, arr);
|
arr.Divide(divisor, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Divide(divisor, arr);
|
arr.Divide(divisor, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return DivideNullableIterator(units, divisor);
|
return DivideNullableIterator(units, divisor);
|
||||||
@@ -517,14 +889,14 @@ public static partial class CollectionsDivideExtensions
|
|||||||
if (units is List<T> list) return dividend.Divide(list);
|
if (units is List<T> list) return dividend.Divide(list);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
dividend.Divide(col, arr);
|
dividend.Divide(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
dividend.Divide(roc, arr);
|
dividend.Divide(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return DivideIterator(dividend, units);
|
return DivideIterator(dividend, units);
|
||||||
@@ -537,14 +909,14 @@ public static partial class CollectionsDivideExtensions
|
|||||||
if (units is List<T?> list) return dividend.Divide(list);
|
if (units is List<T?> list) return dividend.Divide(list);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
dividend.Divide(col, arr);
|
dividend.Divide(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
dividend.Divide(roc, arr);
|
dividend.Divide(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return DivideNullableIterator(dividend, units);
|
return DivideNullableIterator(dividend, units);
|
||||||
|
|||||||
@@ -159,6 +159,372 @@ public static partial class CollectionsMinusExtensions
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// === Array ===
|
||||||
|
internal static R[] Minus<T, R>(this T[] units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
MinusCore(units, subtrahend, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Minus<T, R>(this T?[] units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
MinusCore(units, subtrahend, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R[] Minus<T, R>(this double minuend, T[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
MinusCore(minuend, units, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Minus<T, R>(this double minuend, T?[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
MinusCore(minuend, units, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === List<T> ===
|
||||||
|
internal static List<R> Minus<T, R>(this List<T> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
MinusCore(CollectionsMarshal.AsSpan(units), subtrahend, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Minus<T, R>(this List<T?> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
MinusCore(CollectionsMarshal.AsSpan(units), subtrahend, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R> Minus<T, R>(this double minuend, List<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
MinusCore(minuend, CollectionsMarshal.AsSpan(units), count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Minus<T, R>(this double minuend, List<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
MinusCore(minuend, CollectionsMarshal.AsSpan(units), count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === ICollection<T> ===
|
||||||
|
internal static void Minus<T, R>(this ICollection<T> units, double subtrahend, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { array.MinusCore(subtrahend, count, destination); return; }
|
||||||
|
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).MinusCore(subtrahend, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() - subtrahend).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this ICollection<T?> units, double subtrahend, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { array.MinusCore(subtrahend, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).MinusCore(subtrahend, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() - subtrahend).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this double minuend, ICollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { minuend.MinusCore(array, count, destination); return; }
|
||||||
|
if (units is List<T> list) { minuend.MinusCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (minuend - item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this double minuend, ICollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { minuend.MinusCore(array, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { minuend.MinusCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (minuend - item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IReadOnlyCollection<T> ===
|
||||||
|
internal static void Minus<T, R>(this IReadOnlyCollection<T> units, double subtrahend, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { array.MinusCore(subtrahend, count, destination); return; }
|
||||||
|
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).MinusCore(subtrahend, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() - subtrahend).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this IReadOnlyCollection<T?> units, double subtrahend, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { array.MinusCore(subtrahend, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).MinusCore(subtrahend, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() - subtrahend).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this double minuend, IReadOnlyCollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { minuend.MinusCore(array, count, destination); return; }
|
||||||
|
if (units is List<T> list) { minuend.MinusCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (minuend - item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Minus<T, R>(this double minuend, IReadOnlyCollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { minuend.MinusCore(array, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { minuend.MinusCore(CollectionsMarshal.AsSpan(list), count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (minuend - item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> + yeild ===
|
||||||
|
static IEnumerable<R> MinusIterator<T, R>(IEnumerable<T> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (item.ToDouble() - subtrahend).ToUnit<R>();
|
||||||
|
}
|
||||||
|
static IEnumerable<R?> MinusNullableIterator<T, R>(IEnumerable<T?> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (item.Value.ToDouble() - subtrahend).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
static IEnumerable<R> MinusIterator<T, R>(double minuend, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (minuend - item.ToDouble()).ToUnit<R>();
|
||||||
|
}
|
||||||
|
static IEnumerable<R?> MinusNullableIterator<T, R>(double minuend, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (minuend - item.Value.ToDouble()).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> ===
|
||||||
|
internal static IEnumerable<R> Minus<T, R>(this IEnumerable<T> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return array.Minus<T, R>(subtrahend);
|
||||||
|
if (units is List<T> list) return list.Minus<T, R>(subtrahend);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Minus(subtrahend, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Minus(subtrahend, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MinusIterator<T, R>(units, subtrahend);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Minus<T, R>(this IEnumerable<T?> units, double subtrahend)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return array.Minus<T, R>(subtrahend);
|
||||||
|
if (units is List<T?> list) return list.Minus<T, R>(subtrahend);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Minus(subtrahend, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Minus(subtrahend, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MinusNullableIterator<T, R>(units, subtrahend);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R> Minus<T, R>(this double minuend, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return minuend.Minus<T, R>(array);
|
||||||
|
if (units is List<T> list) return minuend.Minus<T, R>(list);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
minuend.Minus(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
minuend.Minus(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MinusIterator<T, R>(minuend, units);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Minus<T, R>(this double minuend, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return minuend.Minus<T, R>(array);
|
||||||
|
if (units is List<T?> list) return minuend.Minus<T, R>(list);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
minuend.Minus(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
minuend.Minus(arr, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MinusNullableIterator<T, R>(minuend, units);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// === ReadOnlySpan
|
// === ReadOnlySpan
|
||||||
public static void Minus<T>(this ReadOnlySpan<T> units, double subtrahend, Span<T> destination)
|
public static void Minus<T>(this ReadOnlySpan<T> units, double subtrahend, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
@@ -467,14 +833,14 @@ public static partial class CollectionsMinusExtensions
|
|||||||
if (units is List<T> list) return list.Minus(subtrahend);
|
if (units is List<T> list) return list.Minus(subtrahend);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Minus(subtrahend, arr);
|
arr.Minus(subtrahend, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Minus(subtrahend, arr);
|
arr.Minus(subtrahend, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MinusIterator(units, subtrahend);
|
return MinusIterator(units, subtrahend);
|
||||||
@@ -487,14 +853,14 @@ public static partial class CollectionsMinusExtensions
|
|||||||
if (units is List<T?> list) return list.Minus(subtrahend);
|
if (units is List<T?> list) return list.Minus(subtrahend);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Minus(subtrahend, arr);
|
arr.Minus(subtrahend, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Minus(subtrahend, arr);
|
arr.Minus(subtrahend, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MinusNullableIterator(units, subtrahend);
|
return MinusNullableIterator(units, subtrahend);
|
||||||
@@ -507,14 +873,14 @@ public static partial class CollectionsMinusExtensions
|
|||||||
if (units is List<T> list) return minuend.Minus(list);
|
if (units is List<T> list) return minuend.Minus(list);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
minuend.Minus(col, arr);
|
minuend.Minus(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
minuend.Minus(roc, arr);
|
minuend.Minus(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MinusIterator(minuend, units);
|
return MinusIterator(minuend, units);
|
||||||
@@ -527,14 +893,14 @@ public static partial class CollectionsMinusExtensions
|
|||||||
if (units is List<T?> list) return minuend.Minus(list);
|
if (units is List<T?> list) return minuend.Minus(list);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
minuend.Minus(col, arr);
|
minuend.Minus(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
minuend.Minus(roc, arr);
|
minuend.Minus(arr, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MinusNullableIterator(minuend, units);
|
return MinusNullableIterator(minuend, units);
|
||||||
|
|||||||
@@ -90,6 +90,246 @@ public static partial class CollectionsMultiplyExtensions
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// === Array ===
|
||||||
|
internal static R[] Multiply<T, R>(this T[] units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
units.MultiplyCore(multiplicator, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Multiply<T, R>(this T?[] units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
units.MultiplyCore(multiplicator, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R[] Multiply<T, R>(this double multiplicator, T[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply<T, R>(multiplicator);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R?[] Multiply<T, R>(this double multiplicator, T?[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply<T, R>(multiplicator);
|
||||||
|
|
||||||
|
// === List<T> ===
|
||||||
|
internal static List<R> Multiply<T, R>(this List<T> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
MultiplyCore(CollectionsMarshal.AsSpan(units), multiplicator, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Multiply<T, R>(this List<T?> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
MultiplyCore(CollectionsMarshal.AsSpan(units), multiplicator, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R> Multiply<T, R>(this double multiplicator, List<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply<T, R>(multiplicator);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R?> Multiply<T, R>(this double multiplicator, List<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply<T, R>(multiplicator);
|
||||||
|
|
||||||
|
// === ICollection<T> ===
|
||||||
|
internal static void Multiply<T, R>(this ICollection<T> units, double multiplicator, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { MultiplyCore(array, multiplicator, count, destination); return; }
|
||||||
|
if (units is List<T> list) { MultiplyCore(CollectionsMarshal.AsSpan(list), multiplicator, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() * multiplicator).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Multiply<T, R>(this ICollection<T?> units, double multiplicator, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { MultiplyCore(array, multiplicator, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { MultiplyCore(CollectionsMarshal.AsSpan(list), multiplicator, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() * multiplicator).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Multiply<T, R>(this double multiplicator, ICollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply(multiplicator, destination);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Multiply<T, R>(this double multiplicator, ICollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply(multiplicator, destination);
|
||||||
|
|
||||||
|
// === IReadOnlyCollection<T> ===
|
||||||
|
internal static void Multiply<T, R>(this IReadOnlyCollection<T> units, double multiplicator, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { MultiplyCore(array, multiplicator, count, destination); return; }
|
||||||
|
if (units is List<T> list) { MultiplyCore(CollectionsMarshal.AsSpan(list), multiplicator, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() * multiplicator).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Multiply<T, R>(this IReadOnlyCollection<T?> units, double multiplicator, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { MultiplyCore(array, multiplicator, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { MultiplyCore(CollectionsMarshal.AsSpan(list), multiplicator, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() * multiplicator).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Multiply<T, R>(this double multiplicator, IReadOnlyCollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply(multiplicator, destination);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Multiply<T, R>(this double multiplicator, IReadOnlyCollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Multiply(multiplicator, destination);
|
||||||
|
|
||||||
|
// === IEnumerable<T> + yeild ===
|
||||||
|
internal static IEnumerable<R> MultiplyIterator<T, R>(this IEnumerable<T> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (item.ToDouble() * multiplicator).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> MultiplyNullableIterator<T, R>(this IEnumerable<T?> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (item.Value.ToDouble() * multiplicator).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> ===
|
||||||
|
internal static IEnumerable<R> Multiply<T, R>(this IEnumerable<T> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return array.Multiply<T, R>(multiplicator);
|
||||||
|
if (units is List<T> list) return list.Multiply<T, R>(multiplicator);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Multiply(multiplicator, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Multiply(multiplicator, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MultiplyIterator<T, R>(units, multiplicator);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Multiply<T, R>(this IEnumerable<T?> units, double multiplicator)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return array.Multiply<T, R>(multiplicator);
|
||||||
|
if (units is List<T?> list) return list.Multiply<T, R>(multiplicator);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Multiply(multiplicator, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Multiply(multiplicator, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return MultiplyNullableIterator<T, R>(units, multiplicator);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static IEnumerable<R> Multiply<T, R>(this double multiplicator, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => Multiply<T, R>(units, multiplicator);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static IEnumerable<R?> Multiply<T, R>(this double multiplicator, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => Multiply<T, R>(units, multiplicator);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// === ReadOnlySpan
|
// === ReadOnlySpan
|
||||||
public static void Multiply<T>(this ReadOnlySpan<T> units, double multiplicator, Span<T> destination)
|
public static void Multiply<T>(this ReadOnlySpan<T> units, double multiplicator, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
@@ -221,11 +461,11 @@ public static partial class CollectionsMultiplyExtensions
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Multiply<T>(this double multiplicator, ICollection<T> units, Span<T> destination)
|
public static void Multiply<T>(this double multiplicator, ICollection<T> units, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply(multiplicator, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply<T>(multiplicator, destination);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Multiply<T>(this double multiplicator, ICollection<T?> units, Span<T?> destination)
|
public static void Multiply<T>(this double multiplicator, ICollection<T?> units, Span<T?> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply(multiplicator, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply<T>(multiplicator, destination);
|
||||||
|
|
||||||
// === IReadOnlyCollection<T> ===
|
// === IReadOnlyCollection<T> ===
|
||||||
public static void Multiply<T>(this IReadOnlyCollection<T> units, double multiplicator, Span<T> destination)
|
public static void Multiply<T>(this IReadOnlyCollection<T> units, double multiplicator, Span<T> destination)
|
||||||
@@ -264,20 +504,20 @@ public static partial class CollectionsMultiplyExtensions
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Multiply<T>(this double multiplicator, IReadOnlyCollection<T> units, Span<T> destination)
|
public static void Multiply<T>(this double multiplicator, IReadOnlyCollection<T> units, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply(multiplicator, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply<T>(multiplicator, destination);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Multiply<T>(this double multiplicator, IReadOnlyCollection<T?> units, Span<T?> destination)
|
public static void Multiply<T>(this double multiplicator, IReadOnlyCollection<T?> units, Span<T?> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply(multiplicator, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Multiply<T>(multiplicator, destination);
|
||||||
|
|
||||||
// === IEnumerable<T> + yeild ===
|
// === IEnumerable<T> + yeild ===
|
||||||
static IEnumerable<T> MultiplyIterator<T>(IEnumerable<T> units, double multiplicator)
|
internal static IEnumerable<T> MultiplyIterator<T>(this IEnumerable<T> units, double multiplicator)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
{
|
{
|
||||||
foreach (var item in units)
|
foreach (var item in units)
|
||||||
yield return (item.ToDouble() * multiplicator).ToUnit<T>();
|
yield return (item.ToDouble() * multiplicator).ToUnit<T>();
|
||||||
}
|
}
|
||||||
static IEnumerable<T?> MultiplyNullableIterator<T>(IEnumerable<T?> units, double multiplicator)
|
internal static IEnumerable<T?> MultiplyNullableIterator<T>(this IEnumerable<T?> units, double multiplicator)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
{
|
{
|
||||||
foreach (T? item in units)
|
foreach (T? item in units)
|
||||||
@@ -294,14 +534,14 @@ public static partial class CollectionsMultiplyExtensions
|
|||||||
if (units is List<T> list) return list.Multiply(multiplicator);
|
if (units is List<T> list) return list.Multiply(multiplicator);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Multiply(multiplicator, arr);
|
arr.Multiply(multiplicator, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Multiply(multiplicator, arr);
|
arr.Multiply(multiplicator, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MultiplyIterator(units, multiplicator);
|
return MultiplyIterator(units, multiplicator);
|
||||||
@@ -314,14 +554,14 @@ public static partial class CollectionsMultiplyExtensions
|
|||||||
if (units is List<T?> list) return list.Multiply(multiplicator);
|
if (units is List<T?> list) return list.Multiply(multiplicator);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Multiply(multiplicator, arr);
|
arr.Multiply(multiplicator, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Multiply(multiplicator, arr);
|
arr.Multiply(multiplicator, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return MultiplyNullableIterator(units, multiplicator);
|
return MultiplyNullableIterator(units, multiplicator);
|
||||||
|
|||||||
@@ -91,6 +91,246 @@ public static partial class CollectionsPlusExtensions
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// === Array ===
|
||||||
|
internal static R[] Plus<T, R>(this T[] units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R[len];
|
||||||
|
units.PlusCore(summand, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internal static R?[] Plus<T, R>(this T?[] units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int len = units.Length;
|
||||||
|
if (len == 0) return [];
|
||||||
|
|
||||||
|
var result = new R?[len];
|
||||||
|
units.PlusCore(summand, len, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R[] Plus<T, R>(this double summand, T[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus<T, R>(summand);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static R?[] Plus<T, R>(this double summand, T?[] units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus<T, R>(summand);
|
||||||
|
|
||||||
|
// === List<T> ===
|
||||||
|
internal static List<R> Plus<T, R>(this List<T> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R[count];
|
||||||
|
PlusCore(CollectionsMarshal.AsSpan(units), summand, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
internal static List<R?> Plus<T, R>(this List<T?> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return [];
|
||||||
|
|
||||||
|
var resultArray = new R?[count];
|
||||||
|
PlusCore(CollectionsMarshal.AsSpan(units), summand, count, resultArray);
|
||||||
|
return resultArray.WrapAsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R> Plus<T, R>(this double summand, List<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus<T, R>(summand);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static List<R?> Plus<T, R>(this double summand, List<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus<T, R>(summand);
|
||||||
|
|
||||||
|
// === ICollection<T> ===
|
||||||
|
internal static void Plus<T, R>(this ICollection<T> units, double summand, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { PlusCore(array, summand, count, destination); return; }
|
||||||
|
if (units is List<T> list) { PlusCore(CollectionsMarshal.AsSpan(list), summand, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() + summand).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Plus<T, R>(this ICollection<T?> units, double summand, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { PlusCore(array, summand, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { PlusCore(CollectionsMarshal.AsSpan(list), summand, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() + summand).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Plus<T, R>(this double summand, ICollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus(summand, destination);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Plus<T, R>(this double summand, ICollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus(summand, destination);
|
||||||
|
|
||||||
|
// === IReadOnlyCollection<T> ===
|
||||||
|
internal static void Plus<T, R>(this IReadOnlyCollection<T> units, double summand, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T[] array) { PlusCore(array, summand, count, destination); return; }
|
||||||
|
if (units is List<T> list) { PlusCore(CollectionsMarshal.AsSpan(list), summand, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = (item.ToDouble() + summand).ToUnit<R>();
|
||||||
|
}
|
||||||
|
internal static void Plus<T, R>(this IReadOnlyCollection<T?> units, double summand, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return;
|
||||||
|
int count = units.Count;
|
||||||
|
if (count == 0) return;
|
||||||
|
if (destination.Length < count)
|
||||||
|
throw new ArgumentException("Destination too short");
|
||||||
|
|
||||||
|
if (units is T?[] array) { PlusCore(array, summand, count, destination); return; }
|
||||||
|
if (units is List<T?> list) { PlusCore(CollectionsMarshal.AsSpan(list), summand, count, destination); return; }
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in units)
|
||||||
|
destination[i++] = item.HasValue
|
||||||
|
? (item.Value.ToDouble() + summand).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Plus<T, R>(this double summand, IReadOnlyCollection<T> units, Span<R> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus(summand, destination);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Plus<T, R>(this double summand, IReadOnlyCollection<T?> units, Span<R?> destination)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => units.Plus(summand, destination);
|
||||||
|
|
||||||
|
// === IEnumerable<T> + yeild ===
|
||||||
|
static IEnumerable<R> PlusIterator<T, R>(IEnumerable<T> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (var item in units)
|
||||||
|
yield return (item.ToDouble() + summand).ToUnit<R>();
|
||||||
|
}
|
||||||
|
static IEnumerable<R?> PlusNullableIterator<T, R>(IEnumerable<T?> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
foreach (T? item in units)
|
||||||
|
yield return item.HasValue
|
||||||
|
? (item.Value.ToDouble() + summand).ToUnit<R>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IEnumerable<T> ===
|
||||||
|
internal static IEnumerable<R> Plus<T, R>(this IEnumerable<T> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T[] array) return array.Plus<T, R>(summand);
|
||||||
|
if (units is List<T> list) return list.Plus<T, R>(summand);
|
||||||
|
if (units is ICollection<T> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Plus(summand, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Plus(summand, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return PlusIterator<T, R>(units, summand);
|
||||||
|
}
|
||||||
|
internal static IEnumerable<R?> Plus<T, R>(this IEnumerable<T?> units, double summand)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R>
|
||||||
|
{
|
||||||
|
if (units is null) return null!;
|
||||||
|
if (units is T?[] array) return array.Plus<T, R>(summand);
|
||||||
|
if (units is List<T?> list) return list.Plus<T, R>(summand);
|
||||||
|
if (units is ICollection<T?> col)
|
||||||
|
{
|
||||||
|
var arr = col.ToArray();
|
||||||
|
arr.Plus(summand, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
|
{
|
||||||
|
var arr = roc.ToArray();
|
||||||
|
arr.Plus(summand, arr);
|
||||||
|
return arr.ReCast<T, R>();
|
||||||
|
}
|
||||||
|
return PlusNullableIterator<T, R>(units, summand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static IEnumerable<R> Plus<T, R>(this double summand, IEnumerable<T> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => Plus<T, R>(units, summand);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static IEnumerable<R?> Plus<T, R>(this double summand, IEnumerable<T?> units)
|
||||||
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
|
where R : struct, IMensuraUnit, IEquatable<R> => Plus<T, R>(units, summand);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// === ReadOnlySpan
|
// === ReadOnlySpan
|
||||||
public static void Plus<T>(this ReadOnlySpan<T> units, double multiplicator, Span<T> destination)
|
public static void Plus<T>(this ReadOnlySpan<T> units, double multiplicator, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T>
|
where T : struct, IMensuraUnit, IEquatable<T>
|
||||||
@@ -222,11 +462,11 @@ public static partial class CollectionsPlusExtensions
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Plus<T>(this double summand, ICollection<T> units, Span<T> destination)
|
public static void Plus<T>(this double summand, ICollection<T> units, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus(summand, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus<T>(summand, destination);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Plus<T>(this double summand, ICollection<T?> units, Span<T?> destination)
|
public static void Plus<T>(this double summand, ICollection<T?> units, Span<T?> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus(summand, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus<T>(summand, destination);
|
||||||
|
|
||||||
// === IReadOnlyCollection<T> ===
|
// === IReadOnlyCollection<T> ===
|
||||||
public static void Plus<T>(this IReadOnlyCollection<T> units, double summand, Span<T> destination)
|
public static void Plus<T>(this IReadOnlyCollection<T> units, double summand, Span<T> destination)
|
||||||
@@ -265,11 +505,11 @@ public static partial class CollectionsPlusExtensions
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Plus<T>(this double summand, IReadOnlyCollection<T> units, Span<T> destination)
|
public static void Plus<T>(this double summand, IReadOnlyCollection<T> units, Span<T> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus(summand, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus<T>(summand, destination);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Plus<T>(this double summand, IReadOnlyCollection<T?> units, Span<T?> destination)
|
public static void Plus<T>(this double summand, IReadOnlyCollection<T?> units, Span<T?> destination)
|
||||||
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus(summand, destination);
|
where T : struct, IMensuraUnit, IEquatable<T> => units.Plus<T>(summand, destination);
|
||||||
|
|
||||||
// === IEnumerable<T> + yeild ===
|
// === IEnumerable<T> + yeild ===
|
||||||
static IEnumerable<T> PlusIterator<T>(IEnumerable<T> units, double summand)
|
static IEnumerable<T> PlusIterator<T>(IEnumerable<T> units, double summand)
|
||||||
@@ -295,14 +535,14 @@ public static partial class CollectionsPlusExtensions
|
|||||||
if (units is List<T> list) return list.Plus(summand);
|
if (units is List<T> list) return list.Plus(summand);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new T[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Plus(summand, arr);
|
arr.Plus(summand, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new T[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Plus(summand, arr);
|
arr.Plus(summand, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return PlusIterator(units, summand);
|
return PlusIterator(units, summand);
|
||||||
@@ -315,14 +555,14 @@ public static partial class CollectionsPlusExtensions
|
|||||||
if (units is List<T?> list) return list.Plus(summand);
|
if (units is List<T?> list) return list.Plus(summand);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new T?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Plus(summand, arr);
|
arr.Plus(summand, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new T?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Plus(summand, arr);
|
arr.Plus(summand, arr);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
return PlusNullableIterator(units, summand);
|
return PlusNullableIterator(units, summand);
|
||||||
|
|||||||
@@ -325,15 +325,15 @@ public static partial class CollectionsPowExtensions
|
|||||||
if (units is List<T> list) return list.Pow<T, R>(power);
|
if (units is List<T> list) return list.Pow<T, R>(power);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new R[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Pow(power, arr);
|
arr.PowCore(power, arr.Length, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new R[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return PowIterator<T, R>(units, power);
|
else return PowIterator<T, R>(units, power);
|
||||||
}
|
}
|
||||||
@@ -346,15 +346,15 @@ public static partial class CollectionsPowExtensions
|
|||||||
if (units is List<T?> list) return list.Pow<T, R>(power);
|
if (units is List<T?> list) return list.Pow<T, R>(power);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new R?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new R?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return PowNullableIterator<T, R>(units, power);
|
else return PowNullableIterator<T, R>(units, power);
|
||||||
}
|
}
|
||||||
@@ -637,15 +637,15 @@ public static partial class CollectionsPowExtensions
|
|||||||
if (units is List<T> list) return list.Pow<T, R>(power);
|
if (units is List<T> list) return list.Pow<T, R>(power);
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new R[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new R[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return PowIterator<T, R>(units, power);
|
else return PowIterator<T, R>(units, power);
|
||||||
}
|
}
|
||||||
@@ -658,15 +658,15 @@ public static partial class CollectionsPowExtensions
|
|||||||
if (units is List<T?> list) return list.Pow<T, R>(power);
|
if (units is List<T?> list) return list.Pow<T, R>(power);
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new R?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new R?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Pow(power, arr);
|
arr.Pow(power, arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return PowNullableIterator<T, R>(units, power);
|
else return PowNullableIterator<T, R>(units, power);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,15 +281,15 @@ public static partial class CollectionsSqrtExtensions
|
|||||||
if (units is List<T> list) return list.Sqrt<T, R>();
|
if (units is List<T> list) return list.Sqrt<T, R>();
|
||||||
if (units is ICollection<T> col)
|
if (units is ICollection<T> col)
|
||||||
{
|
{
|
||||||
var arr = new R[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Sqrt(arr);
|
arr.Sqrt(arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T> roc)
|
if (units is IReadOnlyCollection<T> roc)
|
||||||
{
|
{
|
||||||
var arr = new R[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Sqrt(arr);
|
arr.Sqrt(arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return SqrtIterator<T, R>(units);
|
else return SqrtIterator<T, R>(units);
|
||||||
}
|
}
|
||||||
@@ -302,15 +302,15 @@ public static partial class CollectionsSqrtExtensions
|
|||||||
if (units is List<T?> list) return list.Sqrt<T, R>();
|
if (units is List<T?> list) return list.Sqrt<T, R>();
|
||||||
if (units is ICollection<T?> col)
|
if (units is ICollection<T?> col)
|
||||||
{
|
{
|
||||||
var arr = new R?[col.Count];
|
var arr = col.ToArray();
|
||||||
col.Sqrt(arr);
|
arr.Sqrt(arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
if (units is IReadOnlyCollection<T?> roc)
|
if (units is IReadOnlyCollection<T?> roc)
|
||||||
{
|
{
|
||||||
var arr = new R?[roc.Count];
|
var arr = roc.ToArray();
|
||||||
roc.Sqrt(arr);
|
arr.Sqrt(arr);
|
||||||
return arr;
|
return arr.ReCast<T, R>();
|
||||||
}
|
}
|
||||||
else return SqrtNullableIterator<T, R>(units);
|
else return SqrtNullableIterator<T, R>(units);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
namespace QWERTYkez.Mensura;
|
namespace QWERTYkez.Mensura;
|
||||||
|
|
||||||
public interface IMensuraUnit
|
public interface IMensuraUnit { }
|
||||||
{
|
|
||||||
internal double Value { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IMensuraUnit<U> where U : struct, IMensuraUnit, IEquatable<U> { }
|
public interface IMensuraUnit<U> where U : struct, IMensuraUnit, IEquatable<U> { }
|
||||||
@@ -10,101 +10,60 @@ namespace QWERTYkez.Mensura.Units
|
|||||||
{
|
{
|
||||||
public readonly partial record struct Length
|
public readonly partial record struct Length
|
||||||
{
|
{
|
||||||
|
|
||||||
// === Array ===
|
// === Array ===
|
||||||
public static Mass[] operator *(PogonMass[] units, Length multiplicator)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator
|
||||||
{
|
*(PogonMass[] units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (units is null) return null!;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator
|
||||||
int len = units.Length;
|
*(PogonMass?[] units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (len == 0) return [];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator
|
||||||
|
*(Length multiplicator, PogonMass[] units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
var result = new Mass[len];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator
|
||||||
units.MultiplyCore(multiplicator._Value, result);
|
*(Length multiplicator, PogonMass?[] units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
return result;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator *(PogonMass[] units, Length? multiplicator) =>
|
||||||
}
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass[units.Length]);
|
||||||
public static Mass?[] operator *(PogonMass?[] units, Length multiplicator)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator *(PogonMass?[] units, Length? multiplicator) =>
|
||||||
{
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass?[units.Length]);
|
||||||
if (units is null) return null!;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator *(Length? multiplicator, PogonMass[] units) =>
|
||||||
int len = units.Length;
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass[units.Length]);
|
||||||
if (len == 0) return [];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator *(Length? multiplicator, PogonMass?[] units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass?[units.Length]);
|
||||||
var result = new Mass?[len];
|
|
||||||
units.MultiplyCore(multiplicator._Value, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static Mass[] operator *(Length multiplicator, PogonMass[] units) => units * multiplicator;
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static Mass?[] operator *(Length multiplicator, PogonMass?[] units) => units * multiplicator;
|
|
||||||
|
|
||||||
// === List<T> ===
|
// === List<T> ===
|
||||||
public static List<Mass> operator *(List<PogonMass> units, Length multiplicator)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator
|
||||||
{
|
*(List<PogonMass> units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (units is null) return null!;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator
|
||||||
int len = units.Count;
|
*(List<PogonMass?> units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (len == 0) return [];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator
|
||||||
|
*(Length multiplicator, List<PogonMass> units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
var resultArray = new Mass[len];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator
|
||||||
Multiply(CollectionsMarshal.AsSpan(units), multiplicator, resultArray);
|
*(Length multiplicator, List<PogonMass?> units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
return resultArray.WrapAsList();
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator *(List<PogonMass> units, Length? multiplicator) =>
|
||||||
}
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass>(units.Count));
|
||||||
public static List<Mass?> operator *(List<PogonMass?> units, Length multiplicator)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator *(List<PogonMass?> units, Length? multiplicator) =>
|
||||||
{
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass?>(units.Count));
|
||||||
if (units is null) return null!;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator *(Length? multiplicator, List<PogonMass> units) =>
|
||||||
int count = units.Count;
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass>(units.Count));
|
||||||
if (count == 0) return [];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator *(Length? multiplicator, List<PogonMass?> units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass?>(units.Count));
|
||||||
var resultArray = new Mass?[count];
|
|
||||||
Multiply(CollectionsMarshal.AsSpan(units), multiplicator, resultArray);
|
|
||||||
return resultArray.WrapAsList();
|
|
||||||
}
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator *(
|
|
||||||
Length multiplicator, List<PogonMass> units) => units * multiplicator;
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator *(
|
|
||||||
Length multiplicator, List<PogonMass?> units) => units * multiplicator;
|
|
||||||
|
|
||||||
// === IEnumerable<T> ===
|
// === IEnumerable<T> ===
|
||||||
public static IEnumerable<Mass> Multiply(IEnumerable<PogonMass> units, Length multiplicator)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator
|
||||||
{
|
*(IEnumerable<PogonMass> units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (units is null) return null!;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator
|
||||||
if (units is PogonMass[] array) return array.Multiply(multiplicator);
|
*(IEnumerable<PogonMass?> units, Length multiplicator) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
if (units is List<PogonMass> list) return list.Multiply(multiplicator);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator
|
||||||
if (units is ICollection<PogonMass> col)
|
*(Length multiplicator, IEnumerable<PogonMass> units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator
|
||||||
var arr = new Mass[col.Count];
|
*(Length multiplicator, IEnumerable<PogonMass?> units) => units.Multiply<PogonMass, Mass>(multiplicator._Value);
|
||||||
col.Multiply(multiplicator, arr);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator *(IEnumerable<PogonMass> units, Length? multiplicator) =>
|
||||||
return arr;
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new Mass(0d)));
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator *(IEnumerable<PogonMass?> units, Length? multiplicator) =>
|
||||||
if (units is IReadOnlyCollection<PogonMass> roc)
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? (Mass?)null : new Mass(0d)));
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator *(Length? multiplicator, IEnumerable<PogonMass> units) =>
|
||||||
var arr = new Mass[roc.Count];
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new Mass(0d)));
|
||||||
roc.Multiply(multiplicator, arr);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator *(Length? multiplicator, IEnumerable<PogonMass?> units) =>
|
||||||
return arr;
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? (Mass?)null : new Mass(0d)));
|
||||||
}
|
|
||||||
return MultiplyIterator(units, multiplicator);
|
|
||||||
}
|
|
||||||
public static IEnumerable<Mass?> Multiply(IEnumerable<PogonMass?> units, Length multiplicator)
|
|
||||||
{
|
|
||||||
if (units is null) return null!;
|
|
||||||
if (units is PogonMass?[] array) return array.Multiply(multiplicator);
|
|
||||||
if (units is List<PogonMass?> list) return list.Multiply(multiplicator);
|
|
||||||
if (units is ICollection<PogonMass?> col)
|
|
||||||
{
|
|
||||||
var arr = new Mass?[col.Count];
|
|
||||||
col.Multiply(multiplicator, arr);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
if (units is IReadOnlyCollection<PogonMass?> roc)
|
|
||||||
{
|
|
||||||
var arr = new Mass?[roc.Count];
|
|
||||||
roc.Multiply(multiplicator, arr);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
return MultiplyNullableIterator(units, multiplicator);
|
|
||||||
}
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> Multiply(
|
|
||||||
Length multiplicator, IEnumerable<PogonMass> units) => Multiply(units, multiplicator);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> Multiply(
|
|
||||||
Length multiplicator, IEnumerable<PogonMass?> units) => Multiply(units, multiplicator);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -150,149 +109,151 @@ namespace QWERTYkez.Mensura.Units
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// === 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];
|
//// ==========================================
|
||||||
PogonMassExtensions.MultiplyCore(left, right, result);
|
//// === MULTIPLY ===
|
||||||
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];
|
//public static Mass[] operator *(PogonMass[] left, Length right)
|
||||||
if (right is { } val)
|
//{
|
||||||
for (int i = 0; i < len; i++)
|
// if (left is null) return null!;
|
||||||
result[i] = val * left[i];
|
// int len = left.Length;
|
||||||
return result;
|
// if (len == 0) return [];
|
||||||
}
|
|
||||||
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];
|
// var result = new Mass[len];
|
||||||
for (int i = 0; i < len; i++)
|
// PogonMassExtensions.MultiplyCore(left, right, result);
|
||||||
result[i] = left * right[i];
|
// return result;
|
||||||
return result;
|
//}
|
||||||
}
|
//public static Mass[] operator *(PogonMass[] left, Length? right)
|
||||||
public static Mass[] operator *(Length? left, PogonMass[] right)
|
//{
|
||||||
{
|
// if (left is null) return null!;
|
||||||
if (right is null) return null!;
|
// int len = left.Length;
|
||||||
int len = right.Length;
|
// if (len == 0) return [];
|
||||||
if (len == 0) return [];
|
|
||||||
|
|
||||||
var result = new Mass[len];
|
// var result = new Mass[len];
|
||||||
if (left is { } val)
|
// if (right is { } val)
|
||||||
for (int i = 0; i < len; i++)
|
// for (int i = 0; i < len; i++)
|
||||||
result[i] = val * right[i];
|
// result[i] = val * left[i];
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
|
//public static Mass[] operator *(Length left, PogonMass[] right)
|
||||||
|
//{
|
||||||
|
// if (right is null) return null!;
|
||||||
|
// int len = right.Length;
|
||||||
|
// if (len == 0) return [];
|
||||||
|
|
||||||
// === ReadOnlySpan ===
|
// 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 [];
|
||||||
|
|
||||||
public static Span<Mass> operator *(Length left, ReadOnlySpan<PogonMass> right)
|
// var result = new Mass[len];
|
||||||
{
|
// if (left is { } val)
|
||||||
int len = right.Length;
|
// for (int i = 0; i < len; i++)
|
||||||
if (len == 0) return [];
|
// result[i] = val * right[i];
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
|
|
||||||
Span<Mass> result = new Mass[len];
|
//// === ReadOnlySpan ===
|
||||||
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];
|
//public static Span<Mass> operator *(Length left, ReadOnlySpan<PogonMass> right)
|
||||||
if (left is { } val)
|
//{
|
||||||
for (int i = 0; i < len; i++)
|
// int len = right.Length;
|
||||||
result[i] = val * right[i];
|
// if (len == 0) return [];
|
||||||
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];
|
// Span<Mass> result = new Mass[len];
|
||||||
for (int i = 0; i < len; i++)
|
// for (int i = 0; i < len; i++)
|
||||||
result[i] = right * left[i];
|
// result[i] = left * right[i];
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
public static Span<Mass> operator *(ReadOnlySpan<PogonMass> left, Length? right)
|
//public static Span<Mass> operator *(Length? left, ReadOnlySpan<PogonMass> right)
|
||||||
{
|
//{
|
||||||
int len = left.Length;
|
// int len = right.Length;
|
||||||
if (len == 0) return [];
|
// if (len == 0) return [];
|
||||||
|
|
||||||
Span<Mass> result = new Mass[len];
|
// Span<Mass> result = new Mass[len];
|
||||||
if (right is { } val)
|
// if (left is { } val)
|
||||||
for (int i = 0; i < len; i++)
|
// for (int i = 0; i < len; i++)
|
||||||
result[i] = val * left[i];
|
// result[i] = val * right[i];
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
|
//public static Span<Mass> operator *(ReadOnlySpan<PogonMass> left, Length right)
|
||||||
|
//{
|
||||||
|
// int len = left.Length;
|
||||||
|
// if (len == 0) return [];
|
||||||
|
|
||||||
// === List ===
|
// 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 [];
|
||||||
|
|
||||||
public static List<Mass> operator *(Length left, List<PogonMass> right)
|
// Span<Mass> result = new Mass[len];
|
||||||
{
|
// if (right is { } val)
|
||||||
if (right is null) return null!;
|
// for (int i = 0; i < len; i++)
|
||||||
int len = right.Count;
|
// result[i] = val * left[i];
|
||||||
if (len == 0) return [];
|
// return result;
|
||||||
|
//}
|
||||||
|
|
||||||
var result = new List<Mass>(len);
|
//// === List ===
|
||||||
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);
|
//public static List<Mass> operator *(Length left, List<PogonMass> right)
|
||||||
if (left is { } val)
|
//{
|
||||||
for (int i = 0; i < len; i++)
|
// if (right is null) return null!;
|
||||||
result[i] = val * right[i];
|
// int len = right.Count;
|
||||||
return result;
|
// if (len == 0) return [];
|
||||||
}
|
|
||||||
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);
|
// var result = new List<Mass>(len);
|
||||||
for (int i = 0; i < len; i++)
|
// for (int i = 0; i < len; i++)
|
||||||
result[i] = right * left[i];
|
// result[i] = left * right[i];
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
public static List<Mass> operator *(List<PogonMass> left, Length? right)
|
//public static List<Mass> operator *(Length? left, List<PogonMass> right)
|
||||||
{
|
//{
|
||||||
if (left is null) return null!;
|
// if (right is null) return null!;
|
||||||
int len = left.Count;
|
// int len = right.Count;
|
||||||
if (len == 0) return [];
|
// if (len == 0) return [];
|
||||||
|
|
||||||
var result = new List<Mass>(len);
|
// var result = new List<Mass>(len);
|
||||||
if (right is { } val)
|
// if (left is { } val)
|
||||||
for (int i = 0; i < len; i++)
|
// for (int i = 0; i < len; i++)
|
||||||
result[i] = val * left[i];
|
// result[i] = val * right[i];
|
||||||
return result;
|
// 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;
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,9 +264,8 @@ namespace QWERTYkez.Mensura.Units.Pogon
|
|||||||
public readonly partial record struct PogonMass : IMensuraUnit<PogonMass>, IEquatable<PogonMass>, IMensuraUnit
|
public readonly partial record struct PogonMass : IMensuraUnit<PogonMass>, IEquatable<PogonMass>, IMensuraUnit
|
||||||
{
|
{
|
||||||
|
|
||||||
[JsonInclude, DataMember, JsonPropertyName("v")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
[JsonInclude, DataMember, JsonPropertyName("v"), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||||
internal double Value { get => _Value; init => _Value = value; }
|
internal double Value { get => _Value; init => _Value = value; }
|
||||||
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
|
|
||||||
internal readonly double _Value;
|
internal readonly double _Value;
|
||||||
internal PogonMass(double value) => _Value = value;
|
internal PogonMass(double value) => _Value = value;
|
||||||
|
|
||||||
@@ -343,167 +303,82 @@ namespace QWERTYkez.Mensura.Units.Pogon
|
|||||||
public static Length operator /(Mass? left, PogonMass? right) => new((left ?? default) / (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 ===
|
// === Array ===
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator
|
||||||
|
*(Length[] units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator
|
||||||
|
*(Length?[] units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator
|
||||||
|
*(PogonMass multiplicator, Length[] units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator
|
||||||
|
*(PogonMass multiplicator, Length?[] units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator *(Length[] units, PogonMass? multiplicator) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass[units.Length]);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator *(Length?[] units, PogonMass? multiplicator) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass?[units.Length]);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass[] operator *(PogonMass? multiplicator, Length[] units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass[units.Length]);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mass?[] operator *(PogonMass? multiplicator, Length?[] units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new Mass?[units.Length]);
|
||||||
|
|
||||||
public static Span<Mass> operator *(PogonMass left, ReadOnlySpan<Length> right)
|
// === List<T> ===
|
||||||
{
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator
|
||||||
int len = right.Length;
|
*(List<Length> units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
if (len == 0) return [];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator
|
||||||
|
*(List<Length?> units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator
|
||||||
|
*(PogonMass multiplicator, List<Length> units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator
|
||||||
|
*(PogonMass multiplicator, List<Length?> units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator *(List<Length> units, PogonMass? multiplicator) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass>(units.Count));
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator *(List<Length?> units, PogonMass? multiplicator) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass?>(units.Count));
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass> operator *(PogonMass? multiplicator, List<Length> units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass>(units.Count));
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<Mass?> operator *(PogonMass? multiplicator, List<Length?> units) =>
|
||||||
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : new List<Mass?>(units.Count));
|
||||||
|
|
||||||
Span<Mass> result = new Mass[len];
|
// === IEnumerable<T> ===
|
||||||
for (int i = 0; i < len; i++)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator
|
||||||
result[i] = left * right[i];
|
*(IEnumerable<Length> units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
return result;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator
|
||||||
}
|
*(IEnumerable<Length?> units, PogonMass multiplicator) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
public static Span<Mass> operator *(PogonMass? left, ReadOnlySpan<Length> right)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator
|
||||||
{
|
*(PogonMass multiplicator, IEnumerable<Length> units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
int len = right.Length;
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator
|
||||||
if (len == 0) return [];
|
*(PogonMass multiplicator, IEnumerable<Length?> units) => units.Multiply<Length, Mass>(multiplicator._Value);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator *(IEnumerable<Length> units, PogonMass? multiplicator) =>
|
||||||
Span<Mass> result = new Mass[len];
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new Mass(0d)));
|
||||||
if (left is { } val)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator *(IEnumerable<Length?> units, PogonMass? multiplicator) =>
|
||||||
for (int i = 0; i < len; i++)
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? (Mass?)null : new Mass(0d)));
|
||||||
result[i] = val * right[i];
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass> operator *(PogonMass? multiplicator, IEnumerable<Length> units) =>
|
||||||
return result;
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => new Mass(0d)));
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<Mass?> operator *(PogonMass? multiplicator, IEnumerable<Length?> units) =>
|
||||||
public static Span<Mass> operator *(ReadOnlySpan<Length> left, PogonMass right)
|
multiplicator.HasValue ? units * multiplicator.Value : (units is null ? null! : units.Select(u => u is null ? (Mass?)null : new Mass(0d)));
|
||||||
{
|
|
||||||
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 class PogonMassExtensions
|
||||||
{
|
{
|
||||||
internal static Mass Protect(this Mass? unit) => unit ?? default;
|
internal static Mass Protect(this Mass? unit) => unit ?? default;
|
||||||
internal static double ToDouble(this PogonMass? unit) => unit?._Value ?? 0d;
|
internal static double ToDouble(this Length? unit) => unit?._Value ?? 0d;
|
||||||
|
|
||||||
|
|
||||||
public static PogonMass MetricSum(this IEnumerable<PogonMass> units) => new(units?.Sum(m => m._Value) ?? 0d);
|
public static Length MetricSum(this IEnumerable<Length> 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 Length MetricAverage(this IEnumerable<Length> 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 Length MetricMax(this IEnumerable<Length> 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 Length MetricMin(this IEnumerable<Length> 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 Length MetricSum(this IEnumerable<Length?> 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 Length MetricAverage(this IEnumerable<Length?> 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 Length MetricMax(this IEnumerable<Length?> 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);
|
public static Length MetricMin(this IEnumerable<Length?> units) => new(units?.Min(m => m.ToDouble()) ?? double.MaxValue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ public class XXXXXXXXXXXXXXConverter : UnitJsonConverter<XXXXXXXXXXXXXX> { }
|
|||||||
[JsonConverter(typeof(XXXXXXXXXXXXXXConverter))]
|
[JsonConverter(typeof(XXXXXXXXXXXXXXConverter))]
|
||||||
public readonly partial record struct XXXXXXXXXXXXXX : IMensuraUnit<XXXXXXXXXXXXXX>, IEquatable<XXXXXXXXXXXXXX>, IMensuraUnit
|
public readonly partial record struct XXXXXXXXXXXXXX : IMensuraUnit<XXXXXXXXXXXXXX>, IEquatable<XXXXXXXXXXXXXX>, IMensuraUnit
|
||||||
{
|
{
|
||||||
[JsonInclude, DataMember, JsonPropertyName("v")] // для JSON / EF на случай сбоев, если пробелма с _Value
|
[JsonInclude, DataMember, JsonPropertyName("v"), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
|
||||||
internal double Value { get => _Value; init => _Value = value; }
|
internal double Value { get => _Value; init => _Value = value; }
|
||||||
double IMensuraUnit.Value { get => _Value; init => _Value = value; }
|
|
||||||
internal readonly double _Value;
|
internal readonly double _Value;
|
||||||
internal XXXXXXXXXXXXXX(double value) => _Value = value;
|
internal XXXXXXXXXXXXXX(double value) => _Value = value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user