Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Harmonised positive and negative movement

  • Loading branch information...
commit 16e859b62de03f7e1326f19c0f6f3afb0b0339f3 1 parent 6883709
@rrees rrees authored
View
6 src/coloured_balls/motion.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))))
View
4 test/coloured_balls/core_test.clj
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.