typing and comment cleanup

This commit is contained in:
walterroach 2020-11-16 22:01:49 -06:00
parent 253e8a209c
commit ecd073e31d
2 changed files with 8 additions and 9 deletions

View File

@ -460,7 +460,7 @@ class GroundConflictGenerator:
def get_valid_position_for_group(self, conflict_position, isplayer, combat_width, distance_from_frontline): def get_valid_position_for_group(self, conflict_position, isplayer, combat_width, distance_from_frontline):
i = 0 i = 0
while i < 1000: # 25 attempt for valid position while i < 1000:
heading_diff = -90 if isplayer else 90 heading_diff = -90 if isplayer else 90
shifted = conflict_position[0].point_from_heading(self.conflict.heading, shifted = conflict_position[0].point_from_heading(self.conflict.heading,
random.randint((int)(-combat_width / 2), (int)(combat_width / 2))) random.randint((int)(-combat_width / 2), (int)(combat_width / 2)))
@ -468,9 +468,8 @@ class GroundConflictGenerator:
if self.conflict.theater.is_on_land(final_position): if self.conflict.theater.is_on_land(final_position):
return final_position return final_position
else: i += 1
i = i + 1 continue
continue
return None return None
def _generate_group(self, side: Country, unit: VehicleType, count: int, at: Point, move_formation: PointAction = PointAction.OffRoad, heading=0): def _generate_group(self, side: Country, unit: VehicleType, count: int, at: Point, move_formation: PointAction = PointAction.OffRoad, heading=0):

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import datetime import datetime
import logging import logging
import math import math
from typing import List, Optional, Tuple from typing import Iterable, List, Optional, Tuple, Iterator
from PySide2.QtCore import QPointF, Qt from PySide2.QtCore import QPointF, Qt
from PySide2.QtGui import ( from PySide2.QtGui import (
@ -47,18 +47,18 @@ from theater.theatergroundobject import (
TheaterGroundObject, TheaterGroundObject,
) )
def binomial(i, n): def binomial(i: int, n: int) -> float:
"""Binomial coefficient""" """Binomial coefficient"""
return math.factorial(n) / float( return math.factorial(n) / float(
math.factorial(i) * math.factorial(n - i)) math.factorial(i) * math.factorial(n - i))
def bernstein(t, i, n): def bernstein(t: float, i: int, n: int) -> float:
"""Bernstein polynom""" """Bernstein polynom"""
return binomial(i, n) * (t ** i) * ((1 - t) ** (n - i)) return binomial(i, n) * (t ** i) * ((1 - t) ** (n - i))
def bezier(t, points): def bezier(t: float, points: Iterable[Tuple[float, float]]) -> Tuple[float, float]:
"""Calculate coordinate of a point in the bezier curve""" """Calculate coordinate of a point in the bezier curve"""
n = len(points) - 1 n = len(points) - 1
x = y = 0 x = y = 0
@ -69,7 +69,7 @@ def bezier(t, points):
return x, y return x, y
def bezier_curve_range(n, points): def bezier_curve_range(n: int, points: Iterable[Tuple[float, float]]) -> Iterator[Tuple[float, float]]:
"""Range of points in a curve bezier""" """Range of points in a curve bezier"""
for i in range(n): for i in range(n):
t = i / float(n - 1) t = i / float(n - 1)