Skip to content
Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 4 revisions

MinMax

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. Float/double uses ManeConst.FloatTolerance / DoubleTolerance, not Epsilon.

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.

Screenshot: minmax-inspector.png — MinMaxFloat on a MonoBehaviour, two endpoints in one row. Host at https://raw.githubusercontent.com/wiki/ManeFunction/ManeTools-Unity/minmax-inspector.png.

Clone this wiki locally