Skip to content

Commit

Permalink
Addendum
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiefl committed Jul 11, 2023
1 parent 9c4d9ad commit f4b91e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pooltool/physics/resolve/ball_cushion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
Han2005Circular,
Han2005Linear,
)
from pooltool.physics.resolve.ball_cushion.unrealistic import UnrealisticLinear
from pooltool.physics.resolve.ball_cushion.unrealistic import (
UnrealisticCircular,
UnrealisticLinear,
)
from pooltool.physics.resolve.types import ModelArgs
from pooltool.utils.strenum import StrEnum, auto

Expand All @@ -20,6 +23,7 @@ class BallLCushionModel(StrEnum):

class BallCCushionModel(StrEnum):
HAN_2005 = auto()
UNREALISTIC = auto()


_ball_lcushion_models: Dict[BallLCushionModel, Type[BallLCushionCollisionStrategy]] = {
Expand All @@ -29,6 +33,7 @@ class BallCCushionModel(StrEnum):

_ball_ccushion_models: Dict[BallCCushionModel, Type[BallCCushionCollisionStrategy]] = {
BallCCushionModel.HAN_2005: Han2005Circular,
BallCCushionModel.UNREALISTIC: UnrealisticCircular,
}


Expand Down
28 changes: 23 additions & 5 deletions pooltool/physics/resolve/ball_cushion/unrealistic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
"""An unrealistic ball-cushion model"""

from typing import Tuple
from typing import Tuple, TypeVar

import numpy as np

import pooltool.constants as const
import pooltool.math as math
from pooltool.objects.ball.datatypes import Ball
from pooltool.objects.table.components import LinearCushionSegment
from pooltool.physics.resolve.ball_cushion.core import CoreBallLCushionCollision
from pooltool.objects.table.components import (
CircularCushionSegment,
LinearCushionSegment,
)
from pooltool.physics.resolve.ball_cushion.core import (
CoreBallCCushionCollision,
CoreBallLCushionCollision,
)

Cushion = TypeVar("Cushion", LinearCushionSegment, CircularCushionSegment)


def _solve(
ball: Ball, cushion: LinearCushionSegment, restitution: bool = True
) -> Tuple[Ball, LinearCushionSegment]:
ball: Ball, cushion: Cushion, restitution: bool = True
) -> Tuple[Ball, Cushion]:
"""Given ball and cushion, unrealistically reflect the ball's momentum
Args:
Expand Down Expand Up @@ -67,3 +75,13 @@ def solve(
self, ball: Ball, cushion: LinearCushionSegment
) -> Tuple[Ball, LinearCushionSegment]:
return _solve(ball, cushion, self.restitution)


class UnrealisticCircular(CoreBallCCushionCollision):
def __init__(self, restitution: bool = True) -> None:
self.restitution = restitution

def solve(
self, ball: Ball, cushion: CircularCushionSegment
) -> Tuple[Ball, CircularCushionSegment]:
return _solve(ball, cushion, self.restitution)

0 comments on commit f4b91e4

Please sign in to comment.