Skip to content

Commit

Permalink
Renamed "HP" pressure unit to "hPa".
Browse files Browse the repository at this point in the history
  • Loading branch information
dbookstaber committed Jan 26, 2024
1 parent d8fe2a2 commit 5f41080
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
20 changes: 5 additions & 15 deletions py_ballisticcalc/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Unit(IntEnum):
MM_HG = 40
IN_HG = 41
BAR = 42
HP = 43
HPA = 43
PSI = 44

FAHRENHEIT = 50
Expand Down Expand Up @@ -154,7 +154,7 @@ class UnitProps(NamedTuple):
Unit.MM_HG: UnitProps('mmhg', 0, 'mmHg'),
Unit.IN_HG: UnitProps('inhg', 6, '?'),
Unit.BAR: UnitProps('bar', 2, 'bar'),
Unit.HP: UnitProps('hp', 4, 'hPa'),
Unit.HPA: UnitProps('hpa', 4, 'hPa'),
Unit.PSI: UnitProps('psi', 4, 'psi'),

Unit.FAHRENHEIT: UnitProps('fahrenheit', 1, '°F'),
Expand Down Expand Up @@ -368,7 +368,7 @@ def to_raw(self, value: float, units: Unit):
result = value * 25.4
elif units == Pressure.Bar:
result = value * 750.061683
elif units == Pressure.HP:
elif units == Pressure.hPa:
result = value * 750.061683 / 1000
elif units == Pressure.PSI:
result = value * 51.714924102396
Expand All @@ -383,7 +383,7 @@ def from_raw(self, value: float, units: Unit):
result = value / 25.4
elif units == Pressure.Bar:
result = value / 750.061683
elif units == Pressure.HP:
elif units == Pressure.hPa:
result = value / 750.061683 * 1000
elif units == Pressure.PSI:
result = value / 51.714924102396
Expand All @@ -394,7 +394,7 @@ def from_raw(self, value: float, units: Unit):
MmHg = Unit.MM_HG
InHg = Unit.IN_HG
Bar = Unit.BAR
HP = Unit.HP
hPa = Unit.HPA
PSI = Unit.PSI


Expand Down Expand Up @@ -634,13 +634,3 @@ def __setattr__(self, key, value):
# if obj is None:
# return None
# raise TypeError(f"Expected Unit, int, or float, found {obj.__class__.__name__}")


# Default units
# Angular.Radian
# Distance.Inch
# Energy.FootPound
# Weight.Grain
# Velocity.MPS
# Temperature.Fahrenheit
# Pressure.MmHg
18 changes: 13 additions & 5 deletions tests/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ def test_no_twist(self):
t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step)
self.assertEqual(t.trajectory[5].windage.raw_value, 0)

def test_twist_right(self):
"""Barrel with right-hand twist should have positive spin drift"""
shot = Shot(weapon=Weapon(twist=10), ammo=self.ammo, atmo=self.atmosphere)
t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step)
self.assertGreater(t.trajectory[5].windage.raw_value, 0)
def test_twist(self):
"""Barrel with right-hand twist should have positive spin drift.
Barrel with left-hand twist should have negative spin drift.
Faster twist rates should produce larger drift.
"""
shot = Shot(weapon=Weapon(twist=12), ammo=self.ammo, atmo=self.atmosphere)
twist_right = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step)
self.assertGreater(twist_right.trajectory[5].windage.raw_value, 0)
shot = Shot(weapon=Weapon(twist=-8), ammo=self.ammo, atmo=self.atmosphere)
twist_left = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step)
self.assertLess(twist_left.trajectory[5].windage.raw_value, 0)
# Faster twist should produce larger drift:
self.assertGreater(-twist_left.trajectory[5].windage.raw_value, twist_right.trajectory[5].windage.raw_value)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def setUp(self) -> None:
self.unit_class = Pressure
self.unit_list = [
Pressure.Bar,
Pressure.HP,
Pressure.hPa,
Pressure.MmHg,
Pressure.InHg
]
Expand Down

0 comments on commit 5f41080

Please sign in to comment.