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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4ba3d0aec12eee3a0bada1d015678f2267b6e6c
4
- data.tar.gz: fe2fe7e3cceeff32a6c978fa03cda97772bcced2
3
+ metadata.gz: 2c933900d7778a88c08d82cd6aa1cf853f3abbbf
4
+ data.tar.gz: b34a53f9ef4609e36b8a59076f422ee8486b88ac
5
5
  SHA512:
6
- metadata.gz: 73c3a515f55a85f155741e103aa8b9ebb1afeb2fc33ae27b8cde926ee1eb651de505c0df974de3c8130a92ef31bbf3f558a4cd2b8cdc109b427805ffd065c0da
7
- data.tar.gz: d01176c7f9f3770846cd694567f957404ddbe434929f4fbc7c3c09bcbcc3fb19a767fd5b63979eaa1fac7845a8912544c6871ce2cf6c93481064ef8d9f66e8ce
6
+ metadata.gz: 813eda1d29613a8f63eb3735a8af8a796de92d9155b217f2f3018ef525be71ec170a88d030b7d2a421f1bd164c2ed4316b85325a315a07528e8ae9335964cda9
7
+ data.tar.gz: 4f1f0aa9c6829851ed7fc93063814753f1671e051f86de0cceb2410147b88411a313324d6755e587200db41c41cd27eecd999ead15546dad0443abb0fe687011
@@ -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, 9);
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
- if (x/3>=n){
77
- VALUE entry = rb_hash_new();
78
- double windage_value = Windage(crosswind,Vi,x,t+dt);
79
- double moa_windage_value = windage_value / (((x/3) / 100) * 1.0465);
80
- rb_hash_aset(entry, rb_str_new2("range"), rb_float_new((int)(x/3)));
81
- rb_hash_aset(entry, rb_str_new2("path"), rb_float_new(y*12));
82
- rb_hash_aset(entry, rb_str_new2("moa_correction"), rb_float_new(-RadtoMOA(atan(y/x))));
83
- rb_hash_aset(entry, rb_str_new2("time"), rb_float_new(t+dt));
84
- rb_hash_aset(entry, rb_str_new2("windage"), rb_float_new(windage_value));
85
- rb_hash_aset(entry, rb_str_new2("moa_windage"), rb_float_new(moa_windage_value));
86
- rb_hash_aset(entry, rb_str_new2("velocity"), rb_float_new(v));
87
- rb_ary_push(result_array, entry);
88
- n++;
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.
@@ -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
@@ -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[100]['range'].round(1)).to eq 100
23
- expect(result_array[200]['range'].round(1)).to eq 200
24
- expect(result_array[300]['range'].round(1)).to eq 300
25
- expect(result_array[400]['range'].round(1)).to eq 400
26
- expect(result_array[500]['range'].round(1)).to eq 500
27
- expect(result_array[1000]['range'].round(1)).to eq 1000
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[100]['path'].round(1)).to eq 1.6
32
- expect(result_array[200]['path'].round(1)).to eq 0
33
- expect(result_array[300]['path'].round(1)).to eq -7
34
- expect(result_array[400]['path'].round(1)).to eq -20.1
35
- expect(result_array[500]['path'].round(1)).to eq -40.1
36
- expect(result_array[1000]['path'].round(1)).to eq -282.5
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[100]['velocity'].to_i).to eq 2691
41
- expect(result_array[200]['velocity'].to_i).to eq 2538
42
- expect(result_array[300]['velocity'].to_i).to eq 2390
43
- expect(result_array[400]['velocity'].to_i).to eq 2246
44
- expect(result_array[500]['velocity'].to_i).to eq 2108
45
- expect(result_array[1000]['velocity'].to_i).to eq 1500
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[100]['moa_correction'].round(1)).to eq -1.5
50
- expect(result_array[200]['moa_correction'].round(1)).to eq 0
51
- expect(result_array[300]['moa_correction'].round(1)).to eq 2.2
52
- expect(result_array[400]['moa_correction'].round(1)).to eq 4.8
53
- expect(result_array[500]['moa_correction'].round(1)).to eq 7.7
54
- expect(result_array[1000]['moa_correction'].round(1)).to eq 27
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[100]['windage'].round(1)).to eq 0.6
59
- expect(result_array[200]['windage'].round(1)).to eq 2.3
60
- expect(result_array[300]['windage'].round(1)).to eq 5.2
61
- expect(result_array[400]['windage'].round(1)).to eq 9.4
62
- expect(result_array[500]['windage'].round(1)).to eq 15.2
63
- expect(result_array[1000]['windage'].round(1)).to eq 71.3
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[100]['moa_windage'].round(1)).to eq 0.5
68
- expect(result_array[200]['moa_windage'].round(1)).to eq 1.1
69
- expect(result_array[300]['moa_windage'].round(1)).to eq 1.6
70
- expect(result_array[400]['moa_windage'].round(1)).to eq 2.3
71
- expect(result_array[500]['moa_windage'].round(1)).to eq 2.9
72
- expect(result_array[1000]['moa_windage'].round(1)).to eq 6.8
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Staton