|
|
@ -30,7 +30,7 @@ exports.orderByEnd = function(items) { |
|
|
|
* other. |
|
|
|
* @param {Item[]} items |
|
|
|
* All visible items |
|
|
|
* @param {{item: number, axis: number}} margin |
|
|
|
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin |
|
|
|
* Margins between items and between items and the axis. |
|
|
|
* @param {boolean} [force=false] |
|
|
|
* If true, all items will be repositioned. If false (default), only |
|
|
@ -67,7 +67,7 @@ exports.stack = function(items, margin, force) { |
|
|
|
|
|
|
|
if (collidingItem != null) { |
|
|
|
// There is a collision. Reposition the items above the colliding element
|
|
|
|
item.top = collidingItem.top + collidingItem.height + margin.item; |
|
|
|
item.top = collidingItem.top + collidingItem.height + margin.item.vertical; |
|
|
|
} |
|
|
|
} while (collidingItem); |
|
|
|
} |
|
|
@ -78,7 +78,7 @@ exports.stack = function(items, margin, force) { |
|
|
|
* Adjust vertical positions of the items without stacking them |
|
|
|
* @param {Item[]} items |
|
|
|
* All visible items |
|
|
|
* @param {{item: number, axis: number}} margin |
|
|
|
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin |
|
|
|
* Margins between items and between items and the axis. |
|
|
|
*/ |
|
|
|
exports.nostack = function(items, margin) { |
|
|
@ -95,16 +95,14 @@ exports.nostack = function(items, margin) { |
|
|
|
* The items must have parameters left, width, top, and height. |
|
|
|
* @param {Item} a The first item |
|
|
|
* @param {Item} b The second item |
|
|
|
* @param {Number} margin A minimum required margin. |
|
|
|
* If margin is provided, the two items will be |
|
|
|
* marked colliding when they overlap or |
|
|
|
* when the margin between the two is smaller than |
|
|
|
* the requested margin. |
|
|
|
* @param {{horizontal: number, vertical: number}} margin |
|
|
|
* An object containing a horizontal and vertical |
|
|
|
* minimum required margin. |
|
|
|
* @return {boolean} true if a and b collide, else false |
|
|
|
*/ |
|
|
|
exports.collision = function(a, b, margin) { |
|
|
|
return ((a.left - margin + EPSILON) < (b.left + b.width) && |
|
|
|
(a.left + a.width + margin - EPSILON) > b.left && |
|
|
|
(a.top - margin + EPSILON) < (b.top + b.height) && |
|
|
|
(a.top + a.height + margin - EPSILON) > b.top); |
|
|
|
return ((a.left - margin.horizontal + EPSILON) < (b.left + b.width) && |
|
|
|
(a.left + a.width + margin.horizontal - EPSILON) > b.left && |
|
|
|
(a.top - margin.vertical + EPSILON) < (b.top + b.height) && |
|
|
|
(a.top + a.height + margin.vertical - EPSILON) > b.top); |
|
|
|
}; |