-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ab0ba
commit 2cb5132
Showing
8 changed files
with
775 additions
and
26 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,70 @@ | ||
define([ | ||
'../ThirdParty/rbush', | ||
'./Check' | ||
], function( | ||
rbush, | ||
Check) { | ||
'use strict'; | ||
|
||
/** | ||
* Wrapper around rbush for use with Rectangle types. | ||
* @private | ||
*/ | ||
function RectangleRbush() { | ||
this._tree = rbush(); | ||
} | ||
|
||
function RectangleWithId() { | ||
this.minX = 0.0; | ||
this.minY = 0.0; | ||
this.maxX = 0.0; | ||
this.maxY = 0.0; | ||
this.id = ''; | ||
} | ||
|
||
function fromRectangleAndId(rectangle, id, result) { | ||
result.minX = rectangle.west; | ||
result.minY = rectangle.south; | ||
result.maxX = rectangle.east; | ||
result.maxY = rectangle.north; | ||
result.id = id; | ||
return result; | ||
} | ||
|
||
function idCompare(a, b) { | ||
return a.id === b.id; | ||
} | ||
|
||
RectangleRbush.prototype.insert = function(id, rectangle) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.string('id', id); | ||
Check.typeOf.object('rectangle', rectangle); | ||
//>>includeEnd('debug'); | ||
|
||
var withId = fromRectangleAndId(rectangle, id, new RectangleWithId()); | ||
this._tree.insert(withId); | ||
}; | ||
|
||
var removalScratch = new RectangleWithId(); | ||
RectangleRbush.prototype.remove = function(id, rectangle) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.string('id', id); | ||
Check.typeOf.object('rectangle', rectangle); | ||
//>>includeEnd('debug'); | ||
|
||
var withId = fromRectangleAndId(rectangle, id, removalScratch); | ||
this._tree.remove(withId, idCompare); | ||
}; | ||
|
||
var collisionScratch = new RectangleWithId(); | ||
RectangleRbush.prototype.collides = function(rectangle) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.object('rectangle', rectangle); | ||
//>>includeEnd('debug'); | ||
|
||
var withId = fromRectangleAndId(rectangle, '', collisionScratch); | ||
return this._tree.collides(withId); | ||
}; | ||
|
||
return RectangleRbush; | ||
}); |
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
Oops, something went wrong.