Struct FixedRange
- Namespace
- FixedMathSharp
- Assembly
- FixedMathSharp.dll
Represents a range of values with fixed precision.
[MemoryPackable(GenerateType.Object)]
public struct FixedRange : IEquatable<FixedRange>, ISpanFormattable, IFormattable, IMemoryPackable<FixedRange>, IMemoryPackFormatterRegister
- Implements
-
IMemoryPackable<FixedRange>IMemoryPackFormatterRegister
- Inherited Members
Remarks
MemoryPack GenerateType: unmanaged
FixedMathSharp.Fixed64 Min
FixedMathSharp.Fixed64 Max
Constructors
FixedRange(Fixed64, Fixed64, bool)
Initializes a new instance of the FixedRange structure with the specified minimum and maximum values.
public FixedRange(Fixed64 min, Fixed64 max, bool enforceOrder = true)
Parameters
minFixed64The minimum value of the range.
maxFixed64The maximum value of the range.
enforceOrderboolIf true, ensures that Min is less than or equal to Max.
Fields
Max
Gets the maximum value of the range.
[JsonInclude]
[MemoryPackOrder(1)]
public Fixed64 Max
Field Value
MaxRange
The largest possible range.
public static readonly FixedRange MaxRange
Field Value
Min
Gets the minimum value of the range.
[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 Min
Field Value
MinRange
The smallest possible range.
public static readonly FixedRange MinRange
Field Value
Properties
Length
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Length { get; }
Property Value
Exceptions
- OverflowException
The signed endpoint difference is outside the representable scalar domain.
MidPoint
The nearest-even Q32.32 midpoint of the range.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 MidPoint { get; }
Property Value
Methods
AddInPlace(Fixed64)
Adds a value to both the minimum and maximum of the range.
public void AddInPlace(Fixed64 val)
Parameters
valFixed64The value to add.
CheckOverlap(Vector3d, FixedRange, FixedRange, Fixed64, Fixed64, out (Vector3d Vector, Fixed64 Depth)?)
Checks for overlap between two ranges and calculates the vector of overlap depth.
public static bool CheckOverlap(Vector3d origin, FixedRange range1, FixedRange range2, Fixed64 limit, Fixed64 sign, out (Vector3d Vector, Fixed64 Depth)? output)
Parameters
originVector3dThe origin vector.
range1FixedRangeThe first range.
range2FixedRangeThe second range.
limitFixed64The overlap limit to check.
signFixed64The direction sign to consider.
output(Vector3d Vector, Fixed64 Depth)?The overlap vector and depth, if any.
Returns
- bool
True if overlap occurs and is below the limit, otherwise false.
ComputeOverlapDepth(FixedRange, FixedRange)
Calculates the overlap depth between two ranges. Assumes the ranges are sorted (min and max are correctly assigned).
public static Fixed64 ComputeOverlapDepth(FixedRange rangeA, FixedRange rangeB)
Parameters
rangeAFixedRangeThe first range.
rangeBFixedRangeThe second range.
Returns
- Fixed64
The depth of the overlap between the ranges.
Equals(FixedRange)
public bool Equals(FixedRange other)
Parameters
otherFixedRange
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetDirection(FixedRange, FixedRange, out Fixed64?)
Determines the direction from one range to another. If they don't overlap, returns -1 or 1 depending on the relative position.
public static bool GetDirection(FixedRange range1, FixedRange range2, out Fixed64? sign)
Parameters
range1FixedRangeThe first range.
range2FixedRangeThe second range.
signFixed64?The direction between ranges (-1 or 1).
Returns
- bool
True if the ranges don't overlap, false if they do.
GetHashCode()
Computes the hash code for the FixedRange instance.
public override int GetHashCode()
Returns
- int
The hash code of the range.
InRange(Fixed64, bool)
Determines whether the specified value is within the range, with an option to include or exclude the upper bound.
public bool InRange(Fixed64 x, bool includeMax = false)
Parameters
xFixed64The value to check.
includeMaxboolIf true, the upper bound (Max) is included in the range check; otherwise, the upper bound is exclusive. Default is false (exclusive).
Returns
- bool
True if the value is within the range; otherwise, false.
Overlaps(FixedRange)
Checks whether this range overlaps with the specified range, ensuring no adjacent edges are considered overlaps.
public bool Overlaps(FixedRange other)
Parameters
otherFixedRangeThe range to compare.
Returns
- bool
True if the ranges overlap; otherwise, false.
SetMinMax(Fixed64, Fixed64)
Sets the minimum and maximum values for the range.
public void SetMinMax(Fixed64 min, Fixed64 max)
Parameters
ToString()
Returns a string that represents the FixedRange instance, formatted as "Min - Max".
public override string ToString()
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents the FixedRange instance, formatted as "Min - Max".
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringformatProviderIFormatProvider
Returns
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Formats this range into the provided destination buffer.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
Operators
operator +(FixedRange, FixedRange)
Adds two FixedRange instances by summing their minimum and maximum values.
public static FixedRange operator +(FixedRange left, FixedRange right)
Parameters
leftFixedRangeThe first FixedRange to add.
rightFixedRangeThe second FixedRange to add.
Returns
- FixedRange
A new FixedRange whose Min is the sum of the Min values and whose Max is the sum of the Max values of the specified ranges.
operator ==(FixedRange, FixedRange)
Determines whether two FixedRange instances are equal.
public static bool operator ==(FixedRange left, FixedRange right)
Parameters
leftFixedRangerightFixedRange
Returns
operator !=(FixedRange, FixedRange)
Determines whether two FixedRange instances are not equal.
public static bool operator !=(FixedRange left, FixedRange right)
Parameters
leftFixedRangerightFixedRange
Returns
operator -(FixedRange, FixedRange)
Subtracts the minimum and maximum values of one FixedRange from another and returns the resulting FixedRange.
public static FixedRange operator -(FixedRange left, FixedRange right)
Parameters
leftFixedRangeThe FixedRange instance to subtract from.
rightFixedRangeThe FixedRange instance whose values are subtracted.
Returns
- FixedRange
A FixedRange whose Min and Max values are the result of subtracting the corresponding values of right from left.