ballistics 0.2.1 → 0.2.2
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 +4 -4
- data/ext/ballistics/ballistics.c +20 -16
- data/lib/ballistics.rb +1 -1
- data/lib/ballistics/trajectory.rb +3 -2
- data/spec/ballistics_spec.rb +52 -37
- 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: 2c933900d7778a88c08d82cd6aa1cf853f3abbbf
|
4
|
+
data.tar.gz: b34a53f9ef4609e36b8a59076f422ee8486b88ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 813eda1d29613a8f63eb3735a8af8a796de92d9155b217f2f3018ef525be71ec170a88d030b7d2a421f1bd164c2ed4316b85325a315a07528e8ae9335964cda9
|
7
|
+
data.tar.gz: 4f1f0aa9c6829851ed7fc93063814753f1671e051f86de0cceb2410147b88411a313324d6755e587200db41c41cd27eecd999ead15546dad0443abb0fe687011
|
data/ext/ballistics/ballistics.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <gnu_ballistics.h>
|
3
3
|
VALUE method_calculate_zero_angle(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE zero_range, VALUE y_intercept);
|
4
|
-
VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE shooting_angle, VALUE zero_angle, VALUE wind_speed, VALUE wind_angle, VALUE max_range);
|
4
|
+
VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE shooting_angle, VALUE zero_angle, VALUE wind_speed, VALUE wind_angle, VALUE max_range, VALUE interval);
|
5
5
|
|
6
6
|
VALUE cBallistics;
|
7
7
|
VALUE cZero;
|
@@ -11,7 +11,7 @@ void Init_ballistics() {
|
|
11
11
|
cZero = rb_define_module_under(cBallistics, "Zero");
|
12
12
|
cTrajectory = rb_define_module_under(cBallistics, "Trajectory");
|
13
13
|
rb_define_singleton_method(cZero, "_calculate_zero_angle", method_calculate_zero_angle, 6);
|
14
|
-
rb_define_singleton_method(cTrajectory, "_map_trajectory", method_map_trajectory,
|
14
|
+
rb_define_singleton_method(cTrajectory, "_map_trajectory", method_map_trajectory, 10);
|
15
15
|
}
|
16
16
|
|
17
17
|
VALUE method_calculate_zero_angle(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE zero_range, VALUE y_intercept) {
|
@@ -19,7 +19,7 @@ VALUE method_calculate_zero_angle(VALUE self, VALUE drag_function, VALUE drag_co
|
|
19
19
|
return rb_float_new(angle);
|
20
20
|
}
|
21
21
|
|
22
|
-
VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE shooting_angle, VALUE zero_angle, VALUE wind_speed, VALUE wind_angle, VALUE max_range) {
|
22
|
+
VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coefficient, VALUE velocity, VALUE sight_height, VALUE shooting_angle, VALUE zero_angle, VALUE wind_speed, VALUE wind_angle, VALUE max_range, VALUE interval) {
|
23
23
|
|
24
24
|
/* cast ruby variables */
|
25
25
|
int DragFunction = FIX2INT(drag_function);
|
@@ -31,6 +31,7 @@ VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coeffici
|
|
31
31
|
double WindSpeed = NUM2DBL(wind_speed);
|
32
32
|
double WindAngle = NUM2DBL(wind_angle);
|
33
33
|
int MaxRange = FIX2INT(max_range);
|
34
|
+
int Interval = FIX2INT(interval);
|
34
35
|
|
35
36
|
/* create ruby objects */
|
36
37
|
VALUE result_array = rb_ary_new2(MaxRange);
|
@@ -73,19 +74,22 @@ VALUE method_map_trajectory(VALUE self, VALUE drag_function, VALUE drag_coeffici
|
|
73
74
|
|
74
75
|
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
77
|
+
int yards = (x/3);
|
78
|
+
if (yards>=n){
|
79
|
+
if (yards % Interval == 0){
|
80
|
+
VALUE entry = rb_hash_new();
|
81
|
+
double windage_value = Windage(crosswind,Vi,x,t+dt);
|
82
|
+
double moa_windage_value = windage_value / ((yards / 100.0) * 1.0465);
|
83
|
+
rb_hash_aset(entry, rb_str_new2("range"), rb_float_new((int)(yards)));
|
84
|
+
rb_hash_aset(entry, rb_str_new2("path"), rb_float_new(y*12));
|
85
|
+
rb_hash_aset(entry, rb_str_new2("moa_correction"), rb_float_new(-RadtoMOA(atan(y/x))));
|
86
|
+
rb_hash_aset(entry, rb_str_new2("time"), rb_float_new(t+dt));
|
87
|
+
rb_hash_aset(entry, rb_str_new2("windage"), rb_float_new(windage_value));
|
88
|
+
rb_hash_aset(entry, rb_str_new2("moa_windage"), rb_float_new(moa_windage_value));
|
89
|
+
rb_hash_aset(entry, rb_str_new2("velocity"), rb_float_new(v));
|
90
|
+
rb_ary_push(result_array, entry);
|
91
|
+
}
|
92
|
+
n++;
|
89
93
|
}
|
90
94
|
|
91
95
|
// Compute position based on average velocity.
|
data/lib/ballistics.rb
CHANGED
@@ -11,7 +11,7 @@ module Ballistics
|
|
11
11
|
|
12
12
|
def self.map_trajectory(options = {})
|
13
13
|
[:drag_function, :drag_coefficient, :velocity, :sight_height, :zero_range].each do |requirement|
|
14
|
-
raise ArgumentError "Failed to specify: #{requirement}" unless options[requirement]
|
14
|
+
raise ArgumentError, "Failed to specify: #{requirement}" unless options[requirement]
|
15
15
|
end
|
16
16
|
|
17
17
|
# correct ballistic coefficient if an environment was passed
|
@@ -3,7 +3,7 @@ require_relative 'df_map'
|
|
3
3
|
module Ballistics
|
4
4
|
module Trajectory
|
5
5
|
def self.map_trajectory(opts = {})
|
6
|
-
options = { shooting_angle: 0, wind_speed: 0, wind_angle: 0, max_range: 500 }.merge(opts)
|
6
|
+
options = { shooting_angle: 0, wind_speed: 0, wind_angle: 0, max_range: 500, interval: 1 }.merge(opts)
|
7
7
|
|
8
8
|
drag_function = Ballistics::DFMap.__convert_df_to_int(options[:drag_function])
|
9
9
|
drag_coefficient = options[:drag_coefficient]
|
@@ -14,8 +14,9 @@ module Ballistics
|
|
14
14
|
wind_speed = options[:wind_speed]
|
15
15
|
wind_angle = options[:wind_angle]
|
16
16
|
max_range = options[:max_range]
|
17
|
+
interval = options[:interval]
|
17
18
|
|
18
|
-
self._map_trajectory(drag_function, drag_coefficient, vi, sight_height, shooting_angle, z_angle, wind_speed, wind_angle, max_range)
|
19
|
+
self._map_trajectory(drag_function, drag_coefficient, vi, sight_height, shooting_angle, z_angle, wind_speed, wind_angle, max_range, interval)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
data/spec/ballistics_spec.rb
CHANGED
@@ -11,65 +11,80 @@ describe Ballistics do
|
|
11
11
|
wind_angle: 90,
|
12
12
|
zero_range: 200,
|
13
13
|
max_range: 1000,
|
14
|
-
environment: environment
|
14
|
+
environment: environment,
|
15
|
+
interval: 25)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:bad_params) do
|
19
|
+
Ballistics.map_trajectory(drag_function: 'G1', drag_coefficient: 0.5, velocity: 2850)
|
15
20
|
end
|
16
21
|
|
17
22
|
it 'returns an environment' do
|
18
23
|
expect(environment).to be_an_instance_of Ballistics::Atmosphere
|
19
24
|
end
|
20
25
|
|
26
|
+
it 'raises an error with incomplete params' do
|
27
|
+
expect{ bad_params }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
21
30
|
it 'returns the range' do
|
22
|
-
expect(result_array[
|
23
|
-
expect(result_array[
|
24
|
-
expect(result_array[
|
25
|
-
expect(result_array[
|
26
|
-
expect(result_array[
|
27
|
-
expect(result_array[
|
31
|
+
expect(result_array[2]['range']).to eq 50
|
32
|
+
expect(result_array[4]['range']).to eq 100
|
33
|
+
expect(result_array[8]['range']).to eq 200
|
34
|
+
expect(result_array[12]['range']).to eq 300
|
35
|
+
expect(result_array[16]['range']).to eq 400
|
36
|
+
expect(result_array[20]['range']).to eq 500
|
37
|
+
expect(result_array[40]['range']).to eq 1000
|
28
38
|
end
|
29
39
|
|
30
40
|
it 'returns the path' do
|
31
|
-
expect(result_array[
|
32
|
-
expect(result_array[
|
33
|
-
expect(result_array[
|
34
|
-
expect(result_array[
|
35
|
-
expect(result_array[
|
36
|
-
expect(result_array[
|
41
|
+
expect(result_array[2]['path'].round(1)).to eq 0.6
|
42
|
+
expect(result_array[4]['path'].round(1)).to eq 1.6
|
43
|
+
expect(result_array[8]['path'].round(1)).to eq 0
|
44
|
+
expect(result_array[12]['path'].round(1)).to eq -7
|
45
|
+
expect(result_array[16]['path'].round(1)).to eq -20.1
|
46
|
+
expect(result_array[20]['path'].round(1)).to eq -40.1
|
47
|
+
expect(result_array[40]['path'].round(1)).to eq -282.5
|
37
48
|
end
|
38
49
|
|
39
50
|
it 'returns the velocity' do
|
40
|
-
expect(result_array[
|
41
|
-
expect(result_array[
|
42
|
-
expect(result_array[
|
43
|
-
expect(result_array[
|
44
|
-
expect(result_array[
|
45
|
-
expect(result_array[
|
51
|
+
expect(result_array[2]['velocity'].to_i).to eq 2769
|
52
|
+
expect(result_array[4]['velocity'].to_i).to eq 2691
|
53
|
+
expect(result_array[8]['velocity'].to_i).to eq 2538
|
54
|
+
expect(result_array[12]['velocity'].to_i).to eq 2390
|
55
|
+
expect(result_array[16]['velocity'].to_i).to eq 2246
|
56
|
+
expect(result_array[20]['velocity'].to_i).to eq 2108
|
57
|
+
expect(result_array[40]['velocity'].to_i).to eq 1500
|
46
58
|
end
|
47
59
|
|
48
60
|
it 'returns the moa correction' do
|
49
|
-
expect(result_array[
|
50
|
-
expect(result_array[
|
51
|
-
expect(result_array[
|
52
|
-
expect(result_array[
|
53
|
-
expect(result_array[
|
54
|
-
expect(result_array[
|
61
|
+
expect(result_array[2]['moa_correction'].round(1)).to eq -1.1
|
62
|
+
expect(result_array[4]['moa_correction'].round(1)).to eq -1.5
|
63
|
+
expect(result_array[8]['moa_correction'].round(1)).to eq 0
|
64
|
+
expect(result_array[12]['moa_correction'].round(1)).to eq 2.2
|
65
|
+
expect(result_array[16]['moa_correction'].round(1)).to eq 4.8
|
66
|
+
expect(result_array[20]['moa_correction'].round(1)).to eq 7.7
|
67
|
+
expect(result_array[40]['moa_correction'].round(1)).to eq 27
|
55
68
|
end
|
56
69
|
|
57
70
|
it 'returns the windage' do
|
58
|
-
expect(result_array[
|
59
|
-
expect(result_array[
|
60
|
-
expect(result_array[
|
61
|
-
expect(result_array[
|
62
|
-
expect(result_array[
|
63
|
-
expect(result_array[
|
71
|
+
expect(result_array[2]['windage'].round(1)).to eq 0.2
|
72
|
+
expect(result_array[4]['windage'].round(1)).to eq 0.6
|
73
|
+
expect(result_array[8]['windage'].round(1)).to eq 2.3
|
74
|
+
expect(result_array[12]['windage'].round(1)).to eq 5.2
|
75
|
+
expect(result_array[16]['windage'].round(1)).to eq 9.4
|
76
|
+
expect(result_array[20]['windage'].round(1)).to eq 15.2
|
77
|
+
expect(result_array[40]['windage'].round(1)).to eq 71.3
|
64
78
|
end
|
65
79
|
|
66
80
|
it 'returns the moa correction for wind drift windage' do
|
67
|
-
expect(result_array[
|
68
|
-
expect(result_array[
|
69
|
-
expect(result_array[
|
70
|
-
expect(result_array[
|
71
|
-
expect(result_array[
|
72
|
-
expect(result_array[
|
81
|
+
expect(result_array[2]['moa_windage'].round(1)).to eq 0.3
|
82
|
+
expect(result_array[4]['moa_windage'].round(1)).to eq 0.5
|
83
|
+
expect(result_array[8]['moa_windage'].round(1)).to eq 1.1
|
84
|
+
expect(result_array[12]['moa_windage'].round(1)).to eq 1.6
|
85
|
+
expect(result_array[16]['moa_windage'].round(1)).to eq 2.3
|
86
|
+
expect(result_array[20]['moa_windage'].round(1)).to eq 2.9
|
87
|
+
expect(result_array[40]['moa_windage'].round(1)).to eq 6.8
|
73
88
|
end
|
74
89
|
|
75
90
|
end
|