Skip to content

Instantly share code, notes, and snippets.

@Loupax
Last active August 29, 2015 14:08
Show Gist options
  • Save Loupax/96f6c87d4f7c9ee74e08 to your computer and use it in GitHub Desktop.
Save Loupax/96f6c87d4f7c9ee74e08 to your computer and use it in GitHub Desktop.
1D collision detection
var collisionsExist = false;
rows.map(function(row){
row.timebands.map(function(timeband){
if(timeband !== $scope.timeband){
var newTb = fixTimeband($scope.timeband), testTb = fixTimeband(timeband);
// The new timeband starts before the test timeband starts, and ends after the test timeband ends
if(newTb.to <= testTb.to && newTb.from >= testTb.from){
collisionsExist = true;
}
// The new timeband begins before the test timeband starts, and ends after the test timeband ends
if(newTb.from < testTb.from && newTb.to > testTb.to){
collisionsExist = true;
}
// The new timeband begins before the end of the test timeband, and ends after the test timeband ends
if(newTb.from < testTb.to && newTb.to > testTb.to){
collisionsExist = true;
}
if(newTb.from < testTb.from && newTb.to > testTb.from){
collisionsExist = true;
}
}
});
});
return collisionsExist;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment