The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



FindNearestItemScreen


Unit: SDL_rchart
Class: TRChart
Declaration: [1] function FindNearestItemScreen (mx, my: double; ItemID: TrcItem; ClassNumber: byte; var Dist: double): longint;
[1] function FindNearestItemScreen (mx, my: double; ItemID: TrcItem; ClassNumber: byte; VisLayersOnly: boolean; var Dist: double): longint;

The function FindNearestItemScreen searches for the item which is closest to the point [mx,my], belongs to the item type ItemID, and has a class number of ClassNumber. In order to search through all items of the data container, ItemID should be set to tkEverything and ClassNumber must be 255. The parameters mx and my refer to the coordinate system of the active layer.

There are two overloaded versions: version [2] provides the option to restrict the search to visible layers only by setting the parameter VisLayersOnly to TRUE.

The function returns the index of the closest item, which can be used to access the found item by means of GetItemParams, and SetItemParams. A value of -1 indicates that no element has been found. In addition, the variable parameter Dist contains the distance of the nearest item.

The distances between the reference point [mx,my] and the items of the chart are calculated using screen coordinates. Note, that there can be a big difference between calculating the distances in the real-world and in the screen coordinate system (in case of unisotropic axes).

Example: This method is used in the following example programs (see http://www.lohninger.com/examples.html for downloading the code): interpol3d, objcur, spline



Last Update: 2023-Dec-13