|
| 1 | +from typing import Optional |
| 2 | + |
1 | 3 | import Rhino # type: ignore |
2 | 4 | import rhinoscriptsyntax as rs # type: ignore |
3 | 5 | import scriptcontext as sc # type: ignore |
@@ -51,39 +53,37 @@ def settings(self): |
51 | 53 |
|
52 | 54 | @property |
53 | 55 | def diagram(self) -> Diagram: |
54 | | - return self.mesh |
| 56 | + return self.mesh # type: ignore |
55 | 57 |
|
56 | 58 | @diagram.setter |
57 | 59 | def diagram(self, diagram: Diagram) -> None: |
58 | 60 | self.mesh = diagram |
59 | 61 |
|
60 | | - def edges(self, **kwargs): |
61 | | - return self.diagram.edges(**kwargs) |
| 62 | + def edges(self, **kwargs) -> list[tuple[int, int]]: |
| 63 | + return self.diagram.edges(**kwargs) # type: ignore |
62 | 64 |
|
63 | | - def faces(self, **kwargs): |
64 | | - return self.diagram.faces(**kwargs) |
| 65 | + def faces(self, **kwargs) -> list[int]: |
| 66 | + return self.diagram.faces(**kwargs) # type: ignore |
65 | 67 |
|
66 | | - def forces(self): |
67 | | - return self.diagram.edges_attribute("_f", keys=self.edges()) |
| 68 | + def forces(self) -> list[float]: |
| 69 | + return self.diagram.edges_attribute("_f", keys=self.edges()) # type: ignore |
68 | 70 |
|
69 | | - def compute_edge_colors(self, tol=1e-3) -> None: |
| 71 | + def compute_edge_colors(self, tol=1e-3) -> list[Color]: |
70 | 72 | forces = self.forces() |
71 | 73 | magnitudes = [abs(f) for f in forces] |
72 | 74 | fmin = min(magnitudes) |
73 | 75 | fmax = max(magnitudes) |
74 | 76 |
|
75 | | - if fmax - fmin < tol: |
76 | | - # size of the range of forces is already checked here |
77 | | - # no need to check again in the loop |
78 | | - return |
79 | | - |
80 | 77 | colors = [] |
81 | 78 |
|
82 | | - for force, magnitude in zip(forces, magnitudes): |
83 | | - # this will need to be updated once we allow for tension forces |
84 | | - # or we have to exclude tension forces from the calculation |
85 | | - # and give tension edges their own style |
86 | | - colors.append(Color.from_i((magnitude - fmin) / (fmax - fmin))) |
| 79 | + if fmax - fmin >= tol: |
| 80 | + # size of the range of forces is already checked here |
| 81 | + # no need to check again in the loop |
| 82 | + for magnitude in magnitudes: |
| 83 | + # this will need to be updated once we allow for tension forces |
| 84 | + # or we have to exclude tension forces from the calculation |
| 85 | + # and give tension edges their own style |
| 86 | + colors.append(Color.from_i((magnitude - fmin) / (fmax - fmin))) |
87 | 87 |
|
88 | 88 | return colors |
89 | 89 |
|
|
0 commit comments