Last active
August 29, 2015 14:08
-
-
Save Loupax/96f6c87d4f7c9ee74e08 to your computer and use it in GitHub Desktop.
1D collision detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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