ballistics-ng 0.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +12 -0
- data/Rakefile +51 -0
- data/examples/table.rb +10 -0
- data/ext/ballistics/ext.c +136 -0
- data/ext/ballistics/extconf.rb +3 -0
- data/ext/ballistics/gnu_ballistics.h +577 -0
- data/lib/ballistics.rb +77 -0
- data/lib/ballistics/atmosphere.rb +110 -0
- data/lib/ballistics/cartridge.rb +177 -0
- data/lib/ballistics/cartridges/300_blk.yaml +159 -0
- data/lib/ballistics/gun.rb +123 -0
- data/lib/ballistics/guns/pistols.yaml +6 -0
- data/lib/ballistics/guns/rifles.yaml +34 -0
- data/lib/ballistics/guns/shotguns.yaml +6 -0
- data/lib/ballistics/problem.rb +102 -0
- data/lib/ballistics/projectile.rb +165 -0
- data/lib/ballistics/projectiles/300_blk.yaml +321 -0
- data/lib/ballistics/util.rb +67 -0
- data/lib/ballistics/yaml.rb +57 -0
- data/test/atmosphere.rb +26 -0
- data/test/ballistics.rb +31 -0
- data/test/cartridge.rb +121 -0
- data/test/gun.rb +85 -0
- data/test/problem.rb +137 -0
- data/test/projectile.rb +163 -0
- data/test/util.rb +28 -0
- metadata +102 -0
data/test/projectile.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ballistics/projectile'
|
3
|
+
|
4
|
+
include Ballistics
|
5
|
+
|
6
|
+
describe Projectile do
|
7
|
+
before do
|
8
|
+
@test_data = {
|
9
|
+
"name" => "Test Projectile",
|
10
|
+
"cal" => 1.0,
|
11
|
+
"grains" => 100,
|
12
|
+
"g1" => 1.0,
|
13
|
+
"sd" => 1.0,
|
14
|
+
"intended" => "test purposes",
|
15
|
+
"base" => "flat",
|
16
|
+
"desc" => "Test Projectile for test purposes",
|
17
|
+
}
|
18
|
+
|
19
|
+
@extra_data = {
|
20
|
+
"foo" => "bar",
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "base" do
|
25
|
+
it "must normalize common base specifiers" do
|
26
|
+
["flat", "fb", "f-b", "f_b", "f b",
|
27
|
+
"flat-base", "flat_base", "flatbase", "flat base"].each { |valid|
|
28
|
+
Projectile.base(valid).must_equal "flat"
|
29
|
+
Projectile.base(valid.upcase).must_equal "flat"
|
30
|
+
}
|
31
|
+
|
32
|
+
["boat", "bt", "b-t", "b_t", "b t",
|
33
|
+
"boat-tail", "boat_tail", "boattail", "boat tail"].each { |valid|
|
34
|
+
Projectile.base(valid).must_equal "boat"
|
35
|
+
Projectile.base(valid.upcase).must_equal "boat"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "must reject invalid base specifiers" do
|
40
|
+
["flute", "fbase", "foo",
|
41
|
+
"brat", "btail", "bar"].each { |invalid|
|
42
|
+
proc { Projectile.base(invalid) }.must_raise RuntimeError
|
43
|
+
proc { Projectile.base(invalid.upcase) }.must_raise RuntimeError
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "new instance" do
|
49
|
+
before do
|
50
|
+
@prj = Projectile.new(@test_data)
|
51
|
+
@prj_ex = Projectile.new(@test_data.merge(@extra_data))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "must raise with insufficient parameters" do
|
55
|
+
params = {}
|
56
|
+
proc { Projectile.new params }.must_raise Exception
|
57
|
+
# accumulate the mandatory fields in params
|
58
|
+
# note, one of Projectile::BALLISTIC_COEFFICIENT is also mandatory
|
59
|
+
Projectile::MANDATORY.keys.each { |mfield|
|
60
|
+
params[mfield] = @test_data.fetch(mfield)
|
61
|
+
proc { Projectile.new params }.must_raise Exception
|
62
|
+
}
|
63
|
+
bc = { 'g1' => 0.123 }
|
64
|
+
proc { Projectile.new bc }.must_raise Exception
|
65
|
+
Projectile.new(params.merge(bc)).must_be_kind_of Projectile
|
66
|
+
end
|
67
|
+
|
68
|
+
it "must have a name" do
|
69
|
+
@prj.name.wont_be_nil
|
70
|
+
@prj.name.must_equal @test_data["name"]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "must have a caliber" do
|
74
|
+
@prj.cal.wont_be_nil
|
75
|
+
@prj.cal.must_equal @test_data["cal"]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "must have grains" do
|
79
|
+
@prj.grains.wont_be_nil
|
80
|
+
@prj.grains.must_equal @test_data["grains"]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "must have a ballistic coefficient" do
|
84
|
+
bc = @prj.ballistic_coefficient
|
85
|
+
bc.wont_be_nil
|
86
|
+
bc.must_be_kind_of Hash
|
87
|
+
bc.wont_be_empty
|
88
|
+
["g1", "g7"].each { |drag_model|
|
89
|
+
test_bc = @test_data[drag_model]
|
90
|
+
if test_bc
|
91
|
+
bc[drag_model].must_equal test_bc
|
92
|
+
@prj.send(drag_model).must_equal test_bc
|
93
|
+
else
|
94
|
+
bc[drag_model].must_be_nil
|
95
|
+
@prj.send(drag_model).must_be_nil
|
96
|
+
end
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
it "must accept optional fields" do
|
101
|
+
Projectile::OPTIONAL.keys.each { |k|
|
102
|
+
if @test_data.key?(k)
|
103
|
+
@prj.send(k).must_equal @test_data[k]
|
104
|
+
else
|
105
|
+
@prj.send(k).must_be_nil
|
106
|
+
end
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
it "must retain initializing data" do
|
111
|
+
@prj.yaml_data.must_equal @test_data
|
112
|
+
@prj_ex.yaml_data.must_equal @test_data.merge(@extra_data)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "must retain extra data" do
|
116
|
+
@prj.extra.must_be_empty
|
117
|
+
@prj_ex.extra.wont_be_empty
|
118
|
+
@prj_ex.extra.must_equal @extra_data
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe Projectile::DRAG_FUNCTION do
|
123
|
+
it "must match keys to Projectile.base" do
|
124
|
+
Projectile::DRAG_FUNCTION.keys.each { |k|
|
125
|
+
Projectile.base(k).must_equal k
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
it "must match values to C::BALLISTIC_COEFFICIENT" do
|
130
|
+
Projectile::DRAG_FUNCTION.values.each { |v|
|
131
|
+
Projectile::BALLISTIC_COEFFICIENT.key?(v).must_equal true
|
132
|
+
}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "drag_function" do
|
137
|
+
before do
|
138
|
+
# Set up various combinations of flat/boat and g1/g7
|
139
|
+
flat = @test_data.merge("base" => "flat")
|
140
|
+
flat.delete("g1")
|
141
|
+
flat.delete("g7")
|
142
|
+
boat = flat.merge("base" => "boat")
|
143
|
+
g1 = { "g1" => 0.123 }
|
144
|
+
g7 = { "g7" => 0.789 }
|
145
|
+
@f1 = flat.merge(g1)
|
146
|
+
@f7 = flat.merge(g7)
|
147
|
+
@f17 = flat.merge(g1).merge(g7)
|
148
|
+
@b1 = boat.merge(g1)
|
149
|
+
@b7 = boat.merge(g7)
|
150
|
+
@b17 = boat.merge(g1).merge(g7)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "must use the preferred nomenclature" do
|
154
|
+
Projectile.new(@f1).drag_function.must_equal "g1"
|
155
|
+
Projectile.new(@f7).drag_function.must_equal "g7"
|
156
|
+
Projectile.new(@f17).drag_function.must_equal "g1"
|
157
|
+
|
158
|
+
Projectile.new(@b1).drag_function.must_equal "g1"
|
159
|
+
Projectile.new(@b7).drag_function.must_equal "g7"
|
160
|
+
Projectile.new(@b17).drag_function.must_equal "g7"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
data/test/util.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ballistics/util'
|
3
|
+
|
4
|
+
describe Ballistics do
|
5
|
+
it "calculates expected bullet sectional density" do
|
6
|
+
Ballistics.sectional_density(230, 0.451).round(3).must_equal 0.162
|
7
|
+
end
|
8
|
+
|
9
|
+
it "calculates expected bullet kinetic energy" do
|
10
|
+
Ballistics.kinetic_energy(800.0, 230).round(2).must_equal 326.78
|
11
|
+
end
|
12
|
+
|
13
|
+
it "calculates expected Taylor Knockout values for a bullet" do
|
14
|
+
Ballistics.taylor_ko(800.0, 230, 0.452).round(0).must_equal 12
|
15
|
+
end
|
16
|
+
|
17
|
+
it "calculates expected recoil impulse" do
|
18
|
+
Ballistics.recoil_impulse(150, 46, 2800).round(2).must_equal 2.68
|
19
|
+
end
|
20
|
+
|
21
|
+
it "calculates expected free recoil" do
|
22
|
+
Ballistics.free_recoil(150, 46, 2800, 8).round(1).must_equal 10.8
|
23
|
+
end
|
24
|
+
|
25
|
+
it "calculates expected recoil energy" do
|
26
|
+
Ballistics.recoil_energy(150, 46, 2800, 8).round(1).must_equal 14.5
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ballistics-ng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Hull
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: buildar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
description: 'Ballistics-ng is based (currently) on C code derived from the GNU Ballistics
|
42
|
+
project; this gem is originally based on the ballistics gem, which was abandoned
|
43
|
+
in 2013. Very little code remains from that project.
|
44
|
+
|
45
|
+
'
|
46
|
+
email:
|
47
|
+
executables: []
|
48
|
+
extensions:
|
49
|
+
- ext/ballistics/extconf.rb
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- examples/table.rb
|
55
|
+
- ext/ballistics/ext.c
|
56
|
+
- ext/ballistics/extconf.rb
|
57
|
+
- ext/ballistics/gnu_ballistics.h
|
58
|
+
- lib/ballistics.rb
|
59
|
+
- lib/ballistics/atmosphere.rb
|
60
|
+
- lib/ballistics/cartridge.rb
|
61
|
+
- lib/ballistics/cartridges/300_blk.yaml
|
62
|
+
- lib/ballistics/gun.rb
|
63
|
+
- lib/ballistics/guns/pistols.yaml
|
64
|
+
- lib/ballistics/guns/rifles.yaml
|
65
|
+
- lib/ballistics/guns/shotguns.yaml
|
66
|
+
- lib/ballistics/problem.rb
|
67
|
+
- lib/ballistics/projectile.rb
|
68
|
+
- lib/ballistics/projectiles/300_blk.yaml
|
69
|
+
- lib/ballistics/util.rb
|
70
|
+
- lib/ballistics/yaml.rb
|
71
|
+
- test/atmosphere.rb
|
72
|
+
- test/ballistics.rb
|
73
|
+
- test/cartridge.rb
|
74
|
+
- test/gun.rb
|
75
|
+
- test/problem.rb
|
76
|
+
- test/projectile.rb
|
77
|
+
- test/util.rb
|
78
|
+
homepage: https://github.com/rickhull/ballistics
|
79
|
+
licenses:
|
80
|
+
- GPL-3.0
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Ballistics library for calculating small arms trajectories
|
102
|
+
test_files: []
|