File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141 (let [{position :position
4242 [_, power :as heading] :heading } player
4343 missile-position (-> (polar->cartesian heading)
44- normilize -vector
44+ normalize -vector
4545 (multiply-by-scalar (+ player-radius
4646 missile-radius))
4747 (vector-sum position))
4848 missile-velocity (-> (polar->cartesian heading)
49- normilize -vector
49+ normalize -vector
5050 (multiply-by-scalar (* power 100 )))]
5151 (add-missile world
5252 missile-position
9191 planet-radius :radius } planet
9292
9393 fragments-position (-> (vector-subtract particle-position planet-position)
94- normilize -vector
94+ normalize -vector
9595 (multiply-by-scalar (+ particle-radius planet-radius 5 ))
9696 (vector-sum planet-position))]
9797 (repeatedly 5
Original file line number Diff line number Diff line change 22
33(def
44 ^{:arglists '([vtr & vtrs])
5- :doc " Returns the sum of vectors. The result vector has a minimum
6- possible dimension." }
5+ :doc " Returns the sum of vectors." }
76 vector-sum (partial mapv +))
87
98(def
109 ^{:arglists '([vtr & vtrs])
11- :doc " If no vtrs are supplied, returns the negation of vtr, else
12- subtracts the vtrs from vtr and returns the result. The result
13- vector has a minimum possible dimension." }
10+ :doc " If vtrs are supplied, returns the negation of vtr, else
11+ subtracts the vtrs from vtr and returns the result." }
1412 vector-subtract
1513 (partial mapv -))
1614
3634 [vtr]
3735 (Math/sqrt (reduce #(+ %1 (* %2 %2 )) 0.0 vtr)))
3836
39- (defn normilize -vector
40- " Normilizes vector, that is returns a vector with the same
37+ (defn normalize -vector
38+ " Normalizes vector, that is returns a vector with the same
4139 direction, but with the length equal 1."
4240 [vtr]
4341 (let [length (vector-length vtr)]
Original file line number Diff line number Diff line change 1313 (* d d))
1414 acceleration (/ force mass1)]
1515 (-> (vector-subtract position2 position1)
16- normilize -vector
16+ normalize -vector
1717 (multiply-by-scalar acceleration))))
Original file line number Diff line number Diff line change 2020 (multiply-by-scalar [0.2 , 0.5 ] 3 ) => (just [(almost= 0.6 ),
2121 (almost= 1.5 )]))
2222
23+ ; ; (facts "about polar->cartesian function"
24+ ; ; )
25+
26+ ; ; (facts "about cartesia->polar function"
27+ ; ; )
28+
2329(facts " about vector-length function"
2430 (vector-length [10 , 10 ]) => (almost= 14.142135623730951 )
2531 (vector-length [1.23 , 10.32 ]) => (almost= 10.393040940937354 ))
3743
3844(facts " about distance function"
3945 (distance [0 , 0 ] [10 , 10 ]) => (almost= (vector-length [10 , 10 ]))
40- (distance [34 , 12 ] [-24 , 42 ]) => (almost= 65.29931086925804 ))
46+ (distance [34 , 12 ] [-24 , 42 ]) => (almost= 65.29931086925804 ))
47+
48+ ; ; (facts "about circle-X-circle? function"
49+ ; ; (circle-X-circle? {:position [0, 0], :radius 10}
50+ ; ; {:position [100, 100], :radius 10})
51+ ; ; => false
52+
53+ ; ; (circle-X-circle? {:position [34, 32], :radius 20}
54+ ; ; {:position []})
55+ ; ; => true
56+ ; ; )
57+
58+ ; ; (facts "about circle-X-any-circle? function"
59+ ; ; )
60+
61+ ; ; (facts "about circle-X-rectangle? fucntion"
62+ ; ; )
You can’t perform that action at this time.
0 commit comments