// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
namespace UltimateXR.Extensions.System.Math
{
///
/// and extensions.
///
public static class IntExt
{
#region Public Methods
///
/// Checks if the given int value has one or more flags set.
///
/// int value
/// Flag(s) to check for
/// Whether the int value has the given flag(s) set
public static bool HasFlags(this int self, int flags)
{
return flags == (flags & self);
}
///
/// Checks if the given uint value has one or more flags set.
///
/// uint value
/// Flag(s) to check for
/// Whether the uint value has the given flag(s) set
public static bool HasFlags(this uint self, uint flags)
{
return flags == (flags & self);
}
///
/// Returns an int value with one or more flags set if they weren't set already.
///
/// int value
/// Flag(s) to set when returned
/// int value with the given flag(s) set
public static int WithFlags(this int self, int flags)
{
return self | flags;
}
///
/// Returns an uint value with one or more flags set if they weren't set already.
///
/// uint value
/// Flag(s) to set when returned
/// uint value with the given flag(s) set
public static uint WithFlags(this uint self, uint flags)
{
return self | flags;
}
///
/// Returns an int value with one or more flags cleared if they were set.
///
/// int value
/// Flag(s) to clear when returned
/// int value with the given flag(s) cleared
public static int WithoutFlags(this int self, int flags)
{
return self & ~flags;
}
///
/// Returns an uint value with one or more flags cleared if they were set.
///
/// uint value
/// Flag(s) to clear when returned
/// uint value with the given flag(s) cleared
public static uint WithoutFlags(this uint self, uint flags)
{
return self & ~flags;
}
///
/// Clamps a value so that it doesn't go beyond a given range.
///
/// Value to clamp
/// Minimum value
/// Maximum value
/// Clamped value between [min, max]
public static int Clamp(this ref int self, int min, int max)
{
self = Mathf.Clamp(self, min, max);
return self;
}
///
/// Returns a clamped value.
///
/// Value to clamp
/// Minimum value
/// Maximum value
/// Clamped value between [min, max]
public static int Clamped(this int self, int min, int max)
{
return Mathf.Clamp(self, min, max);
}
#endregion
}
}