Commit 5c975b32 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

Make RectUtil a shared class amongst a11y extensions

As part of the overall effort to share more code between the
accessibility component extensions, move Switch Access' RectUtil class
into the common/ directory.

This change is a pure refactor.

AX-Relnotes: n/a.
Bug: None.
Change-Id: I2980080ad643bef76720095c67bbd9165e645f6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368481Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#801604}
parent 469da494
...@@ -145,21 +145,21 @@ js2gtest("misc_unit_tests_js") { ...@@ -145,21 +145,21 @@ js2gtest("misc_unit_tests_js") {
test_type = "unit" test_type = "unit"
sources = [ sources = [
"braille_ime/braille_ime_unittest.js", "braille_ime/braille_ime_unittest.js",
"common/rect_util_unittest.js",
"select_to_speak/node_utils_unittest.js", "select_to_speak/node_utils_unittest.js",
"select_to_speak/paragraph_utils_unittest.js", "select_to_speak/paragraph_utils_unittest.js",
"select_to_speak/rect_utils_unittest.js", "select_to_speak/rect_utils_unittest.js",
"select_to_speak/select_to_speak_unittest.js", "select_to_speak/select_to_speak_unittest.js",
"select_to_speak/word_utils_unittest.js", "select_to_speak/word_utils_unittest.js",
"switch_access/rect_helper_unittest.js",
] ]
extra_js_files = [ extra_js_files = [
"braille_ime/braille_ime.js", "braille_ime/braille_ime.js",
"common/rect_util.js",
"select_to_speak/paragraph_utils.js", "select_to_speak/paragraph_utils.js",
"select_to_speak/rect_utils.js", "select_to_speak/rect_utils.js",
"select_to_speak/select_to_speak.js", "select_to_speak/select_to_speak.js",
"select_to_speak/test_support.js", "select_to_speak/test_support.js",
"select_to_speak/word_utils.js", "select_to_speak/word_utils.js",
"select_to_speak/node_utils.js", "select_to_speak/node_utils.js",
"switch_access/rect_helper.js",
] ]
} }
...@@ -30,6 +30,7 @@ run_jsbundler("accessibility_common_copied_files") { ...@@ -30,6 +30,7 @@ run_jsbundler("accessibility_common_copied_files") {
"closure_shim.js", "closure_shim.js",
"constants.js", "constants.js",
"event_handler.js", "event_handler.js",
"rect_util.js",
"repeated_event_handler.js", "repeated_event_handler.js",
"repeated_tree_change_handler.js", "repeated_tree_change_handler.js",
"tree_walker.js", "tree_walker.js",
...@@ -85,6 +86,10 @@ js_library("event_handler") { ...@@ -85,6 +86,10 @@ js_library("event_handler") {
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
js_library("rect_util") {
externs_list = [ "$externs_path/accessibility_private.js" ]
}
js_library("repeated_event_handler") { js_library("repeated_event_handler") {
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
......
...@@ -41,7 +41,7 @@ TEST_F('ArrayUtilTest', 'ContentsAreEqual', function() { ...@@ -41,7 +41,7 @@ TEST_F('ArrayUtilTest', 'ContentsAreEqual', function() {
assertTrue( assertTrue(
ArrayUtil.contentsAreEqual(arrayWithObj, secondArrayWithObj), ArrayUtil.contentsAreEqual(arrayWithObj, secondArrayWithObj),
'Different array instances with references to the same object ' + 'Different array instances with references to the same object ' +
'instance should be equal with contentsareEqual.'); 'instance should be equal with contentsAreEqual.');
assertFalse( assertFalse(
ArrayUtil.contentsAreEqual(arrayWithObj, arrayWithDifferentObj), ArrayUtil.contentsAreEqual(arrayWithObj, arrayWithDifferentObj),
'Arrays with different objects should not be equal (ArrayUtil.' + 'Arrays with different objects should not be equal (ArrayUtil.' +
......
...@@ -2,62 +2,55 @@ ...@@ -2,62 +2,55 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/**
* Equivalent to chrome.accessibilityPrivate.ScreenRect.
* @typedef {{top: number, left: number, width: number, height: number}}
*/
let ScreenRect;
/** A collection of helper functions when dealing with rects. */ /** A collection of helper functions when dealing with rects. */
const RectHelper = { const RectUtil = {
/** @type {!chrome.accessibilityPrivate.ScreenRect} */ /** @type {!ScreenRect} */
ZERO_RECT: {top: 0, left: 0, width: 0, height: 0}, ZERO_RECT: {top: 0, left: 0, width: 0, height: 0},
/** /**
* @param {chrome.accessibilityPrivate.ScreenRect|undefined} rect * @param {!ScreenRect} rect1
* @return {number} * @param {!ScreenRect} rect2
* @return {boolean}
*/ */
area: (rect) => rect ? rect.width * rect.height : 0, adjacent: (rect1, rect2) => {
const verticallyStacked = rect1.top === RectUtil.bottom(rect2) ||
areAdjacent: (rect1, rect2) => { RectUtil.bottom(rect1) === rect2.top;
const verticallyStacked = rect1.top === RectHelper.bottom(rect2) || const horizontallyStacked = rect1.left === RectUtil.right(rect2) ||
RectHelper.bottom(rect1) === rect2.top; RectUtil.right(rect1) === rect2.left;
const horizontallyStacked = rect1.left === RectHelper.right(rect2) ||
RectHelper.right(rect1) === rect2.left;
const verticallyOverlap = const verticallyOverlap =
(rect1.top >= rect2.top && rect1.top <= RectHelper.bottom(rect2)) || (rect1.top >= rect2.top && rect1.top <= RectUtil.bottom(rect2)) ||
(rect2.top >= rect1.top && rect2.top <= RectHelper.bottom(rect1)); (rect2.top >= rect1.top && rect2.top <= RectUtil.bottom(rect1));
const horizontallyOverlap = const horizontallyOverlap =
(rect1.left >= rect2.left && rect1.left <= RectHelper.right(rect2)) || (rect1.left >= rect2.left && rect1.left <= RectUtil.right(rect2)) ||
(rect2.left >= rect1.left && rect2.left <= RectHelper.right(rect1)); (rect2.left >= rect1.left && rect2.left <= RectUtil.right(rect1));
return (verticallyStacked && horizontallyOverlap) || return (verticallyStacked && horizontallyOverlap) ||
(horizontallyStacked && verticallyOverlap); (horizontallyStacked && verticallyOverlap);
}, },
/** /**
* Returns true if the two rects are equal. * @param {ScreenRect|undefined} rect
* * @return {number}
* @param {chrome.accessibilityPrivate.ScreenRect=} rect1
* @param {chrome.accessibilityPrivate.ScreenRect=} rect2
* @return {boolean}
*/ */
areEqual: (rect1, rect2) => { area: (rect) => rect ? rect.width * rect.height : 0,
if (!rect1 && !rect2) {
return true;
}
if (!rect1 || !rect2) {
return false;
}
return rect1.left === rect2.left && rect1.top === rect2.top &&
rect1.width === rect2.width && rect1.height === rect2.height;
},
/** /**
* Finds the bottom of a rect. * Finds the bottom of a rect.
* @param {!chrome.accessibilityPrivate.ScreenRect} rect * @param {!ScreenRect} rect
* @return {number} * @return {number}
*/ */
bottom: (rect) => rect.top + rect.height, bottom: (rect) => rect.top + rect.height,
/** /**
* Returns the point at the center of the rectangle. * Returns the point at the center of the rectangle.
* @param {!chrome.accessibilityPrivate.ScreenRect} rect * @param {!ScreenRect} rect
* @return {!{x: number, y: number}} an object containing the x and y * @return {!{x: number, y: number}} an object containing the x and y
* coordinates of the center. * coordinates of the center.
*/ */
...@@ -68,8 +61,8 @@ const RectHelper = { ...@@ -68,8 +61,8 @@ const RectHelper = {
}, },
/** /**
* @param {chrome.accessibilityPrivate.ScreenRect} outer * @param {ScreenRect} outer
* @param {chrome.accessibilityPrivate.ScreenRect} inner * @param {ScreenRect} inner
* @return {boolean} * @return {boolean}
*/ */
contains: (outer, inner) => { contains: (outer, inner) => {
...@@ -77,43 +70,40 @@ const RectHelper = { ...@@ -77,43 +70,40 @@ const RectHelper = {
return false; return false;
} }
return outer.left <= inner.left && outer.top <= inner.top && return outer.left <= inner.left && outer.top <= inner.top &&
RectHelper.right(outer) >= RectHelper.right(inner) && RectUtil.right(outer) >= RectUtil.right(inner) &&
RectHelper.bottom(outer) >= RectHelper.bottom(inner); RectUtil.bottom(outer) >= RectUtil.bottom(inner);
}, },
/** /**
* @param {!chrome.accessibilityPrivate.ScreenRect} rect * @param {!ScreenRect} rect
* @return {!chrome.accessibilityPrivate.ScreenRect} * @return {!ScreenRect}
*/ */
deepCopy: (rect) => { deepCopy: (rect) => /** @type {!ScreenRect} */ (Object.assign({}, rect)),
const copy = (Object.assign({}, rect));
return /** @type {!chrome.accessibilityPrivate.ScreenRect} */ (copy);
},
/** /**
* Returns the largest rectangle contained within the outer rect that does not * Returns the largest rectangle contained within the outer rect that does not
* overlap with the subtrahend (what is being subtracted). * overlap with the subtrahend (what is being subtracted).
* @param {chrome.accessibilityPrivate.ScreenRect|undefined} outer * @param {ScreenRect|undefined} outer
* @param {chrome.accessibilityPrivate.ScreenRect|undefined} subtrahend * @param {ScreenRect|undefined} subtrahend
* @return {chrome.accessibilityPrivate.ScreenRect|undefined} * @return {ScreenRect|undefined}
*/ */
difference: (outer, subtrahend) => { difference: (outer, subtrahend) => {
if (!outer || !subtrahend) { if (!outer || !subtrahend) {
return outer; return outer;
} }
if (outer.left >= RectHelper.right(subtrahend) || if (outer.left >= RectUtil.right(subtrahend) ||
RectHelper.right(outer) <= subtrahend.left || RectUtil.right(outer) <= subtrahend.left ||
outer.top >= RectHelper.bottom(subtrahend) || outer.top >= RectUtil.bottom(subtrahend) ||
RectHelper.bottom(outer) <= subtrahend.top) { RectUtil.bottom(outer) <= subtrahend.top) {
// If the rectangles do not overlap, return the outer rect. // If the rectangles do not overlap, return the outer rect.
return outer; return outer;
} }
if (RectHelper.contains(subtrahend, outer)) { if (RectUtil.contains(subtrahend, outer)) {
// If the subtrahend contains the outer rect, there is no region that does // If the subtrahend contains the outer rect, there is no region that does
// not overlap. Return the zero rect. // not overlap. Return the zero rect.
return RectHelper.ZERO_RECT; return RectUtil.ZERO_RECT;
} }
let above, below, toTheLeft, toTheRight; let above, below, toTheLeft, toTheRight;
...@@ -127,12 +117,12 @@ const RectHelper = { ...@@ -127,12 +117,12 @@ const RectHelper = {
}; };
} }
if (RectHelper.bottom(outer) > RectHelper.bottom(subtrahend)) { if (RectUtil.bottom(outer) > RectUtil.bottom(subtrahend)) {
below = { below = {
top: RectHelper.bottom(subtrahend), top: RectUtil.bottom(subtrahend),
left: outer.left, left: outer.left,
width: outer.width, width: outer.width,
height: (RectHelper.bottom(outer) - RectHelper.bottom(subtrahend)) height: (RectUtil.bottom(outer) - RectUtil.bottom(subtrahend))
}; };
} }
...@@ -145,20 +135,20 @@ const RectHelper = { ...@@ -145,20 +135,20 @@ const RectHelper = {
}; };
} }
if (RectHelper.right(outer) > RectHelper.right(subtrahend)) { if (RectUtil.right(outer) > RectUtil.right(subtrahend)) {
toTheRight = { toTheRight = {
top: outer.top, top: outer.top,
left: RectHelper.right(subtrahend), left: RectUtil.right(subtrahend),
width: (RectHelper.right(outer) - RectHelper.right(subtrahend)), width: (RectUtil.right(outer) - RectUtil.right(subtrahend)),
height: outer.height height: outer.height
}; };
} }
// Of the four rects calculated above, find the one with the greatest area. // Of the four rects calculated above, find the one with the greatest area.
const areaAbove = RectHelper.area(above); const areaAbove = RectUtil.area(above);
const areaBelow = RectHelper.area(below); const areaBelow = RectUtil.area(below);
const areaToTheLeft = RectHelper.area(toTheLeft); const areaToTheLeft = RectUtil.area(toTheLeft);
const areaToTheRight = RectHelper.area(toTheRight); const areaToTheRight = RectUtil.area(toTheRight);
if (areaAbove > areaBelow && areaAbove > areaToTheLeft && if (areaAbove > areaBelow && areaAbove > areaToTheLeft &&
areaAbove > areaToTheRight) { areaAbove > areaToTheRight) {
...@@ -172,58 +162,76 @@ const RectHelper = { ...@@ -172,58 +162,76 @@ const RectHelper = {
return areaToTheLeft > areaToTheRight ? toTheLeft : toTheRight; return areaToTheLeft > areaToTheRight ? toTheLeft : toTheRight;
}, },
/**
* Returns true if the two rects are equal.
*
* @param {ScreenRect=} rect1
* @param {ScreenRect=} rect2
* @return {boolean}
*/
equal: (rect1, rect2) => {
if (!rect1 && !rect2) {
return true;
}
if (!rect1 || !rect2) {
return false;
}
return rect1.left === rect2.left && rect1.top === rect2.top &&
rect1.width === rect2.width && rect1.height === rect2.height;
},
/** /**
* Increases the size of |outer| to entirely enclose |inner|, with |padding| * Increases the size of |outer| to entirely enclose |inner|, with |padding|
* buffer on each side. * buffer on each side.
* @param {number} padding * @param {number} padding
* @param {chrome.accessibilityPrivate.ScreenRect=} outer * @param {ScreenRect=} outer
* @param {chrome.accessibilityPrivate.ScreenRect=} inner * @param {ScreenRect=} inner
* @return {chrome.accessibilityPrivate.ScreenRect|undefined} * @return {ScreenRect|undefined}
*/ */
expandToFitWithPadding: (padding, outer, inner) => { expandToFitWithPadding: (padding, outer, inner) => {
if (!outer || !inner) { if (!outer || !inner) {
return outer; return outer;
} }
const newOuter = RectHelper.deepCopy(outer); const newOuter = RectUtil.deepCopy(outer);
if (newOuter.top > inner.top - padding) { if (newOuter.top > inner.top - padding) {
newOuter.top = inner.top - padding; newOuter.top = inner.top - padding;
// The height should be the original bottom point less the new top point. // The height should be the original bottom point less the new top point.
newOuter.height = RectHelper.bottom(outer) - newOuter.top; newOuter.height = RectUtil.bottom(outer) - newOuter.top;
} }
if (newOuter.left > inner.left - padding) { if (newOuter.left > inner.left - padding) {
newOuter.left = inner.left - padding; newOuter.left = inner.left - padding;
// The new width should be the original right point less the new left. // The new width should be the original right point less the new left.
newOuter.width = RectHelper.right(outer) - newOuter.left; newOuter.width = RectUtil.right(outer) - newOuter.left;
} }
if (RectHelper.bottom(newOuter) < RectHelper.bottom(inner) + padding) { if (RectUtil.bottom(newOuter) < RectUtil.bottom(inner) + padding) {
newOuter.height = RectHelper.bottom(inner) + padding - newOuter.top; newOuter.height = RectUtil.bottom(inner) + padding - newOuter.top;
} }
if (RectHelper.right(newOuter) < RectHelper.right(inner) + padding) { if (RectUtil.right(newOuter) < RectUtil.right(inner) + padding) {
newOuter.width = RectHelper.right(inner) + padding - newOuter.left; newOuter.width = RectUtil.right(inner) + padding - newOuter.left;
} }
return newOuter; return newOuter;
}, },
/** /**
* @param {chrome.accessibilityPrivate.ScreenRect=} rect1 * @param {ScreenRect=} rect1
* @param {chrome.accessibilityPrivate.ScreenRect=} rect2 * @param {ScreenRect=} rect2
* @return {chrome.accessibilityPrivate.ScreenRect} * @return {ScreenRect}
*/ */
intersection: (rect1, rect2) => { intersection: (rect1, rect2) => {
if (!rect1 || !rect2) { if (!rect1 || !rect2) {
return RectHelper.ZERO_RECT; return RectUtil.ZERO_RECT;
} }
const left = Math.max(rect1.left, rect2.left); const left = Math.max(rect1.left, rect2.left);
const top = Math.max(rect1.top, rect2.top); const top = Math.max(rect1.top, rect2.top);
const right = Math.min(RectHelper.right(rect1), RectHelper.right(rect2)); const right = Math.min(RectUtil.right(rect1), RectUtil.right(rect2));
const bottom = Math.min(RectHelper.bottom(rect1), RectHelper.bottom(rect2)); const bottom = Math.min(RectUtil.bottom(rect1), RectUtil.bottom(rect2));
if (right <= left || bottom <= top) { if (right <= left || bottom <= top) {
return RectHelper.ZERO_RECT; return RectUtil.ZERO_RECT;
} }
const width = right - left; const width = right - left;
...@@ -233,29 +241,30 @@ const RectHelper = { ...@@ -233,29 +241,30 @@ const RectHelper = {
}, },
/** /**
* Finds the right of a rect. * Finds the right edge of a rect.
* @param {!chrome.accessibilityPrivate.ScreenRect} rect * @param {!ScreenRect} rect
* @return {number} * @return {number}
*/ */
right: (rect) => rect.left + rect.width, right: (rect) => rect.left + rect.width,
/* /*
* @param {chrome.accessibilityPrivate.ScreenRect=} rect1 * @param {ScreenRect=} rect1
* @param {chrome.accessibilityPrivate.ScreenRect=} rect2 * @param {ScreenRect=} rect2
* @return {boolean}
*/ */
sameRow: (rect1, rect2) => { sameRow: (rect1, rect2) => {
if (!rect1 || !rect2) { if (!rect1 || !rect2) {
return false; return false;
} }
const bottom1 = RectHelper.bottom(rect1); const bottom1 = RectUtil.bottom(rect1);
const middle2 = RectHelper.center(rect2).y; const middle2 = RectUtil.center(rect2).y;
return rect1.top < middle2 && bottom1 > middle2; return rect1.top < middle2 && bottom1 > middle2;
}, },
/** /**
* Returns a string representing the given rectangle. * Returns a string representing the given rectangle.
* @param {chrome.accessibilityPrivate.ScreenRect|undefined} rect * @param {ScreenRect|undefined} rect
* @return {string} * @return {string}
*/ */
toString: (rect) => { toString: (rect) => {
...@@ -269,20 +278,20 @@ const RectHelper = { ...@@ -269,20 +278,20 @@ const RectHelper = {
/** /**
* Returns the union of the specified rectangles. * Returns the union of the specified rectangles.
* @param {!chrome.accessibilityPrivate.ScreenRect} rect1 * @param {!ScreenRect} rect1
* @param {!chrome.accessibilityPrivate.ScreenRect} rect2 * @param {!ScreenRect} rect2
* @return {!chrome.accessibilityPrivate.ScreenRect} * @return {!ScreenRect}
*/ */
union: (rect1, rect2) => { union: (rect1, rect2) => {
const top = rect1.top < rect2.top ? rect1.top : rect2.top; const top = rect1.top < rect2.top ? rect1.top : rect2.top;
const left = rect1.left < rect2.left ? rect1.left : rect2.left; const left = rect1.left < rect2.left ? rect1.left : rect2.left;
const r1Bottom = RectHelper.bottom(rect1); const r1Bottom = RectUtil.bottom(rect1);
const r2Bottom = RectHelper.bottom(rect2); const r2Bottom = RectUtil.bottom(rect2);
const bottom = r1Bottom > r2Bottom ? r1Bottom : r2Bottom; const bottom = r1Bottom > r2Bottom ? r1Bottom : r2Bottom;
const r1Right = RectHelper.right(rect1); const r1Right = RectUtil.right(rect1);
const r2Right = RectHelper.right(rect2); const r2Right = RectUtil.right(rect2);
const right = r1Right > r2Right ? r1Right : r2Right; const right = r1Right > r2Right ? r1Right : r2Right;
const height = bottom - top; const height = bottom - top;
...@@ -293,17 +302,17 @@ const RectHelper = { ...@@ -293,17 +302,17 @@ const RectHelper = {
/** /**
* Returns the union of all the rectangles specified. * Returns the union of all the rectangles specified.
* @param {!Array<!chrome.accessibilityPrivate.ScreenRect>} rects * @param {!Array<!ScreenRect>} rects
* @return {!chrome.accessibilityPrivate.ScreenRect} * @return {!ScreenRect}
*/ */
unionAll: (rects) => { unionAll: (rects) => {
if (rects.length < 1) { if (rects.length < 1) {
return RectHelper.ZERO_RECT; return RectUtil.ZERO_RECT;
} }
let result = rects[0]; let result = rects[0];
for (let i = 1; i < rects.length; i++) { for (let i = 1; i < rects.length; i++) {
result = RectHelper.union(result, rects[i]); result = RectUtil.union(result, rects[i]);
} }
return result; return result;
} }
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** Test fixture for rect_helper.js. */ /** Test fixture for rect_util.js. */
SwitchAccessRectHelperUnitTest = class extends testing.Test {}; RectUtilUnitTest = class extends testing.Test {};
/** @override */ /** @override */
SwitchAccessRectHelperUnitTest.prototype.extraLibraries = ['rect_helper.js']; RectUtilUnitTest.prototype.extraLibraries = ['rect_util.js'];
TEST_F('SwitchAccessRectHelperUnitTest', 'Adjacent', function() { TEST_F('RectUtilUnitTest', 'Adjacent', function() {
const baseRect = {left: 10, top: 10, width: 10, height: 10}; const baseRect = {left: 10, top: 10, width: 10, height: 10};
const adjacentRects = [ const adjacentRects = [
{left: 0, top: 0, width: 10, height: 10}, {left: 0, top: 0, width: 10, height: 10},
...@@ -50,28 +50,28 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Adjacent', function() { ...@@ -50,28 +50,28 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Adjacent', function() {
for (const rect of adjacentRects) { for (const rect of adjacentRects) {
assertTrue( assertTrue(
RectHelper.areAdjacent(baseRect, rect), RectUtil.adjacent(baseRect, rect),
RectHelper.toString(baseRect) + ' should be adjacent to ' + RectUtil.toString(baseRect) + ' should be adjacent to ' +
RectHelper.toString(rect)); RectUtil.toString(rect));
assertTrue( assertTrue(
RectHelper.areAdjacent(rect, baseRect), RectUtil.adjacent(rect, baseRect),
RectHelper.toString(rect) + ' should be adjacent to ' + RectUtil.toString(rect) + ' should be adjacent to ' +
RectHelper.toString(baseRect)); RectUtil.toString(baseRect));
} }
for (const rect of nonAdjacentRects) { for (const rect of nonAdjacentRects) {
assertFalse( assertFalse(
RectHelper.areAdjacent(baseRect, rect), RectUtil.adjacent(baseRect, rect),
RectHelper.toString(baseRect) + ' should not be adjacent to ' + RectUtil.toString(baseRect) + ' should not be adjacent to ' +
RectHelper.toString(rect)); RectUtil.toString(rect));
assertFalse( assertFalse(
RectHelper.areAdjacent(rect, baseRect), RectUtil.adjacent(rect, baseRect),
RectHelper.toString(rect) + ' should not be adjacent to ' + RectUtil.toString(rect) + ' should not be adjacent to ' +
RectHelper.toString(baseRect)); RectUtil.toString(baseRect));
} }
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Equals', function() { TEST_F('RectUtilUnitTest', 'Equals', function() {
const rect1 = {left: 0, top: 0, width: 10, height: 10}; const rect1 = {left: 0, top: 0, width: 10, height: 10};
const rect2 = {left: 0, top: 0, width: 10, height: 10}; const rect2 = {left: 0, top: 0, width: 10, height: 10};
const rect3 = {left: 1, top: 0, width: 10, height: 10}; const rect3 = {left: 1, top: 0, width: 10, height: 10};
...@@ -79,43 +79,37 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Equals', function() { ...@@ -79,43 +79,37 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Equals', function() {
const rect5 = {left: 0, top: 0, width: 11, height: 10}; const rect5 = {left: 0, top: 0, width: 11, height: 10};
const rect6 = {left: 0, top: 0, width: 10, height: 11}; const rect6 = {left: 0, top: 0, width: 10, height: 11};
assertTrue(RectHelper.areEqual(rect1, rect1), 'areEqual should be reflexive'); assertTrue(RectUtil.equal(rect1, rect1), 'equal should be reflexive');
assertTrue( assertTrue(RectUtil.equal(rect1, rect2), 'Rect1 and Rect2 should be equal');
RectHelper.areEqual(rect1, rect2), 'Rect1 and Rect2 should be equal'); assertTrue(RectUtil.equal(rect2, rect1), 'equal should be symmetric');
assertTrue(
RectHelper.areEqual(rect2, rect1), 'areEqual should be symmetric (1)');
assertFalse(
RectHelper.areEqual(rect1, rect3), 'rect1 and rect3 should not be equal');
assertFalse(
RectHelper.areEqual(rect3, rect1), 'areEqual should be symmetric (2)');
assertFalse(
RectHelper.areEqual(rect1, rect4), 'rect1 and rect4 should not be equal');
assertFalse(
RectHelper.areEqual(rect4, rect1), 'areEqual should be symmetric (3)');
assertFalse( assertFalse(
RectHelper.areEqual(rect1, rect5), 'rect1 and rect5 should not be equal'); RectUtil.equal(rect1, rect3), 'rect1 and rect3 should not be equal');
assertFalse(RectUtil.equal(rect3, rect1), 'equal should be symmetric');
assertFalse( assertFalse(
RectHelper.areEqual(rect5, rect1), 'areEqual should be symmetric (4)'); RectUtil.equal(rect1, rect4), 'rect1 and rect4 should not be equal');
assertFalse(RectUtil.equal(rect4, rect1), 'equal should be symmetric');
assertFalse( assertFalse(
RectHelper.areEqual(rect1, rect6), 'rect1 and rect6 should not be equal'); RectUtil.equal(rect1, rect5), 'rect1 and rect5 should not be equal');
assertFalse(RectUtil.equal(rect5, rect1), 'equal should be symmetric');
assertFalse( assertFalse(
RectHelper.areEqual(rect6, rect1), 'areEqual should be symmetric (5)'); RectUtil.equal(rect1, rect6), 'rect1 and rect6 should not be equal');
assertFalse(RectUtil.equal(rect6, rect1), 'equal should be symmetric');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Center', function() { TEST_F('RectUtilUnitTest', 'Center', function() {
const rect1 = {left: 0, top: 0, width: 10, height: 10}; const rect1 = {left: 0, top: 0, width: 10, height: 10};
const rect2 = {left: 10, top: 20, width: 10, height: 40}; const rect2 = {left: 10, top: 20, width: 10, height: 40};
const center1 = RectHelper.center(rect1); const center1 = RectUtil.center(rect1);
assertEquals(5, center1.x, 'Center1 x should be 5'); assertEquals(5, center1.x, 'Center1 x should be 5');
assertEquals(5, center1.y, 'Center1 y should be 5'); assertEquals(5, center1.y, 'Center1 y should be 5');
const center2 = RectHelper.center(rect2); const center2 = RectUtil.center(rect2);
assertEquals(15, center2.x, 'Center2 x should be 15'); assertEquals(15, center2.x, 'Center2 x should be 15');
assertEquals(40, center2.y, 'Center2 y should be 40'); assertEquals(40, center2.y, 'Center2 y should be 40');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Union', function() { TEST_F('RectUtilUnitTest', 'Union', function() {
const rect1 = {left: 0, top: 0, width: 10, height: 10}; const rect1 = {left: 0, top: 0, width: 10, height: 10};
const rect2 = {left: 4, top: 4, width: 2, height: 2}; const rect2 = {left: 4, top: 4, width: 2, height: 2};
const rect3 = {left: 10, top: 20, width: 10, height: 40}; const rect3 = {left: 10, top: 20, width: 10, height: 40};
...@@ -123,74 +117,74 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Union', function() { ...@@ -123,74 +117,74 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'Union', function() {
const rect5 = {left: 5, top: 5, width: 10, height: 10}; const rect5 = {left: 5, top: 5, width: 10, height: 10};
// When one rect entirely contains the other, that rect is returned. // When one rect entirely contains the other, that rect is returned.
const unionRect1Rect2 = RectHelper.union(rect1, rect2); const unionRect1Rect2 = RectUtil.union(rect1, rect2);
assertTrue( assertTrue(
RectHelper.areEqual(rect1, unionRect1Rect2), RectUtil.equal(rect1, unionRect1Rect2),
'Union of rect1 and rect2 should be rect1'); 'Union of rect1 and rect2 should be rect1');
const unionRect1Rect3 = RectHelper.union(rect1, rect3); const unionRect1Rect3 = RectUtil.union(rect1, rect3);
let expected = {left: 0, top: 0, width: 20, height: 60}; let expected = {left: 0, top: 0, width: 20, height: 60};
assertTrue( assertTrue(
RectHelper.areEqual(expected, unionRect1Rect3), RectUtil.equal(expected, unionRect1Rect3),
'Union of rect1 and rect3 does not match expected value'); 'Union of rect1 and rect3 does not match expected value');
const unionRect1Rect4 = RectHelper.union(rect1, rect4); const unionRect1Rect4 = RectUtil.union(rect1, rect4);
expected = {left: 0, top: 0, width: 10, height: 20}; expected = {left: 0, top: 0, width: 10, height: 20};
assertTrue( assertTrue(
RectHelper.areEqual(expected, unionRect1Rect4), RectUtil.equal(expected, unionRect1Rect4),
'Union of rect1 and rect4 does not match expected value'); 'Union of rect1 and rect4 does not match expected value');
const unionRect1Rect5 = RectHelper.union(rect1, rect5); const unionRect1Rect5 = RectUtil.union(rect1, rect5);
expected = {left: 0, top: 0, width: 15, height: 15}; expected = {left: 0, top: 0, width: 15, height: 15};
assertTrue( assertTrue(
RectHelper.areEqual(expected, unionRect1Rect5), RectUtil.equal(expected, unionRect1Rect5),
'Union of rect1 and rect5 does not match expected value'); 'Union of rect1 and rect5 does not match expected value');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'UnionAll', function() { TEST_F('RectUtilUnitTest', 'UnionAll', function() {
const rect1 = {left: 0, top: 0, width: 10, height: 10}; const rect1 = {left: 0, top: 0, width: 10, height: 10};
const rect2 = {left: 0, top: 10, width: 10, height: 10}; const rect2 = {left: 0, top: 10, width: 10, height: 10};
const rect3 = {left: 10, top: 0, width: 10, height: 10}; const rect3 = {left: 10, top: 0, width: 10, height: 10};
const rect4 = {left: 10, top: 10, width: 10, height: 10}; const rect4 = {left: 10, top: 10, width: 10, height: 10};
const rect5 = {left: 0, top: 0, width: 100, height: 10}; const rect5 = {left: 0, top: 0, width: 100, height: 10};
const union1 = RectHelper.unionAll([rect1, rect2, rect3, rect4]); const union1 = RectUtil.unionAll([rect1, rect2, rect3, rect4]);
let expected = {left: 0, top: 0, width: 20, height: 20}; let expected = {left: 0, top: 0, width: 20, height: 20};
assertTrue( assertTrue(
RectHelper.areEqual(expected, union1), RectUtil.equal(expected, union1),
'Union of rects 1-4 does not match expected value'); 'Union of rects 1-4 does not match expected value');
const union2 = RectHelper.unionAll([rect1, rect2, rect3, rect4, rect5]); const union2 = RectUtil.unionAll([rect1, rect2, rect3, rect4, rect5]);
expected = {left: 0, top: 0, width: 100, height: 20}; expected = {left: 0, top: 0, width: 100, height: 20};
assertTrue( assertTrue(
RectHelper.areEqual(expected, union2), RectUtil.equal(expected, union2),
'Union of rects 1-5 does not match expected value'); 'Union of rects 1-5 does not match expected value');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'ExpandToFitWithPadding', function() { TEST_F('RectUtilUnitTest', 'ExpandToFitWithPadding', function() {
const padding = 5; const padding = 5;
let inner = {left: 100, top: 100, width: 100, height: 100}; let inner = {left: 100, top: 100, width: 100, height: 100};
let outer = {left: 120, top: 120, width: 20, height: 20}; let outer = {left: 120, top: 120, width: 20, height: 20};
let expected = {left: 95, top: 95, width: 110, height: 110}; let expected = {left: 95, top: 95, width: 110, height: 110};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
expected, RectHelper.expandToFitWithPadding(padding, outer, inner)), expected, RectUtil.expandToFitWithPadding(padding, outer, inner)),
'When outer is contained in inner, expandToFitWithPadding does not ' + 'When outer is contained in inner, expandToFitWithPadding does not ' +
'match expected value'); 'match expected value');
inner = {left: 100, top: 100, width: 100, height: 100}; inner = {left: 100, top: 100, width: 100, height: 100};
outer = {left: 50, top: 50, width: 200, height: 200}; outer = {left: 50, top: 50, width: 200, height: 200};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
outer, RectHelper.expandToFitWithPadding(padding, outer, inner)), outer, RectUtil.expandToFitWithPadding(padding, outer, inner)),
'When outer contains inner, expandToFitWithPadding should equal outer'); 'When outer contains inner, expandToFitWithPadding should equal outer');
inner = {left: 100, top: 100, width: 100, height: 100}; inner = {left: 100, top: 100, width: 100, height: 100};
outer = {left: 10, top: 10, width: 10, height: 10}; outer = {left: 10, top: 10, width: 10, height: 10};
expected = {left: 10, top: 10, width: 195, height: 195}; expected = {left: 10, top: 10, width: 195, height: 195};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
expected, RectHelper.expandToFitWithPadding(padding, outer, inner)), expected, RectUtil.expandToFitWithPadding(padding, outer, inner)),
'When there is no overlap, expandToFitWithPadding does not match ' + 'When there is no overlap, expandToFitWithPadding does not match ' +
'expected value'); 'expected value');
...@@ -198,8 +192,8 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'ExpandToFitWithPadding', function() { ...@@ -198,8 +192,8 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'ExpandToFitWithPadding', function() {
outer = {left: 120, top: 50, width: 200, height: 200}; outer = {left: 120, top: 50, width: 200, height: 200};
expected = {left: 95, top: 50, width: 225, height: 200}; expected = {left: 95, top: 50, width: 225, height: 200};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
expected, RectHelper.expandToFitWithPadding(padding, outer, inner)), expected, RectUtil.expandToFitWithPadding(padding, outer, inner)),
'When there is some overlap, expandToFitWithPadding does not match ' + 'When there is some overlap, expandToFitWithPadding does not match ' +
'expected value'); 'expected value');
...@@ -207,168 +201,165 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'ExpandToFitWithPadding', function() { ...@@ -207,168 +201,165 @@ TEST_F('SwitchAccessRectHelperUnitTest', 'ExpandToFitWithPadding', function() {
outer = {left: 97, top: 95, width: 108, height: 110}; outer = {left: 97, top: 95, width: 108, height: 110};
expected = {left: 95, top: 95, width: 110, height: 110}; expected = {left: 95, top: 95, width: 110, height: 110};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
expected, RectHelper.expandToFitWithPadding(padding, outer, inner)), expected, RectUtil.expandToFitWithPadding(padding, outer, inner)),
'When outer contains inner but without sufficient padding, ' + 'When outer contains inner but without sufficient padding, ' +
'expandToFitWithPadding does not match expected value'); 'expandToFitWithPadding does not match expected value');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Contains', function() { TEST_F('RectUtilUnitTest', 'Contains', function() {
const outer = {left: 10, top: 10, width: 10, height: 10}; const outer = {left: 10, top: 10, width: 10, height: 10};
assertTrue(RectHelper.contains(outer, outer), 'Rect should contain itself'); assertTrue(RectUtil.contains(outer, outer), 'Rect should contain itself');
let inner = {left: 10, top: 12, width: 10, height: 5}; let inner = {left: 10, top: 12, width: 10, height: 5};
assertTrue( assertTrue(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should contain rect with same left/right bounds'); 'Rect should contain rect with same left/right bounds');
inner = {left: 12, top: 10, width: 5, height: 10}; inner = {left: 12, top: 10, width: 5, height: 10};
assertTrue( assertTrue(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should contain rect with same top/bottom bounds'); 'Rect should contain rect with same top/bottom bounds');
inner = {left: 12, top: 12, width: 5, height: 5}; inner = {left: 12, top: 12, width: 5, height: 5};
assertTrue( assertTrue(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should contain rect that is entirely within its bounds'); 'Rect should contain rect that is entirely within its bounds');
inner = {left: 5, top: 12, width: 10, height: 5}; inner = {left: 5, top: 12, width: 10, height: 5};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that extends past the left edge'); 'Rect should not contain rect that extends past the left edge');
inner = {left: 12, top: 8, width: 5, height: 10}; inner = {left: 12, top: 8, width: 5, height: 10};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that extends past the top edge'); 'Rect should not contain rect that extends past the top edge');
inner = {left: 15, top: 5, width: 10, height: 20}; inner = {left: 15, top: 5, width: 10, height: 20};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that extends past right edge and has ' + 'Rect should not contain rect that extends past right edge and has ' +
'larger height'); 'larger height');
inner = {left: 5, top: 15, width: 10, height: 10}; inner = {left: 5, top: 15, width: 10, height: 10};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that extends below and left of it'); 'Rect should not contain rect that extends below and left of it');
inner = {left: 2, top: 12, width: 5, height: 5}; inner = {left: 2, top: 12, width: 5, height: 5};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect directly to its left'); 'Rect should not contain rect directly to its left');
inner = {left: 12, top: 22, width: 5, height: 5}; inner = {left: 12, top: 22, width: 5, height: 5};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect directly below it'); 'Rect should not contain rect directly below it');
inner = {left: 22, top: 2, width: 5, height: 5}; inner = {left: 22, top: 2, width: 5, height: 5};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect above the the top-right corner'); 'Rect should not contain rect above the the top-right corner');
inner = {left: 12, top: 2, width: 5, height: 20}; inner = {left: 12, top: 2, width: 5, height: 20};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that has a greater height'); 'Rect should not contain rect that has a greater height');
inner = {left: 2, top: 12, width: 20, height: 5}; inner = {left: 2, top: 12, width: 20, height: 5};
assertFalse( assertFalse(
RectHelper.contains(outer, inner), RectUtil.contains(outer, inner),
'Rect should not contain rect that has a larger width'); 'Rect should not contain rect that has a larger width');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Difference', function() { TEST_F('RectUtilUnitTest', 'Difference', function() {
const outer = {left: 10, top: 10, width: 10, height: 10}; const outer = {left: 10, top: 10, width: 10, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(RectUtil.ZERO_RECT, RectUtil.difference(outer, outer)),
RectHelper.ZERO_RECT, RectHelper.difference(outer, outer)),
'Difference of rect with itself should the zero rect'); 'Difference of rect with itself should the zero rect');
let subtrahend = {left: 2, top: 2, width: 5, height: 5}; let subtrahend = {left: 2, top: 2, width: 5, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(outer, RectHelper.difference(outer, subtrahend)), RectUtil.equal(outer, RectUtil.difference(outer, subtrahend)),
'Difference of non-overlapping rects should be the outer rect'); 'Difference of non-overlapping rects should be the outer rect');
subtrahend = {left: 5, top: 5, width: 20, height: 20}; subtrahend = {left: 5, top: 5, width: 20, height: 20};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(
RectHelper.ZERO_RECT, RectHelper.difference(outer, subtrahend)), RectUtil.ZERO_RECT, RectUtil.difference(outer, subtrahend)),
'Difference where subtrahend contains outer should be the zero rect'); 'Difference where subtrahend contains outer should be the zero rect');
subtrahend = {left: 12, top: 15, width: 6, height: 3}; subtrahend = {left: 12, top: 15, width: 6, height: 3};
let expected = {left: 10, top: 10, width: 10, height: 5}; let expected = {left: 10, top: 10, width: 10, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.difference(outer, subtrahend)), RectUtil.equal(expected, RectUtil.difference(outer, subtrahend)),
'Difference above should be largest'); 'Difference above should be largest');
subtrahend = {left: 15, top: 8, width: 3, height: 10}; subtrahend = {left: 15, top: 8, width: 3, height: 10};
expected = {left: 10, top: 10, width: 5, height: 10}; expected = {left: 10, top: 10, width: 5, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.difference(outer, subtrahend)), RectUtil.equal(expected, RectUtil.difference(outer, subtrahend)),
'Difference to the left should be the largest'); 'Difference to the left should be the largest');
subtrahend = {left: 5, top: 5, width: 13, height: 10}; subtrahend = {left: 5, top: 5, width: 13, height: 10};
expected = {left: 10, top: 15, width: 10, height: 5}; expected = {left: 10, top: 15, width: 10, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.difference(outer, subtrahend)), RectUtil.equal(expected, RectUtil.difference(outer, subtrahend)),
'Difference below should be the largest'); 'Difference below should be the largest');
subtrahend = {left: 8, top: 8, width: 10, height: 15}; subtrahend = {left: 8, top: 8, width: 10, height: 15};
expected = {left: 18, top: 10, width: 2, height: 10}; expected = {left: 18, top: 10, width: 2, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.difference(outer, subtrahend)), RectUtil.equal(expected, RectUtil.difference(outer, subtrahend)),
'Difference to the right should be the largest'); 'Difference to the right should be the largest');
}); });
TEST_F('SwitchAccessRectHelperUnitTest', 'Intersection', function() { TEST_F('RectUtilUnitTest', 'Intersection', function() {
const rect1 = {left: 10, top: 10, width: 10, height: 10}; const rect1 = {left: 10, top: 10, width: 10, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual(rect1, RectHelper.intersection(rect1, rect1)), RectUtil.equal(rect1, RectUtil.intersection(rect1, rect1)),
'Intersection of a rectangle with itself should be itself'); 'Intersection of a rectangle with itself should be itself');
let rect2 = {left: 12, top: 12, width: 5, height: 5}; let rect2 = {left: 12, top: 12, width: 5, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(rect2, RectHelper.intersection(rect1, rect2)), RectUtil.equal(rect2, RectUtil.intersection(rect1, rect2)),
'When one rect contains another, intersection should be the inner rect'); 'When one rect contains another, intersection should be the inner rect');
assertTrue( assertTrue(
RectHelper.areEqual(rect2, RectHelper.intersection(rect2, rect1)), RectUtil.equal(rect2, RectUtil.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
rect2 = {left: 5, top: 5, width: 20, height: 20}; rect2 = {left: 5, top: 5, width: 20, height: 20};
assertTrue( assertTrue(
RectHelper.areEqual(rect1, RectHelper.intersection(rect1, rect2)), RectUtil.equal(rect1, RectUtil.intersection(rect1, rect2)),
'When one rect contains another, intersection should be the inner rect'); 'When one rect contains another, intersection should be the inner rect');
assertTrue( assertTrue(
RectHelper.areEqual(rect1, RectHelper.intersection(rect2, rect1)), RectUtil.equal(rect1, RectUtil.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
rect2 = {left: 30, top: 10, width: 10, height: 10}; rect2 = {left: 30, top: 10, width: 10, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(RectUtil.ZERO_RECT, RectUtil.intersection(rect1, rect2)),
RectHelper.ZERO_RECT, RectHelper.intersection(rect1, rect2)),
'Intersection of non-overlapping rects should be zero rect'); 'Intersection of non-overlapping rects should be zero rect');
assertTrue( assertTrue(
RectHelper.areEqual( RectUtil.equal(RectUtil.ZERO_RECT, RectUtil.intersection(rect2, rect1)),
RectHelper.ZERO_RECT, RectHelper.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
rect2 = {left: 15, top: 10, width: 10, height: 10}; rect2 = {left: 15, top: 10, width: 10, height: 10};
let expected = {left: 15, top: 10, width: 5, height: 10}; let expected = {left: 15, top: 10, width: 5, height: 10};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect1, rect2)), RectUtil.equal(expected, RectUtil.intersection(rect1, rect2)),
'Side-by-side overlap is not computed correctly'); 'Side-by-side overlap is not computed correctly');
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect2, rect1)), RectUtil.equal(expected, RectUtil.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
rect2 = {left: 15, top: 5, width: 10, height: 10}; rect2 = {left: 15, top: 5, width: 10, height: 10};
expected = {left: 15, top: 10, width: 5, height: 5}; expected = {left: 15, top: 10, width: 5, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect1, rect2)), RectUtil.equal(expected, RectUtil.intersection(rect1, rect2)),
'Top corner overlap is not computed correctly'); 'Top corner overlap is not computed correctly');
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect2, rect1)), RectUtil.equal(expected, RectUtil.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
rect2 = {left: 5, top: 15, width: 20, height: 10}; rect2 = {left: 5, top: 15, width: 20, height: 10};
expected = {left: 10, top: 15, width: 10, height: 5}; expected = {left: 10, top: 15, width: 10, height: 5};
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect1, rect2)), RectUtil.equal(expected, RectUtil.intersection(rect1, rect2)),
'Bottom overlap is not computed correctly'); 'Bottom overlap is not computed correctly');
assertTrue( assertTrue(
RectHelper.areEqual(expected, RectHelper.intersection(rect2, rect1)), RectUtil.equal(expected, RectUtil.intersection(rect2, rect1)),
'Intersection should be symmetric'); 'Intersection should be symmetric');
}); });
...@@ -74,7 +74,6 @@ run_jsbundler("switch_access_copied_files") { ...@@ -74,7 +74,6 @@ run_jsbundler("switch_access_copied_files") {
"nodes/tab_node.js", "nodes/tab_node.js",
"nodes/window_node.js", "nodes/window_node.js",
"preferences.js", "preferences.js",
"rect_helper.js",
"switch_access.js", "switch_access.js",
"switch_access_constants.js", "switch_access_constants.js",
"switch_access_predicate.js", "switch_access_predicate.js",
...@@ -150,7 +149,6 @@ js_type_check("closure_compile") { ...@@ -150,7 +149,6 @@ js_type_check("closure_compile") {
":navigation_manager", ":navigation_manager",
":node_wrapper", ":node_wrapper",
":preferences", ":preferences",
":rect_helper",
":slider_node", ":slider_node",
":switch_access", ":switch_access",
":switch_access_constants", ":switch_access_constants",
...@@ -162,6 +160,7 @@ js_type_check("closure_compile") { ...@@ -162,6 +160,7 @@ js_type_check("closure_compile") {
"../common:automation_predicate", "../common:automation_predicate",
"../common:closure_shim", "../common:closure_shim",
"../common:constants", "../common:constants",
"../common:rect_util",
"../common:repeated_event_handler", "../common:repeated_event_handler",
"../common:repeated_tree_change_handler", "../common:repeated_tree_change_handler",
"../common:tree_walker", "../common:tree_walker",
...@@ -180,9 +179,9 @@ js_library("background") { ...@@ -180,9 +179,9 @@ js_library("background") {
js_library("back_button_node") { js_library("back_button_node") {
sources = [ "nodes/back_button_node.js" ] sources = [ "nodes/back_button_node.js" ]
deps = [ deps = [
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ externs_list = [
"$externs_path/accessibility_private.js", "$externs_path/accessibility_private.js",
...@@ -250,9 +249,9 @@ js_library("group_node") { ...@@ -250,9 +249,9 @@ js_library("group_node") {
deps = [ deps = [
":back_button_node", ":back_button_node",
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ externs_list = [
"$externs_path/accessibility_private.js", "$externs_path/accessibility_private.js",
...@@ -277,11 +276,11 @@ js_library("keyboard_node") { ...@@ -277,11 +276,11 @@ js_library("keyboard_node") {
":event_helper", ":event_helper",
":group_node", ":group_node",
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
":switch_access_predicate", ":switch_access_predicate",
"../common:constants", "../common:constants",
"../common:rect_util",
"../common:tree_walker", "../common:tree_walker",
] ]
externs_list = [ externs_list = [
...@@ -365,10 +364,6 @@ js_library("preferences") { ...@@ -365,10 +364,6 @@ js_library("preferences") {
externs_list = [ "$externs_path/settings_private.js" ] externs_list = [ "$externs_path/settings_private.js" ]
} }
js_library("rect_helper") {
externs_list = [ "$externs_path/accessibility_private.js" ]
}
js_library("slider_node") { js_library("slider_node") {
sources = [ "nodes/slider_node.js" ] sources = [ "nodes/slider_node.js" ]
deps = [ deps = [
...@@ -424,9 +419,9 @@ js_library("tab_node") { ...@@ -424,9 +419,9 @@ js_library("tab_node") {
sources = [ "nodes/tab_node.js" ] sources = [ "nodes/tab_node.js" ]
deps = [ deps = [
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
......
...@@ -97,7 +97,7 @@ class FocusRingManager { ...@@ -97,7 +97,7 @@ class FocusRingManager {
if (childRect) { if (childRect) {
// If the current element is not the back button, the focus rect should // If the current element is not the back button, the focus rect should
// expand to contain the child rect. // expand to contain the child rect.
focusRect = RectHelper.expandToFitWithPadding( focusRect = RectUtil.expandToFitWithPadding(
SAConstants.Focus.GROUP_BUFFER, focusRect, childRect); SAConstants.Focus.GROUP_BUFFER, focusRect, childRect);
manager.rings_.get(SAConstants.Focus.ID.NEXT).rects = [childRect]; manager.rings_.get(SAConstants.Focus.ID.NEXT).rects = [childRect];
} }
......
...@@ -203,11 +203,11 @@ class NavigationManager { ...@@ -203,11 +203,11 @@ class NavigationManager {
if (!location) { if (!location) {
// Closure compiler doesn't realize we already checked isValidAndVisible // Closure compiler doesn't realize we already checked isValidAndVisible
// before calling tryMoving, so we need to explicitly check location here // before calling tryMoving, so we need to explicitly check location here
// so that RectHelper.center does not cause a closure error. // so that RectUtil.center does not cause a closure error.
NavigationManager.moveToValidNode(); NavigationManager.moveToValidNode();
return; return;
} }
const center = RectHelper.center(location); const center = RectUtil.center(location);
// Check if the top center is visible as a proxy for occlusion. It's // Check if the top center is visible as a proxy for occlusion. It's
// possible that other parts of the window are occluded, but in Chrome we // possible that other parts of the window are occluded, but in Chrome we
// can't drag windows off the top of the screen. // can't drag windows off the top of the screen.
......
...@@ -36,7 +36,7 @@ class GroupNode extends SAChildNode { ...@@ -36,7 +36,7 @@ class GroupNode extends SAChildNode {
/** @override */ /** @override */
get location() { get location() {
const childLocations = this.children_.map(c => c.location); const childLocations = this.children_.map(c => c.location);
return RectHelper.unionAll(childLocations); return RectUtil.unionAll(childLocations);
} }
/** @override */ /** @override */
...@@ -134,7 +134,7 @@ class GroupNode extends SAChildNode { ...@@ -134,7 +134,7 @@ class GroupNode extends SAChildNode {
i++; i++;
while (i < nodes.length && while (i < nodes.length &&
RectHelper.sameRow(children[0].location, nodes[i].location)) { RectUtil.sameRow(children[0].location, nodes[i].location)) {
children.push(nodes[i]); children.push(nodes[i]);
i++; i++;
} }
......
...@@ -47,7 +47,7 @@ class KeyboardNode extends NodeWrapper { ...@@ -47,7 +47,7 @@ class KeyboardNode extends NodeWrapper {
// doDefault() does nothing on Virtual Keyboard buttons, so we must // doDefault() does nothing on Virtual Keyboard buttons, so we must
// simulate a mouse click. // simulate a mouse click.
const center = RectHelper.center(keyLocation); const center = RectUtil.center(keyLocation);
EventHelper.simulateMouseClick( EventHelper.simulateMouseClick(
center.x, center.y, SAConstants.VK_KEY_PRESS_DURATION_MS); center.x, center.y, SAConstants.VK_KEY_PRESS_DURATION_MS);
......
...@@ -224,7 +224,7 @@ class SAChildNode { ...@@ -224,7 +224,7 @@ class SAChildNode {
const loc = this.location; const loc = this.location;
if (loc) { if (loc) {
str += 'loc(' + RectHelper.toString(loc) + ') '; str += 'loc(' + RectUtil.toString(loc) + ') ';
} }
if (this.isGroup()) { if (this.isGroup()) {
...@@ -299,7 +299,7 @@ class SARootNode { ...@@ -299,7 +299,7 @@ class SARootNode {
const children = const children =
this.children_.filter((c) => !(c instanceof BackButtonNode)); this.children_.filter((c) => !(c instanceof BackButtonNode));
const childLocations = children.map((c) => c.location); const childLocations = children.map((c) => c.location);
return RectHelper.unionAll(childLocations); return RectUtil.unionAll(childLocations);
} }
// ================= General methods ================= // ================= General methods =================
...@@ -413,7 +413,7 @@ class SARootNode { ...@@ -413,7 +413,7 @@ class SARootNode {
const loc = this.location; const loc = this.location;
if (loc) { if (loc) {
str += 'loc(' + RectHelper.toString(loc) + ') '; str += 'loc(' + RectUtil.toString(loc) + ') ';
} }
......
...@@ -102,7 +102,7 @@ class ActionableTabNode extends NodeWrapper { ...@@ -102,7 +102,7 @@ class ActionableTabNode extends NodeWrapper {
if (!this.closeButton_) { if (!this.closeButton_) {
return super.location; return super.location;
} }
return RectHelper.difference(super.location, this.closeButton_.location); return RectUtil.difference(super.location, this.closeButton_.location);
} }
// ================= General methods ================= // ================= General methods =================
......
...@@ -42,7 +42,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -42,7 +42,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
const tabAsRoot = NavigationManager.instance.group_; const tabAsRoot = NavigationManager.instance.group_;
assertTrue( assertTrue(
RectHelper.areEqual(tab.location, tabAsRoot.location), RectUtil.equal(tab.location, tabAsRoot.location),
'Tab location should not change when treated as root'); 'Tab location should not change when treated as root');
assertEquals( assertEquals(
3, tabAsRoot.children.length, 'Tab as root should have 3 children'); 3, tabAsRoot.children.length, 'Tab as root should have 3 children');
...@@ -57,7 +57,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -57,7 +57,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
tabToSelect.hasAction(SwitchAccessMenuAction.SELECT), tabToSelect.hasAction(SwitchAccessMenuAction.SELECT),
'Tab as a group should have a SELECT action'); 'Tab as a group should have a SELECT action');
assertFalse( assertFalse(
RectHelper.areEqual(tabAsRoot.location, tabToSelect.location), RectUtil.equal(tabAsRoot.location, tabToSelect.location),
'Tab node to select should not have the same location as tab as root'); 'Tab node to select should not have the same location as tab as root');
assertEquals( assertEquals(
null, tabToSelect.asRootNode(), null, tabToSelect.asRootNode(),
...@@ -74,12 +74,11 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -74,12 +74,11 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
close.hasAction(SwitchAccessMenuAction.SELECT), close.hasAction(SwitchAccessMenuAction.SELECT),
'Close button should have a SELECT action'); 'Close button should have a SELECT action');
assertFalse( assertFalse(
RectHelper.areEqual(tabAsRoot.location, close.location), RectUtil.equal(tabAsRoot.location, close.location),
'Close button should not have the same location as tab as root'); 'Close button should not have the same location as tab as root');
const overlap = const overlap = RectUtil.intersection(tabToSelect.location, close.location);
RectHelper.intersection(tabToSelect.location, close.location);
assertTrue( assertTrue(
RectHelper.areEqual(RectHelper.ZERO_RECT, overlap), RectUtil.equal(RectUtil.ZERO_RECT, overlap),
'Close button and tab node to select should not overlap'); 'Close button and tab node to select should not overlap');
BackButtonNode BackButtonNode
......
...@@ -134,7 +134,7 @@ const SwitchAccessPredicate = { ...@@ -134,7 +134,7 @@ const SwitchAccessPredicate = {
(scope instanceof SARootNode ? scope.isEquivalentTo(node) : (scope instanceof SARootNode ? scope.isEquivalentTo(node) :
scope === node); scope === node);
if (scope && !scopeEqualsNode && if (scope && !scopeEqualsNode &&
RectHelper.areEqual(node.location, scope.location)) { RectUtil.equal(node.location, scope.location)) {
cache.isGroup.set(node, false); cache.isGroup.set(node, false);
return false; return false;
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"common/automation_predicate.js", "common/automation_predicate.js",
"common/automation_util.js", "common/automation_util.js",
"common/event_handler.js", "common/event_handler.js",
"common/rect_util.js",
"common/repeated_event_handler.js", "common/repeated_event_handler.js",
"common/repeated_tree_change_handler.js", "common/repeated_tree_change_handler.js",
"common/tree_walker.js", "common/tree_walker.js",
...@@ -42,7 +43,6 @@ ...@@ -42,7 +43,6 @@
"switch_access/nodes/tab_node.js", "switch_access/nodes/tab_node.js",
"switch_access/nodes/window_node.js", "switch_access/nodes/window_node.js",
"switch_access/preferences.js", "switch_access/preferences.js",
"switch_access/rect_helper.js",
"switch_access/switch_access.js", "switch_access/switch_access.js",
"switch_access/switch_access_constants.js", "switch_access/switch_access_constants.js",
"switch_access/switch_access_predicate.js", "switch_access/switch_access_predicate.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment