79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
|
namespace PMaker.Extension
|
|||
|
{
|
|||
|
public static class IntExtension
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7>
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="min"><3E><>Сֵ</param>
|
|||
|
/// <param name="max"><3E><><EFBFBD><EFBFBD>ֵ</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool IsClamp(this int value, int min, int max)
|
|||
|
{
|
|||
|
return value <= max & value >= min;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// ijһ<C4B3><D2BB>Χ<EFBFBD><CEA7>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="max"></param>
|
|||
|
/// <param name="min"></param>
|
|||
|
public static void CyclicAdd(ref this int value, int max, int min = 0)
|
|||
|
{
|
|||
|
value = (value - min + 1) % max + min;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// ijһ<C4B3><D2BB>Χ<EFBFBD><CEA7>ѭ<EFBFBD><D1AD><EFBFBD>Լ<EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="max"></param>
|
|||
|
/// <param name="min"></param>
|
|||
|
public static void CyclicSub(ref this int value, int max, int min = 0)
|
|||
|
{
|
|||
|
value = (value - min + max - 1) % max + min;
|
|||
|
}
|
|||
|
//public static int CyclicAdd(this int value, int max, int min = 0)
|
|||
|
//{
|
|||
|
// return (value - min + 1) % max + min;
|
|||
|
//}
|
|||
|
//public static int CyclicSub(this int value, int max, int min = 0)
|
|||
|
//{
|
|||
|
// return (value - min + max - 1) % max + min;
|
|||
|
//}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>bitλΪ1
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="index">0base</param>
|
|||
|
public static void BitOn(ref this int value, int index)
|
|||
|
{
|
|||
|
value |= (1 << index);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>bitλΪ0
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="index">0base</param>
|
|||
|
public static void BitOff(ref this int value, int index)
|
|||
|
{
|
|||
|
value &= ~(1 << index);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <param name="target"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool BitIs(this int value, int target)
|
|||
|
{
|
|||
|
return (value & target) == target;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|