-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CollisionHelpers extraction and tests
- Loading branch information
Paulo Procopiou
committed
Mar 11, 2017
1 parent
09a5c5a
commit e127669
Showing
4 changed files
with
51 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = {segmentsCollide}; | ||
|
||
function segmentsCollide (segment1_start, segment1_end, segment2_start, segment2_end) { | ||
return segment1_end >= segment2_start && | ||
segment1_start <= segment2_end; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const {segmentsCollide} = require('../lib/collision-helpers'); | ||
const expect = require('chai').expect; | ||
|
||
describe('CollisionHelpers', function () { | ||
|
||
describe('.segmentsCollide', function () { | ||
|
||
it('returns true if segments touch', function () { | ||
expect(segmentsCollide(1, 2, 2, 3)).to.equal(true); | ||
expect(segmentsCollide(2, 3, 1, 2)).to.equal(true); | ||
}); | ||
|
||
it('returns true if segments intersect', function () { | ||
expect(segmentsCollide(1, 2.5, 2, 3)).to.equal(true); | ||
expect(segmentsCollide(1.9, 3, 1, 2)).to.equal(true); | ||
}); | ||
|
||
it('returns true if one segment is inside the other', function () { | ||
expect(segmentsCollide(1, 5, 2, 3)).to.equal(true); | ||
expect(segmentsCollide(2, 3, 1, 5)).to.equal(true); | ||
}); | ||
|
||
it('returns false if segments do not touch or intersect', function () { | ||
expect(segmentsCollide(1, 2, 3, 4)).to.equal(false); | ||
expect(segmentsCollide(3, 4, 1, 2)).to.equal(false); | ||
}); | ||
|
||
}); | ||
|
||
}); |