Class: ConnectionDB

Constructor

ConnectionDB

new ConnectionDB()

Database of connections. Connections are stored in order of their vertical component. This way connections in an area may be looked up quickly using a binary search.

Methods

init

static

init() returns Array of non-null Blockly.ConnectionDB

Initialize a set of connection DBs for a workspace.

Returns

non-null Array of non-null Blockly.ConnectionDB Array of databases.

addConnection

package

addConnection(connection, yPos)

Add a connection to the database. Should not already exist in the database.

Parameter

connection

Blockly.RenderedConnection

The connection to be added.

Value must not be null.

yPos

number

The y position used to decide where to insert the connection.

getNeighbours

getNeighbours(connection, maxRadius) returns Array of non-null Blockly.RenderedConnection

Find all nearby connections to the given connection. Type checking does not apply, since this function is used for bumping.

Parameter

connection

Blockly.RenderedConnection

The connection whose neighbours should be returned.

Value must not be null.

maxRadius

number

The maximum radius to another connection.

Returns

non-null Array of non-null Blockly.RenderedConnection List of connections.

removeConnection

removeConnection(connection, yPos)

Remove a connection from the database. Must already exist in DB.

Parameter

connection

Blockly.RenderedConnection

The connection to be removed.

Value must not be null.

yPos

number

The y position used to find the index of the connection.

Throws

Error If the connection cannot be found in the database.

searchForClosest

searchForClosest(conn, maxRadius, dxy) returns Object

Find the closest compatible connection to this connection.

Parameter

conn

Blockly.RenderedConnection

The connection searching for a compatible mate.

Value must not be null.

maxRadius

number

The maximum radius to another connection.

dxy

Blockly.utils.Coordinate

Offset between this connection's location in the database and the current location (as a result of dragging).

Value must not be null.

Returns

non-null {connection: Blockly.RenderedConnection, radius: number} Contains two properties: 'connection' which is either another connection or null, and 'radius' which is the distance.