Coverage for yaptide/converter/converter/fluka/cards/figure_card.py: 60%
42 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-07-01 12:55 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-07-01 12:55 +0000
1from dataclasses import dataclass, field
2from converter.common import format_float
4from converter.fluka.helper_parsers.figure_parser import FlukaBox, FlukaCylinder, FlukaFigure, FlukaSphere
7@dataclass
8class FiguresCard:
9 """Class representing description of figures in Fluka input"""
11 data: list[FlukaFigure] = field(default_factory=lambda: [])
13 def __str__(self) -> str:
14 """Return the card as a string."""
15 result = ""
16 for index, figure in enumerate(self.data):
17 if index == 0:
18 line = ""
19 else:
20 line = "\n"
21 if type(figure) is FlukaBox:
22 x_min = format_float(figure.x_min, n=16)
23 x_max = format_float(figure.x_max, n=16)
24 y_min = format_float(figure.y_min, n=16)
25 y_max = format_float(figure.y_max, n=16)
26 z_min = format_float(figure.z_min, n=16)
27 z_max = format_float(figure.z_max, n=16)
28 x_length = format_float(figure.x_max - figure.x_min, n=16)
29 y_length = format_float(figure.y_max - figure.y_min, n=16)
30 z_length = format_float(figure.z_max - figure.z_min, n=16)
31 line += (f"* box {figure.name}\n"
32 f"* X range {x_min:+#}, {x_max:+#}\n"
33 f"* Y range {y_min:+#}, {y_max:+#}\n"
34 f"* Z range {z_min:+#}, {z_max:+#}\n"
35 f"* X, Y, Z side lengths:"
36 f" {x_length:+#}, {y_length:+#}, {z_length:+#}\n"
37 f"{figure.figure_type} {figure.name}"
38 f" {x_min:+#}"
39 f" {x_max:+#}"
40 f" {y_min:+#}"
41 f" {y_max:+#}"
42 f" {z_min:+#}"
43 f" {z_max:+#}")
44 elif type(figure) is FlukaCylinder:
45 x = format_float(figure.coordinates[0], n=16)
46 y = format_float(figure.coordinates[1], n=16)
47 z = format_float(figure.coordinates[2], n=16)
48 vector_x = format_float(figure.height_vector[0], n=16)
49 vector_y = format_float(figure.height_vector[1], n=16)
50 vector_z = format_float(figure.height_vector[2], n=16)
51 radius = format_float(figure.radius, n=16)
52 height = format_float(figure.height, n=16)
53 line += (f"* cylinder {figure.name}\n"
54 f"* bottom center ({x:+#}, {y:+#}, {z:+#}),"
55 f" spanning vector ({vector_x:+#}, {vector_y:+#}, {vector_z:+#}),\n"
56 f"* radius {radius:+#}, height {height:+#} cm\n"
57 f"* rotation angles: {figure.rotation[0]}*, "
58 f"{figure.rotation[1]}*, {figure.rotation[2]}*\n"
59 f"{figure.figure_type} {figure.name}"
60 f" {x:+#}"
61 f" {y:+#}"
62 f" {z:+#}"
63 f" {vector_x:+#}"
64 f" {vector_y:+#}\n"
65 f"{vector_z:+#}"
66 f" {radius:+#}")
67 elif type(figure) is FlukaSphere:
68 x = format_float(figure.coordinates[0], n=16)
69 y = format_float(figure.coordinates[1], n=16)
70 z = format_float(figure.coordinates[2], n=16)
71 radius = format_float(figure.radius, n=16)
72 line += (f"* sphere {figure.name}\n"
73 f"* center ({x:+#}, {y:+#}, {z:+#}),"
74 f" radius {radius:+#}\n"
75 f"{figure.figure_type} {figure.name}"
76 f" {x:+#}"
77 f" {y:+#}"
78 f" {z:+#}"
79 f" {radius:+#}")
80 else:
81 raise ValueError(f"Unexpected figure type: {figure}")
83 result += line
85 return result