Range
The Range class makes it simple to represent and perform operations on a range of numeric
values.
Example
Below is an example which demonstrates how to use the Range class.
local MyModule = select(2, ...).MyModule
local Range = MyModule:From("LibTSMUtil"):IncludeClassType("Range")
do
local spellRange = Range.AcquireStartEnd(0, 10)
local enemyStrikeRange = Range.AcquireStartEnd(0, 5)
local currentDistance = 7
print(spellRange:Includes(currentDistance)) -- true
print(enemyStrikeRange:Includes(currentDistance)) -- false
spellRange:Release()
enemyStrikeRange:Release()
end
do
local groupLevelRange = Range.AcquireStartEnd(73, 74)
local zoneLevelRange = Range.AcquireStartEnd(71, 75)
print(zoneLevelRange:Contains(groupLevelRange)) -- true
groupLevelRange:Release()
zoneLevelRange:Release()
end
Memory Management
The lifecycle of range objects is owned by the Range module. They are acquired via the
Range.Acquire*() functions and its up to the caller to ensure they are properly released back
to the Range module for recycling by calling the Release() method. It’s also possible to
create a static Range object which is owned by the application layer via the
Range.StaticStartEnd() function.
API
-
class Range:
Class -
staticmethod StaticStartEnd(startValue:
number, endValue:number):Range Acquires a static range object (can’t be released or mutated) for a given start and end value.
- Parameters:
startValue (
number) – The start value of the rangeendValue (
number) – The end value of the range
-
staticmethod AcquireStartEnd(startValue:
number, endValue:number):Range Acquires a range object for a given start and end value.
- Parameters:
startValue (
number) – The start value of the rangeendValue (
number) – The end value of the range
-
staticmethod AcquireStartLength(startValue:
number, length:number):Range Acquires a range object from a given start value and length.
- Parameters:
startValue (
number) – The start value of the rangelength (
number) – The length of the range
-
SetStartEnd(self:
Range, startValue:number, endValue:number):Range Sets the start value and end value of the range.
- Parameters:
startValue (
number) – The start value of the rangeendValue (
number) – The end value of the range
-
SetStartLength(self:
Range, startValue:number, length:number):Range Sets the start value and length of the range.
- Parameters:
startValue (
number) – The start value of the rangelength (
number) – The length of the range
-
GetValues(self:
Range): (startValue:number, endValue:number) Gets the start and end values of a range.
-
IntersectionLength(self:
Range, other:Range):number Returns the length of the intersection with another range or 0 if they don’t intersect.
- Parameters:
other (
Range) – The other range
-
Includes(self:
Range, value:number):boolean Returns whether or not the range includes a value.
- Parameters:
value (
number) – The value to check
-
Contains(self:
Range, other:Range):boolean Returns whether or not the range completely contains another range.
- Parameters:
other (
Range) – The other range
-
staticmethod StaticStartEnd(startValue: