@@ -65,6 +65,7 @@ class SightReticleStep(NamedTuple):
6565 )
6666 ```
6767 """
68+
6869 vertical : Angular
6970 horizontal : Angular
7071
@@ -84,6 +85,7 @@ class SightClicks(NamedTuple):
8485 clicks = SightClicks(vertical=5.0, horizontal=2.5)
8586 ```
8687 """
88+
8789 vertical : float
8890 horizontal : float
8991
@@ -114,6 +116,7 @@ class Sight:
114116 )
115117 ```
116118 """
119+
117120 focal_plane : SightFocalPlane
118121 scale_factor : Distance
119122 h_click_size : Angular
@@ -154,7 +157,6 @@ def __init__(self,
154157 )
155158 ```
156159 """
157-
158160 if focal_plane not in get_args (SightFocalPlane ):
159161 raise ValueError ("Wrong focal plane" )
160162
@@ -164,14 +166,14 @@ def __init__(self,
164166 if (not isinstance (h_click_size , (Angular , float , int ))
165167 or not isinstance (v_click_size , (Angular , float , int ))
166168 ):
167- raise TypeError ("type Angular expected for 'h_click_size' and 'v_click_size'" )
169+ raise TypeError ("Angle expected for 'h_click_size' and 'v_click_size'" )
168170
169171 self .focal_plane = focal_plane
170172 self .scale_factor = PreferredUnits .distance (scale_factor or 1 )
171173 self .h_click_size = PreferredUnits .adjustment (h_click_size )
172174 self .v_click_size = PreferredUnits .adjustment (v_click_size )
173175 if self .h_click_size .raw_value <= 0 or self .v_click_size .raw_value <= 0 :
174- raise TypeError ("'h_click_size' and 'v_click_size' have to be positive" )
176+ raise TypeError ("'h_click_size' and 'v_click_size' must be positive" )
175177
176178 def _adjust_sfp_reticle_steps (self , target_distance : Union [float , Distance ],
177179 magnification : float ) -> SightReticleStep :
@@ -200,16 +202,14 @@ def _adjust_sfp_reticle_steps(self, target_distance: Union[float, Distance],
200202 ```
201203 """
202204 assert self .focal_plane == 'SFP' , "SFP focal plane required"
203- # adjust reticle scale relative to target distance and magnification
205+ _td = PreferredUnits .distance (target_distance )
206+ if _td .raw_value <= 0 :
207+ raise ValueError ("target_distance must be positive" )
204208 def get_sfp_step (click_size : Angular ):
209+ """Calculate SFP reticle step size for a given click size."""
210+ scale_ratio = self .scale_factor .raw_value / _td .raw_value
205211 # Don't need distances conversion because units cancel:
206- return click_size .units (
207- click_size .unit_value
208- * self .scale_factor .raw_value
209- / _td .raw_value
210- * magnification
211- )
212- _td = PreferredUnits .distance (target_distance )
212+ return click_size .units (click_size .unit_value * scale_ratio * magnification )
213213 _h_step = get_sfp_step (self .h_click_size )
214214 _v_step = get_sfp_step (self .v_click_size )
215215 return SightReticleStep (_h_step , _v_step )
@@ -251,6 +251,8 @@ def get_adjustment(self, target_distance: Distance,
251251 print(f"Adjust: {clicks.vertical} up, {clicks.horizontal} right")
252252 ```
253253 """
254+ if magnification <= 0 :
255+ raise ValueError ("magnification must be positive" )
254256 if self .focal_plane == 'SFP' :
255257 steps = self ._adjust_sfp_reticle_steps (target_distance , magnification )
256258 return SightClicks (
@@ -263,8 +265,7 @@ def get_adjustment(self, target_distance: Distance,
263265 windage_adj .raw_value / self .h_click_size .raw_value
264266 )
265267 if self .focal_plane == 'LWIR' :
266- # adjust clicks to magnification
267- return SightClicks (
268+ return SightClicks ( # adjust clicks to magnification
268269 drop_adj .raw_value / (self .v_click_size .raw_value / magnification ),
269270 windage_adj .raw_value / (self .h_click_size .raw_value / magnification )
270271 )
@@ -328,6 +329,7 @@ class Weapon:
328329 )
329330 ```
330331 """
332+
331333 sight_height : Distance
332334 twist : Distance
333335 zero_elevation : Angular
@@ -510,6 +512,8 @@ def calc_powder_sens(self, other_velocity: Union[float, Velocity],
510512 v1 = PreferredUnits .velocity (other_velocity ) >> Velocity .MPS
511513 t1 = PreferredUnits .temperature (other_temperature ) >> Temperature .Celsius
512514
515+ if v0 <= 0 or v1 <= 0 :
516+ raise ValueError ("calc_powder_sens requires positive muzzle velocities" )
513517 v_delta = math .fabs (v0 - v1 )
514518 t_delta = math .fabs (t0 - t1 )
515519 v_lower = v1 if v1 < v0 else v0
0 commit comments