Skip to content
Ilia Petrov-Komotskii edited this page Oct 16, 2026 · 4 revisions

Inclusive numeric intervals. Endpoints A and B are unordered: (5, 1) is the same interval as (1, 5). Min / Max always return the numeric bounds.

Three structs: MinMaxInt, MinMaxFloat, MinMaxDouble. All are [Serializable] and IEquatable<>.

using Mane.DotNet;

MinMaxInt damage = new(3, 10);
int rolled = damage.Clamp(12);      // 10
bool inside = damage.Contains(3);   // true

MinMaxFloat speed = new(.5f, 2f);
float capped = 3f.Clamp(speed);     // 2 — MinMaxExtensions

Contains and clamp

Contains(value, includeMin = true, includeMax = true) is inclusive by default. Pass includeMin: false or includeMax: false for half-open ranges.

Clamp(value) returns value limited to [Min, Max].

Sugar on the value side (same types): value.IsInRange(range) and value.Clamp(range).

Operators

  • + — [a.Min + b.Min, a.Max + b.Max]
  • - — [a.Min - b.Max, a.Max - b.Min]
  • * / / — scale stored endpoints A and B (int division is integer division)
  • MinMaxInt +, -, * use checked arithmetic and throw on overflow

Equality compares normalized bounds, so (5, 1) equals (1, 5).

For MinMaxFloat and MinMaxDouble, == and != compare within ManeConst.FloatTolerance / DoubleTolerance, while Equals and GetHashCode are exact, the same split as Unity's Vector3. Dictionaries and sets use Equals, so they work as keys: two intervals that are only within the tolerance of each other are different keys.

Assert.IsTrue(new MinMaxInt(5, 1) == new MinMaxInt(1, 5));
Console.WriteLine(new MinMaxInt(1, 5)); // [1, 5]

Unity inspector

When you serialize these structs from ManeTools-Unity, a property drawer draws linked min/max fields and swaps them if you invert the order. Decorators from that package can still sit on the same field.

MinMaxFloat on a MonoBehaviour, two endpoints in one row.

Clone this wiki locally