From 4ac980043d16f9ba9d9f1aab8cdd5a75ce981096 Mon Sep 17 00:00:00 2001 From: gambon0120 Date: Sun, 18 Aug 2024 18:43:01 +0200 Subject: [PATCH] added forgotten files --- py_ballisticcalc/trajectory_calc.py | 4 ++-- py_ballisticcalc/trajectory_data.py | 24 ++++++++++++------------ tests/test_computer.py | 28 ++++++++++++++-------------- tests/test_trajectory.py | 6 +++--- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/py_ballisticcalc/trajectory_calc.py b/py_ballisticcalc/trajectory_calc.py index 2b0d5e5..8455d7b 100644 --- a/py_ballisticcalc/trajectory_calc.py +++ b/py_ballisticcalc/trajectory_calc.py @@ -207,7 +207,7 @@ def zero_angle(self, shot_info: Shot, distance: Distance) -> Angular: while zero_finding_error > cZeroFindingAccuracy and iterations_count < cMaxIterations: # Check height of trajectory at the zero distance (using current self.barrel_elevation) t = self._trajectory(shot_info, maximum_range, zero_distance, TrajFlag.NONE)[0] - height = t.height >> Distance.Foot + height = t.y >> Distance.Foot zero_finding_error = math.fabs(height - height_at_zero) if zero_finding_error > cZeroFindingAccuracy: # Adjust barrel elevation to close height at zero distance @@ -446,7 +446,7 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve distance=Distance.Foot(range_vector.x), velocity=Velocity.FPS(velocity), mach=velocity / mach, - height=Distance.Foot(range_vector.y), + y=Distance.Foot(range_vector.y), target_drop=Distance.Foot((range_vector.y - range_vector.x * math.tan(look_angle)) * math.cos(look_angle)), drop_angle=Angular.Radian(drop_angle - (look_angle if range_vector.x else 0)), windage=Distance.Foot(windage), diff --git a/py_ballisticcalc/trajectory_data.py b/py_ballisticcalc/trajectory_data.py index daa3302..cce1487 100644 --- a/py_ballisticcalc/trajectory_data.py +++ b/py_ballisticcalc/trajectory_data.py @@ -56,7 +56,7 @@ class TrajectoryData(NamedTuple): distance (Distance): x-axis coordinate velocity (Velocity): velocity mach (float): velocity in Mach prefer_units - height (Distance): y-axis coordinate + y (Distance): y-axis coordinate target_drop (Distance): drop relative to sight-line drop_angle (Angular): sight adjustment to zero target_drop at this distance windage (Distance): @@ -75,7 +75,7 @@ class TrajectoryData(NamedTuple): distance: Distance velocity: Velocity mach: float - height: Distance + y: Distance target_drop: Distance drop_angle: Angular windage: Distance @@ -102,7 +102,7 @@ def _fmt(v: AbstractUnit, u: Unit): _fmt(self.distance, PreferredUnits.distance), _fmt(self.velocity, PreferredUnits.velocity), f'{self.mach:.2f} mach', - _fmt(self.height, PreferredUnits.drop), + _fmt(self.y, PreferredUnits.drop), _fmt(self.target_drop, PreferredUnits.drop), _fmt(self.drop_angle, PreferredUnits.adjustment), _fmt(self.windage, PreferredUnits.drop), @@ -126,7 +126,7 @@ def in_def_units(self) -> tuple: self.distance >> PreferredUnits.distance, self.velocity >> PreferredUnits.velocity, self.mach, - self.height >> PreferredUnits.drop, + self.y >> PreferredUnits.drop, self.target_drop >> PreferredUnits.drop, self.drop_angle >> PreferredUnits.adjustment, self.windage >> PreferredUnits.drop, @@ -163,11 +163,11 @@ def overlay(self, ax: 'Axes', label: Optional[str] = None): # type: ignore cosine = math.cos(self.look_angle >> Angular.Radian) begin_dist = (self.begin.distance >> PreferredUnits.distance) * cosine - begin_drop = (self.begin.height >> PreferredUnits.drop) * cosine + begin_drop = (self.begin.y >> PreferredUnits.drop) * cosine end_dist = (self.end.distance >> PreferredUnits.distance) * cosine - end_drop = (self.end.height >> PreferredUnits.drop) * cosine + end_drop = (self.end.y >> PreferredUnits.drop) * cosine range_dist = (self.at_range.distance >> PreferredUnits.distance) * cosine - range_drop = (self.at_range.height >> PreferredUnits.drop) * cosine + range_drop = (self.at_range.y >> PreferredUnits.drop) * cosine h = self.target_height >> PreferredUnits.drop # Target position and height: @@ -326,20 +326,20 @@ def plot(self, look_angle: Optional[Angular] = None) -> 'Axes': # type: ignore "Use Calculator.fire(..., extra_data=True)") font_size = PLOT_FONT_SIZE df = self.dataframe() - ax = df.plot(x='distance', y=['height'], ylabel=PreferredUnits.drop.symbol) + ax = df.plot(x='distance', y=['y'], ylabel=PreferredUnits.drop.symbol) max_range = self.trajectory[-1].distance >> PreferredUnits.distance for p in self.trajectory: if TrajFlag(p.flag) & TrajFlag.ZERO: ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], - [df['height'].min(), p.height >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['height'].min(), + [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') + ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), f"{(TrajFlag(p.flag) & TrajFlag.ZERO).name}", fontsize=font_size, rotation=90) if TrajFlag(p.flag) & TrajFlag.MACH: ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], - [df['height'].min(), p.height >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['height'].min(), + [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') + ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), "Mach 1", fontsize=font_size, rotation=90) max_range_in_drop_units = self.trajectory[-1].distance >> PreferredUnits.drop diff --git a/tests/test_computer.py b/tests/test_computer.py index c35ef3d..1847965 100644 --- a/tests/test_computer.py +++ b/tests/test_computer.py @@ -33,8 +33,8 @@ def test_cant_zero_elevation(self): canted = copy.copy(self.baseline_shot) canted.cant_angle = Angular.Degree(90) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value) self.assertAlmostEqual(t.trajectory[5].windage.raw_value + self.weapon.sight_height.raw_value, self.baseline_trajectory[5].windage.raw_value) @@ -45,8 +45,8 @@ def test_cant_positive_elevation(self): canted = Shot(weapon=Weapon(sight_height=self.weapon.sight_height, twist=0, zero_elevation=Angular.Mil(2)), ammo=self.ammo, atmo=self.atmosphere, cant_angle=Angular.Degree(90)) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value, 2) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value, 2) self.assertAlmostEqual(t.trajectory[0].windage.raw_value, -self.weapon.sight_height.raw_value) self.assertGreater(t.trajectory[5].windage.raw_value, t.trajectory[3].windage.raw_value) @@ -57,8 +57,8 @@ def test_cant_zero_sight_height(self): canted = Shot(weapon=Weapon(sight_height=0, twist=self.weapon.twist), ammo=self.ammo, atmo=self.atmosphere, cant_angle=Angular.Degree(90)) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value) self.assertAlmostEqual(t.trajectory[5].windage, self.baseline_trajectory[5].windage) # endregion Cant_angle @@ -83,14 +83,14 @@ def test_wind_from_back(self): shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=self.atmosphere, winds=[Wind(Velocity(5, Velocity.MPH), Angular(0, Angular.OClock))]) t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_wind_from_front(self): """Wind from in front should increase drop""" shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=self.atmosphere, winds=[Wind(Velocity(5, Velocity.MPH), Angular(6, Angular.OClock))]) t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertLess(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertLess(t.trajectory[5].y, self.baseline_trajectory[5].y) # endregion Wind @@ -123,28 +123,28 @@ def test_humidity(self): humid = Atmo(humidity=.9) # 90% humidity shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=humid) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_temp_atmo(self): """Dropping temperature should increase drop (due to increasing density)""" cold = Atmo(temperature=Temperature.Celsius(0)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=cold) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertLess(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertLess(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_altitude(self): """Increasing altitude should decrease drop (due to decreasing density)""" high = Atmo.icao(Distance.Foot(5000)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=high) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_pressure(self): """Decreasing pressure should decrease drop (due to decreasing density)""" thin = Atmo(pressure=Pressure.InHg(20.0)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=thin) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) # endregion Atmo @@ -155,7 +155,7 @@ def test_ammo_drag(self): slick = Ammo(tdm, self.ammo.mv) shot = Shot(weapon=self.weapon, ammo=slick, atmo=self.atmosphere) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_ammo_optional(self): """DragModel.weight and .diameter, and Ammo.length, are only relevant when computing @@ -165,7 +165,7 @@ def test_ammo_optional(self): tammo = Ammo(tdm, mv=self.ammo.mv) shot = Shot(weapon=self.weapon, ammo=tammo, atmo=self.atmosphere) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertEqual(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertEqual(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_powder_sensitivity(self): """With _globalUsePowderSensitivity: Reducing temperature should reduce muzzle velocity""" diff --git a/tests/test_trajectory.py b/tests/test_trajectory.py index 42cf0db..a851b19 100644 --- a/tests/test_trajectory.py +++ b/tests/test_trajectory.py @@ -48,11 +48,11 @@ def validate_one(self, data: TrajectoryData, distance: float, velocity: float, self.custom_assert_equal(ogv, data.ogw >> Weight.Pound, 1, "OGV") if distance >= 800: - self.custom_assert_equal(path, data.height >> Distance.Inch, 4, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 4, 'Drop') elif distance >= 500: - self.custom_assert_equal(path, data.height >> Distance.Inch, 1, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 1, 'Drop') else: - self.custom_assert_equal(path, data.height >> Distance.Inch, 0.5, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 0.5, 'Drop') if distance > 1: self.custom_assert_equal(hold, data.drop_angle >> adjustment_unit, 0.5, 'Hold')