oursin.utils

Sanitizing inputs to send through API

Functions

formatted_color

Converts a color, either a hex or list of floats, to a Color object

formatted_vector2

Convert a list of floats to a Vector2

formatted_vector3

Convert a list of floats to a Vector3

hex_to_rgb

list_of_list2vector3

Convert a list of lists to a list of Vector3 objects

rgb_to_hex

rgba_to_hex

sanitize_color

Convert input color to a list of r/g/b/a values in the range 0->1.

sanitize_float

sanitize_list

Guarantee that a list is of at least size length, or try to broadcast to that size

sanitize_material

sanitize_side

sanitize_string

sanitize_vector3

Guarantee that a vector is a vector 3, or raise an exception

Classes

Side

An enumeration.

class Side(value)[source]

Bases: Enum

An enumeration.

LEFT = -1
FULL = 0
RIGHT = 1
ALL = 3
sanitize_vector3(vector)[source]

Guarantee that a vector is a vector 3, or raise an exception

Parameters

inputany

arbitrary input parameter

Returns

list

vector3 as a list [x,y,z]

Raises

Exception

Failed to coerce input to a length 3 list

sanitize_color(color)[source]

Convert input color to a list of r/g/b/a values in the range 0->1.

Parameters

colorstr or list

Hex code or list of floats representing color values.

Returns

list

List of r/g/b/a values in the range 0->1.

sanitize_float(value)[source]
sanitize_material(material)[source]
sanitize_list(input, length=0)[source]

Guarantee that a list is of at least size length, or try to broadcast to that size

Parameters

input : list length : int, optional

length to broadcast to, by default 0

Returns

list

sanitize_string(string)[source]
sanitize_side(acronym, sided)[source]
rgb_to_hex(rgb)[source]
rgba_to_hex(rgba)[source]
hex_to_rgb(hex_code)[source]
list_of_list2vector3(list_of_list)[source]

Convert a list of lists to a list of Vector3 objects

Parameters

list_of_listlist of length 3 lists

_description_

formatted_vector3(list_of_float)[source]

Convert a list of floats to a Vector3

Parameters

list_of_float : list

formatted_vector2(list_of_float)[source]

Convert a list of floats to a Vector2

Parameters

list_of_float : list

formatted_color(color)[source]

Converts a color, either a hex or list of floats, to a Color object

Parameters

colorlist/str

Length 3 for RGB, 4 for RGBA, or a hex color string