Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(rect-helpers): make getBoundingRect take an array of rectangles #8789

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions lighthouse-core/lib/rect-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ function rectsTouchOrOverlap(rectA, rectB) {

/**
* Returns a bounding rect for all the passed in rects, with padded with half of
* `minimumSize` on all sides.
* `padding` on all sides.
* @param {LH.Artifacts.Rect[]} rects
* @param {number} minimumSize
* @param {number} padding
* @return {LH.Artifacts.Rect}
*/
function getBoundingRectWithPadding(rects, minimumSize) {
function getBoundingRectWithPadding(rects, padding) {
if (rects.length === 0) {
throw new Error('No rects to take bounds of');
}
Expand All @@ -114,7 +114,7 @@ function getBoundingRectWithPadding(rects, minimumSize) {
}

// Pad on all sides.
const halfMinSize = minimumSize / 2;
const halfMinSize = padding / 2;
left -= halfMinSize;
right += halfMinSize;
top -= halfMinSize;
Expand All @@ -131,20 +131,10 @@ function getBoundingRectWithPadding(rects, minimumSize) {
}

/**
* @param {LH.Artifacts.Rect} rectA
* @param {LH.Artifacts.Rect} rectB
* @param {LH.Artifacts.Rect[]} rects
*/
function getBoundingRect(rectA, rectB) {
const left = Math.min(rectA.left, rectB.left);
const right = Math.max(rectA.right, rectB.right);
const top = Math.min(rectA.top, rectB.top);
const bottom = Math.max(rectA.bottom, rectB.bottom);
return addRectWidthAndHeight({
left,
right,
top,
bottom,
});
function getBoundingRect(rects) {
return getBoundingRectWithPadding(rects, 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/tappable-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function mergeTouchingClientRects(clientRects) {
(rectsLineUpHorizontally || rectsLineUpVertically);

if (canMerge) {
const replacementClientRect = getBoundingRect(crA, crB);
const replacementClientRect = getBoundingRect([crA, crB]);
const mergedRectCenter = getRectCenterPoint(replacementClientRect);

if (
Expand Down