Show / Hide Table of Contents

Class IntExtensions

Inheritance
System.Object
IntExtensions
Namespace: Eco.Shared.Math
Assembly: Eco.Shared.dll
Syntax
public static class IntExtensions : Object

Methods

InWrappedRange(Int32, Int32, Int32, Int32)

Checks if value is in a range which enclosed in wrapped range. Wrap(Int32, Int32)

It means that "wrappedStart" and "wrappedEnd" values defines a range [wrappedStart, wrappedEnd), but this range itself is wrapped to [0, wrappedTo).

So it may create situation when we have initial values: "start" = 80, "end" = 150, but after wrapping to [0, 100) they become: "wrappedStart" = 80 and "wrappedEnd" = 50.

And in this case we have "wrappedStart" > "wrappedEnd", because of wrapping. It may be represented as:

xxxxxxx*********************xxxxxxx.

where "x" belongs to wrappedStart to wrappedEnd range.

And for this kind of range we have to make special check where "value" contained in [min, max) range when it either contained in [wrappedStart, wrappedTo) or [0, wrappedEnd).

If min <= max, then standard check will be used.

Declaration
public static bool InWrappedRange(this int value, int wrappedStart, int wrappedEnd, int wrappedTo)
Parameters
Type Name Description
System.Int32 value

value to check if it contains in range.

System.Int32 wrappedStart

start range value (wrapped).

System.Int32 wrappedEnd

end range value (open, wrapped).

System.Int32 wrappedTo

end of wrapping range.

Returns
Type Description
System.Boolean

True if value contained in wrappedStart to wrappedEnd range, False otherwise.

See Also
Wrap(Int32, Int32)

PostfixIncrementWrapped(ref Int32, Int32)

Wrapped alternative of value++. Increments value (which should already be wrapped in wrapTo space) and returns value before increment.

Declaration
public static int PostfixIncrementWrapped(this ref int value, int wrapTo)
Parameters
Type Name Description
System.Int32 value
System.Int32 wrapTo
Returns
Type Description
System.Int32

Wrap(Int32, Int32)

Wraps value to a range starting with 0 and ending with wrapTo. It ensures value in this range and if value is negative it will start from end of range.

For wrapped range we means a some range starting with 0 and ended with concrete end value. I.e. [0, 100) When value wrapped it should be enclosed in this range:

  • reduce it to length of this range with "modulo" operation.
  • if it negative then it should be aligned at the end of range Some examples for range [0, 100): 250 -> 250 % 100 = 50 | - -> 50 -175 -> -175 % 100 = -75 | 100 - 75 = 25 -> 25.
Declaration
public static int Wrap(this int value, int wrapTo)
Parameters
Type Name Description
System.Int32 value

Value to wrap.

System.Int32 wrapTo

Ending value of range.

Returns
Type Description
System.Int32

Value wrapped to range.

☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾