diff --git a/core/block_svg.js b/core/block_svg.js index f441486db..f67179913 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -469,32 +469,30 @@ Blockly.BlockSvg.prototype.snapToGrid = function() { * Returns the coordinates of a bounding box describing the dimensions of this * block and any blocks stacked below it. * Coordinate system: workspace coordinates. - * @return {!{topLeft: Blockly.utils.Coordinate, bottomRight: Blockly.utils.Coordinate}} - * Object with top left and bottom right coordinates of the bounding box. + * @return {!{top: number, bottom: number, left: number, right: number}} + * Object with top, bottom, left, and right coordinates of the bounding box. */ Blockly.BlockSvg.prototype.getBoundingRectangle = function() { var blockXY = this.getRelativeToSurfaceXY(this); var tab = this.outputConnection ? Blockly.BlockSvg.TAB_WIDTH : 0; var blockBounds = this.getHeightWidth(); - var topLeft; - var bottomRight; + var top = blockXY.y; + var bottom = blockXY.y + blockBounds.height; + var left, right; if (this.RTL) { // Width has the tab built into it already so subtract it here. - topLeft = new Blockly.utils.Coordinate( - blockXY.x - (blockBounds.width - tab), blockXY.y); + left = blockXY.x - (blockBounds.width - tab); // Add the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. - bottomRight = new Blockly.utils.Coordinate(blockXY.x + tab, - blockXY.y + blockBounds.height); + right = blockXY.x + tab; } else { // Subtract the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. - topLeft = new Blockly.utils.Coordinate(blockXY.x - tab, blockXY.y); + left = blockXY.x - tab; // Width has the tab built into it already so subtract it here. - bottomRight = new Blockly.utils.Coordinate( - blockXY.x + blockBounds.width - tab, blockXY.y + blockBounds.height); + right = blockXY.x + blockBounds.width - tab; } - return {topLeft: topLeft, bottomRight: bottomRight}; + return {top: top, bottom: bottom, left: left, right: right}; }; /** diff --git a/core/inject.js b/core/inject.js index 8ad0de9d0..93b1277fc 100644 --- a/core/inject.js +++ b/core/inject.js @@ -308,26 +308,26 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, var objectMetrics = object.getBoundingRectangle(); // Bump any object that's above the top back inside. - var overflowTop = metrics.viewTop - objectMetrics.topLeft.y; + var overflowTop = metrics.viewTop - objectMetrics.top; if (overflowTop > 0) { object.moveBy(0, overflowTop); } // Bump any object that's below the bottom back inside. var overflowBottom = - metrics.viewBottom - objectMetrics.bottomRight.y; + metrics.viewBottom - objectMetrics.bottom; if (overflowBottom < 0) { object.moveBy(0, overflowBottom); } // Bump any object that's off the left back inside. - var overflowLeft = metrics.viewLeft - objectMetrics.topLeft.x; + var overflowLeft = metrics.viewLeft - objectMetrics.left; if (overflowLeft > 0) { object.moveBy(overflowLeft, 0); } // Bump any object that's off the right back inside. - var overflowRight = metrics.viewRight - objectMetrics.bottomRight.x; + var overflowRight = metrics.viewRight - objectMetrics.right; if (overflowRight < 0) { object.moveBy(overflowRight, 0); } diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index a8051e812..e8d8720da 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -419,30 +419,28 @@ Blockly.WorkspaceCommentSvg.prototype.clearTransformAttributes_ = function() { * Returns the coordinates of a bounding box describing the dimensions of this * comment. * Coordinate system: workspace coordinates. - * @return {!{topLeft: Blockly.utils.Coordinate, bottomRight: Blockly.utils.Coordinate}} - * Object with top left and bottom right coordinates of the bounding box. + * @return {!{top: number, bottom: number, left: number, right: number}} + * Object with top, bottom, left, and right coordinates of the bounding box. * @package */ Blockly.WorkspaceCommentSvg.prototype.getBoundingRectangle = function() { var blockXY = this.getRelativeToSurfaceXY(); var commentBounds = this.getHeightWidth(); - var topLeft; - var bottomRight; + var top = blockXY.y; + var bottom = blockXY.y + commentBounds.height; + var left, right; if (this.RTL) { - topLeft = new Blockly.utils.Coordinate(blockXY.x - (commentBounds.width), - blockXY.y); + left = blockXY.x - (commentBounds.width); // Add the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. - bottomRight = new Blockly.utils.Coordinate(blockXY.x, - blockXY.y + commentBounds.height); + right = blockXY.x; } else { // Subtract the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. - topLeft = new Blockly.utils.Coordinate(blockXY.x, blockXY.y); - bottomRight = new Blockly.utils.Coordinate(blockXY.x + commentBounds.width, - blockXY.y + commentBounds.height); + left = blockXY.x; + right = blockXY.x + commentBounds.width; } - return {topLeft: topLeft, bottomRight: bottomRight}; + return {top: top, bottom: bottom, left: left, right: right}; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 6c95a623d..b86e6a13c 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1370,24 +1370,24 @@ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { // Start at 1 since the 0th block was used for initialization for (var i = 1; i < topElements.length; i++) { var blockBoundary = topElements[i].getBoundingRectangle(); - if (blockBoundary.topLeft.x < boundary.topLeft.x) { - boundary.topLeft.x = blockBoundary.topLeft.x; + if (blockBoundary.left < boundary.left) { + boundary.left = blockBoundary.left; } - if (blockBoundary.bottomRight.x > boundary.bottomRight.x) { - boundary.bottomRight.x = blockBoundary.bottomRight.x; + if (blockBoundary.right > boundary.right) { + boundary.right = blockBoundary.right; } - if (blockBoundary.topLeft.y < boundary.topLeft.y) { - boundary.topLeft.y = blockBoundary.topLeft.y; + if (blockBoundary.top < boundary.top) { + boundary.top = blockBoundary.top; } - if (blockBoundary.bottomRight.y > boundary.bottomRight.y) { - boundary.bottomRight.y = blockBoundary.bottomRight.y; + if (blockBoundary.bottom > boundary.bottom) { + boundary.bottom = blockBoundary.bottom; } } return { - x: boundary.topLeft.x, - y: boundary.topLeft.y, - width: boundary.bottomRight.x - boundary.topLeft.x, - height: boundary.bottomRight.y - boundary.topLeft.y + x: boundary.left, + y: boundary.top, + width: boundary.right - boundary.left, + height: boundary.bottom - boundary.top }; };