Permalink
Browse files

Harmonised positive and negative movement

  • Loading branch information...
1 parent 6883709 commit 16e859b62de03f7e1326f19c0f6f3afb0b0339f3 Robert Rees committed May 1, 2011
Showing with 5 additions and 5 deletions.
  1. +3 −3 src/coloured_balls/motion.clj
  2. +2 −2 test/coloured_balls/core_test.clj
@@ -1,5 +1,5 @@
(ns coloured-balls.motion
- (:use [clojure.contrib.generic.math-functions :only (floor, cos, sin)]))
+ (:use [clojure.contrib.generic.math-functions :only (round, cos, sin)]))
(defn degrees-to-radians [degrees]
(* (/ Math/PI 180) degrees))
@@ -9,7 +9,7 @@
velocity (:velocity item)
old-x (:x item)
old-y (:y item)
- new-x (floor (* velocity (cos heading)))
- new-y (floor (* velocity (sin heading)))]
+ new-x (round (* velocity (cos heading)))
+ new-y (round (* velocity (sin heading)))]
(conj {:x (+ old-x new-x) :y (+ old-y new-y)} (dissoc item :x :y))))
@@ -2,9 +2,9 @@
(:use coloured-balls.motion coloured-balls.collision
midje.sweet))
-(fact (:x (move {:x 0 :y 0 :heading 45 :velocity 5})) => 3)
+(fact (:x (move {:x 0 :y 0 :heading 45 :velocity 5})) => 4)
-(fact (:y (move {:x 0 :y 0 :heading 45 :velocity 5})) => 3)
+(fact (:y (move {:x 0 :y 0 :heading 45 :velocity 5})) => 4)
(fact (:x (move {:x 4 :y 4 :heading 225 :velocity 5})) => 0)

0 comments on commit 16e859b

Please sign in to comment.