-
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.
added distance check and collision tests
- Loading branch information
root
committed
Sep 26, 2012
1 parent
ca0702e
commit 744341d
Showing
21 changed files
with
3,764 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var Point = function(x, y) { | ||
return { | ||
x: x, | ||
y: y | ||
} | ||
}; | ||
|
||
var Line = function(p1, p2) { | ||
return { | ||
p1: new Point(p1.x, p1.y), | ||
p2: new Point(p2.x, p2.y) | ||
} | ||
}; | ||
|
||
var checkIntersection = function(line1, line2) { | ||
var returnVal = {}; | ||
|
||
var d = (line2.p2.y - line2.p1.y) * (line1.p2.x - line1.p1.x) - (line2.p2.x - line2.p1.x) * (line1.p2.y - line1.p1.y); | ||
var n_a = (line2.p2.x - line2.p1.x) * (line1.p1.y - line2.p1.y) - (line2.p2.y - line2.p1.y) * (line1.p1.x - line2.p1.x); | ||
var n_b = (line1.p2.x - line1.p1.x) * (line1.p1.y - line2.p1.y) - (line1.p2.y - line1.p1.y) * (line1.p1.x - line2.p1.x); | ||
|
||
if (d == 0) return false; | ||
|
||
var ua = (n_a << 14)/d; | ||
var ub = (n_b << 14)/d; | ||
|
||
if (ua >=0 && ua <= (1 << 14) && ub >= 0 && ub <= (1 << 14)) { | ||
returnVal.x = line1.p1.x + ((ua * (line1.p2.x - line1.p1.x)) >> 14); | ||
returnVal.y = line1.p1.y + ((ua * (line1.p2.y - line1.p1.y)) >> 14); | ||
return returnVal; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
exports.Point = Point; | ||
exports.Line = Line; | ||
exports.checkIntersection = checkIntersection; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.