rj-action-library/Runtime/LOD/NTree/OcTree/OcTreeWalker.cs

53 lines
1000 B
C#

using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
public class OcTreeWalker<T>:TreeWalker<OcTreeNode<T>>
{
public override OcTreeNode<T> Parent( OcTreeNode<T> node )
{
if ( node is OcTree<T> )
{
return null;
}
var cell = node as OcTreeCell<T>;
return cell.isRoot ? cell.tree : cell.parent;
}
public override int NumChildren( OcTreeNode<T> node )
{
if ( node is OcTree<T> tree )
{
return tree.rootCells.Count;
}
var cell = node as OcTreeCell<T>;
return cell.numCells;
}
public override OcTreeNode<T> ChildAt( OcTreeNode<T> node, int index )
{
if ( index < 0 || index >= NumChildren( node ) )
{
return null;
}
if ( node is OcTree<T> tree )
{
return tree.rootCells[ index ];
}
var cell = node as OcTreeCell<T>;
return cell.cells[ index ];
}
}
}