physicist 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25ec556fd4d506229e77d77f8d449b1c3d0f54b1
4
- data.tar.gz: 0c1a334ccf5cbf505e87606ab54fc484947f4c00
3
+ metadata.gz: 76440466d9ad32c5399bb29a7968595bba52ef50
4
+ data.tar.gz: 66230d9062e4fbf8454c9823167a0c0e99e5d5bc
5
5
  SHA512:
6
- metadata.gz: 1925d82228e4c198913dd95e24a1884ffd3a1454300c1f00b771064054c795a6e667c154adf0326ac5a2eff264485c8078a0c406c85bb81b3e2a798e1bd8ec05
7
- data.tar.gz: 4212d6b0ef66e42ca3018960b86949b7da0e6050136c7feb2e818231525819e47f6b5b80e98d46e03712a39053ba74f0577a40ae14b3e362f4dab859f62bd456
6
+ metadata.gz: db17689f1ffb37c76c579e6a0f0f3ae2f457cc43a9fb92b27b1115a9fa97c830fedc5b16b87db263751ce9d24b21321e80eddd9a44ac21d54e8c4db379e9dda4
7
+ data.tar.gz: 188d057238537f28f5d384d028b68b9f13bb498e4a791564a2ea33d7204a6d7039be21d71e13aa48a9d9e3c34e7b9b797507307ef60960ca43ffa4d7ca000001
@@ -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 -0.05 < vx && vx < 0.05
61
- vyt = 0 if -0.05 < vy && vy < 0.05
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) - 0.001, 0]
124
- else
125
- yield [next_y_obstacle.position[1] + next_y_obstacle.dimensions[1] + 0.1, 0]
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 + width
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
- # x0 += width/4
178
- w = width #/2
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
8
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ],
9
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ],
10
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ],
11
- [ nil, 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, nil, nil, nil, nil, 2, nil, nil, nil, nil, 1 ],
15
- [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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
- -12
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
- @body = body.at(Time.now, obstacles: space.obstacles)
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
@@ -1,4 +1,4 @@
1
1
  module Physicist
2
2
  # physicist version
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
@@ -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 - 0.001).to eq(y)
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.799).to eq(y)
116
+ expect(y0 + 9.8 - body.epsilon).to eq(y)
117
117
  expect(vy).to eq(0)
118
118
  end
119
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: physicist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman