Graphic.SpatialContainer Class
A spatial container is a data structure used for storage of spatial 2D objects (generally GraphicObject). It propose many method for manipulate these objects using theirs coordinates.
This class provide a basic implementation of all methods, and also represent an interface to others spatial containers. Different containers provides different complexities, and for each situation, someone are more adapted than others.
Constructor
Graphic.SpatialContainer
()
Item Index
Methods
addElement
-
element
This method allow you to add a GraphicalObject to the SpatialContainer
Parameters:
-
element
Objectthis object will be added to the internal list of the SpatialContainer. element SHOULD BE a GraphicObject, otherwise the spatial container would have undetermined behavior.
applyAll
-
callback
This method allow you to apply a callback for every GraphicObject contained in the SpatialContainer.
The callback shouldn't remove directly an element until the end of applyAll
.
The behavior in this case is undefined.
Parameters:
-
callback
Functionmust be a callback function
-
element
Objectelement contained in spatial container.
-
Example:
container.applyAll(function(element) {
element.draw();
});
applyToPoint
-
x
-
y
-
callback
This method allow you to apply a callback to the GraphicObject who are at the specified position.
Parameters:
-
x
Numberthe x position where the GraphicObject must be to get the callback applied on them
-
y
Numberthe y position where the GraphicObject must be to get the callback applied on them.
-
callback
Functionto apply to every GraphicObject which position match the x, y parameters.
applyToZone
-
pointsArray
-
callback
This method allow you to apply a callback only on the object that are inside of the polygon specified by the points.
The goal is to process optimization to apply callback only if necessary, for improve speed. Objects that are not in the zone can be used: somes optimizations can be aproximate.
The default method use directly applyAll
and no optimization is done. (selecting good and bas objects
whithout tree structure take more time than display them)
Parameters:
-
pointsArray
Arrayarray of points like `{{10,0},{0,10},{2,3}} Note that the polygon MUST BE composed at least of 3 points, otherwise the method will throw an error.
-
callback
Functionfunction to be called on every GraphicObject that are inside of the polygon specified by pointsArray.
removeElement
-
element
This method allow you to remove a graphical element from the SpatialContainer
Parameters:
-
element
Objectthe reference to the object to remove from the SpatialContainer List.
Returns:
true
if the element to remove from the list was found. Otherwise it returns false
.