Table of Contents

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

min Fixed64

The minimum value of the range.

max Fixed64

The maximum value of the range.

enforceOrder bool

If 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

Fixed64

MaxRange

The largest possible range.

public static readonly FixedRange MaxRange

Field Value

FixedRange

Min

Gets the minimum value of the range.

[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 Min

Field Value

Fixed64

MinRange

The smallest possible range.

public static readonly FixedRange MinRange

Field Value

FixedRange

Properties

Length

The exact signed length of the range, computed as Max minus Min.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Length { get; }

Property Value

Fixed64

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

Fixed64

Methods

AddInPlace(Fixed64)

Adds a value to both the minimum and maximum of the range.

public void AddInPlace(Fixed64 val)

Parameters

val Fixed64

The 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

origin Vector3d

The origin vector.

range1 FixedRange

The first range.

range2 FixedRange

The second range.

limit Fixed64

The overlap limit to check.

sign Fixed64

The 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

rangeA FixedRange

The first range.

rangeB FixedRange

The second range.

Returns

Fixed64

The depth of the overlap between the ranges.

Equals(FixedRange)

public bool Equals(FixedRange other)

Parameters

other FixedRange

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

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

range1 FixedRange

The first range.

range2 FixedRange

The second range.

sign Fixed64?

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

x Fixed64

The value to check.

includeMax bool

If 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

other FixedRange

The 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

min Fixed64

The new minimum value.

max Fixed64

The new maximum value.

ToString()

Returns a string that represents the FixedRange instance, formatted as "Min - Max".

public override string ToString()

Returns

string

ToString(string?, IFormatProvider?)

Returns a string that represents the FixedRange instance, formatted as "Min - Max".

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

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

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

Operators

operator +(FixedRange, FixedRange)

Adds two FixedRange instances by summing their minimum and maximum values.

public static FixedRange operator +(FixedRange left, FixedRange right)

Parameters

left FixedRange

The first FixedRange to add.

right FixedRange

The 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

left FixedRange
right FixedRange

Returns

bool

operator !=(FixedRange, FixedRange)

Determines whether two FixedRange instances are not equal.

public static bool operator !=(FixedRange left, FixedRange right)

Parameters

left FixedRange
right FixedRange

Returns

bool

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

left FixedRange

The FixedRange instance to subtract from.

right FixedRange

The 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.