IMensuraUnit<U>
All checks were successful
Publish NuGet packages / publish (push) Successful in 52s

This commit is contained in:
melekhin
2026-06-15 09:37:03 +07:00
parent d49374b482
commit 587b6d9ed1
3 changed files with 29 additions and 3 deletions

View File

@@ -195,7 +195,7 @@ using System.Runtime.Serialization;
namespace QWERTYkez.Mensura.Units;
[JsonConverter(typeof(UnitJsonConverter<{typeNameZ}>))]
public readonly partial record struct {typeNameZ} : IEquatable<{typeNameZ}>, IMensuraUnit
public readonly partial record struct {typeNameZ} : IEquatable<{typeNameZ}>, IMensuraUnit, IMensuraUnit<{typeNameZ}>
{
[JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
@@ -212,6 +212,16 @@ public readonly partial record struct {typeNameZ} : IEquatable<{typeNameZ}>, IMe
public static explicit operator double({typeNameZ} unit) => unit._Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public {typeNameZ} Abs() => new(Math.Abs(_Value));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Pow2_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => (_Value * _Value).ToUnit<R>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal R Sqrt_Internal<R>() where R : struct, IMensuraUnit, IEquatable<R> => Math.Sqrt(_Value).ToUnit<R>();
[JsonIgnore, IgnoreDataMember] public bool IsPositive => _Value >= 0;
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero => _Value > 0;
[JsonIgnore, IgnoreDataMember] public bool IsNegative => double.IsNegative(_Value);

View File

@@ -144,7 +144,7 @@ using System.Runtime.Serialization;
namespace QWERTYkez.Mensura.Units;
[JsonConverter(typeof(UnitJsonConverter<{typeName}>))]
public readonly partial record struct {typeName} : IEquatable<{typeName}>, IMensuraUnit
public readonly partial record struct {typeName} : IEquatable<{typeName}>, IMensuraUnit, IMensuraUnit<{typeName}>
{
[JsonInclude, DataMember, JsonPropertyName(""v""), Obsolete] // для JSON / EF на случай сбоев, если пробелма с _Value
internal double Value { get => _Value; init => _Value = value; }

View File

@@ -1,3 +1,19 @@
namespace QWERTYkez.Mensura;
public interface IMensuraUnit { }
public interface IMensuraUnit
{
[JsonIgnore, IgnoreDataMember] public bool IsPositive { get; }
[JsonIgnore, IgnoreDataMember] public bool IsGreaterThanZero { get; }
[JsonIgnore, IgnoreDataMember] public bool IsNegative { get; }
[JsonIgnore, IgnoreDataMember] public bool IsZero { get; }
[JsonIgnore, IgnoreDataMember] public bool IsNaN { get; }
[JsonIgnore, IgnoreDataMember] public bool IsFinite { get; }
[JsonIgnore, IgnoreDataMember] public bool IsInfinity { get; }
[JsonIgnore, IgnoreDataMember] public bool IsPositiveInfinity { get; }
[JsonIgnore, IgnoreDataMember] public bool IsNegativeInfinity { get; }
}
internal interface IMensuraUnit<U> where U : struct, IMensuraUnit, IEquatable<U>
{
public U Abs();
}