summaryrefslogtreecommitdiff
path: root/public/assets/test/intersect.html
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/test/intersect.html')
-rw-r--r--public/assets/test/intersect.html15
1 files changed, 11 insertions, 4 deletions
diff --git a/public/assets/test/intersect.html b/public/assets/test/intersect.html
index 5e16f2e..4e5b0bb 100644
--- a/public/assets/test/intersect.html
+++ b/public/assets/test/intersect.html
@@ -1,4 +1,5 @@
<canvas id="canvas"></canvas>
+<div id="hud"></div>
<script src="/assets/javascripts/util.js"></script>
<script src="/assets/javascripts/vendor/tube.js"></script>
@@ -73,16 +74,21 @@ function draw () {
var collinear = is_collinear( intersect, vec_b )
var long_enough_to_intersect = 0 <= t && t <= 1
+ var msg
if (long_enough_to_intersect && collinear) {
ctx.fillStyle = "#f00"
+ msg = "through"
}
else if (collinear) {
ctx.fillStyle = "#0f0"
+ msg = "to"
}
else {
ctx.fillStyle = "#000"
+ msg = "off"
}
+ hud.innerHTML = [intersect.exactString(), vec_b.exactString(), msg].join("<br>")
drawPoint(intersect)
}
@@ -105,19 +111,20 @@ function perp (va, vb) {
}
function is_collinear (p, vec) {
var on_x, on_y
+ var pa = round(p.a), pb = round(p.b)
if (vec.x.a < vec.y.a) {
- on_x = vec.x.a <= p.a && p.a <= vec.y.a
+ on_x = vec.x.a <= pa && pa <= vec.y.a
}
else {
- on_x = vec.x.a >= p.a && p.a >= vec.y.a
+ on_x = vec.x.a >= pa && pa >= vec.y.a
}
if (vec.x.b < vec.y.b) {
- on_y = vec.x.b <= p.b && p.b <= vec.y.b
+ on_y = vec.x.b <= pb && pb <= vec.y.b
}
else {
- on_y = vec.x.b >= p.b && p.b >= vec.y.b
+ on_y = vec.x.b >= pb && pb >= vec.y.b
}
return !! (on_x && on_y)