Flocc
    Preparing search index...

    Class KDTree

    0.3.5

    Index

    Constructors

    • Parameters

      • agents: Agent[]
      • dimension: number = 2
      • depth: number = 0
      • Optionalbbox: BBox

      Returns KDTree

    Properties

    agents: Agent[] = null
    bbox: BBox
    depth: number = 0
    dimension: number = 2
    left: KDTree = null
    median: number = null
    needsUpdating: boolean = false
    parent: KDTree = null
    right: KDTree = null

    Methods

    • Return all the Agents in this KDTree that are within d distance of the given Point or Agent pt, optionally restricted to agents that pass filterFn.

      Parameters

      • pt: Agent | Point
      • d: number
      • OptionalfilterFn: (a: Agent) => boolean = ...

        Optional predicate; only matching agents are returned. Defaults to accepting all agents.

      Returns Agent[]

      0.3.5

    • Parameters

      • pt: Agent | Point
      • d: number
      • coord: "x" | "y" | "z"

      Returns boolean

    • Returns the Agent in this KDTree that is closest spatially to the given Point or Agent pt, optionally restricted to agents that pass filterFn.

      When pt is an Agent, its cached __subtree reference is used directly instead of traversing from the root, avoiding an O(log n) traversal and a potential out-of-bounds error. The search expands outward until a qualifying candidate is found, then widens to all subtrees within that distance to guarantee the true nearest filtered neighbor is returned. Distance values are computed once per candidate and cached to avoid redundant calculations during sorting.

      Parameters

      • pt: Agent | Point

        The reference point or agent to search from.

      • OptionalfilterFn: (a: Agent) => boolean = ...

        Optional predicate. Only agents for which filterFn(agent) returns true are considered. Defaults to accepting all agents.

      Returns Agent

      The nearest qualifying agent.

      0.3.5

    • Rebalance the KDTree (if it has been marked as needing updating). Optionally pass the agents that belong to this tree (relevant for trees of higher depth than the top level).

      Parameters

      Returns void

      0.3.5