physicist 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/physicist/body.rb +25 -15
- data/lib/physicist/laboratory/handlers/create_scientist_handler.rb +9 -9
- data/lib/physicist/laboratory/models/scientist.rb +2 -2
- data/lib/physicist/laboratory/views/scientist_view.rb +4 -4
- data/lib/physicist/version.rb +1 -1
- data/spec/physicist_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76440466d9ad32c5399bb29a7968595bba52ef50
|
4
|
+
data.tar.gz: 66230d9062e4fbf8454c9823167a0c0e99e5d5bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db17689f1ffb37c76c579e6a0f0f3ae2f457cc43a9fb92b27b1115a9fa97c830fedc5b16b87db263751ce9d24b21321e80eddd9a44ac21d54e8c4db379e9dda4
|
7
|
+
data.tar.gz: 188d057238537f28f5d384d028b68b9f13bb498e4a791564a2ea33d7204a6d7039be21d71e13aa48a9d9e3c34e7b9b797507307ef60960ca43ffa4d7ca000001
|
data/lib/physicist/body.rb
CHANGED
@@ -25,6 +25,11 @@ module Physicist
|
|
25
25
|
10.0
|
26
26
|
end
|
27
27
|
|
28
|
+
# some tiny number
|
29
|
+
def epsilon
|
30
|
+
0.000001
|
31
|
+
end
|
32
|
+
|
28
33
|
def at(t, obstacles:[])
|
29
34
|
x0, _ = *position
|
30
35
|
vx0,vy0 = *velocity
|
@@ -57,8 +62,8 @@ module Physicist
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
|
-
vxt = 0 if -
|
61
|
-
vyt = 0 if -
|
65
|
+
vxt = 0 if -epsilon < vx && vx < epsilon
|
66
|
+
vyt = 0 if -epsilon < vy && vy < epsilon
|
62
67
|
|
63
68
|
Body.new(
|
64
69
|
position: [xt,yt],
|
@@ -80,9 +85,9 @@ module Physicist
|
|
80
85
|
|
81
86
|
distance_to_next_x_obstacle =
|
82
87
|
if vx > 0
|
83
|
-
((x0+width) - ox).abs
|
88
|
+
((x0+3*(width/4.0)) - ox).abs
|
84
89
|
elsif vx < 0
|
85
|
-
((x0) - (ox+ow)).abs
|
90
|
+
((x0+(width/4.0)) - (ox+ow)).abs
|
86
91
|
end
|
87
92
|
|
88
93
|
distance_travelled_in_x_axis_if_no_obstacles = vx * dt
|
@@ -91,9 +96,9 @@ module Physicist
|
|
91
96
|
yield [x0 + (vx*dt), vx]
|
92
97
|
else
|
93
98
|
if vx > 0
|
94
|
-
yield [next_x_obstacle.position[0]-width, 0]
|
99
|
+
yield [next_x_obstacle.position[0]-3*(width/4.0)-epsilon, 0]
|
95
100
|
else
|
96
|
-
yield [next_x_obstacle.position[0]+next_x_obstacle.dimensions[0], 0]
|
101
|
+
yield [next_x_obstacle.position[0]+next_x_obstacle.dimensions[0]-(width/4.0)+epsilon, 0]
|
97
102
|
end
|
98
103
|
end
|
99
104
|
else
|
@@ -120,9 +125,9 @@ module Physicist
|
|
120
125
|
yield [y0 + (vy * dt), vy ]
|
121
126
|
else
|
122
127
|
if vy > 0
|
123
|
-
yield [next_y_obstacle.position[1] - (height) -
|
124
|
-
else
|
125
|
-
yield [next_y_obstacle.position[1] + next_y_obstacle.dimensions[1] +
|
128
|
+
yield [next_y_obstacle.position[1] - (height) - epsilon, 0]
|
129
|
+
else
|
130
|
+
yield [next_y_obstacle.position[1] + next_y_obstacle.dimensions[1] + epsilon, 0]
|
126
131
|
end
|
127
132
|
end
|
128
133
|
else
|
@@ -133,11 +138,16 @@ module Physicist
|
|
133
138
|
def next_obstacle_on_x_axis(y,vx,t,obstacles:)
|
134
139
|
x0,_ = *position
|
135
140
|
|
141
|
+
# w = width/2.0
|
142
|
+
# x0 += w/2.0
|
143
|
+
w = width/2.0
|
144
|
+
x0 += w/2.0
|
145
|
+
|
136
146
|
obstacles_along_axis = obstacles.select do |obstacle|
|
137
147
|
_,oy = *obstacle.position
|
138
148
|
_,oh = *obstacle.dimensions
|
139
149
|
|
140
|
-
oy <= y + height && y <= oy + oh
|
150
|
+
oy <= y + height && y <= oy + oh - (2*epsilon)
|
141
151
|
end
|
142
152
|
|
143
153
|
obstacles_in_direction_of_movement =
|
@@ -146,7 +156,7 @@ module Physicist
|
|
146
156
|
ox,_ = *obstacle.position
|
147
157
|
# ow,oh = *obstacle.dimensions
|
148
158
|
|
149
|
-
ox >= x0 +
|
159
|
+
ox >= x0 + w #/2.0)
|
150
160
|
end
|
151
161
|
elsif vx < 0
|
152
162
|
# require 'pry'
|
@@ -174,8 +184,8 @@ module Physicist
|
|
174
184
|
def next_obstacle_on_y_axis(vy,t,obstacles:)
|
175
185
|
x0,y0 = *position
|
176
186
|
|
177
|
-
|
178
|
-
|
187
|
+
w = width/2.0
|
188
|
+
x0 += w/2.0
|
179
189
|
|
180
190
|
obstacles_along_axis = obstacles.select do |obstacle|
|
181
191
|
ox,_ = *obstacle.position
|
@@ -188,14 +198,14 @@ module Physicist
|
|
188
198
|
obstacles_along_axis.select do |obstacle|
|
189
199
|
_,oy = *obstacle.position
|
190
200
|
|
191
|
-
oy >= y0 + height
|
201
|
+
oy >= y0 + height - epsilon
|
192
202
|
end
|
193
203
|
elsif vy < 0
|
194
204
|
obstacles_along_axis.select do |obstacle|
|
195
205
|
_,oy = *obstacle.position
|
196
206
|
_,oh = *obstacle.dimensions
|
197
207
|
|
198
|
-
oy + oh <= y0
|
208
|
+
oy + oh <= y0 + epsilon
|
199
209
|
end
|
200
210
|
else
|
201
211
|
[]
|
@@ -4,15 +4,15 @@ module Physicist
|
|
4
4
|
def handle(scientist_id:, name:, title:, position:, velocity:)
|
5
5
|
map_data = (
|
6
6
|
[
|
7
|
-
[ 1,
|
8
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
9
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
10
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
11
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
12
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ],
|
13
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ],
|
14
|
-
[ 1,
|
15
|
-
[ 1,
|
7
|
+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
|
8
|
+
[ nil, nil, nil, nil, nil, 1, 1, nil, nil, nil, nil, 2, 1 ],
|
9
|
+
[ nil, nil, nil, nil, nil, 1, 1, nil, nil, nil, nil, nil, 1 ],
|
10
|
+
[ nil, nil, nil, nil, nil, 1, 1, nil, nil, nil, nil, nil, 1 ],
|
11
|
+
[ nil, nil, nil, nil, nil, 1, 1, nil, nil, nil, nil, nil, 1 ],
|
12
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 1 ],
|
13
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 3, 1 ],
|
14
|
+
[ 1, 1, nil, nil, 1, 1, 1, 1, nil, nil, nil, 2, 1 ],
|
15
|
+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
16
16
|
]
|
17
17
|
)
|
18
18
|
|
@@ -26,7 +26,7 @@ module Physicist
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def leg_strength # ??
|
29
|
-
-
|
29
|
+
-15
|
30
30
|
end
|
31
31
|
|
32
32
|
def max_jump_velocity
|
@@ -60,7 +60,7 @@ module Physicist
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def current
|
63
|
-
|
63
|
+
body.at(Time.now, obstacles: space.obstacles)
|
64
64
|
end
|
65
65
|
|
66
66
|
def body
|
@@ -13,10 +13,6 @@ module Physicist
|
|
13
13
|
@body = body.at(Time.now, obstacles: workspace_view.obstacles)
|
14
14
|
end
|
15
15
|
|
16
|
-
def workspace_view
|
17
|
-
WorkspaceView.find_by(space_id: space_id)
|
18
|
-
end
|
19
|
-
|
20
16
|
def body
|
21
17
|
# ... integrate physicist bodies ...
|
22
18
|
@body ||= construct_body
|
@@ -30,6 +26,10 @@ module Physicist
|
|
30
26
|
dimensions: [2,2]
|
31
27
|
)
|
32
28
|
end
|
29
|
+
|
30
|
+
def workspace_view
|
31
|
+
WorkspaceView.find_by(space_id: space_id)
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
class NullScientistView
|
data/lib/physicist/version.rb
CHANGED
data/spec/physicist_spec.rb
CHANGED
@@ -96,7 +96,7 @@ describe Body do
|
|
96
96
|
_,vy = *body_at_t.velocity
|
97
97
|
_,y = *body_at_t.position
|
98
98
|
expect(vy).to eq(0)
|
99
|
-
expect(y0 -
|
99
|
+
expect(y0 - body.epsilon).to eq(y)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -113,7 +113,7 @@ describe Body do
|
|
113
113
|
it 'should stop vertical movement after 1s' do
|
114
114
|
_,vy = *body_at_t.velocity
|
115
115
|
_,y = *body_at_t.position
|
116
|
-
expect(y0 + 9.
|
116
|
+
expect(y0 + 9.8 - body.epsilon).to eq(y)
|
117
117
|
expect(vy).to eq(0)
|
118
118
|
end
|
119
119
|
end
|