Skip to main content

Class: Coordinate

Defined in: packages/blockly/core/utils/coordinate.ts:19

Class for representing coordinates and positions.

Properties index​

PropertyDescription
xLeft.
yTop.

Methods index​

MethodDescription
cloneCreates a new copy of this coordinate.
scaleScales this coordinate by the given scale factor.
translateTranslates this coordinate by the given offsets. respectively.
equalsCompares coordinates for equality.
distanceReturns the distance between two coordinates.
magnitudeReturns the magnitude of a coordinate.
differenceReturns the difference between two coordinates as a new Coordinate.
sumReturns the sum of two coordinates as a new Coordinate.

Constructors​

Constructor​

new Coordinate(x, y): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:24

Parameters​

ParameterTypeDescription
xnumberLeft.
ynumberTop.

Returns​

Coordinate

Properties​

x​

x: number;

Defined in: packages/blockly/core/utils/coordinate.ts:25

Left.


y​

y: number;

Defined in: packages/blockly/core/utils/coordinate.ts:26

Top.

Methods​

clone()​

clone(): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:34

Creates a new copy of this coordinate.

Returns​

Coordinate

A copy of this coordinate.


scale()​

scale(s): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:44

Scales this coordinate by the given scale factor.

Parameters​

ParameterTypeDescription
snumberThe scale factor to use for both x and y dimensions.

Returns​

Coordinate

This coordinate after scaling.


translate()​

translate(tx, ty): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:58

Translates this coordinate by the given offsets. respectively.

Parameters​

ParameterTypeDescription
txnumberThe value to translate x by.
tynumberThe value to translate y by.

Returns​

Coordinate

This coordinate after translating.


equals()​

static equals(a?, b?): boolean;

Defined in: packages/blockly/core/utils/coordinate.ts:71

Compares coordinates for equality.

Parameters​

ParameterTypeDescription
a?Coordinate | nullA Coordinate.
b?Coordinate | nullA Coordinate.

Returns​

boolean

True iff the coordinates are equal, or if both are null.


distance()​

static distance(a, b): number;

Defined in: packages/blockly/core/utils/coordinate.ts:88

Returns the distance between two coordinates.

Parameters​

ParameterTypeDescription
aCoordinateA Coordinate.
bCoordinateA Coordinate.

Returns​

number

The distance between a and b.


magnitude()​

static magnitude(a): number;

Defined in: packages/blockly/core/utils/coordinate.ts:100

Returns the magnitude of a coordinate.

Parameters​

ParameterTypeDescription
aCoordinateA Coordinate.

Returns​

number

The distance between the origin and a.


difference()​

static difference(a, b): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:112

Returns the difference between two coordinates as a new Coordinate.

Parameters​

ParameterTypeDescription
aCoordinate | DOMPointAn x/y coordinate.
bCoordinate | DOMPointAn x/y coordinate.

Returns​

Coordinate

A Coordinate representing the difference between a and b.


sum()​

static sum(a, b): Coordinate;

Defined in: packages/blockly/core/utils/coordinate.ts:126

Returns the sum of two coordinates as a new Coordinate.

Parameters​

ParameterTypeDescription
aCoordinate | DOMPointAn x/y coordinate.
bCoordinate | DOMPointAn x/y coordinate.

Returns​

Coordinate

A Coordinate representing the sum of the two coordinates.