API Docs for: 0.3.0
Show:

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

()

Methods

addElement

(
  • element
)

This method allow you to add a GraphicalObject to the SpatialContainer

Parameters:

  • element Object

    this 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 Function

    must be a callback function

    • element Object

      element 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 Number

    the x position where the GraphicObject must be to get the callback applied on them

  • y Number

    the y position where the GraphicObject must be to get the callback applied on them.

  • callback Function

    to 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 Array

    array 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 Function

    function to be called on every GraphicObject that are inside of the polygon specified by pointsArray.

removeElement

(
  • element
)
Boolean

This method allow you to remove a graphical element from the SpatialContainer

Parameters:

  • element Object

    the reference to the object to remove from the SpatialContainer List.

Returns:

Boolean: true if the element to remove from the list was found. Otherwise it returns false.