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.

Property

constructor

static

non-null function()

Don't inherit the constructor from Array.

Methods

init

static

init(workspace)

Initialize a set of connection DBs for a specified workspace.

Parameter

workspace

Blockly.Workspace

The workspace this DB is for.

Value must not be null.

addConnection

addConnection(connection)

Add a connection to the database. Must not already exist in DB.

Parameter

connection

Blockly.Connection

The connection to be added.

Value must not be null.

findConnection

findConnection(conn) returns number

Find the given connection. Starts by doing a binary search to find the approximate location, then linearly searches nearby for the exact connection.

Parameter

conn

Blockly.Connection

The connection to find.

Value must not be null.

Returns

number The index of the connection, or -1 if the connection was not found.

getNeighbours

getNeighbours(connection, maxRadius) returns Array of Blockly.Connection

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

Parameter

connection

Blockly.Connection

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 Blockly.Connection List of connections.

searchForClosest

searchForClosest(conn, maxRadius, dxy) returns Object

Find the closest compatible connection to this connection.

Parameter

conn

Blockly.Connection

The connection searching for a compatible mate.

Value must not be null.

maxRadius

number

The maximum radius to another connection.

dxy

goog.math.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: nullable Blockly.Connection, radius: number} Contains two properties:' connection' which is either another connection or null, and 'radius' which is the distance.