Interface: octree

syngen.tool.octree

Provides an octree interface for storing and querying objects in three-dimensional space.

Source:
See:
To Do:
  • Document private members

Methods

(static) create(optionsopt) → {syngen.tool.octree}

Instantiates a new octree.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}
Properties
Name Type Attributes Default Description
depth Number <optional>
syngen.const.maxSafeFloat * 2

Range of values along the z-axis. Typically this is set programmatically.

height Number <optional>
syngen.const.maxSafeFloat * 2

Range of values along the y-axis. Typically this is set programmatically.

maxItems Number <optional>
12

Number of items before the tree branches. This value is passed to child nodes.

width Number <optional>
syngen.const.maxSafeFloat * 2

Range of values along the y-axis. Typically this is set programmatically.

x Number <optional>
-syngen.const.maxSafeFloat

Lower bound for valeus along the x-axis. Typically this is set programmatically.

y Number <optional>
-syngen.const.maxSafeFloat

Lower bound for valeus along the y-axis. Typically this is set programmatically.

z Number <optional>
-syngen.const.maxSafeFloat

Lower bound for valeus along the z-axis. Typically this is set programmatically.

Source:
Returns:
Type
syngen.tool.octree

(static) from(itemsopt, optionsopt) → {syngen.tool.octree}

Instantiates a new octree with items and options.

Parameters:
Name Type Attributes Default Description
items Array.<Object> <optional>
[]
options Object <optional>
{}

See syngen.tool.octree.create for a full reference.

Source:
Returns:
Type
syngen.tool.octree

clear()

Clears all nodes and items.

Source:

destroy()

Prepares the instance for garbage collection.

Source:

filter(filterNode, filterItem, depthopt) → {Array.<Object>}

Returns the items which satisfy filterNode and filterItem.

Parameters:
Name Type Attributes Default Description
filterNode function

Returns true if the passed center and radius describing the node's bounding cube should be traversed. Use this as an optimization.

filterItem function

Returns whether the passed item is included in the result set.

depth Number <optional>
0

Do not use. Used internally to track recursion.

Source:
Returns:
Type
Array.<Object>

find(query, radiusopt) → {Object|undefined}

Finds the closest item to query within radius. If query is contained within the tree, then the next closest item is returned. If no result is found, then undefined is returned.

Parameters:
Name Type Attributes Default Description
query Object
Properties
Name Type Description
x Number
y Number
z Number
radius Number <optional>
Infinity
Source:
Returns:
Type
Object | undefined

insert(item)

Inserts item into the tree.

Parameters:
Name Type Description
item Object
Source:

intersects(prism) → {Boolean}

Returns whether this node intersects the rectanglular prism prism.

Parameters:
Name Type Description
prism Object
Properties
Name Type Attributes Default Description
depth Number <optional>
0
height Number <optional>
0
width Number <optional>
0
x Number <optional>
0
y Number <optional>
0
z Number <optional>
0
Source:
See:
To Do:
  • Define a rectangular prism utility or type
Returns:
Type
Boolean

reduce(filterNode, filterItemopt) → {Array.<Object>}

Reduces items in tree with filter functions.

Parameters:
Name Type Attributes Description
filterNode function

Accepts center and radius of nodes described as spheres.

filterItem function <optional>

Accepts the current item.

Source:
To Do:
  • Describe tree nodes as rectangular prisms for intersection tests.
Returns:
Type
Array.<Object>

remove(item)

Removes item from the tree, if it exists.

Parameters:
Name Type Description
item Object
Source:

retrieve(prism) → {Array.<Object>}

Retrieves all items within the rectanglular prism prism.

Parameters:
Name Type Description
prism Object
Properties
Name Type Attributes Default Description
depth Number <optional>
0
height Number <optional>
0
width Number <optional>
0
x Number <optional>
0
y Number <optional>
0
z Number <optional>
0
Source:
To Do:
  • Define a rectangular prism utility or type
Returns:
Type
Array.<Object>