Skip to content

Commit 706aa70

Browse files
authored
Update create_2pt_wall.py (IfcOpenShell#3553)
* Update create_2pt_wall.py included unit scale for use cases other than si unit * Revised Update create_2pt_wall.py included is_si kwarg to select between si units and other units and also changed the dtype of p1 and p2 array to float incase they are entered as integers
1 parent fe5a674 commit 706aa70

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/ifcopenshell-python/ifcopenshell/api/geometry/create_2pt_wall.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class Usecase:
25-
def __init__(self, file, element=None, context=None, p1=None, p2=None, elevation=None, height=None, thickness=None):
25+
def __init__(self, file, element=None, context=None, p1=None, p2=None, elevation=None, height=None, thickness=None, is_si=True):
2626
self.file = file
2727
self.settings = {
2828
"element": element,
@@ -32,15 +32,25 @@ def __init__(self, file, element=None, context=None, p1=None, p2=None, elevation
3232
"elevation": elevation,
3333
"height": height,
3434
"thickness": thickness,
35+
"is_si": is_si
3536
}
3637

3738
def execute(self):
3839
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
3940

40-
self.settings["p1"] = np.array(self.settings["p1"])
41-
self.settings["p2"] = np.array(self.settings["p2"])
41+
self.settings["p1"] = np.array(self.settings["p1"]).astype(float)
42+
self.settings["p2"] = np.array(self.settings["p2"]).astype(float)
4243

4344
length = float(np.linalg.norm(self.settings["p2"] - self.settings["p1"]))
45+
46+
if not self.settings["is_si"]:
47+
length=self.convert_unit_to_si(length)
48+
self.settings["height"]=self.convert_unit_to_si(self.settings["height"])
49+
self.settings["thickness"]=self.convert_unit_to_si(self.settings["thickness"])
50+
self.settings["p1"][0] = self.convert_unit_to_si(self.settings["p1"][0])
51+
self.settings["p1"][1] = self.convert_unit_to_si(self.settings["p1"][1])
52+
self.settings["elevation"] = self.convert_unit_to_si(self.settings["elevation"])
53+
4454
representation = ifcopenshell.api.run(
4555
"geometry.add_wall_representation",
4656
self.file,
@@ -55,7 +65,7 @@ def execute(self):
5565
[
5666
[v[0], -v[1], 0, self.settings["p1"][0]],
5767
[v[1], v[0], 0, self.settings["p1"][1]],
58-
[0, 0, 1, self.convert_si_to_unit(self.settings["elevation"])],
68+
[0, 0, 1, self.settings["elevation"]],
5969
[0, 0, 0, 1],
6070
]
6171
)
@@ -64,7 +74,5 @@ def execute(self):
6474
)
6575
return representation
6676

67-
def convert_si_to_unit(self, co):
68-
if isinstance(co, (tuple, list)):
69-
return [self.convert_si_to_unit(o) for o in co]
70-
return co / self.settings["unit_scale"]
77+
def convert_unit_to_si(self, co):
78+
return co * self.settings["unit_scale"]

0 commit comments

Comments
 (0)