virtual_knitting_machine.visualizer.visualizer_elements.diagram_elements.float_path module
Module containing the components of Float Paths in machine state diagrams.
- class Float_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration mapping the orientation of a float relative to its neighboring loops to a specific type of curve best used to represent it.
- Direct_Neighbor = 'direct line'
- Behind_Neighbors = 'downward arc'
- In_Front_Of_Neighbors = 'upward arc'
- Crosses_Beds = 's-curve'
- Simple_Line = 'long line'
- property path_type: Path_Type
Returns: Path_Type: The path type used to create the specified float curvature.
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Float_Orientation_To_Neighbors(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of possible orientations of a float along a single bed.
- Curve_Into_Bed = 'curve into bed'
- Curve_Away_From_Bed = 'curve away from bed'
- Along_Bed = 'along bed'
- float_type_by_bed(is_front_bed)[source]
- Parameters:
is_front_bed (bool) – True if both loops are on a front bed. False if they are on a back bed.
- Returns:
Float type based on the orientation of the float and the given bed of its loops.
- Return type:
Notes
This method assumes the floats are both on the same bed.
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Float_Path(loop_1, loop_2, diagram_settings, same_bed_orientation=Float_Orientation_To_Neighbors.Curve_Away_From_Bed, **path_kwargs)[source]
Bases:
Path_ElementForms a path between to loop circles in the diagram.
Automatically adjusts the curvature of the path based on the relative positions of the loops and the assigned orientation to the loops already on that bed.
- __init__(loop_1, loop_2, diagram_settings, same_bed_orientation=Float_Orientation_To_Neighbors.Curve_Away_From_Bed, **path_kwargs)[source]
Initialize the Path SVG element.
- Parameters:
start_x (float) – The x coordinate of the path’s starting point relative to its parent.
start_y (float) – The y coordinate of the path’s starting point relative to its parent.
end_x (float) – The x coordinate of the path’s ending point relative to its parent.
end_y (float) – The y coordinate of the path’s ending point relative to its parent.
name (str) – The name of the path element used as the element id.
stroke (str) – The name of the stroke color used for this path.
stroke_width (int) – The width of the path line.
control_points (list[tuple[float, float]], optional) – The control points of the path. Defaults to an empty list to form lines.
path_type (Path_Type) – The type of path element this SVG element represents. This should match the provided number of control points.
darken_stroke (bool, optional) – If True, the stroke color is automatically darkened (as in a fill color for loops on a yarn). Defaults to True.
**element_kwargs (Any) – Keyword arguments to configure the Path SVG element. Usually includes “stroke_width”.
- property same_slot: bool
Returns: bool: True if both loops are on a needle on the same slot. Otherwise, False.
- property float_type: Float_Type
Returns: Float_Type: The type of float curve to draw based on the relationship between the loops.
- property path_type: Path_Type
Returns: Path_Type: The path type that determines the curve of the float based on its relationship to other loops.
- property loop_1: Machine_Knit_Loop
Returns: Machine_Knit_Loop: The first loop in this float.
- property loop_2: Machine_Knit_Loop
Returns: Machine_Knit_Loop: The second loop in this float.
- property float_unique_id: str
Returns: str: The unique string identifier of the loop based on its id, the carrier that formed it, and the needle it is formed on.
- add_to_drawing(drawing)
Adds this element to the given svg drawing. :param drawing: The drawing to add. :type drawing: Drawing
- control_x(cp_index=1)
- control_y(cp_index=1)
- property cubic_bezier_path_data: str
Create a cubic Bézier curve with two control points.
- Visual appearance:
A smooth S-curve or complex curve that can change direction. The curve starts tangent to the line from start to control1 and ends tangent to the line from control2 to end. Can create S-shapes, loops, and complex paths.
Use cases: * Long yarn floats across multiple needles (creates natural drape). * Yarn paths that need to avoid obstacles (can curve around other elements). * Connecting loops on opposite beds with graceful curves. * Split operations where yarn paths diverge smoothly. * Transfer operations showing yarn movement across beds. * Any complex path requiring more control than quadratic Bezier.
This is the most flexible curve type, allowing for sophisticated yarn representations.
- Returns:
SVG path data string for the cubic Bézier curve.
- Return type:
- static darken_color(color='none', factor=0.7)
Darken a hex or named color.
- Parameters:
- Returns:
The color-string of the darkened color. If “none” color is given, this will return “black”.
- Return type:
- static fill_from_stroke(stroke, lighten_factor=0.3)
- property global_x: float
Returns: float: The global x coordinate of this element based on its parent’s coordinates.
- global_x_position(x)
- property global_y: float
Returns: float: The global y coordinate of this element based on its parent’s coordinates.
- global_y_position(y)
- static lighten_color(color='none', factor=0.3)
Lighten a hex or named color.
- Parameters:
- Returns:
The color-string of the lightened color. If “none” color is given, this will return “black”.
- Return type:
- property line_path_data: str
Create a straight line path.
Visual appearance: A direct straight line from start to end point.
Use cases: - Connecting loops on the same needle bed (vertical connections). - Drawing grid lines or reference marks. - Simple direct connections where curves are not needed. - Representing tight yarn segments with no slack.
- Returns:
The Path data string used to create a straight line path.
- Return type:
- property mid_x: float
Returns: float: The midpoint between the x coordinates at the start and end of the path.
- property mid_y: float
Returns: float: The midpoint between the y coordinates at the start and end of the path.
- property name: str
Returns: str: The unique name of this element. This will match the id of the svg element being wrapped.
- property quadratic_bezier_path_data: str
Create a quadratic Bézier curve with one control point.
- Visual appearance:
A smooth parabolic curve that bends toward the control point. The curve is always tangent to the line from start to control and from control to end. Creates a single, symmetric arc.
Use cases: * Simple yarn floats between adjacent needles (gentle arc) * Connecting parent and child loops in stitch diagrams * Tuck operations where yarn curves around a needle * Any connection requiring a single smooth bend * When you want a simpler, more predictable curve than cubic Bezier
- Default behavior:
If control point not specified, places it at the midpoint between start and end, offset perpendicular to create a gentle arc.
- Returns:
SVG path data string for the quadratic Bézier curve.
- Return type:
- set_cubic_crossing_curve()
Sets the path type to form a cube curve between the two points at diagonal positions from each other.
- set_cubic_downward_curve(peak_of_curve)
Sets the path type to a downward facing arc set at the midpoint between the start and end position and peaking above the highest end point.
- Parameters:
peak_of_curve (float) – The amount for the arc to peak above the highest end point.
- set_cubic_upward_curve(peak_of_curve)
Sets the path type to an up facing arc set at the midpoint between the start and end position and peaking below the lowest end point.
- Parameters:
peak_of_curve (int) – The amount for the arc to peak below the lowest end point.
- property start_x: float
Returns: float: The x coordinate of the path’s starting point relative to its parent.
- property start_y: float
Returns: float: The y coordinate of the path’s starting point relative to its parent.
- static stroke_from_fill(fill, darken_factor=0.7)
- property x: float
Returns: float: The x coordinate of this element relative to its parent (or globally).
- property x_dist: float
Returns: float: The distance between the x coordinates at the start and end of the path.