Table of Contents

Class QuadTree<T>

Namespace
CADability
Assembly
CADability.dll

A quadtree of 2d objects which implement IQuadTreeInsertable: the plane is recursively divided into quadrants so that the objects at a position or in a rectangle can be found without testing all of them (GetObjectsFromRect(BoundingRect), GetObjectsCloseTo(T), ObjectsFromRect(BoundingRect)...). Objects are added with AddObject(T); a leaf is split when it holds more than MaxListLen objects, down to a depth of MaxDeepth. Used e.g. for picking in 2d, for the triangulation of faces and for intersecting 2d curves. This generic version supersedes the older non-generic QuadTree.

public class QuadTree<T> where T : class, IQuadTreeInsertable

Type Parameters

T

Type of the objects in the tree

Inheritance
QuadTree<T>
Inherited Members

Constructors

QuadTree()

public QuadTree()

QuadTree(BoundingRect)

public QuadTree(BoundingRect initialRect)

Parameters

initialRect BoundingRect

Fields

MaxDeepth

The maximum deepth of the tree. If a node has this deepth no more subnodes will be generated but the list of objects in that node might increase MaxListlen.

public int MaxDeepth

Field Value

int

MaxListLen

The maximum number of objects in a leaf-node unless MaxDeepth has been reached

public int MaxListLen

Field Value

int

Properties

AllLists

public IEnumerable<List<T>> AllLists { get; }

Property Value

IEnumerable<List<T>>

Size

public BoundingRect Size { get; }

Property Value

BoundingRect

SomeObject

public T SomeObject { get; }

Property Value

T

Methods

AddObject(T)

Adds the specified object to the QuadTree

public void AddObject(T ObjectToAdd)

Parameters

ObjectToAdd T

Object to add

AddObjects(List<T>)

public void AddObjects(List<T> ObjectsToAdd)

Parameters

ObjectsToAdd List<T>

AllObjects()

Returns an enumerator for all objects in this QuadTree. Each object is returned only once.

public IEnumerable<T> AllObjects()

Returns

IEnumerable<T>

Enumerator for all objects

Check(IQuadTreeInsertable, CheckOne)

public bool Check(IQuadTreeInsertable closeTo, QuadTree<T>.CheckOne check)

Parameters

closeTo IQuadTreeInsertable
check QuadTree<T>.CheckOne

Returns

bool

GetAllLists()

public (BoundingRect Bounds, T[] Objects)[] GetAllLists()

Returns

(BoundingRect Bounds, T[] Objects)[]

GetAllObjects()

public T[] GetAllObjects()

Returns

T[]

GetObjectsCloseTo(IQuadTreeInsertable)

public T[] GetObjectsCloseTo(IQuadTreeInsertable CloseToThis)

Parameters

CloseToThis IQuadTreeInsertable

Returns

T[]

GetObjectsCloseTo(T)

Returns an array of objects that are close to the specified object. The returned objects may or may not interfere with the specified object, but it is guaranteed that all objects touching or intersecting the specified object are in the returned array.

public T[] GetObjectsCloseTo(T CloseToThis)

Parameters

CloseToThis T

Object to filter result with

Returns

T[]

Array of all appropriate objects

GetObjectsFromRect(BoundingRect)

Returns an array of objects that are close to the specified bounding rectangle. The objects may overlap the rectangle or even be totaly outside of the rectangle depending on the granularity of the Quadtree. But all objects inside the rectangle or interfering with the rectangle are guaranteed to be returned.

public T[] GetObjectsFromRect(BoundingRect r)

Parameters

r BoundingRect

The filter rectangle

Returns

T[]

Array of all appropriate objects

GetObjectsInsideRect(BoundingRect)

Returns an array of objects that are inside the specified bounding rectangle.

public T[] GetObjectsInsideRect(BoundingRect r)

Parameters

r BoundingRect

The filter rectangle

Returns

T[]

Array of all appropriate objects

ObjectsCloseTo(IQuadTreeInsertable, bool)

Returns an enumerator for all objects that are closed to the specified object. The distance depends upon the granularity of the QuadTree. if eliminateMultiple is false, the same object may be yielded in the enumerator multiple times, but the execution speed is much faster, if eliminateMultiple is true, there will be bookkeeping not to yield the same object multiple times.

public IEnumerable<T> ObjectsCloseTo(IQuadTreeInsertable CloseToThis, bool eliminateMultiple)

Parameters

CloseToThis IQuadTreeInsertable

Filter objects close to this object

eliminateMultiple bool

false: fast mode, multiple yields, true: single yield per object

Returns

IEnumerable<T>

Enumertor for those objects

ObjectsCloseTo(T)

Returns an enumerator for all objects that are closed to the specified object. The distance depends upon the granularity of the QuadTree.

public IEnumerable<T> ObjectsCloseTo(T CloseToThis)

Parameters

CloseToThis T

Filter objects close to this object

Returns

IEnumerable<T>

Enumertor for those objects

ObjectsFromRect(BoundingRect)

Returns an enumerator for all objects that are close to the specified bounding rectangle.

public IEnumerable<T> ObjectsFromRect(BoundingRect r)

Parameters

r BoundingRect

The rectangle to filter objects

Returns

IEnumerable<T>

Enumerator for those objects

ObjectsInsideRect(BoundingRect)

Returns an enumerator for all objects that are completely inside the specified bounding rectangle.

public IEnumerable<T> ObjectsInsideRect(BoundingRect r)

Parameters

r BoundingRect

The rectangle to filter objects

Returns

IEnumerable<T>

Enumerator for those objects

RemoveObject(T)

Removes the specified object from the QuadTree

public void RemoveObject(T ObjectToRemove)

Parameters

ObjectToRemove T

Object to remove

RemoveObjects(List<T>)

public void RemoveObjects(List<T> ObjectsToRemove)

Parameters

ObjectsToRemove List<T>