Merge pull request #4894 from maribethb/clone-coord

Add a clone method to Coordinate
This commit is contained in:
Maribeth Bottorff
2021-06-10 16:24:41 -07:00
committed by GitHub
2 changed files with 9 additions and 2 deletions

View File

@@ -232,8 +232,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
*/
Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() {
// Returning a copy so the coordinate can not be changed outside this class.
return new Blockly.utils.Coordinate(
this.childSurfaceXY_.x, this.childSurfaceXY_.y);
return this.childSurfaceXY_.clone();
};
/**

View File

@@ -100,6 +100,14 @@ Blockly.utils.Coordinate.sum = function(a, b) {
return new Blockly.utils.Coordinate(a.x + b.x, a.y + b.y);
};
/**
* Creates a new copy of this coordinate.
* @return {!Blockly.utils.Coordinate} A copy of this coordinate.
*/
Blockly.utils.Coordinate.prototype.clone = function() {
return new Blockly.utils.Coordinate(this.x, this.y);
};
/**
* Scales this coordinate by the given scale factor.
* @param {number} s The scale factor to use for both x and y dimensions.