Skip to content

Commit 3cb9d3f

Browse files
authored
Merge pull request #120 from ekiefl/api-redesign
Api redesign
2 parents 00c933a + 8e4feb9 commit 3cb9d3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+692
-396
lines changed

docs/_templates/autoapi/python/module.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
.. py:module:: {{ obj.name }}
1111
1212
{% if obj.docstring %}
13-
{{ obj.docstring|indent(3) }}
13+
{% set docstring_lines = obj.docstring.split('\n') %}
14+
{% set first_line = docstring_lines[0] %}
15+
{{ first_line }}
16+
{{ "-" * first_line|length }}
17+
18+
{% if docstring_lines|length > 1 %}
19+
{% for line in docstring_lines[1:] %}
20+
{{ line }}
21+
{% endfor %}
22+
{% endif %}
1423
{% endif %}
1524

1625
{% block subpackages %}

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
"*/ani/mouse.py",
134134
"*/ani/tasks.py",
135135
"*/ani/utils.py",
136+
"*/error.py",
137+
"*/terminal.py",
136138
]
137139
)
138140

docs/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Pooltool is a general purpose billiards simulator crafted specifically for scien
44

55
Its core design principles focus on speed, flexibility, and the ease of visualization and analysis. With an interactive 3D interface, a robust API, and extensive documentation, pooltool aims to be a systemic tool in billiards-related research. Continuously evolving through active maintenance and bolstered by a growing community, this vision for pooltool emphasizes not just its current capabilities, but also its potential for growth and adaptation within billiards simulation.
66

7-
## Contents
8-
97
```{eval-rst}
108
.. toctree::
9+
:hidden:
1110
:maxdepth: 3
1211
1312
self

docs/local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
rm -rf autoapi _build
33
sphinx-build -b html . _build
4-
#open _build/index.html
4+
open _build/index.html

pooltool/__init__.py

Lines changed: 57 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,94 @@
1-
"""The primary interface for the pooltool library
1+
"""The top-level API for the pooltool library
22
3-
Members on this page have been chosen to selectively capture the most common /
4-
expected use cases of pooltool, and can be used simply by importing the ``pooltool``
5-
package. For instance:
3+
**Important and highly used objects are placed in this top-level API**. For example,
4+
``System`` can be imported directly from the top module:
65
76
>>> import pooltool as pt
8-
>>> ball = pt.Ball("cue")
7+
>>> system = pt.System.example()
98
10-
Note:
11-
You can of course, also import ``Ball`` from it's source
12-
(:class:`pooltool.objects.ball.datatypes.Ball`):
9+
Alternatively, it can be imported directly from its source location:
1310
14-
>>> from pooltool.objects.ball.datatypes import Ball
11+
>>> from pooltool.system.datatypes import System
12+
>>> system = System.example()
1513
16-
There are many other components of pooltool's API that can also be accessed, but
17-
that require a more detailed importing. As just an example:
18-
19-
>>> from pooltool.physics.resolve.ball_cushion.han_2005 import model
20-
21-
If you believe that a component deserves to graduate to the top-level API, your
22-
input is valuable and such changes can be considered.
14+
If the object you're looking for isn't in this top-level API, **search for it in
15+
the submodules** listed below. Relatedly, if you believe that an objects deserves to
16+
graduate to the top-level API, **your input is valuable** and such changes can be
17+
considered.
2318
"""
2419

2520
__version__ = "0.2.2.1-dev"
2621

2722
import pooltool.ai as ai
2823
import pooltool.ai.aim as aim
2924
import pooltool.ai.pot as pot
30-
from pooltool import terminal
31-
from pooltool.ani.animate import FrameStepper
32-
from pooltool.ani.image import (
33-
GzipArrayImages,
34-
HDF5Images,
35-
ImageZip,
36-
NpyImages,
37-
image_stack,
38-
save_images,
39-
)
40-
from pooltool.events import (
41-
Agent,
42-
AgentType,
43-
Event,
44-
EventType,
45-
ball_ball_collision,
46-
ball_circular_cushion_collision,
47-
ball_linear_cushion_collision,
48-
ball_pocket_collision,
49-
by_ball,
50-
by_time,
51-
by_type,
52-
filter_ball,
53-
filter_events,
54-
filter_time,
55-
filter_type,
56-
null_event,
57-
rolling_spinning_transition,
58-
rolling_stationary_transition,
59-
sliding_rolling_transition,
60-
spinning_stationary_transition,
61-
stick_ball_collision,
62-
)
63-
from pooltool.evolution import simulate
64-
from pooltool.evolution.continuize import continuize
25+
import pooltool.ani.image as image
26+
import pooltool.constants as constants
27+
import pooltool.events as events
28+
import pooltool.evolution as evolution
29+
import pooltool.game as game
30+
import pooltool.interact as interact
31+
import pooltool.layouts as layouts
32+
import pooltool.objects as objects
33+
import pooltool.physics as physics
34+
import pooltool.ptmath as ptmath
35+
import pooltool.ruleset as ruleset
36+
import pooltool.serialize as serialize
37+
import pooltool.system as system
38+
import pooltool.terminal as terminal
39+
import pooltool.utils as utils
40+
from pooltool.events import EventType
41+
from pooltool.evolution import continuize, simulate
6542
from pooltool.game.datatypes import GameType
66-
from pooltool.game.layouts import generate_layout, get_rack
67-
from pooltool.game.ruleset import get_ruleset
68-
from pooltool.game.ruleset.datatypes import Player, Ruleset
6943
from pooltool.interact import Game, ShotViewer
44+
from pooltool.layouts import generate_layout, get_rack
7045
from pooltool.objects import (
7146
Ball,
72-
BallHistory,
73-
BallOrientation,
7447
BallParams,
75-
BallSet,
76-
BallState,
77-
BilliardTableSpecs,
78-
CircularCushionSegment,
7948
Cue,
80-
CueSpecs,
81-
CushionDirection,
82-
CushionSegments,
83-
LinearCushionSegment,
84-
Pocket,
85-
PocketTableSpecs,
86-
SnookerTableSpecs,
8749
Table,
88-
TableModelDescr,
8950
TableType,
90-
get_ballset,
9151
)
92-
from pooltool.physics.engine import PhysicsEngine
93-
from pooltool.system import MultiSystem, System, SystemController, multisystem, visual
94-
95-
run = terminal.Run()
96-
progress = terminal.Progress()
97-
52+
from pooltool.ruleset import Player, get_ruleset
53+
from pooltool.system import MultiSystem, System
9854

9955
__all__ = [
56+
# subpackages
57+
"serialize",
58+
"constants",
59+
"game",
60+
"system",
61+
"physics",
62+
"ptmath",
63+
"objects",
64+
"interact",
65+
"evolution",
66+
"ruleset",
67+
"layouts",
68+
"events",
69+
"terminal",
70+
"image",
71+
"ai",
72+
"pot",
73+
"aim",
74+
"utils",
75+
# objects
76+
"Player",
10077
"System",
101-
"MultiSystem",
102-
"PhysicsEngine",
103-
"multisystem",
104-
"SystemController",
105-
"visual",
106-
"filter_ball",
107-
"filter_time",
108-
"filter_type",
109-
"filter_events",
110-
"by_type",
111-
"by_ball",
112-
"by_time",
113-
"FrameStepper",
114-
"null_event",
115-
"ball_ball_collision",
116-
"ball_linear_cushion_collision",
117-
"ball_circular_cushion_collision",
118-
"ball_pocket_collision",
119-
"stick_ball_collision",
120-
"spinning_stationary_transition",
121-
"rolling_stationary_transition",
122-
"rolling_spinning_transition",
123-
"sliding_rolling_transition",
12478
"GameType",
125-
"Event",
126-
"EventType",
127-
"AgentType",
128-
"Agent",
79+
"MultiSystem",
12980
"Ball",
130-
"BallSet",
131-
"BallState",
13281
"BallParams",
133-
"BallHistory",
134-
"BallOrientation",
135-
"CueSpecs",
13682
"Cue",
137-
"Pocket",
138-
"LinearCushionSegment",
139-
"CircularCushionSegment",
140-
"CushionSegments",
141-
"CushionDirection",
142-
"ImageZip",
143-
"HDF5Images",
144-
"GzipArrayImages",
145-
"NpyImages",
14683
"Table",
147-
"TableModelDescr",
14884
"TableType",
149-
"PocketTableSpecs",
150-
"BilliardTableSpecs",
151-
"SnookerTableSpecs",
15285
"Game",
153-
"save_images",
154-
"image_stack",
15586
"ShotViewer",
87+
"EventType",
88+
# functions
89+
"get_rack",
90+
"get_ruleset",
15691
"simulate",
15792
"continuize",
158-
"get_rack",
15993
"generate_layout",
160-
"get_ruleset",
161-
"Player",
162-
"Ruleset",
163-
"get_ballset",
164-
"ai",
165-
"pot",
166-
"aim",
16794
]

pooltool/ai/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
"""This is a test"""

pooltool/ani/animate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
from pooltool.ani.mouse import mouse
3131
from pooltool.evolution.continuize import continuize
3232
from pooltool.game.datatypes import GameType
33-
from pooltool.game.layouts import get_rack
34-
from pooltool.game.ruleset import get_ruleset
35-
from pooltool.game.ruleset.datatypes import Player
33+
from pooltool.layouts import get_rack
3634
from pooltool.objects.cue.datatypes import Cue
3735
from pooltool.objects.table.datatypes import Table
36+
from pooltool.ruleset import get_ruleset
37+
from pooltool.ruleset.datatypes import Player
3838
from pooltool.system.datatypes import MultiSystem, System, multisystem
3939
from pooltool.system.render import PlaybackMode, visual
4040
from pooltool.utils import get_total_memory_usage

pooltool/ani/modes/ball_in_hand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pooltool.ani.globals import Global
1414
from pooltool.ani.modes.datatypes import BaseMode, Mode
1515
from pooltool.ani.mouse import MouseMode, mouse
16-
from pooltool.game.ruleset.datatypes import BallInHandOptions
16+
from pooltool.ruleset.datatypes import BallInHandOptions
1717
from pooltool.system.render import visual
1818
from pooltool.utils import panda_path
1919

pooltool/constants.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#! /usr/bin/env python
2-
"""Constants and other
2+
"""Constants
33
4-
All units are SI unless otherwise stated.
4+
Notes:
5+
- **Developer note**: This should really be dissolved into config and motion state
6+
sections of code
57
"""
68

9+
from typing import Dict
10+
711
import numpy as np
812

913
use_numba_cache = True
@@ -13,13 +17,35 @@
1317
EPS_SPACE = 1e-9
1418

1519
# Ball states
16-
stationary = 0
17-
spinning = 1
18-
sliding = 2
19-
rolling = 3
20-
pocketed = 4
20+
stationary: int = 0
21+
"""The stationary motion state label
22+
23+
A ball with this motion state is both motionless and not in a pocket.
24+
"""
25+
spinning: int = 1
26+
"""The spinning motion state label
27+
28+
A ball with this motion state is spinning in place.
29+
"""
30+
sliding: int = 2
31+
"""The sliding motion state label
32+
33+
A ball with this motion state is sliding. For details on what this means precisely, see
34+
this `blog <https://ekiefl.github.io/2020/04/24/pooltool-theory/#case-4-sliding>`_.
35+
"""
36+
rolling: int = 3
37+
"""The rolling motion state label
38+
39+
A ball with this motion state is rolling. For details on what this means precisely, see
40+
this `blog <https://ekiefl.github.io/2020/04/24/pooltool-theory/#case-3-rolling>`_.
41+
"""
42+
pocketed: int = 4
43+
"""The pocketed motion state label
44+
45+
A ball with this motion state is in a pocket.
46+
"""
2147

22-
state_dict = {
48+
state_dict: Dict[int, str] = {
2349
0: "stationary",
2450
1: "spinning",
2551
2: "sliding",

pooltool/events/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Event, detection, and filtration
2+
3+
See `here <https://ekiefl.github.io/2020/12/20/pooltool-alg/#2-what-are-events>`_ to
4+
learn about events and why they matter.
5+
"""
6+
17
from pooltool.events.datatypes import Agent, AgentType, Event, EventType
28
from pooltool.events.factory import (
39
ball_ball_collision,

pooltool/events/filter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def filter_events(events: List[Event], *funcs: FilterFunc) -> List[Event]:
147147
filtering for the cue-ball pocket event. Option 1 is to call :func:`filter_type`
148148
and then :func:`filter_ball`:
149149
150-
>>> filtered_events = pt.filter_type(events, pt.EventType.BALL_POCKET)
151-
>>> filtered_events = pt.filter_ball(filtered_events, "cue")
150+
>>> filtered_events = pt.events.filter_type(events, pt.EventType.BALL_POCKET)
151+
>>> filtered_events = pt.events.filter_ball(filtered_events, "cue")
152152
>>> event_of_interest = filtered_events[0]
153153
>>> event_of_interest
154154
<Event object at 0x7fa855e7e6c0>
@@ -158,10 +158,10 @@ def filter_events(events: List[Event], *funcs: FilterFunc) -> List[Event]:
158158
159159
Option 2, the better option, is to use :func:`filter_events`:
160160
161-
>>> filtered_events = pt.filter_events(
161+
>>> filtered_events = pt.events.filter_events(
162162
>>> events,
163-
>>> pt.by_type(pt.EventType.BALL_POCKET),
164-
>>> pt.by_ball("cue"),
163+
>>> pt.events.by_type(pt.EventType.BALL_POCKET),
164+
>>> pt.events.by_ball("cue"),
165165
>>> )
166166
>>> event_of_interest = filtered_events[0]
167167
>>> event_of_interest

pooltool/evolution/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Shot evolution algorithm routines"""
2+
13
from pooltool.evolution.continuize import continuize
24
from pooltool.evolution.event_based.simulate import simulate
35

0 commit comments

Comments
 (0)