kumiki.patternbook¶
Flat import path
kumiki/__init__.py re-exports everything on this page via from kumiki import *, so every name below is also available directly as kumiki.PatternLambda -- you do not need to import from the submodule path shown in the heading above.
kumiki.patternbook
¶
PatternBook - Helper structure for generating and organizing example patterns
This module provides a convenient way to organize multiple patterns (frames or CSG objects) and raise them at different positions for visualization and testing.
Pattern
dataclass
¶
Pattern(path: str, lambda_: PatternLambda, tags: List[str] = list(), pattern_type: Literal['frame', 'csg'] = 'frame')
A single renderable pattern in the new pattern system.
hierarchical path like "corner_joints/cut_plain_miter_joint".
Each path segment is an implicit tag for filtering.
lambda_: callable(center: V3, **kwargs) -> Frame | CutCSG tags: explicit tags. Special values: 'main' (default display when file opened), 'poop' (hide from sidebar). pattern_type: 'frame' or 'csg'
PatternMetadata
dataclass
¶
PatternMetadata(pattern_name: str, pattern_group_names: List[str] = list(), pattern_type: Literal['frame', 'csg'] = 'frame')
Metadata describing a pattern in the pattern book.
Attributes:
| Name | Type | Description |
|---|---|---|
pattern_name |
str
|
Unique name for this pattern |
pattern_group_names |
List[str]
|
List of group names to organize related patterns |
pattern_type |
Literal['frame', 'csg']
|
Type of pattern - either 'frame' or 'csg' |
pattern_group_names
class-attribute
instance-attribute
¶
PatternBook
dataclass
¶
PatternBook(patterns: List[Tuple[PatternMetadata, PatternLambda]] = list())
A collection of patterns with functions to raise them at different positions.
Patterns can be either Frame objects or CutCSG objects, and can be organized into groups for batch visualization with spacing.
Attributes:
| Name | Type | Description |
|---|---|---|
patterns |
List[Tuple[PatternMetadata, PatternLambda]]
|
List of (PatternMetadata, PatternLambda) pairs |
patterns
class-attribute
instance-attribute
¶
patterns: List[Tuple[PatternMetadata, PatternLambda]] = field(default_factory=list)
__post_init__
¶
Validate pattern names are unique.
Source code in kumiki/patternbook.py
raise_pattern
¶
raise_pattern(pattern_name: str, center: Optional[V3] = None, **pattern_kwargs: Any) -> Union[Frame, CutCSG]
Raise a single pattern by name at the specified center location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_name
|
str
|
Name of the pattern to raise |
required |
center
|
Optional[V3]
|
Center location for the pattern (default: origin) |
None
|
Returns:
| Type | Description |
|---|---|
Union[Frame, CutCSG]
|
Frame or CutCSG object at the specified location |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pattern_name is not found |
Source code in kumiki/patternbook.py
raise_pattern_group
¶
raise_pattern_group(group_name: str, separation_distance: Union[float, int], start_center: Optional[V3] = None) -> Union[Frame, List[CutCSG]]
Raise all patterns in a group, separated by the specified distance along the X-axis.
For frame patterns: Breaks apart individual frames and builds a megaframe from all of them. For CSG patterns: Returns a list of CSG objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_name
|
str
|
Name of the group to raise |
required |
separation_distance
|
Union[float, int]
|
Distance between pattern centers along X-axis |
required |
start_center
|
Optional[V3]
|
Starting center location (default: origin) |
None
|
Returns:
| Type | Description |
|---|---|
Union[Frame, List[CutCSG]]
|
For frame patterns: A single Frame containing all cut timbers from all patterns |
Union[Frame, List[CutCSG]]
|
For CSG patterns: A list of CutCSG objects |
Raises:
| Type | Description |
|---|---|
ValueError
|
If group_name is not found or if frame and CSG patterns are mixed |
Source code in kumiki/patternbook.py
raise_patternbook_as_frame
¶
raise_patternbook_as_frame(separation_distance: Union[float, int] = scalar(2), start_center: Optional[V3] = None) -> Frame
Raise this PatternBook as a single combined Frame.
Prefers raise_pattern_group when one group covers all patterns.
Falls back to raising each frame pattern by position and combining.
Source code in kumiki/patternbook.py
list_patterns
¶
List all pattern names in the book.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of pattern names |
list_groups
¶
List all unique group names in the book.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of group names (flattened from all patterns) |
Source code in kumiki/patternbook.py
get_patterns_in_group
¶
Get all pattern names in a specific group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_name
|
str
|
Name of the group |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of pattern names in the group |
Source code in kumiki/patternbook.py
merge
¶
merge(other: PatternBook) -> PatternBook
Merge another PatternBook into a new PatternBook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
PatternBook
|
Another PatternBook to merge with this one |
required |
Returns:
| Type | Description |
|---|---|
PatternBook
|
A new PatternBook containing patterns from both books |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are duplicate pattern names |
Source code in kumiki/patternbook.py
merge_multiple
staticmethod
¶
merge_multiple(pattern_books: List[PatternBook]) -> PatternBook
Merge multiple PatternBooks into a single PatternBook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_books
|
List[PatternBook]
|
List of PatternBooks to merge |
required |
Returns:
| Type | Description |
|---|---|
PatternBook
|
A new PatternBook containing patterns from all books |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are duplicate pattern names |
Source code in kumiki/patternbook.py
make_pattern_from_joint
¶
make_pattern_from_joint(joint_func: Callable[..., Joint]) -> PatternLambda
Convert a joint function (no args, returns a joint with cut_timbers and jointAccessories) to a pattern lambda that accepts center and returns a Frame with all timbers and accessories translated by center.
Source code in kumiki/patternbook.py
make_pattern_from_frame
¶
make_pattern_from_frame(frame_func: Callable[..., Frame]) -> PatternLambda
Convert a Frame-returning function (no args) to a pattern lambda that accepts center and returns a Frame with all timbers and accessories translated by center.
Source code in kumiki/patternbook.py
make_pattern_from_csg
¶
make_pattern_from_csg(csg_func: Callable[..., CutCSG]) -> PatternLambda
Convert a CSG-returning function (no args) to a pattern lambda that accepts center and returns the CSG translated by center. Consistent with frame/joint patterns: the returned CSG is positioned at the given center.