Skip to content

Commit

Permalink
Update type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelMess committed Aug 8, 2024
1 parent 42eeb61 commit 1b20d71
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions code/simulator/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def __init__(self, particles: List[Particle], constraints: List[Constraint],
self.ks = np.float64(1000)
self.kd = np.sqrt(4 * self.ks)
self.t = np.float64(0)
self.lastSecondIterations = []
self.lastSecondIterations: List[float] = []
self.error = "0"

def initDrawer(self) -> None:
from simulator.drawers.SimulationDrawer import SimulationDrawer

super(Simulation, self).setDrawer(SimulationDrawer(self))

def generateGraph(self, grapher: 'Graph'): # noqa: F821
def acceleration(x, v) -> np.ndarray:
def generateGraph(self, grapher: 'Graph') -> None: # type: ignore[name-defined] # noqa: F821
def acceleration(x: np.ndarray, v: np.ndarray) -> np.ndarray:
particle = self.particles[0]
particle.x = x
particle.v = v
Expand Down
2 changes: 1 addition & 1 deletion code/simulator/drawers/DistanceConstraintDrawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, distanceConstraint: DistanceConstraint):
def draw(self, surface: pygame.Surface, origin: np.ndarray) -> None:
a = origin + self.distanceConstraint.particles[0].x * np.array([1, -1], dtype=np.float64)
b = origin + self.distanceConstraint.particles[1].x * np.array([1, -1], dtype=np.float64)
pygame.draw.line(surface, (0, 0, 0), a, b)
pygame.draw.line(surface, (0, 0, 0), (a[0].item(), a[1].item()), (b[0].item(), b[1].item()))

def getText(self) -> str:
return ""
2 changes: 1 addition & 1 deletion code/simulator/drawers/Drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Drawer(ABC):
Allows something to be drawn on a surface
"""
@abstractmethod
def draw(self, surface: 'pygame.Surface', origin: np.ndarray) -> None: # noqa: F821
def draw(self, surface: 'pygame.Surface', origin: np.ndarray) -> None: # type: ignore[name-defined] # noqa: F821
"""
Override this method to draw on the surface
"""
Expand Down
9 changes: 6 additions & 3 deletions code/simulator/drawers/ParticleDrawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ def draw(self, surface: pygame.Surface, origin: np.ndarray) -> None:
p = origin + self.particle.x * np.array([1, -1], dtype=np.float64)
aApplied = p + self.particle.aApplied * c * np.array([1, -1], dtype=np.float64)
aConstraint = p + self.particle.aConstraint * c * np.array([1, -1], dtype=np.float64)
pygame.draw.line(surface, (0, 255, 0), p, aApplied)
pygame.draw.line(surface, (255, 0, 0), p, aConstraint)
pygame.draw.circle(surface, (255, 0, 0) if self.particle.static else (0, 0, 255), p, self.radius)
pygame.draw.line(surface, (0, 255, 0), (p[0].item(), p[1].item()),
(aApplied[0].item(), aApplied[1].item()))
pygame.draw.line(surface, (255, 0, 0), (p[0].item(), p[1].item()),
(aConstraint[0].item(), aConstraint[1].item()))
pygame.draw.circle(surface, (255, 0, 0) if self.particle.static else (0, 0, 255), (p[0].item(), p[1].item()),
self.radius)
surface.blit(self.label, p + np.array([self.radius*0.5, self.radius*0.5]))

def getText(self) -> str:
Expand Down

0 comments on commit 1b20d71

Please sign in to comment.