pooltool.events.datatypes#

Overview#

Classes#

EventType

An Enum of event types

AgentType

An Enum of event agents

Agent

An event agent.

Event

Represents an event.

Classes#

class pooltool.events.datatypes.EventType(value)[source]#

An Enum of event types

NONE#

The null event.

BALL_BALL#

A ball-ball collision.

BALL_LINEAR_CUSHION#

A ball collision with a linear cushion segment.

BALL_CIRCULAR_CUSHION#

A ball collision with a circular cushion segment.

BALL_POCKET#

A ball pocket “collision”. This marks the point at which the ball crosses the point of no return.

STICK_BALL#

A cue-stick ball collision.

SPINNING_STATIONARY#

A ball transition from spinning to stationary.

ROLLING_STATIONARY#

A ball transition from rolling to stationary.

ROLLING_SPINNING#

A ball transition from rolling to spinning.

SLIDING_ROLLING#

A ball transition from sliding to rolling.

Bases: pooltool.utils.strenum.StrEnum

Methods:

is_collision() bool[source]#

Returns whether the member is a collision

Return type:

bool

is_transition() bool[source]#

Returns whether the member is a transition

Return type:

bool

class pooltool.events.datatypes.AgentType(value)[source]#

An Enum of event agents

NULL#

A null agent.

CUE#

A cue stick agent.

BALL#

A ball agent.

POCKET#

A pocket agent.

LINEAR_CUSHION_SEGMENT#

A linear cushion segment agent.

CIRCULAR_CUSHION_SEGMENT#

A circular cushion segment agent.

Bases: pooltool.utils.strenum.StrEnum

class pooltool.events.datatypes.Agent(id: str, agent_type: AgentType, initial: NullObject | Cue | Ball | Pocket | LinearCushionSegment | CircularCushionSegment | None = None, final: NullObject | Cue | Ball | Pocket | LinearCushionSegment | CircularCushionSegment | None = None)[source]#

An event agent.

This class represents an agent involved in events. The agent can be in different states before and after an event, represented by initial and final states.

id#

ID for the agent.

Type:

str

agent_type#

The type of the agent.

Type:

pooltool.events.datatypes.AgentType

initial#

The state of the agent before an event.

Type:

pooltool.objects.datatypes.NullObject | pooltool.objects.cue.datatypes.Cue | pooltool.objects.ball.datatypes.Ball | pooltool.objects.table.components.Pocket | pooltool.objects.table.components.LinearCushionSegment | pooltool.objects.table.components.CircularCushionSegment | None

final#

The state of the agent after an event.

Type:

pooltool.objects.datatypes.NullObject | pooltool.objects.cue.datatypes.Cue | pooltool.objects.ball.datatypes.Ball | pooltool.objects.table.components.Pocket | pooltool.objects.table.components.LinearCushionSegment | pooltool.objects.table.components.CircularCushionSegment | None

Methods:

set_initial(obj: Object) None[source]#

Sets the initial state of the agent (before event resolution).

This makes a copy of the passed object and sets it to initial.

In the case of a AgentType.BALL agent type, it drops history fields before copying to save time and memory.

Parameters:

obj (Object) -- The object from which initial will be set.

set_final(obj: Object) None[source]#

Sets the final state of the agent (after event resolution).

This makes a copy of the passed object and sets it to final.

In the case of a AgentType.BALL agent type, it drops history fields before copying to save time and memory.

Parameters:

obj (Object) -- The object from which final will be set.

matches(obj: Object) bool[source]#

Determines if the given object matches the agent.

It checks if the object is of the correct class type and if the IDs match.

Parameters:

obj (Object) -- The object to compare with the agent.

Returns:

True if the object’s class type and ID match the agent’s type and ID, False otherwise.

Return type:

bool

static from_object(obj: Object, set_initial: bool = False) Agent[source]#

Creates an agent instance from an object.

Optionally sets the initial state of the agent based on the provided object. The final state is not set.

Parameters:
  • obj (Object) -- The object to create the agent from.

  • set_initial (bool) -- If True, sets the initial state of the agent to the object’s state.

Returns:

A new instance of Agent.

Return type:

Agent

copy() Agent[source]#

Create a copy.

Return type:

Agent

class pooltool.events.datatypes.Event(event_type: EventType, agents: Tuple[Agent, ...], time: float)[source]#

Represents an event.

This class models an event characterized by its type, the agents involved, and the time at which the event occurs.

Agent states before and after event resolution are stored in the Agent.initial and Agent.final attributes of agents within agents.

event_type#

The type of the event, indicating the nature of the event.

Type:

pooltool.events.datatypes.EventType

agents#

A tuple containing one or two agents involved in the event.

Events that are collisions (EventType.is_collision()) have two agents, while events that are transitions (EventType.is_transition()), or events with event type EventType.NONE, have one agent.

By convention, the order of the agents matches how the EventType attributes are named.

Type:

Tuple[pooltool.events.datatypes.Agent, …]

time#

The time at which the event occurs.

Type:

float

property ids: Tuple[str, Ellipsis]#

Retrieves the IDs of the agents involved in the event.

This property provides access to a tuple of agent IDs, allowing identification of the agents involved in the event.

Returns:

A tuple containing the IDs of the agents involved in the event.

Return type:

Tuple[str, …]

Methods:

copy() Event[source]#

Create a copy.

Return type:

Event