simetri.helpers package¶
Submodules¶
simetri.helpers.constraint_solver module¶
Geometric constraint solver for points, segments, circles. Uses Sequential Least Squares Programming (SLSQP) to solve the given constraints.
- class simetri.helpers.constraint_solver.Constraint(item1: object, item2: object, type: ConstraintType, value: float | None = None, value2: float | None = None)[source]¶
Bases:
object
Constraint class for geometric constraints.
- check()[source]¶
Check the constraint value.
- Returns:
The result of the constraint equation.
- Return type:
float
- item1: object¶
- item2: object¶
- type: ConstraintType¶
- value: float = None¶
- value2: float = None¶
- simetri.helpers.constraint_solver.collinear_eq(constraint)[source]¶
Return the difference in direction for collinear items.
Items can be: segments, segment and a circle, or a segment and a point.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference in direction.
- Return type:
float
- simetri.helpers.constraint_solver.distance_eq(constraint)[source]¶
Return the difference between the target and current distance.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference between the target and current distance.
- Return type:
float
- simetri.helpers.constraint_solver.equal_size_eq(constraint)[source]¶
Return the difference between the sizes of the items.
For segments, item size is the length of the segment. For circles, item size is the radius of the circle.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference between the sizes of the items.
- Return type:
float
- simetri.helpers.constraint_solver.equal_value_eq(constraint)[source]¶
Return the difference between the values.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference between the values.
- Return type:
float
- simetri.helpers.constraint_solver.inner_tangent_eq(constraint)[source]¶
Return the difference between the distance of the circles and the sum of the radii.
If the circles are tangent, the difference is 0.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference between the distance of the circles and the sum of the radii.
- Return type:
float
- simetri.helpers.constraint_solver.line_angle_eq(constraint)[source]¶
Return the angle between two segments.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The angle between the two segments.
- Return type:
float
- simetri.helpers.constraint_solver.outer_tangent_eq(constraint)[source]¶
Return the difference between the distance of the circles and the sum of the radii.
If the circles are tangent, the difference is 0.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The difference between the distance of the circles and the sum of the radii.
- Return type:
float
- simetri.helpers.constraint_solver.parallel_eq(constraint)[source]¶
Return the cross product. If the segments are parallel, the cross product is 0.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The cross product of the vectors.
- Return type:
float
- simetri.helpers.constraint_solver.perpendicular_eq(constraint)[source]¶
Return the dot product. If the segments are perpendicular, the dot product is 0.
- Parameters:
constraint (Constraint) – The constraint object.
- Returns:
The dot product of the vectors.
- Return type:
float
- simetri.helpers.constraint_solver.solve(constraints, update_func, initial_guess, bounds=None, tol=0.0001)[source]¶
Solve the geometric constraints.
- Parameters:
constraints (list) – List of Constraint objects.
update_func (function) – Function that updates the constraint items.
initial_guess (list) – Initial guess for the solution.
bounds (list, optional) – Bounds for the solution. Defaults to None.
tol (float, optional) – Tolerance for the solution. Defaults to 1e-04.
- Returns:
The optimization result represented as a OptimizeResult object.
- Return type:
OptimizeResult
simetri.helpers.graph module¶
Graph related functions and classes. Uses NetworkX for graph operations.
- class simetri.helpers.graph.Graph(type: Types = 'undirected', subtype: Types = 'none', nx_graph: Graph | None = None)[source]¶
Bases:
object
A Graph object is a collection of nodes and edges.
- nx_graph¶
The NetworkX graph object.
- Type:
nx.Graph
- property cycles¶
Return a list of cycles.
- Returns:
List of cycles.
- Return type:
List
- property edges¶
Return the edges of the graph.
- Returns:
Edges of the graph.
- Return type:
EdgeView
- property islands¶
Return a list of all islands both cyclic and acyclic.
- Returns:
List of all islands.
- Return type:
List
- property nodes¶
Return the nodes of the graph.
- Returns:
Nodes of the graph.
- Return type:
NodeView
- nx_graph: Graph = None¶
- property open_walks¶
Return a list of open walks (aka open chains).
- Returns:
List of open walks.
- Return type:
List
- class simetri.helpers.graph.GraphEdge(start: Sequence[float], end: Sequence[float])[source]¶
Bases:
object
Edge in a graph. It has a start and end point as nodes.
- end: Sequence[float]¶
- property nodes¶
Return the start and end nodes of the edge.
- start: Sequence[float]¶
- class simetri.helpers.graph.Node(x: float, y: float)[source]¶
Bases:
object
A Node object is a 2D point with x and y coordinates. Used in graphs corresponding to shapes and batches.
- x¶
X coordinate.
- Type:
float
- y¶
Y coordinate.
- Type:
float
- property pos¶
Return the position of the node.
- x: float¶
- y: float¶
- simetri.helpers.graph.edges2nodes(edges: Sequence[Sequence]) Sequence [source]¶
Given a list of edges, return a connected list of nodes.
- Parameters:
edges (Sequence[Sequence]) – List of edges.
- Returns:
Connected list of nodes.
- Return type:
Sequence
- simetri.helpers.graph.find_all_paths(graph, node)[source]¶
Find all paths starting from a given node.
- Parameters:
graph (nx.Graph) – The graph.
node – The starting node.
- Returns:
All paths starting from the given node.
- Return type:
List
- simetri.helpers.graph.get_cycles(edges: Sequence[GraphEdge]) Sequence[GraphEdge] [source]¶
Computes all the cycles in a given graph of edges.
- simetri.helpers.graph.graph_summary(graph: Graph) str [source]¶
Return a summary of a graph including cycles, open walks and degenerate nodes.
- Parameters:
graph (nx.Graph) – The graph.
- Returns:
Summary of the graph.
- Return type:
str
- simetri.helpers.graph.is_cycle(graph: Graph, island: Sequence) bool [source]¶
Given a NetworkX Graph and an island, return True if the given island is a cycle.
- Parameters:
graph (nx.Graph) – The graph.
island (Sequence) – The island.
- Returns:
True if the island is a cycle, False otherwise.
- Return type:
bool
- simetri.helpers.graph.is_open_walk(graph: Graph, island: Sequence) bool [source]¶
Given a NetworkX Graph and an island, return True if the given island is an open walk.
- Parameters:
graph (nx.Graph) – The graph.
island (Sequence) – The island.
- Returns:
True if the island is an open walk, False otherwise.
- Return type:
bool
simetri.helpers.illustration module¶
This module contains functions and classes for creating annotations, arrows, dimensions, etc.
- class simetri.helpers.illustration.AngularDimension(center: Sequence[float], radius: float, start_angle: float, end_angle: float, ext_angle: float, gap_angle: float, text_offset: float | None = None, gap: float | None = None, **kwargs)[source]¶
Bases:
Batch
An AngularDimension object is a dimension that represents an angle.
- Parameters:
center (Point) – The center of the angle.
radius (float) – The radius of the angle.
start_angle (float) – The starting angle.
end_angle (float) – The ending angle.
ext_angle (float) – The extension angle.
gap_angle (float) – The gap angle.
text_offset (float, optional) – The text offset. Defaults to None.
gap (float, optional) – The gap. Defaults to None.
**kwargs – Additional keyword arguments for angular dimension styling.
- class simetri.helpers.illustration.Annotation(text, pos, frame, root_pos, arrow_line=ArrowLine.STRAIGHT_END, **kwargs)[source]¶
Bases:
Batch
An Annotation object is a label with an arrow pointing to a specific location.
- Parameters:
text (str) – The annotation text.
pos (tuple) – The position of the annotation.
frame (FrameShape) – The frame shape of the annotation.
root_pos (tuple) – The root position of the arrow.
arrow_line (ArrowLine, optional) – The type of arrow line. Defaults to ArrowLine.STRAIGHT_END.
**kwargs – Additional keyword arguments for annotation styling.
- class simetri.helpers.illustration.ArcArrow(center: Sequence[float], radius: float, start_angle: float, end_angle: float, xform_matrix: array | None = None, **kwargs)[source]¶
Bases:
Batch
An ArcArrow object is an arrow with an arc.
- Parameters:
center (Point) – The center of the arc.
radius (float) – The radius of the arc.
start_angle (float) – The starting angle of the arc.
end_angle (float) – The ending angle of the arc.
xform_matrix (array, optional) – The transformation matrix. Defaults to None.
**kwargs – Additional keyword arguments for arc arrow styling.
- class simetri.helpers.illustration.Arrow(p1: Sequence[float], p2: Sequence[float], head_pos: HeadPos = HeadPos.END, head: Shape | None = None, **kwargs)[source]¶
Bases:
Batch
An Arrow object is a line with an arrow head.
- Parameters:
p1 (Point) – The starting point of the arrow.
p2 (Point) – The ending point of the arrow.
head_pos (HeadPos, optional) – The position of the arrow head. Defaults to HeadPos.END.
head (Shape, optional) – The shape of the arrow head. Defaults to None.
**kwargs – Additional keyword arguments for arrow styling.
- class simetri.helpers.illustration.ArrowHead(length: float | None = None, width_: float | None = None, points: list | None = None, **kwargs)[source]¶
Bases:
Shape
An ArrowHead object is a shape that represents the head of an arrow.
- Parameters:
length (float, optional) – The length of the arrow head. Defaults to None.
width (float, optional) – The width of the arrow head. Defaults to None.
points (list, optional) – The points defining the arrow head. Defaults to None.
**kwargs – Additional keyword arguments for arrow head styling.
- class simetri.helpers.illustration.Dimension(text: str, p1: Sequence[float], p2: Sequence[float], ext_length: float, ext_length2: float | None = None, orientation: Anchor | None = None, text_pos: Anchor = Anchor.CENTER, text_offset: float = 0, gap: float | None = None, reverse_arrows: bool = False, reverse_arrow_length: float | None = None, parallel: bool = False, ext1pnt: Sequence[float] | None = None, ext2pnt: Sequence[float] | None = None, scale: float = 1, font_size: int = 12, **kwargs)[source]¶
Bases:
Batch
A Dimension object is a line with arrows and a text.
- Parameters:
text (str) – The text of the dimension.
p1 (Point) – The starting point of the dimension.
p2 (Point) – The ending point of the dimension.
ext_length (float) – The length of the extension lines.
ext_length2 (float, optional) – The length of the second extension line. Defaults to None.
orientation (Anchor, optional) – The orientation of the dimension. Defaults to None.
text_pos (Anchor, optional) – The position of the text. Defaults to Anchor.CENTER.
text_offset (float, optional) – The offset of the text. Defaults to 0.
gap (float, optional) – The gap. Defaults to None.
reverse_arrows (bool, optional) – Whether to reverse the arrows. Defaults to False.
reverse_arrow_length (float, optional) – The length of the reversed arrows. Defaults to None.
parallel (bool, optional) – Whether the dimension is parallel. Defaults to False.
ext1pnt (Point, optional) – The first extension point. Defaults to None.
ext2pnt (Point, optional) – The second extension point. Defaults to None.
scale (float, optional) – The scale factor. Defaults to 1.
font_size (int, optional) – The font size. Defaults to 12.
**kwargs – Additional keyword arguments for dimension styling.
- class simetri.helpers.illustration.Tag(text: str, pos: Sequence[float], font_family: str | None = None, font_size: int | None = None, font_color: Color | None = None, anchor: Anchor = Anchor.CENTER, bold: bool = False, italic: bool = False, text_width: float | None = None, placement: Placement | None = None, minimum_size: float | None = None, minimum_width: float | None = None, minimum_height: float | None = None, frame=None, xform_matrix=None, **kwargs)[source]¶
Bases:
Base
A Tag object is very similar to TikZ library’s nodes. It is a text with a frame.
- Parameters:
text (str) – The text of the tag.
pos (Point) – The position of the tag.
font_family (str, optional) – The font family. Defaults to None.
font_size (int, optional) – The font size. Defaults to None.
font_color (Color, optional) – The font color. Defaults to None.
anchor (Anchor, optional) – The anchor point. Defaults to Anchor.CENTER.
bold (bool, optional) – Whether the text is bold. Defaults to False.
italic (bool, optional) – Whether the text is italic. Defaults to False.
text_width (float, optional) – The width of the text. Defaults to None.
placement (Placement, optional) – The placement of the tag. Defaults to None.
minimum_size (float, optional) – The minimum size of the tag. Defaults to None.
minimum_width (float, optional) – The minimum width of the tag. Defaults to None.
minimum_height (float, optional) – The minimum height of the tag. Defaults to None.
frame (TagFrame, optional) – The frame of the tag. Defaults to None.
xform_matrix (array, optional) – The transformation matrix. Defaults to None.
**kwargs – Additional keyword arguments for tag styling.
- property b_box¶
Returns the bounding box of the text.
- Returns:
The bounding box of the text.
- Return type:
tuple
- copy() Tag [source]¶
Returns a copy of the Tag object.
- Returns:
A copy of the Tag object.
- Return type:
- property final_coords¶
Returns the final coordinates of the text.
- Returns:
The final coordinates of the text.
- Return type:
array
- property pos: Sequence[float]¶
Returns the position of the text.
- Returns:
The position of the text.
- Return type:
Point
- class simetri.helpers.illustration.TagFrame(frame_shape: FrameShape = 'rectangle', line_width: float = 1, line_dash_array: list | None = None, line_join: LineJoin = 'miter', line_color: Color = Color(0.0, 0.0, 0.0), back_color: Color = Color(1.0, 1.0, 1.0), fill: bool = False, stroke: bool = True, double: bool = False, double_distance: float = 2, inner_sep: float = 10, outer_sep: float = 10, smooth: bool = False, rounded_corners: bool = False, fillet_radius: float = 10, draw_fillets: bool = False, blend_mode: str | None = None, gradient: str | None = None, pattern: str | None = None, min_width: float | None = None, min_height: float | None = None, min_size: float | None = None)[source]¶
Bases:
object
Frame objects are used with Tag objects to create boxes.
- Parameters:
frame_shape (FrameShape, optional) – The shape of the frame. Defaults to “rectangle”.
line_width (float, optional) – The width of the frame line. Defaults to 1.
line_dash_array (list, optional) – The dash pattern for the frame line. Defaults to None.
line_join (LineJoin, optional) – The line join style. Defaults to “miter”.
line_color (Color, optional) – The color of the frame line. Defaults to colors.black.
back_color (Color, optional) – The background color of the frame. Defaults to colors.white.
fill (bool, optional) – Whether to fill the frame. Defaults to False.
stroke (bool, optional) – Whether to stroke the frame. Defaults to True.
double (bool, optional) – Whether to use a double line. Defaults to False.
double_distance (float, optional) – The distance between double lines. Defaults to 2.
inner_sep (float, optional) – The inner separation. Defaults to 10.
outer_sep (float, optional) – The outer separation. Defaults to 10.
smooth (bool, optional) – Whether to smooth the frame. Defaults to False.
rounded_corners (bool, optional) – Whether to use rounded corners. Defaults to False.
fillet_radius (float, optional) – The radius of the fillet. Defaults to 10.
draw_fillets (bool, optional) – Whether to draw fillets. Defaults to False.
blend_mode (str, optional) – The blend mode. Defaults to None.
gradient (str, optional) – The gradient. Defaults to None.
pattern (str, optional) – The pattern. Defaults to None.
min_width (float, optional) – The minimum width. Defaults to None.
min_height (float, optional) – The minimum height. Defaults to None.
min_size (float, optional) – The minimum size. Defaults to None.
- blend_mode: str = None¶
- double: bool = False¶
- double_distance: float = 2¶
- draw_fillets: bool = False¶
- fill: bool = False¶
- fillet_radius: float = 10¶
- frame_shape: FrameShape = 'rectangle'¶
- gradient: str = None¶
- inner_sep: float = 10¶
- line_dash_array: list = None¶
- line_width: float = 1¶
- min_height: float = None¶
- min_size: float = None¶
- min_width: float = None¶
- outer_sep: float = 10¶
- pattern: str = None¶
- rounded_corners: bool = False¶
- smooth: bool = False¶
- stroke: bool = True¶
- simetri.helpers.illustration.arrow(p1, p2, head_length=10, head_width=4, line_width=1, line_color=Color(0.0, 0.0, 0.0), fill_color=Color(0.0, 0.0, 0.0), centered=False)[source]¶
Return an arrow from p1 to p2.
- Parameters:
p1 (tuple) – The starting point of the arrow.
p2 (tuple) – The ending point of the arrow.
head_length (int, optional) – The length of the arrow head. Defaults to 10.
head_width (int, optional) – The width of the arrow head. Defaults to 4.
line_width (int, optional) – The width of the arrow line. Defaults to 1.
line_color (Color, optional) – The color of the arrow line. Defaults to colors.black.
fill_color (Color, optional) – The fill color of the arrow head. Defaults to colors.black.
centered (bool, optional) – Whether the arrow is centered. Defaults to False.
- Returns:
A Batch object containing the arrow shapes.
- Return type:
- simetri.helpers.illustration.convert_latex_font_size(latex_font_size: FontSize)[source]¶
Converts LaTeX font size to a numerical value.
- Parameters:
latex_font_size (FontSize) – The LaTeX font size.
- Returns:
The corresponding numerical font size.
- Return type:
int
- simetri.helpers.illustration.cube(size: float = 100)[source]¶
Returns a Batch object representing a cube.
- Parameters:
size (float, optional) – The size of the cube. Defaults to 100.
- Returns:
A Batch object representing the cube.
- Return type:
- simetri.helpers.illustration.draw_cs_small(canvas, pos=(0, 0), x_len=80, y_len=100, neg_x_len=5, neg_y_len=5)[source]¶
Draws a small coordinate system.
- Parameters:
canvas – The canvas to draw on.
pos (tuple, optional) – The position of the coordinate system. Defaults to (0, 0).
x_len (int, optional) – The length of the x-axis. Defaults to 80.
y_len (int, optional) – The length of the y-axis. Defaults to 100.
neg_x_len (int, optional) – The negative length of the x-axis. Defaults to 5.
neg_y_len (int, optional) – The negative length of the y-axis. Defaults to 5.
- simetri.helpers.illustration.draw_cs_tiny(canvas, pos=(0, 0), x_len=25, y_len=25, neg_x_len=5, neg_y_len=5)[source]¶
Draws a tiny coordinate system.
- Parameters:
canvas – The canvas to draw on.
pos (tuple, optional) – The position of the coordinate system. Defaults to (0, 0).
x_len (int, optional) – The length of the x-axis. Defaults to 25.
y_len (int, optional) – The length of the y-axis. Defaults to 25.
neg_x_len (int, optional) – The negative length of the x-axis. Defaults to 5.
neg_y_len (int, optional) – The negative length of the y-axis. Defaults to 5.
- simetri.helpers.illustration.letter_F(scale=1, **kwargs)[source]¶
Returns a Shape object representing the capital letter F.
- Parameters:
scale (int, optional) – Scale factor for the letter. Defaults to 1.
**kwargs – Additional keyword arguments for shape styling.
- Returns:
A Shape object representing the letter F.
- Return type:
- simetri.helpers.illustration.letter_F_points()[source]¶
Returns the points of the capital letter F.
- Returns:
A list of points representing the letter F.
- Return type:
list
simetri.helpers.modifiers module¶
- class simetri.helpers.modifiers.Modifier(function, life_span=10000, randomness=1.0, condition=True, *args, **kwargs)[source]¶
Bases:
object
Used to modify the properties of a Batch object.
- function¶
The function to modify the property.
- Type:
callable
- life_span¶
The number of times the modifier can be applied.
- Type:
int
- randomness¶
Determines the randomness of the modification.
- Type:
float or callable
- condition¶
Condition to apply the modification.
- Type:
bool or callable
- _d_state¶
Mapping of control states to modifier states.
- Type:
dict
- count¶
Counter for the number of times the modifier has been applied.
- Type:
int
- args¶
Additional arguments for the function.
- Type:
tuple
- kwargs¶
Additional keyword arguments for the function.
- Type:
dict
- apply(element)[source]¶
Applies the modifier to an element.
If a function returns a control value, it will be applied to the modifier. Control.STOP, Control.PAUSE, Control.RESUME, and Control.RESTART are the only control values. Functions should have the following signature: def funct(target, modifier, *args, **kwargs):
- Parameters:
element (object) – The element to apply the modifier to.
- can_continue(target)[source]¶
Checks if the modifier can continue to be applied.
- Parameters:
target (object) – The target object.
- Returns:
True if the modifier can continue, False otherwise.
- Return type:
bool
- get_value(obj, target, *args, **kwargs)[source]¶
Gets the value from an object or callable.
- Parameters:
obj (object or callable) – The object or callable to get the value from.
target (object) – The target object.
*args – Additional arguments for the callable.
**kwargs – Additional keyword arguments for the callable.
- Returns:
The value obtained from the object or callable.
- Return type:
object
- simetri.helpers.modifiers.random() x in the interval [0, 1). ¶
simetri.helpers.utilities module¶
Simetri graphics library’s utility functions.
- simetri.helpers.utilities.abcdef_pil(xform_matrix)[source]¶
Return the a, b, c, d, e, f for PIL transformations.
- Parameters:
xform_matrix – A Numpy array representing the transformation matrix.
- Returns:
A tuple containing the a, b, c, d, e, f components.
- simetri.helpers.utilities.abcdef_reportlab(xform_matrix)[source]¶
Return the a, b, c, d, e, f for Reportlab transformations.
- Parameters:
xform_matrix – A Numpy array representing the transformation matrix.
- Returns:
A tuple containing the a, b, c, d, e, f components.
- simetri.helpers.utilities.abcdef_svg(transform_matrix)[source]¶
Return the a, b, c, d, e, f for SVG transformations.
- Parameters:
transform_matrix – A Numpy array representing the transformation matrix.
- Returns:
A tuple containing the a, b, c, d, e, f components.
- simetri.helpers.utilities.analyze_path(file_path, overwrite)[source]¶
Check if a file path is valid and writable.
- Parameters:
file_path – The path to the file.
overwrite – Whether to overwrite the file if it exists.
- Returns:
A tuple containing a boolean indicating validity, the file extension, and an error message.
- simetri.helpers.utilities.binomial(n, k)[source]¶
Calculate the binomial coefficient.
- Parameters:
n – The number of trials.
k – The number of successes.
- Returns:
The binomial coefficient.
- simetri.helpers.utilities.can_be_xform_matrix(seq)[source]¶
Check if a sequence can be converted to a transformation matrix.
- Parameters:
seq – The sequence to check.
- Returns:
True if the sequence can be converted to a transformation matrix, False otherwise.
- simetri.helpers.utilities.catalan(n)[source]¶
Calculate the nth Catalan number.
- Parameters:
n – The index of the Catalan number.
- Returns:
The nth Catalan number.
- simetri.helpers.utilities.check_directory(dir_path)[source]¶
Check if a directory is valid and writable.
- Parameters:
dir_path – The path to the directory.
- Returns:
A tuple containing a boolean indicating validity and an error message.
- simetri.helpers.utilities.close_logger(logger)[source]¶
Close the logger and remove all handlers.
- Parameters:
logger – The logger instance to close.
- simetri.helpers.utilities.decompose_svg_transform(transform)[source]¶
Decompose a SVG transformation string.
- Parameters:
transform – The SVG transformation string.
- Returns:
A tuple containing the decomposed transformation components.
- simetri.helpers.utilities.decompose_transformations(transformation_matrix)[source]¶
Decompose a 3x3 transformation matrix into translation, rotation, and scale components.
- Parameters:
transformation_matrix – A 3x3 transformation matrix.
- Returns:
A tuple containing the translation, rotation, and scale components.
- simetri.helpers.utilities.detokenize(text: str) str [source]¶
Replace the special Latex characters with their Latex commands.
- Parameters:
text – The text to detokenize.
- Returns:
The detokenized text.
- simetri.helpers.utilities.equal_cycles(cycle1: list[float], cycle2: list[float], rtol=None, atol=None) bool [source]¶
Check if two cycles are circularly equal.
- Parameters:
cycle1 – The first cycle.
cycle2 – The second cycle.
rtol – The relative tolerance.
atol – The absolute tolerance.
- Returns:
True if the cycles are circularly equal, False otherwise.
- simetri.helpers.utilities.find_closest_value(a_sorted_list, value)[source]¶
Return the index of the closest value and the value itself in a sorted list.
- Parameters:
a_sorted_list – A sorted list of values.
value – The value to find the closest match for.
- Returns:
A tuple containing the closest value and its index.
- simetri.helpers.utilities.find_nearest_value(values: array, value: float) float [source]¶
Find the closest value in an array to a given number.
- Parameters:
values – A NumPy array.
value – The number to find the closest value to.
- Returns:
The closest value in the array to the given number.
- simetri.helpers.utilities.flatten(points)[source]¶
Flatten the points and return it as a list.
- Parameters:
points – A sequence of points.
- Returns:
A flattened list of points.
- simetri.helpers.utilities.flatten2(nested_list)[source]¶
Flatten a nested list.
- Parameters:
nested_list – The nested list to flatten.
- Yields:
The flattened elements.
- simetri.helpers.utilities.get_file_path_with_rev(directory, script_path, ext='.pdf')[source]¶
Get the file path with a revision number.
- Parameters:
directory – The directory to search for files.
script_path – The script file path.
ext – The file extension.
- Returns:
The file path with a revision number.
- simetri.helpers.utilities.get_text_dimensions(text, font_path, font_size)[source]¶
Return the width and height of the text.
- Parameters:
text – The text to measure.
font_path – The path to the font file.
font_size – The size of the font.
- Returns:
A tuple containing the width and height of the text.
- simetri.helpers.utilities.get_transform(transform)[source]¶
Return the transformation matrix.
- Parameters:
transform – The transformation matrix or sequence.
- Returns:
The transformation matrix.
- simetri.helpers.utilities.group_into_bins(values, delta)[source]¶
Group values into bins.
- Parameters:
values – A list of numbers.
delta – The bin size.
- Returns:
A list of bins.
- simetri.helpers.utilities.inv_lerp(start, end, value)[source]¶
Inverse linear interpolation of two values.
- Parameters:
start – The start value.
end – The end value.
value – The value to interpolate.
- Returns:
The interpolation factor (0 <= t <= 1).
- simetri.helpers.utilities.is_file_empty(file_path)[source]¶
Check if a file is empty.
- Parameters:
file_path – The path to the file.
- Returns:
True if the file is empty, False otherwise.
- simetri.helpers.utilities.is_nested_sequence(value)[source]¶
Check if a value is a nested sequence.
- Parameters:
value – The value to check.
- Returns:
True if the value is a nested sequence, False otherwise.
- simetri.helpers.utilities.is_numeric_numpy_array(array_)[source]¶
Check if it is an array of numbers.
- Parameters:
array – The array to check.
- Returns:
True if the array is numeric, False otherwise.
- simetri.helpers.utilities.is_sequence(value)[source]¶
Check if a value is a sequence.
- Parameters:
value – The value to check.
- Returns:
True if the value is a sequence, False otherwise.
- simetri.helpers.utilities.is_xform_matrix(matrix)[source]¶
Check if it is a 3x3 transformation matrix.
- Parameters:
matrix – The matrix to check.
- Returns:
True if the matrix is a 3x3 transformation matrix, False otherwise.
- simetri.helpers.utilities.lerp(start, end, t)[source]¶
Linear interpolation of two values.
- Parameters:
start – The start value.
end – The end value.
t – The interpolation factor (0 <= t <= 1).
- Returns:
The interpolated value.
- simetri.helpers.utilities.map_ranges(value: float, range1_min: float, range1_max: float, range2_min: float, range2_max: float) float [source]¶
Map a value from one range to another.
- Parameters:
value – The value to map.
range1_min – The minimum of the first range.
range1_max – The maximum of the first range.
range2_min – The minimum of the second range.
range2_max – The maximum of the second range.
- Returns:
The mapped value.
- simetri.helpers.utilities.nested_count(nested_sequence)[source]¶
Return the total number of items in a nested sequence.
- Parameters:
nested_sequence – A nested sequence.
- Returns:
The total number of items in the nested sequence.
- simetri.helpers.utilities.pretty_print_coords(coords: Sequence[Sequence[float]]) str [source]¶
Print the coordinates with a precision of 2.
- Parameters:
coords – A sequence of Point objects.
- Returns:
A string representation of the coordinates.
- simetri.helpers.utilities.prime_factors(n)[source]¶
Prime factorization.
- Parameters:
n – The number to factorize.
- Returns:
A list of prime factors.
- simetri.helpers.utilities.rc(dx: float, dy: float, origin)¶
Return the relative coordinates.
- Parameters:
dx – The x-coordinate difference.
dy – The y-coordinate difference.
origin – The origin coordinates.
- Returns:
The relative coordinates.
- simetri.helpers.utilities.reg_poly_points(pos: Sequence[float], n: int, r: float) Sequence[Sequence[float]] [source]¶
Return a regular polygon points list with n sides, r radius, and pos center.
- Parameters:
pos – The center position of the polygon.
n – The number of sides.
r – The radius.
- Returns:
A sequence of points representing the polygon.
- simetri.helpers.utilities.rel_coord(dx: float, dy: float, origin)[source]¶
Return the relative coordinates.
- Parameters:
dx – The x-coordinate difference.
dy – The y-coordinate difference.
origin – The origin coordinates.
- Returns:
The relative coordinates.
- simetri.helpers.utilities.rel_polar(r: float, angle: float, origin)[source]¶
Return the coordinates.
- Parameters:
r – The radius.
angle – The angle in radians.
origin – The origin coordinates.
- Returns:
The coordinates.
- simetri.helpers.utilities.remove_file_handler(logger, handler)[source]¶
Remove a handler from a logger.
- Parameters:
logger – The logger instance.
handler – The handler to remove.
- simetri.helpers.utilities.round2(n: float, cutoff: int = 25) int [source]¶
Round a number to the nearest multiple of cutoff.
- Parameters:
n – The number to round.
cutoff – The cutoff value.
- Returns:
The rounded number.
- simetri.helpers.utilities.rp(r: float, angle: float, origin)¶
Return the coordinates.
- Parameters:
r – The radius.
angle – The angle in radians.
origin – The origin coordinates.
- Returns:
The coordinates.
- simetri.helpers.utilities.sanitize_graph_edges(edges)[source]¶
Sanitize graph edges.
- Parameters:
edges – A list of graph edges.
- Returns:
A sanitized list of graph edges.
- simetri.helpers.utilities.sanitize_weighted_graph_edges(edges)[source]¶
Sanitize weighted graph edges.
- Parameters:
edges – A list of weighted graph edges.
- Returns:
A sanitized list of weighted graph edges.
- simetri.helpers.utilities.timing(func)[source]¶
Print the execution time of a function.
- Parameters:
func – The function to time.
- Returns:
The wrapped function.
- simetri.helpers.utilities.wait_for_file_availability(file_path, timeout=None, check_interval=1)[source]¶
Check if a file is available for writing.
- Parameters:
file_path – The path to the file.
timeout – The timeout period in seconds.
check_interval – The interval to check the file availability.
- Returns:
True if the file is available, False otherwise.
simetri.helpers.validation module¶
Validation functions for the user entered argument values and kwargs.
- exception simetri.helpers.validation.VersionConflict[source]¶
Bases:
Exception
Exception raised for version conflicts.
- simetri.helpers.validation.check_anchor(anchor: Any) bool [source]¶
Check if the anchor is a valid anchor.
- Parameters:
anchor (Any) – The anchor to check.
- Returns:
True if the anchor is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_blend_mode(blend_mode: Any) bool [source]¶
Check if the blend mode is a valid blend mode.
- Parameters:
blend_mode (Any) – The blend mode to check.
- Returns:
True if the blend mode is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_bool(value: Any) bool [source]¶
Check if the value is a boolean.
Boolean values need to be explicitly set to True or False. None is not a valid boolean value.
- Parameters:
value (Any) – The value to check.
- Returns:
True if the value is a boolean, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_color(color: Any) bool [source]¶
Check if the color is a valid color.
- Parameters:
color (Any) – The color to check.
- Returns:
True if the color is a valid color, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_dash_array(dash_array: Any) bool [source]¶
Check if the dash array is a list of numbers or predefined.
- Parameters:
dash_array (Any) – The dash array to check.
- Returns:
True if the dash array is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_enum(value: Any, enum: Any) bool [source]¶
Check if the value is a valid enum value.
- Parameters:
value (Any) – The value to check.
enum (Any) – The enum to check against.
- Returns:
True if the value is a valid enum value, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_int(value: Any) bool [source]¶
Check if the value is an integer.
- Parameters:
value (Any) – The value to check.
- Returns:
True if the value is an integer, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_line_width(line_width: Any) bool [source]¶
Check if the line width is a valid line width.
- Parameters:
line_width (Any) – The line width to check.
- Returns:
True if the line width is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_mask(mask: Any) bool [source]¶
This check is done in Batch class.
- Parameters:
mask (Any) – The mask to check.
- Returns:
True if the mask is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_number(number: Any) bool [source]¶
Check if the number is a valid number.
- Parameters:
number (Any) – The number to check.
- Returns:
True if the number is a valid number, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_points(points: Any) bool [source]¶
Check if the points are a valid list of points.
- Parameters:
points (Any) – The points to check.
- Returns:
True if the points are valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_position(pos: Any) bool [source]¶
Check if the position is a valid position.
- Parameters:
pos (Any) – The position to check.
- Returns:
True if the position is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_str(value: Any) bool [source]¶
Check if the value is a string.
- Parameters:
value (Any) – The value to check.
- Returns:
True if the value is a string, False otherwise.
- Return type:
bool
- simetri.helpers.validation.check_subtype(subtype: Any) bool [source]¶
This check is done in Shape class.
- Parameters:
subtype (Any) – The subtype to check.
- Returns:
True
- Return type:
bool
- simetri.helpers.validation.check_version(required_version: str) bool [source]¶
Check if the current version is compatible with the required version.
- Parameters:
required_version (str) – The required version as a string.
- Raises:
VersionConflict – If the current version is lower than the required version.
- Returns:
True if the current version is compatible.
- Return type:
bool
- simetri.helpers.validation.check_xform_matrix(matrix: Any) bool [source]¶
Check if the matrix is a valid transformation matrix.
- Parameters:
matrix (Any) – The matrix to check.
- Returns:
True if the matrix is valid, False otherwise.
- Return type:
bool
- simetri.helpers.validation.validate_args(args: Dict[str, Any], valid_args: list[str]) None [source]¶
Validate the user entered arguments.
- Parameters:
args (Dict[str, Any]) – The arguments to validate.
valid_args (list[str]) – The list of valid argument keys.
- Raises:
ValueError – If an invalid key or value is found.
- Returns:
None
simetri.helpers.vector module¶
- class simetri.helpers.vector.Vector2D(x: float, y: float)[source]¶
Bases:
object
A 2D vector class.
- vector¶
The vector represented as a numpy array.
- Type:
np.ndarray
- cross(other: Tuple[float, float]) float [source]¶
Returns the cross product of self and other.
- Parameters:
other (Vec2) – The vector to cross with.
- Returns:
The cross product.
- Return type:
float
- dot(other: Tuple[float, float]) float [source]¶
Returns the dot product of self and other.
- Parameters:
other (Vec2) – The vector to dot with.
- Returns:
The dot product.
- Return type:
float