pepper.framework.util module

class pepper.framework.util.Bounds(x0, y0, x1, y1)[source]

Bases: object

Rectangle Bounds Object

Parameters:
  • x0 (float) –
  • y0 (float) –
  • x1 (float) –
  • y1 (float) –
area

Bounds Area

Returns:area
Return type:float
center

Bounds Center

Returns:center
Return type:tuple
contains(point)[source]

Whether Point lies in Bounds

Parameters:point (Tuple[float, float]) –
Returns:is_in – Whether Point lies in Bounds
Return type:bool
dict()[source]

Export Bounds as Dict

Returns:dict
Return type:Dict[str, float]
equals(other)[source]

Whether ‘other’ bounds equals ‘this’ bounds

Parameters:other (Bounds) –
Returns:equals – Whether ‘other’ bounds equals ‘this’ bounds
Return type:bool
classmethod from_json(data)[source]

Create Bounds Object from Dictionary

Parameters:data (dict) – Dictionary containing x0, y0, x1, y1 keys
Returns:bounds
Return type:Bounds
height

Bounds Height

Returns:height
Return type:float
intersection(bounds)[source]

Bounds Intersection with another Bounds

Parameters:bounds (Bounds) –
Returns:intersection
Return type:Bounds or None
is_subset_of(other)[source]

Whether ‘other’ Bounds is subset of ‘this’ Bounds

Parameters:other (Bounds) –
Returns:is_subset_of – Whether ‘other’ Bounds is subset of ‘this’ Bounds
Return type:bool
is_superset_of(other)[source]

Whether ‘other’ Bounds is superset of ‘this’ Bounds

Parameters:other (Bounds) –
Returns:is_superset_of – Whether ‘other’ Bounds is superset of ‘this’ Bounds
Return type:bool
json

Export Bounds as JSON

Returns:json
Return type:str
overlap(other)[source]

Bounds Overlap Ratio

Parameters:other (Bounds) –
Returns:overlap
Return type:float
scaled(x_scale, y_scale)[source]

Return Scaled Bounds Object

Parameters:
  • x_scale (float) –
  • y_scale (float) –
Returns:

bounds – Scaled Bounds object

Return type:

Bounds

to_list()[source]

Export Bounds as List

Returns:bounds
Return type:List[float]
width

Bounds Width

Returns:width
Return type:float
x0

X0

Returns:x0
Return type:float
x1

X1

Returns:x1
Return type:float
y0

Y0

Returns:y0
Return type:float
y1

Y1

Returns:y1
Return type:float
class pepper.framework.util.Mailbox[source]

Bases: object

Mailbox Object: Single-Item Queue with Override on ‘put’

EPSILON = 0.1
get(block=True)[source]

Get latest Mail from Mailbox

Parameters:block (bool) – If True: Wait for Mail until it arrives in Mailbox If False: Return Empty Exception when Mailbox is Empty
Returns:mail
Return type:Any
put(mail)[source]

Put new Mail in Mailbox, overriding any mail that might be there already

Parameters:mail (Any) –
class pepper.framework.util.Scheduler(target, interval=0.1, name=None, args=(), kwargs={})[source]

Bases: threading.Thread

Runs Threaded Task Continuously with certain interval

This is useful for long running Real-Time tasks:
When there are many of these tasks, they start to conflict with each other. By specifying an interval in which the CPU on this thread is told to sleep, breathing room is realized for the other threads to execute their commands.
Parameters:
  • target (Callable) – Function to Run
  • interval (float) – Interval between function calls
  • name (str or None) – Name of Thread (for identification in debug mode)
  • args (tuple) – Target Arguments
  • kwargs (dict) – Target Keyword Arguments
join(timeout=None)[source]

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

pepper.framework.util.spherical2cartesian(phi, theta, depth)[source]

Spherical Coordinates to Cartesian Coordinates

Phi: Left to Right, Theta: Down to Up, Depth: Distance x: Left to Right, y: down to up, z: close to far

Parameters:
  • phi (float) –
  • theta (float) –
  • depth (float) –
Returns:

x,y,z

Return type:

float, float, float