From 866d23ff03226c4c7e314f1c4fc6a56724c578d5 Mon Sep 17 00:00:00 2001 From: Alex Chapman Date: Mon, 12 May 2008 10:34:51 +1000 Subject: [PATCH] jamshred: fix failing unit test --- extra/jamshred/tunnel/tunnel-tests.factor | 5 +++-- extra/jamshred/tunnel/tunnel.factor | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/extra/jamshred/tunnel/tunnel-tests.factor b/extra/jamshred/tunnel/tunnel-tests.factor index c6755318e6..903ff94739 100644 --- a/extra/jamshred/tunnel/tunnel-tests.factor +++ b/extra/jamshred/tunnel/tunnel-tests.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. -USING: jamshred.oint jamshred.tunnel kernel sequences tools.test ; +USING: arrays jamshred.oint jamshred.tunnel kernel math.vectors sequences tools.test ; IN: jamshred.tunnel.tests [ 0 ] [ T{ segment f { 0 0 0 } f f f 0 } @@ -41,4 +41,5 @@ IN: jamshred.tunnel.tests [ { 0 1 0 } ] [ simple-collision-up sideways-heading ] unit-test [ { 0 0 0 } ] [ simple-collision-up sideways-relative-location ] unit-test -[ { 0 1 0 } ] [ simple-collision-up collision-vector ] unit-test +[ { 0 1 0 } ] +[ simple-collision-up collision-vector 0 bounce-offset 0 3array v+ ] unit-test diff --git a/extra/jamshred/tunnel/tunnel.factor b/extra/jamshred/tunnel/tunnel.factor index f3fa9a0354..5cf1e33e64 100755 --- a/extra/jamshred/tunnel/tunnel.factor +++ b/extra/jamshred/tunnel/tunnel.factor @@ -126,10 +126,14 @@ C: segment : sideways-relative-location ( oint segment -- loc ) [ [ location>> ] bi@ v- ] keep forward>> proj-perp ; +: bounce-offset 0.1 ; inline + +: bounce-radius ( segment -- r ) + radius>> bounce-offset - ; ! bounce before we hit so that we can't see through the wall (hack?) + : collision-vector ( oint segment -- v ) [ sideways-heading ] [ sideways-relative-location ] - [ radius>> 0.1 - ] ! bounce before we hit so that we can't see through the wall (hack?) - 2tri + [ bounce-radius ] 2tri swap [ collision-coefficient ] dip forward>> n*v ; : distance-to-collision ( oint segment -- distance )