mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
73 lines
1.3 KiB
C#
73 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace IsoTools.Internal {
|
|
public struct IsoMinMax {
|
|
public float min;
|
|
public float max;
|
|
|
|
public IsoMinMax(float min, float max) : this() {
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
|
|
public IsoMinMax(IsoMinMax other) : this() {
|
|
min = other.min;
|
|
max = other.max;
|
|
}
|
|
|
|
public float size {
|
|
get { return max - min; }
|
|
}
|
|
|
|
public float center {
|
|
get { return min + (max - min) * 0.5f; }
|
|
}
|
|
|
|
public void Set(float min, float max) {
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
|
|
public void Set(IsoMinMax other) {
|
|
min = other.min;
|
|
max = other.max;
|
|
}
|
|
|
|
public void Translate(float delta) {
|
|
min += delta;
|
|
max += delta;
|
|
}
|
|
|
|
public bool Contains(float other) {
|
|
return other >= min && other <= max;
|
|
}
|
|
|
|
public bool Contains(IsoMinMax other) {
|
|
return
|
|
max >= other.max &&
|
|
min <= other.min;
|
|
}
|
|
|
|
public bool Overlaps(IsoMinMax other) {
|
|
return
|
|
max > other.min &&
|
|
min < other.max;
|
|
}
|
|
|
|
public bool Approximately(IsoMinMax other) {
|
|
return
|
|
Mathf.Approximately(min, other.min) &&
|
|
Mathf.Approximately(max, other.max);
|
|
}
|
|
|
|
public static IsoMinMax zero {
|
|
get { return new IsoMinMax(); }
|
|
}
|
|
|
|
public static IsoMinMax Merge(IsoMinMax a, IsoMinMax b) {
|
|
return new IsoMinMax(
|
|
a.min < b.min ? a.min : b.min,
|
|
a.max > b.max ? a.max : b.max);
|
|
}
|
|
}
|
|
} |