Class TRbwQuadTree

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TRbwQuadTree = class(TComponent)

Description

TRbwQuadTree is used to quickly retrieve data by their X and Y coordinates.

Methods are provided to search at a location or within a defined region

Hierarchy

Overview

Fields

Private FMaxPoints: integer;
Private FQTreeNode: TQtreeNode;

Methods

Private function GetCount: integer;
Private function GetPoints(Index: Integer): TQuadPoint;
Private function GetXMax: double;
Private function GetXMin: double;
Private function GetYMax: double;
Private function GetYMin: double;
Private procedure SetXMax(const AValue: double);
Private procedure SetXMin(const AValue: double);
Private procedure SetYMax(const AValue: double);
Private procedure SetYMin(const AValue: double);
Private procedure SetMaxPoints(const Value: integer);
Public procedure AddPoint(X, Y: double; Data: pointer);
Public procedure Clear;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure FindClosestPointsData(var X, Y: double; var Data: TPointerArray);
Public procedure FindNearestPoints(const CenterX, CenterY: double; const Count: Integer; var Points: TQuadPointArray);
Public procedure FindPointsInBlock(const Block: T2DBlock; var Points: TQuadPointInRegionArray);
Public procedure FindPointsInCircle(const CenterX, CenterY, Radius: double; var Points: TQuadPointInRegionArray);
Public procedure FirstNearestPoint(var X, Y: double; var Data: pointer);
Public function NearestPointsFirstData(X, Y: double): pointer;
Public function RemovePoint(X, Y: double; Data: pointer): boolean;

Properties

Public property Count: integer read GetCount;
Public property Points[Index:Integer]: TQuadPoint read GetPoints;
Published property MaxPoints: integer read FMaxPoints write SetMaxPoints;
Published property XMax: double read GetXMax write SetXMax;
Published property XMin: double read GetXMin write SetXMin;
Published property YMax: double read GetYMax write SetYMax;
Published property YMin: double read GetYMin write SetYMin;

Description

Fields

Private FMaxPoints: integer;

FMaxPoints: integer; See MaxPoints.

Private FQTreeNode: TQtreeNode;

FQTreeNode: TQtreeNode; FQTreeNode does the actual work of the TRbwQuadTree.

Methods

Private function GetCount: integer;

See Count.

Private function GetPoints(Index: Integer): TQuadPoint;

See Points.

Private function GetXMax: double;

See XMax.

Private function GetXMin: double;

See XMin.

Private function GetYMax: double;

See YMax.

Private function GetYMin: double;

See YMin.

Private procedure SetXMax(const AValue: double);

See XMax.

Private procedure SetXMin(const AValue: double);

See XMin.

Private procedure SetYMax(const AValue: double);

See YMax.

Private procedure SetYMin(const AValue: double);

See YMin.

Private procedure SetMaxPoints(const Value: integer);

See MaxPoints.

Public procedure AddPoint(X, Y: double; Data: pointer);

AddPoint stores Data at location X, Y.

If there is already a point at that location the number of pointers stored at that point will be increased by one and the new data will be added at the end of the list of data for the point. Count will be unaffected.

If there is not already a point at that location, one will be created and the data will be associated with it, and the Count will be incremented by one.

If required, XMax, XMin, YMax, or YMin will be adjusted to accomodate the new data point.

The Data associated with a location is not owned by the TRbwQuadTree; users are responsible for freeing that memory when it is no longer needed.

Public procedure Clear;

Clear deletes all data locations in the TRbwQuadTree and resets the Count to 0.

The Data associated with a location is not owned by the TRbwQuadTree; users are responsible for freeing that memory when it is no longer needed.

Public constructor Create(AOwner: TComponent); override;

Creates an instance of TRbwQuadTree;

Public destructor Destroy; override;

Destroy and instance of TRbwQuadTree. Applications should not call Destroy directly. Instead call Free;

Public procedure FindClosestPointsData(var X, Y: double; var Data: TPointerArray);

FindClosestPointsData locates the location nearest to the X, Y values provided as input. It than returns the X and Y values of that location. The length of Data is changed to the number of pointers stored at the location that was found and the Data pointers are copied into Data.

Public procedure FindNearestPoints(const CenterX, CenterY: double; const Count: Integer; var Points: TQuadPointArray);

FindNearestPoints finds the Count locations in the TRbwQuadTree that are closest to CenterX, CenterY and returns them and their associated data in Points. In the event of ties, the length of Points may be larger than Count. If the number of locations in the TRbwQuadTree is less than Count, all the locations will be returned. Points are sorted from the closest locations to CenterX, CenterY to those that are most distant.

See also FirstNearestPoint, NearestPointsFirstData

Public procedure FindPointsInBlock(const Block: T2DBlock; var Points: TQuadPointInRegionArray);

FindPointsInBlock finds all locations stored in the TRbwQuadTree that are inside Block and returns them in Points along with their associated data. Points is not sorted.

Public procedure FindPointsInCircle(const CenterX, CenterY, Radius: double; var Points: TQuadPointInRegionArray);

FindPointsInCircle finds all the locations stored in the TRbwQuadTree that are within a distance of Radius from CenterX, CenterY and returns them and their associated data in Points. Points is not sorted.

Public procedure FirstNearestPoint(var X, Y: double; var Data: pointer);

FirstNearestPoint, finds the location in the TRbwQuadTree that is closest to X, Y and returns it in X, Y. The associated data is returned in Data. In the event of ties in location, the location that is returned is chosen arbitrarily from the locations that are closest. If more than one piece of data is stored at X, Y, the one that is returned is chosen arbitrarily.

See also: FindNearestPoints and NearestPointsFirstData.

Public function NearestPointsFirstData(X, Y: double): pointer;

NearestPointsFirstData finds the location stored in the TRbwQuadTree that is closest to X, Y and returns the first piece of data associated with that location.

See also: FindNearestPoints and FirstNearestPoint.

Public function RemovePoint(X, Y: double; Data: pointer): boolean;

RemovePoint removes Data at location X, Y.

If the number of data pointers stored at X, Y is greater than 1, Data will be deleted from the list of data pointers and Count will be unaffected.

If there is only one data pointer stored at X, Y, that location will be deleted and the Count will be decremented by one.

The Data associated with a location is not owned by the TRbwQuadTree; users are responsible for freeing that memory when it is no longer needed.

Properties

Public property Count: integer read GetCount;

Count is the number of unique locations stored in a TRbwQuadTree.

Public property Points[Index:Integer]: TQuadPoint read GetPoints;

Points can be treated as an indexed array of the locations stored in the TRbwQuadTree.

Published property MaxPoints: integer read FMaxPoints write SetMaxPoints;

MaxPoints is the maximum number of data locations in any node of a TRbwQuadTree. MaxPoints affects the performance of the TRbwQuadTree in the retrieval of data in a manner that depends on the particular application.

Published property XMax: double read GetXMax write SetXMax;

XMax is the largest X value of any of the data points that are expected to be or have already been added to the TRbwQuadTree. Although it is not required that XMax be greater than the X coordinate of all locations added to the TRbwQuadTree, performance may suffer if too many of them are greater than XMax.

Published property XMin: double read GetXMin write SetXMin;

XMin is the smallest X value of any of the data points that are expected to be or have already been added to the TRbwQuadTree. Although it is not required that XMin be less than the X coordinate of all locations added to the TRbwQuadTree, performance may suffer if too many of them are less than XMin.

Published property YMax: double read GetYMax write SetYMax;

YMax is the largest Y value of any of the data points that are expected to be or have already been added to the TRbwQuadTree. Although it is not required that YMax be greater than the Y coordinate of all locations added to the TRbwQuadTree, performance may suffer if too many of them are greater than YMax.

Published property YMin: double read GetYMin write SetYMin;

YMin is the smallest Y value of any of the data points that are expected to be or have already been added to the TRbwQuadTree. Although it is not required that YMin be less than the Y coordinate of all locations added to the TRbwQuadTree, performance may suffer if too many of them are less than YMin.


Generated by PasDoc 0.12.1 on 2013-05-13 15:41:58