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

fix: collisionByTimes updated to be exclusive #360

Merged
merged 1 commit into from
Mar 9, 2020
Merged
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
28 changes: 16 additions & 12 deletions lib/timeline/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ export function stack(items, margin, force, shouldBailItemsRedrawFunction) {
}

/**
* Adjust vertical positions of the items within a single subgroup such that they
* Adjust vertical positions of the items within a single subgroup such that they
* don't overlap each other.
* @param {Item[]} items
* All items withina subgroup
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
* Margins between items and between items and the axis.
* @param {subgroup} subgroup
* The subgroup that is being stacked
* The subgroup that is being stacked
*/
export function substack(items, margin, subgroup) {
for (var i = 0; i < items.length; i++) {
Expand Down Expand Up @@ -212,11 +212,11 @@ export function stackSubgroups(items, margin, subgroups) {
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
* Margins between items and between items and the axis.
* @param {subgroups[]} subgroups
* All subgroups
* All subgroups
*/
export function stackSubgroupsWithInnerStack(subgroupItems, margin, subgroups) {
let doSubStack = false;

// Run subgroups in their order (if any)
const subgroupOrder = [];

Expand All @@ -234,7 +234,7 @@ export function stackSubgroupsWithInnerStack(subgroupItems, margin, subgroups) {
if (subgroups.hasOwnProperty(subgroup)) {

doSubStack = doSubStack || subgroups[subgroup].stack;
subgroups[subgroup].top = 0;
subgroups[subgroup].top = 0;

for (const otherSubgroup in subgroups) {
if (subgroups[otherSubgroup].visible && subgroups[subgroup].index > subgroups[otherSubgroup].index) {
Expand All @@ -248,16 +248,16 @@ export function stackSubgroupsWithInnerStack(subgroupItems, margin, subgroups) {
items[i].top = subgroups[items[i].data.subgroup].top + 0.5 * margin.item.vertical;

if (subgroups[subgroup].stack) {
items[i].baseTop = items[i].top;
items[i].baseTop = items[i].top;
}
}
}
}

if (doSubStack && subgroups[subgroup].stack) {
substack(subgroupItems[subgroup], margin, subgroups[subgroup]);
substack(subgroupItems[subgroup], margin, subgroups[subgroup]);
}
}
}
}
}

/**
Expand Down Expand Up @@ -293,6 +293,10 @@ export function collision(a, b, margin, rtl) {
* @return {boolean} true if a and b collide, else false
*/
export function collisionByTimes(a, b) {
return (a.start <= b.start && a.end >= b.start && a.top < (b.top + b.height) && (a.top + a.height) > b.top ) ||
(b.start <= a.start && b.end >= a.start && b.top < (a.top + a.height) && (b.top + b.height) > a.top );
}

// Check for overlap by time and height. Abutting is OK and
// not considered a collision while overlap is considered a collision.
const timeOverlap = a.start < b.end && a.end > b.start;
const heightOverlap = a.top < (b.top + b.height) && (a.top + a.height) > b.top;
return timeOverlap && heightOverlap;
}