mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
[refactor]: use fromPolar() in randomDirection()
More compact code and one less temporary table in vector:randomDirection()
This commit is contained in:
parent
cdafc00075
commit
96c9648a62
@ -87,14 +87,11 @@ local function randomDirection(len_min, len_max)
|
||||
len_min = len_min or 1
|
||||
len_max = len_max or len_min
|
||||
|
||||
assert(len_max > 0, "randomDirection: len_max must be greater than zero")
|
||||
assert(len_max >= len_min, "randomDirection: len_max must be greater than or equal to len_min")
|
||||
assert(len_max > 0, "len_max must be greater than zero")
|
||||
assert(len_max >= len_min, "len_max must be greater than or equal to len_min")
|
||||
|
||||
local range = len_max - len_min
|
||||
local rnd = math.random() * range
|
||||
|
||||
local x,y = fromPolar(math.random()*2*math.pi)
|
||||
return x * (rnd + len_min), y * (rnd + len_min)
|
||||
return fromPolar(math.random()*2*math.pi,
|
||||
math.random() * (len_max-len_min) + len_min)
|
||||
end
|
||||
|
||||
local function toPolar(x, y)
|
||||
|
@ -44,12 +44,13 @@ local function randomDirection(len_min, len_max)
|
||||
len_min = len_min or 1
|
||||
len_max = len_max or len_min
|
||||
|
||||
assert(len_max > 0, "randomDirection: len_max must be greater than zero")
|
||||
assert(len_max >= len_min, "randomDirection: len_max must be greater than or equal to len_min")
|
||||
assert(len_max > 0, "len_max must be greater than zero")
|
||||
assert(len_max >= len_min, "len_max must be greater than or equal to len_min")
|
||||
|
||||
local range = len_max - len_min
|
||||
local rnd = math.random() * range
|
||||
return fromPolar(math.random()*2*math.pi) * (rnd + len_min)
|
||||
return fromPolar(math.random()*2*math.pi,
|
||||
math.random() * (len_max-len_min) + len_min)
|
||||
end
|
||||
|
||||
local function isvector(v)
|
||||
|
Loading…
Reference in New Issue
Block a user