Class: Quadtree

rune.display.Quadtree(boundsopt, thresholdopt, maxDepthopt, depthopt)

The Quadtree class represents a tree data structure that divides objects within a rectangular two-dimensional surface into nodes of four. When a node has been populated with a number of objects that exceed a specified threshold value, the current node is divided into four new nodes and so on. The data structure makes it easy to find objects that are in the geometric proximity of another object.

Constructor

new Quadtree(boundsopt, thresholdopt, maxDepthopt, depthopt)

Creates a new Quadtree object.
Parameters:
Name Type Attributes Default Description
bounds rune.geom.Rectangle <optional>
Represents the rectangular size of the quad tree.
threshold number <optional>
8 Threshold for subdivision, ie objects per node.
maxDepth number <optional>
4 Maximum node depth.
depth number <optional>
0 Standard depth.
Source:
See:

Extends

Members

bottom :number

The sum of the y and height properties.
Type:
  • number
Inherited From:
Source:

bottomLeft :rune.geom.Rectangle

The location of the Rectangle object's bottom-left corner, determined by the values of the left and bottom properties.
Type:
Inherited From:
Source:

bottomRight :rune.geom.Rectangle

The location of the Rectangle object's bottom-right corner, determined by the values of the right and bottom properties.
Type:
Inherited From:
Source:

center :rune.geom.Point

The center point of the rectangle object.
Type:
Inherited From:
Source:

centerX :number

The x coordinate of the center of the object.
Type:
  • number
Inherited From:
Source:

centerY :number

The y coordinate of the center of the object.
Type:
  • number
Inherited From:
Source:

height :number

The height of the rectangle, in pixels.
Type:
  • number
Inherited From:
Source:

left :number

The x coordinate of the top-left corner of the rectangle.
Type:
  • number
Inherited From:
Source:
The sum of the x and width properties.
Type:
  • number
Inherited From:
Source:

size :rune.geom.Point

The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
Type:
Inherited From:
Source:

top :number

The y coordinate of the top-left corner of the rectangle.
Type:
  • number
Inherited From:
Source:

topLeft :rune.geom.Point

The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.
Type:
Inherited From:
Source:

topRight :rune.geom.Point

The location of the Rectangle object's top-right corner, determined by the x and y coordinates of the point.
Type:
Inherited From:
Source:

width :number

The width of the rectangle, in pixels.
Type:
  • number
Inherited From:
Source:

x :number

The horizontal coordinate of the point. The default value is 0.
Type:
  • number
Inherited From:
Source:

y :number

The vertical coordinate of the point. The default value is 0.
Type:
  • number
Inherited From:
Source:

Methods

clear() → {undefined}

Clears the current tree structure. This includes all nodes.
Source:
Returns:
Type
undefined

containsPoint(point) → {boolean}

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.
Parameters:
Name Type Description
point rune.geom.Point The point, as represented by its x and y coordinates.
Inherited From:
Source:
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
Type
boolean

containsRectangle(rect) → {boolean}

Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object. A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Parameters:
Name Type Description
rect rune.geom.Rectangle The Rectangle object being checked.
Inherited From:
Source:
Returns:
A value of true if the Rectangle object that you specify is contained by this Rectangle object; otherwise false.
Type
boolean

distance(point) → {number}

Returns the distance between the current and specified point.
Parameters:
Name Type Description
point rune.geom.Point The specified point.
Inherited From:
Source:
Returns:
Type
number

getIndexOfPoint(point) → {number}

Returns within which node the passed Point object belongs to. Note that the method returns the node index and not the actual node.
Parameters:
Name Type Description
point rune.geom.Point Current point.
Source:
Returns:
Type
number

getIndexOfRectangle(rectangle) → {Array.<number>}

Returns within which nodes a Rectangel object is located. The method returns a list of node indexes. Note that the same node index can only occur once. For example, if all the corners of the rectangle are within the same node index, the length of the list will be 1.
Parameters:
Name Type Description
rectangle rune.geom.Rectangle Current rectangle.
Source:
Returns:
Type
Array.<number>

insert(rectangle) → {undefined}

The object to be sorted according to the tree structure.
Parameters:
Name Type Description
rectangle rune.geom.Rectangle Object to sort.
Source:
Returns:
Type
undefined

interpolate(point, fractionopt, outputopt) → {rune.geom.Point}

Determines a point between two specified points. The parameter fraction determines where the new interpolated point is located relative to the two end points.
Parameters:
Name Type Attributes Description
point rune.geom.Point The second point.
fraction number <optional>
The level of interpolation between the two points.
output rune.geom.Point <optional>
Save results to this object.
Inherited From:
Source:
Returns:
The new, interpolated point.
Type
rune.geom.Point

intersection(toIntersect, outputopt) → {rune.geom.Rectangle}

If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Parameters:
Name Type Attributes Description
toIntersect rune.geom.Rectangle The Rectangle object to compare against to see if it intersects with this Rectangle object.
output rune.geom.Rectangle <optional>
A Rectangle object to store the intersection results in.
Inherited From:
Source:
Returns:
A Rectangle object that equals the area of intersection.
Type
rune.geom.Rectangle

intersects(toIntersect) → {boolean}

Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object.
Parameters:
Name Type Description
toIntersect rune.geom.Rectangle The Rectangle object to compare against this Rectangle object.
Inherited From:
Source:
Returns:
A value of true if the specified object intersects with this Rectangle object; otherwise false.
Type
boolean

retrieve(rectangle) → {Array.<rune.geom.Rectangle>}

Retrieves objects from the tree structure that are in the same node as the argument object.
Parameters:
Name Type Description
rectangle rune.geom.Rectangle Current object.
Source:
Returns:
Type
Array.<rune.geom.Rectangle>

split() → {undefined}

Divides the tree into four new nodes.
Source:
Returns:
Type
undefined

toString() → {string}

Returns a string representation of the hitbox. Useful for troubleshooting.
Overrides:
Source:
Returns:
Type
string