Skip to content

solid_figures

converter.converter.solid_figures

BoxFigure dataclass

Bases: SolidFigure

A rectangular box (cuboid). The figure can be rotated (meaning its walls don't have to be aligned with the axes of the coordinate system). The edge lengths are the final lengths of each edge, not the distance from the center of the figure (meaning they are full-size not half-size, for example: the edge lengths 1, 1, 1 will result in a 1 by 1 by 1 cube).

Source code in yaptide/converter/converter/solid_figures.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@dataclass(frozen=False)
class BoxFigure(SolidFigure):
    """
    A rectangular box (cuboid). The figure can be rotated (meaning its walls don't have
    to be aligned with the axes of the coordinate system). The edge lengths are the final lengths of
    each edge, not the distance from the center of the figure (meaning they are full-size not half-size,
    for example: the edge lengths 1, 1, 1 will result in a 1 by 1 by 1 cube).
    """

    x_edge_length: float = 1.
    y_edge_length: float = 1.
    z_edge_length: float = 1.

    def expand(self, margin: float) -> None:
        """
        Expand the figure by `margin` in each dimension.
        Increases figures weight, depth and height by 2 * `margin` to achieve the same
        expansion (1 * `margin`) on each side.
        """
        self.x_edge_length += margin * 2
        self.y_edge_length += margin * 2
        self.z_edge_length += margin * 2

x_edge_length class-attribute instance-attribute

x_edge_length = 1.0

y_edge_length class-attribute instance-attribute

y_edge_length = 1.0

z_edge_length class-attribute instance-attribute

z_edge_length = 1.0

__init__

__init__(
    uuid="AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
    name="",
    position=lambda: (0.0, 0.0, 0.0)(),
    rotation=lambda: (0.0, 0.0, 0.0)(),
    x_edge_length=1.0,
    y_edge_length=1.0,
    z_edge_length=1.0,
)

expand

expand(margin)

Expand the figure by margin in each dimension. Increases figures weight, depth and height by 2 * margin to achieve the same expansion (1 * margin) on each side.

Source code in yaptide/converter/converter/solid_figures.py
71
72
73
74
75
76
77
78
79
def expand(self, margin: float) -> None:
    """
    Expand the figure by `margin` in each dimension.
    Increases figures weight, depth and height by 2 * `margin` to achieve the same
    expansion (1 * `margin`) on each side.
    """
    self.x_edge_length += margin * 2
    self.y_edge_length += margin * 2
    self.z_edge_length += margin * 2

CylinderFigure dataclass

Bases: SolidFigure

A cylinder, a cone or a truncated cone. It's defined by the radii of both of its bases(top and bottom) and height. A cone can be created by setting one of the radii to zero.

Source code in yaptide/converter/converter/solid_figures.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@dataclass(frozen=False)
class CylinderFigure(SolidFigure):
    """
    A cylinder, a cone or a truncated cone. It's defined by the radii of both of
    its bases(top and bottom) and height. A cone can be created by setting one
    of the radii to zero.
    """

    radius_top: float = 1.
    radius_bottom: float = 1.
    height: float = 1.

    def expand(self, margin: float) -> None:
        """
        Expand the figure by `margin` in each dimension.
        Increases figures height by 2 * `margin` (to achieve the same expansion by 1 * `margin` on the
        bottom and top side.
        Increase as well bottom and top radius by 1 * `margin`.
        """
        self.radius_top += margin
        self.radius_bottom += margin
        self.height += margin * 2

height class-attribute instance-attribute

height = 1.0

radius_bottom class-attribute instance-attribute

radius_bottom = 1.0

radius_top class-attribute instance-attribute

radius_top = 1.0

__init__

__init__(
    uuid="AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
    name="",
    position=lambda: (0.0, 0.0, 0.0)(),
    rotation=lambda: (0.0, 0.0, 0.0)(),
    radius_top=1.0,
    radius_bottom=1.0,
    height=1.0,
)

expand

expand(margin)

Expand the figure by margin in each dimension. Increases figures height by 2 * margin (to achieve the same expansion by 1 * margin on the bottom and top side. Increase as well bottom and top radius by 1 * margin.

Source code in yaptide/converter/converter/solid_figures.py
46
47
48
49
50
51
52
53
54
55
def expand(self, margin: float) -> None:
    """
    Expand the figure by `margin` in each dimension.
    Increases figures height by 2 * `margin` (to achieve the same expansion by 1 * `margin` on the
    bottom and top side.
    Increase as well bottom and top radius by 1 * `margin`.
    """
    self.radius_top += margin
    self.radius_bottom += margin
    self.height += margin * 2

SolidFigure dataclass

Bases: ABC

Abstract solid figure in 3D space. It is characterised by position in space and rotation along X,Y,Z axis in its own reference frame. Size of the figure (its extend in space) is defined in its subclasses.

Source code in yaptide/converter/converter/solid_figures.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
@dataclass(frozen=False)
class SolidFigure(ABC):
    """
    Abstract solid figure in 3D space. It is characterised by position in
    space and rotation along X,Y,Z axis in its own reference frame. Size of
    the figure (its extend in space) is defined in its subclasses.
    """

    uuid: str = "AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
    name: str = ""

    position: tuple[float, float, float] = field(default_factory=lambda: (0., 0., 0.))
    rotation: tuple[float, float, float] = field(default_factory=lambda: (0., 0., 0.))

    def expand(self, margin: float) -> None:
        """Expand figure by `expansion` in each dimension."""

name class-attribute instance-attribute

name = ''

position class-attribute instance-attribute

position = field(default_factory=lambda: (0.0, 0.0, 0.0))

rotation class-attribute instance-attribute

rotation = field(default_factory=lambda: (0.0, 0.0, 0.0))

uuid class-attribute instance-attribute

uuid = 'AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'

__init__

__init__(
    uuid="AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
    name="",
    position=lambda: (0.0, 0.0, 0.0)(),
    rotation=lambda: (0.0, 0.0, 0.0)(),
)

expand

expand(margin)

Expand figure by expansion in each dimension.

Source code in yaptide/converter/converter/solid_figures.py
19
20
def expand(self, margin: float) -> None:
    """Expand figure by `expansion` in each dimension."""

SphereFigure dataclass

Bases: SolidFigure

A sphere. Its size is defined by its radius.

Source code in yaptide/converter/converter/solid_figures.py
23
24
25
26
27
28
29
30
31
@dataclass(frozen=False)
class SphereFigure(SolidFigure):
    """A sphere. Its size is defined by its radius."""

    radius: float = 1.

    def expand(self, margin: float) -> None:
        """Expand figure by `margin` in each dimension. Increases figure radius by adding to it a `margin`"""
        self.radius += margin

radius class-attribute instance-attribute

radius = 1.0

__init__

__init__(
    uuid="AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
    name="",
    position=lambda: (0.0, 0.0, 0.0)(),
    rotation=lambda: (0.0, 0.0, 0.0)(),
    radius=1.0,
)

expand

expand(margin)

Expand figure by margin in each dimension. Increases figure radius by adding to it a margin

Source code in yaptide/converter/converter/solid_figures.py
29
30
31
def expand(self, margin: float) -> None:
    """Expand figure by `margin` in each dimension. Increases figure radius by adding to it a `margin`"""
    self.radius += margin

parse_figure

parse_figure(figure_dict)

Parse json containing information about figure to figure.

Source code in yaptide/converter/converter/solid_figures.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def parse_figure(figure_dict: dict) -> SolidFigure:
    """Parse json containing information about figure to figure."""
    geometry_type = figure_dict['geometryData'].get('geometryType')
    if geometry_type in ("CyliderGeometry", "HollowCylinderGeometry"):
        return CylinderFigure(
            uuid=figure_dict["uuid"],
            name=figure_dict["name"],
            position=tuple(figure_dict["geometryData"]["position"]),
            rotation=tuple(figure_dict["geometryData"]["rotation"]),
            radius_top=figure_dict["geometryData"]['parameters']["radius"],
            radius_bottom=figure_dict["geometryData"]['parameters']["radius"],
            height=figure_dict["geometryData"]['parameters']["depth"],
        )
    if geometry_type == "BoxGeometry":
        return BoxFigure(
            uuid=figure_dict["uuid"],
            name=figure_dict["name"],
            position=tuple(figure_dict["geometryData"]["position"]),
            rotation=tuple(figure_dict["geometryData"]["rotation"]),
            y_edge_length=figure_dict["geometryData"]['parameters']["height"],
            x_edge_length=figure_dict["geometryData"]['parameters']["width"],
            z_edge_length=figure_dict["geometryData"]['parameters']["depth"],
        )
    if geometry_type == "SphereGeometry":
        return SphereFigure(
            uuid=figure_dict["uuid"],
            name=figure_dict["name"],
            position=tuple(figure_dict["geometryData"]["position"]),
            rotation=tuple(figure_dict["geometryData"]["rotation"]),
            radius=figure_dict["geometryData"]['parameters']["radius"],
        )
    print(f"Invalid geometry of type \"{geometry_type}\" in figure \"{figure_dict.get('name')}\".")
    raise ValueError(
        "Geometry type must be either 'HollowCylinderGeometry', 'CylinderGeometry', 'BoxGeometry', or 'SphereGeometry'")