Notifications
Clear all
[Closed] Reorder an object array
Page 2 / 2
Prev
Feb 17, 2014 9:38 pm
and finally:
fn isParent node parent =
(
local act = off
while node.parent != undefined and not (act = node.parent == parent) do node = node.parent
act
)
fn sortByHierarchy n1 n2 dir:1 =
(
(if isParent n1 n2 then 1 else if isParent n2 n1 then -1 else 0)*dir
)
fn makeHierarchyOrder nodes dir:1 =
(
qsort nodes sortByHierarchy dir:dir
nodes
)
-- makeHierarchyOrder (selection as array)
Feb 18, 2014 2:34 pm
my IsParent fn
fn isParent n1 n2 =
(
local obj = n2
while obj.parent != undefined do
(
obj = obj.parent
if obj == n1 do return true
)
return false
)
clearly not as advanced as denis fn
denis I get what your dir is doing but got an example why you would need to change that?
Feb 18, 2014 2:34 pm
yeah haha I already knew that your fonction was way better than mine and more efficient
what I meant is why would you use dir:dir in your functions … why would you want to set dir to something else than 1 in the qsort fn ?
I hope you dont mind my curiosity
Feb 18, 2014 2:34 pm
if you set dir to -1 it will sort objects in reverse order (from children to parent). for example using exactly this order is safer in many cases delete nodes from hierarchy.
Page 2 / 2
Prev