Skip to content

Commit b0d30ef

Browse files
committed
fixed typing and added small bug fixes
1 parent f0dd7c5 commit b0d30ef

File tree

6 files changed

+64
-30
lines changed

6 files changed

+64
-30
lines changed

src/compas_model/geometry/gjk2.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from typing import Sequence
2+
from typing import Union
3+
14
from compas.geometry import Point
25
from compas.geometry import Polygon
36
from compas.geometry import Vector
47
from compas.geometry import dot_vectors
58

69

7-
def triplecross(u: Vector, v: Vector) -> Vector:
10+
def triplecross(u: Vector, v: Union[Point, Vector]) -> Vector:
811
"""Compute the vector perpendicular to u in the plane uxv and in the same directio as v.
912
1013
Parameters
@@ -27,7 +30,7 @@ def triplecross(u: Vector, v: Vector) -> Vector:
2730
# =============================================================================
2831

2932

30-
def support_poly(points: list[Point], direction: Vector) -> Point:
33+
def support_poly(points: Union[Polygon, Sequence[Union[Point, Vector]]], direction: Vector) -> Union[Point, Vector]:
3134
"""Find the point in a list of points that is farthest away from the origin in a given direction.
3235
3336
Parameters
@@ -52,7 +55,11 @@ def support_poly(points: list[Point], direction: Vector) -> Point:
5255
return point
5356

5457

55-
def support_poly_poly(A: list[Vector], B: list[Vector], direction: Vector) -> Vector:
58+
def support_poly_poly(
59+
A: Union[Polygon, Sequence[Union[Point, Vector]]],
60+
B: Union[Polygon, Sequence[Union[Point, Vector]]],
61+
direction: Vector,
62+
) -> Vector:
5663
"""Compute a support point on the Minkowski sum of A and -B in the given direction.
5764
5865
Parameters
@@ -77,7 +84,8 @@ def support_poly_poly(A: list[Vector], B: list[Vector], direction: Vector) -> Ve
7784
# =============================================================================
7885

7986

80-
def do_simplex(simplex: list[Point], direction: Vector) -> bool:
87+
def do_simplex(simplex: Sequence[Union[Point, Vector]], direction: Vector) -> bool:
88+
simplex = list(simplex)
8189
s = len(simplex)
8290

8391
if s < 2:
@@ -212,7 +220,7 @@ def is_collision_poly_poly_xy(A: Polygon, B: Polygon) -> bool:
212220
True
213221
214222
"""
215-
direction = [1, 0, 0]
223+
direction = Vector(1, 0, 0)
216224
point = support_poly_poly(A, B, direction)
217225
simplex = [point]
218226
direction = point * -1

src/compas_model/geometry/intersections.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
# =============================================================================
1515

1616

17-
def is_line_contained_locally(point: Point, direction: Vector, dx: float, dy: float, dz: float) -> bool:
17+
def is_line_contained_locally(
18+
point: Union[Point, Vector],
19+
direction: Vector,
20+
dx: float,
21+
dy: float,
22+
dz: float,
23+
) -> bool:
1824
"""Determine whether the direction vector from a specific point is contained within the specified coordinate extents.
1925
2026
Parameters
@@ -55,7 +61,11 @@ def is_line_contained_locally(point: Point, direction: Vector, dx: float, dy: fl
5561
return True
5662

5763

58-
def is_ray_contained_locally(point: Point, direction: Vector, extents: list[float]) -> bool:
64+
def is_ray_contained_locally(
65+
point: Union[Point, Vector],
66+
direction: Vector,
67+
extents: list[float],
68+
) -> bool:
5969
"""Determine whether a ray is contained within the given extents along local axes.
6070
6171
Parameters
@@ -81,7 +91,12 @@ def is_ray_contained_locally(point: Point, direction: Vector, extents: list[floa
8191
return is_line_contained_locally(point, direction, *extents)
8292

8393

84-
def is_segment_contained_locally(point: Point, direction: Vector, box_extents: list[float], segment_extent: float) -> bool:
94+
def is_segment_contained_locally(
95+
point: Union[Point, Vector],
96+
direction: Vector,
97+
box_extents: list[float],
98+
segment_extent: float,
99+
) -> bool:
85100
"""Determine whether a segment is contained within the given extents along local axes.
86101
87102
Parameters
@@ -588,7 +603,7 @@ def is_clipped(denominator: float, numerator: float, t: list[float]) -> bool:
588603
return numerator <= 0
589604

590605

591-
def intersections_line_box_locally(point: Point, direction: Vector, extents: list[float]) -> tuple[int, list[Point]]:
606+
def intersections_line_box_locally(point: Union[Point, Vector], direction: Vector, extents: list[float]) -> tuple[int, list[float]]:
592607
t = [-inf, inf]
593608
dx, dy, dz = extents
594609

@@ -616,7 +631,7 @@ def intersections_line_box_locally(point: Point, direction: Vector, extents: lis
616631
return count, t
617632

618633

619-
def intersections_ray_box_locally(point: Point, direction: Vector, extents: list[float]) -> tuple[int, list[Point]]:
634+
def intersections_ray_box_locally(point: Union[Point, Vector], direction: Vector, extents: list[float]) -> tuple[int, list[float]]:
620635
count, t = intersections_line_box_locally(point, direction, extents)
621636

622637
if count > 0:
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
# points = []
2-
# for a in A:
3-
# for b in B:
4-
# points.append(Point(*(a + b)))
5-
# indices, lines = convex_hull_xy_numpy(points)
6-
# C = Polygon([points[i] for i in indices])

src/compas_model/materials/concrete.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Literal
22
from typing import Optional
33

4+
from .errors import PropertyNotDefined
45
from .material import Material
56

67

@@ -135,7 +136,9 @@ def nu(self) -> float:
135136

136137
@property
137138
def G(self) -> float:
138-
return self.Ecm / (2 * (1 + self.nu))
139+
if self.Ecm:
140+
return self.Ecm / (2 * (1 + self.nu))
141+
raise PropertyNotDefined
139142

140143
@classmethod
141144
def from_strength_class(cls, strength_class: Literal["C10", "C15", "C20", "C25", "C30", "C35"]) -> "Concrete":
@@ -151,8 +154,8 @@ def from_strength_class(cls, strength_class: Literal["C10", "C15", "C20", "C25",
151154
:class:`Concrete`
152155
153156
"""
154-
strength_class = strength_class.upper()
155-
if strength_class not in cls.STRENGTH_CLASSES:
156-
raise ValueError("Strength class not supported: {}".format(strength_class))
157-
params = cls.STRENGTH_CLASSES[strength_class]
157+
strength_class_upper = strength_class.upper()
158+
if strength_class_upper not in cls.STRENGTH_CLASSES:
159+
raise ValueError("Strength class not supported: {}".format(strength_class_upper))
160+
params = cls.STRENGTH_CLASSES[strength_class_upper]
158161
return cls(**params)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class PropertyNotDefined(Exception):
2+
pass

src/compas_model/materials/steel.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@
66

77
class Steel(Material):
88
STRENGTH_CLASSES: dict[str, dict[str, float]] = {
9-
"S235": {"fy": 235, "fu": 360},
10-
"S275": {"fy": 275, "fu": 430},
11-
"S355": {"fy": 355, "fu": 490},
12-
"S450": {"fy": 450, "fu": 550},
9+
"S235": {
10+
"fy": 235,
11+
"fu": 360,
12+
},
13+
"S275": {
14+
"fy": 275,
15+
"fu": 430,
16+
},
17+
"S355": {
18+
"fy": 355,
19+
"fu": 490,
20+
},
21+
"S450": {
22+
"fy": 450,
23+
"fu": 550,
24+
},
1325
}
1426

1527
@property
@@ -58,8 +70,8 @@ def from_strength_class(cls, strength_class: Literal["S235", "S275", "S355", "S4
5870
:class:`Steel`
5971
6072
"""
61-
strength_class = strength_class.upper()
62-
if strength_class not in cls.STRENGTH_CLASSES:
63-
raise ValueError("This strength class is not supported: {}".format(strength_class))
64-
params = cls.STRENGTH_CLASSES[strength_class]
65-
return cls(**params)
73+
strength_class_upper = strength_class.upper()
74+
if strength_class_upper not in cls.STRENGTH_CLASSES:
75+
raise ValueError("This strength class is not supported: {}".format(strength_class_upper))
76+
params = cls.STRENGTH_CLASSES[strength_class_upper]
77+
return cls(**params) # type: ignore

0 commit comments

Comments
 (0)