Class: KDTreeXY

PD.Path. KDTreeXY

A class that implements a KDTree for XY nearest neighbor search.

This class is used to build a KDTree from a set of 2D points and perform nearest neighbor and bounding box searches. It is particularly useful for efficiently finding points that are close to a given point within a specified radius or within a rectangular region.

This class is primarily used by the BIM.Level class to build a tree of adjacent junctions between BIM.Space paths.


new KDTreeXY(points)

Creates a new KDTree instance from an array of path points.

Parameters:
Name Type Description
points Array.<PD.PathPoint>

The array of path points to search through.

Author:
  • drajmarsh

Methods


buildTree(points, depth)

Recursively builds a 3D KD tree.

Parameters:
Name Type Description
points Array.<Object>

Array of points, each with {x, y, z}.

depth number

The current depth within the tree.

Returns:

A node representing part of the KD tree.

Type
Object | null

findColinear(pathPoint, tolerance, results, depth)

Searches for all points within the bounds of the path segment that are within the given tolerance of its linear path.

Parameters:
Name Type Default Description
pathPoint PD.PathPoint

The path segment to search around.

tolerance number

The distance from the segment to search within.

results Array.<PD.PathPoint>

An array to store the found points.

depth number 0

The current depth of the tree.

Returns:

Returns the results array containing the found points.

Type
Array.<PD.PathPoint>

fromPaths(paths) <static>

Creates a new KDTree instance from points in the given paths.

Parameters:
Name Type Description
paths Array.<PD.Path>

The list of paths to search through.

Returns:

Returns a new KDTreeXY instance.

Type
KDTreeXY