honeybee-core 1.64.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- honeybee/__init__.py +23 -0
- honeybee/__main__.py +4 -0
- honeybee/_base.py +331 -0
- honeybee/_basewithshade.py +310 -0
- honeybee/_lockable.py +99 -0
- honeybee/altnumber.py +47 -0
- honeybee/aperture.py +997 -0
- honeybee/boundarycondition.py +358 -0
- honeybee/checkdup.py +173 -0
- honeybee/cli/__init__.py +118 -0
- honeybee/cli/compare.py +132 -0
- honeybee/cli/create.py +265 -0
- honeybee/cli/edit.py +559 -0
- honeybee/cli/lib.py +103 -0
- honeybee/cli/setconfig.py +43 -0
- honeybee/cli/validate.py +224 -0
- honeybee/colorobj.py +363 -0
- honeybee/config.json +5 -0
- honeybee/config.py +347 -0
- honeybee/dictutil.py +54 -0
- honeybee/door.py +746 -0
- honeybee/extensionutil.py +208 -0
- honeybee/face.py +2360 -0
- honeybee/facetype.py +153 -0
- honeybee/logutil.py +79 -0
- honeybee/model.py +4272 -0
- honeybee/orientation.py +132 -0
- honeybee/properties.py +845 -0
- honeybee/room.py +3485 -0
- honeybee/search.py +107 -0
- honeybee/shade.py +514 -0
- honeybee/shademesh.py +362 -0
- honeybee/typing.py +498 -0
- honeybee/units.py +88 -0
- honeybee/writer/__init__.py +7 -0
- honeybee/writer/aperture.py +6 -0
- honeybee/writer/door.py +6 -0
- honeybee/writer/face.py +6 -0
- honeybee/writer/model.py +6 -0
- honeybee/writer/room.py +6 -0
- honeybee/writer/shade.py +6 -0
- honeybee/writer/shademesh.py +6 -0
- honeybee_core-1.64.12.dist-info/METADATA +94 -0
- honeybee_core-1.64.12.dist-info/RECORD +48 -0
- honeybee_core-1.64.12.dist-info/WHEEL +5 -0
- honeybee_core-1.64.12.dist-info/entry_points.txt +2 -0
- honeybee_core-1.64.12.dist-info/licenses/LICENSE +661 -0
- honeybee_core-1.64.12.dist-info/top_level.txt +1 -0
honeybee/face.py
ADDED
|
@@ -0,0 +1,2360 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
"""Honeybee Face."""
|
|
3
|
+
from __future__ import division
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from ladybug_geometry.geometry2d import Vector2D, Point2D, Polygon2D, Mesh2D
|
|
8
|
+
from ladybug_geometry.geometry3d import Vector3D, Point3D, Plane, Face3D
|
|
9
|
+
from ladybug.color import Color
|
|
10
|
+
|
|
11
|
+
from ._basewithshade import _BaseWithShade
|
|
12
|
+
from .typing import clean_string, invalid_dict_error
|
|
13
|
+
from .search import get_attr_nested
|
|
14
|
+
from .properties import FaceProperties
|
|
15
|
+
from .facetype import face_types, get_type_from_normal, AirBoundary, Wall, \
|
|
16
|
+
Floor, RoofCeiling
|
|
17
|
+
from .boundarycondition import boundary_conditions, get_bc_from_position, \
|
|
18
|
+
_BoundaryCondition, Outdoors, Surface, Ground
|
|
19
|
+
from .shade import Shade
|
|
20
|
+
from .aperture import Aperture
|
|
21
|
+
from .door import Door
|
|
22
|
+
import honeybee.boundarycondition as hbc
|
|
23
|
+
import honeybee.writer.face as writer
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Face(_BaseWithShade):
|
|
27
|
+
"""A single planar face.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
identifier: Text string for a unique Face ID. Must be < 100 characters and
|
|
31
|
+
not contain any spaces or special characters.
|
|
32
|
+
geometry: A ladybug-geometry Face3D.
|
|
33
|
+
type: Face type. Default varies depending on the direction that
|
|
34
|
+
the Face geometry is points.
|
|
35
|
+
RoofCeiling = pointing upward within 30 degrees
|
|
36
|
+
Wall = oriented vertically within +/- 60 degrees
|
|
37
|
+
Floor = pointing downward within 30 degrees
|
|
38
|
+
boundary_condition: Face boundary condition (Outdoors, Ground, etc.)
|
|
39
|
+
Default is Outdoors unless all vertices of the geometry lie
|
|
40
|
+
below the below the XY plane, in which case it will be set to Ground.
|
|
41
|
+
|
|
42
|
+
Properties:
|
|
43
|
+
* identifier
|
|
44
|
+
* display_name
|
|
45
|
+
* type
|
|
46
|
+
* boundary_condition
|
|
47
|
+
* apertures
|
|
48
|
+
* doors
|
|
49
|
+
* sub_faces
|
|
50
|
+
* indoor_shades
|
|
51
|
+
* outdoor_shades
|
|
52
|
+
* parent
|
|
53
|
+
* has_parent
|
|
54
|
+
* has_sub_faces
|
|
55
|
+
* can_be_ground
|
|
56
|
+
* geometry
|
|
57
|
+
* punched_geometry
|
|
58
|
+
* vertices
|
|
59
|
+
* punched_vertices
|
|
60
|
+
* upper_left_vertices
|
|
61
|
+
* normal
|
|
62
|
+
* center
|
|
63
|
+
* area
|
|
64
|
+
* perimeter
|
|
65
|
+
* min
|
|
66
|
+
* max
|
|
67
|
+
* aperture_area
|
|
68
|
+
* aperture_ratio
|
|
69
|
+
* tilt
|
|
70
|
+
* altitude
|
|
71
|
+
* azimuth
|
|
72
|
+
* is_exterior
|
|
73
|
+
* type_color
|
|
74
|
+
* bc_color
|
|
75
|
+
* user_data
|
|
76
|
+
"""
|
|
77
|
+
TYPES = face_types
|
|
78
|
+
__slots__ = ('_geometry', '_parent', '_punched_geometry',
|
|
79
|
+
'_apertures', '_doors', '_type', '_boundary_condition')
|
|
80
|
+
TYPE_COLORS = {
|
|
81
|
+
'Wall': Color(230, 180, 60),
|
|
82
|
+
'RoofCeiling': Color(128, 20, 20),
|
|
83
|
+
'Floor': Color(128, 128, 128),
|
|
84
|
+
'AirBoundary': Color(255, 255, 200, 100),
|
|
85
|
+
'InteriorWall': Color(230, 215, 150),
|
|
86
|
+
'InteriorRoofCeiling': Color(255, 128, 128),
|
|
87
|
+
'InteriorFloor': Color(255, 128, 128),
|
|
88
|
+
'InteriorAirBoundary': Color(255, 255, 200, 100)
|
|
89
|
+
}
|
|
90
|
+
BC_COLORS = {
|
|
91
|
+
'Outdoors': Color(64, 180, 255),
|
|
92
|
+
'Surface': Color(0, 128, 0),
|
|
93
|
+
'Ground': Color(165, 82, 0),
|
|
94
|
+
'Adiabatic': Color(255, 128, 128),
|
|
95
|
+
'Other': Color(255, 255, 200)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
def __init__(self, identifier, geometry, type=None, boundary_condition=None):
|
|
99
|
+
"""A single planar face."""
|
|
100
|
+
_BaseWithShade.__init__(self, identifier) # process the identifier
|
|
101
|
+
|
|
102
|
+
# process the geometry
|
|
103
|
+
assert isinstance(geometry, Face3D), \
|
|
104
|
+
'Expected ladybug_geometry Face3D. Got {}'.format(geometry)
|
|
105
|
+
self._geometry = geometry
|
|
106
|
+
self._parent = None # _parent will be set when the Face is added to a Room
|
|
107
|
+
# initialize with no apertures/doors (they can be assigned later)
|
|
108
|
+
self._punched_geometry = None
|
|
109
|
+
self._apertures = []
|
|
110
|
+
self._doors = []
|
|
111
|
+
|
|
112
|
+
# initialize properties for extensions
|
|
113
|
+
self._properties = FaceProperties(self)
|
|
114
|
+
|
|
115
|
+
# set face type based on normal if not provided
|
|
116
|
+
if type is not None:
|
|
117
|
+
assert type in self.TYPES, '{} is not a valid face type.'.format(type)
|
|
118
|
+
self._type = type or get_type_from_normal(geometry.normal)
|
|
119
|
+
|
|
120
|
+
# set boundary condition by the relation to a zero ground plane if not provided
|
|
121
|
+
self.boundary_condition = boundary_condition or \
|
|
122
|
+
get_bc_from_position(geometry.boundary)
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def from_dict(cls, data):
|
|
126
|
+
"""Initialize an Face from a dictionary.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
data: A dictionary representation of an Face object.
|
|
130
|
+
"""
|
|
131
|
+
try:
|
|
132
|
+
# check the type of dictionary
|
|
133
|
+
assert data['type'] == 'Face', 'Expected Face dictionary. ' \
|
|
134
|
+
'Got {}.'.format(data['type'])
|
|
135
|
+
|
|
136
|
+
# first serialize it with an outdoor boundary condition
|
|
137
|
+
face_type = face_types.by_name(data['face_type'])
|
|
138
|
+
face = cls(data['identifier'], Face3D.from_dict(data['geometry']),
|
|
139
|
+
face_type, boundary_conditions.outdoors)
|
|
140
|
+
if 'display_name' in data and data['display_name'] is not None:
|
|
141
|
+
face.display_name = data['display_name']
|
|
142
|
+
if 'user_data' in data and data['user_data'] is not None:
|
|
143
|
+
face.user_data = data['user_data']
|
|
144
|
+
|
|
145
|
+
# add sub-faces and shades
|
|
146
|
+
if 'apertures' in data and data['apertures'] is not None:
|
|
147
|
+
aps = []
|
|
148
|
+
for ap in data['apertures']:
|
|
149
|
+
try:
|
|
150
|
+
aps.append(Aperture.from_dict(ap))
|
|
151
|
+
except Exception as e:
|
|
152
|
+
invalid_dict_error(ap, e)
|
|
153
|
+
face.add_apertures(aps)
|
|
154
|
+
if 'doors' in data and data['doors'] is not None:
|
|
155
|
+
drs = []
|
|
156
|
+
for dr in data['doors']:
|
|
157
|
+
try:
|
|
158
|
+
drs.append(Door.from_dict(dr))
|
|
159
|
+
except Exception as e:
|
|
160
|
+
invalid_dict_error(dr, e)
|
|
161
|
+
face.add_doors(drs)
|
|
162
|
+
face._recover_shades_from_dict(data)
|
|
163
|
+
|
|
164
|
+
# get the boundary condition and assign it
|
|
165
|
+
try:
|
|
166
|
+
bc_class = getattr(hbc, data['boundary_condition']['type'])
|
|
167
|
+
face.boundary_condition = bc_class.from_dict(data['boundary_condition'])
|
|
168
|
+
except AttributeError: # extension boundary condition; default to Outdoors
|
|
169
|
+
pass
|
|
170
|
+
|
|
171
|
+
# assign extension properties
|
|
172
|
+
if data['properties']['type'] == 'FaceProperties':
|
|
173
|
+
face.properties._load_extension_attr_from_dict(data['properties'])
|
|
174
|
+
return face
|
|
175
|
+
except Exception as e:
|
|
176
|
+
cls._from_dict_error_message(data, e)
|
|
177
|
+
|
|
178
|
+
@classmethod
|
|
179
|
+
def from_vertices(cls, identifier, vertices, type=None, boundary_condition=None):
|
|
180
|
+
"""Create a Face from vertices with each vertex as an iterable of 3 floats.
|
|
181
|
+
|
|
182
|
+
Note that this method is not recommended for a face with one or more holes
|
|
183
|
+
since the distinction between hole vertices and boundary vertices cannot
|
|
184
|
+
be derived from a single list of vertices.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
identifier: Text string for a unique Face ID. Must be < 100 characters and
|
|
188
|
+
not contain any spaces or special characters.
|
|
189
|
+
vertices: A flattened list of 3 or more vertices as (x, y, z).
|
|
190
|
+
type: Face type object (eg. Wall, Floor).
|
|
191
|
+
boundary_condition: Boundary condition object (eg. Outdoors, Ground)
|
|
192
|
+
"""
|
|
193
|
+
geometry = Face3D(tuple(Point3D(*v) for v in vertices))
|
|
194
|
+
return cls(identifier, geometry, type, boundary_condition)
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def type(self):
|
|
198
|
+
"""Get or set an object for Type of Face (ie. Wall, Floor, Roof).
|
|
199
|
+
|
|
200
|
+
Note that setting this property will reset extension attributes on this
|
|
201
|
+
Face to their default values.
|
|
202
|
+
"""
|
|
203
|
+
return self._type
|
|
204
|
+
|
|
205
|
+
@type.setter
|
|
206
|
+
def type(self, value):
|
|
207
|
+
assert value in self.TYPES, '{} is not a valid face type.'.format(value)
|
|
208
|
+
if isinstance(value, AirBoundary):
|
|
209
|
+
assert self._apertures == [] or self._doors == [], \
|
|
210
|
+
'{} cannot be assigned to a Face with Apertures or Doors.'.format(value)
|
|
211
|
+
self.properties.reset_to_default() # reset constructions/modifiers
|
|
212
|
+
self._type = value
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def boundary_condition(self):
|
|
216
|
+
"""Get or set the boundary condition of the Face. (ie. Outdoors, Ground, etc.).
|
|
217
|
+
"""
|
|
218
|
+
return self._boundary_condition
|
|
219
|
+
|
|
220
|
+
@boundary_condition.setter
|
|
221
|
+
def boundary_condition(self, value):
|
|
222
|
+
assert isinstance(value, _BoundaryCondition), \
|
|
223
|
+
'Expected BoundaryCondition. Got {}'.format(type(value))
|
|
224
|
+
if self._apertures != [] or self._doors != []:
|
|
225
|
+
assert isinstance(value, (Outdoors, Surface)), \
|
|
226
|
+
'{} cannot be assigned to a Face with apertures or doors.'.format(value)
|
|
227
|
+
self._boundary_condition = value
|
|
228
|
+
|
|
229
|
+
@property
|
|
230
|
+
def apertures(self):
|
|
231
|
+
"""Get a tuple of apertures in this Face."""
|
|
232
|
+
return tuple(self._apertures)
|
|
233
|
+
|
|
234
|
+
@property
|
|
235
|
+
def doors(self):
|
|
236
|
+
"""Get a tuple of doors in this Face."""
|
|
237
|
+
return tuple(self._doors)
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def sub_faces(self):
|
|
241
|
+
"""Get a tuple of apertures and doors in this Face."""
|
|
242
|
+
return tuple(self._apertures + self._doors)
|
|
243
|
+
|
|
244
|
+
@property
|
|
245
|
+
def parent(self):
|
|
246
|
+
"""Get the parent Room if assigned. None if not assigned."""
|
|
247
|
+
return self._parent
|
|
248
|
+
|
|
249
|
+
@property
|
|
250
|
+
def has_parent(self):
|
|
251
|
+
"""Get a boolean noting whether this Face has a parent Room."""
|
|
252
|
+
return self._parent is not None
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def has_sub_faces(self):
|
|
256
|
+
"""Get a boolean noting whether this Face has Apertures or Doors."""
|
|
257
|
+
return not (self._apertures == [] and self._doors == [])
|
|
258
|
+
|
|
259
|
+
@property
|
|
260
|
+
def can_be_ground(self):
|
|
261
|
+
"""Get a boolean for whether this Face can support a Ground boundary condition.
|
|
262
|
+
"""
|
|
263
|
+
return self._apertures == [] and self._doors == [] \
|
|
264
|
+
and not isinstance(self._type, AirBoundary)
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def geometry(self):
|
|
268
|
+
"""Get a ladybug_geometry Face3D object representing the Face.
|
|
269
|
+
|
|
270
|
+
Note that this Face3D only represents the parent face and does not have any
|
|
271
|
+
holes cut in it for apertures or doors.
|
|
272
|
+
"""
|
|
273
|
+
return self._geometry
|
|
274
|
+
|
|
275
|
+
@property
|
|
276
|
+
def punched_geometry(self):
|
|
277
|
+
"""Get a Face3D object with holes cut in it for apertures and doors.
|
|
278
|
+
"""
|
|
279
|
+
if self._punched_geometry is None:
|
|
280
|
+
_sub_faces = tuple(sub_f.geometry for sub_f in self._apertures + self._doors)
|
|
281
|
+
if len(_sub_faces) != 0:
|
|
282
|
+
self._punched_geometry = Face3D.from_punched_geometry(
|
|
283
|
+
self._geometry, _sub_faces)
|
|
284
|
+
else:
|
|
285
|
+
self._punched_geometry = self._geometry
|
|
286
|
+
return self._punched_geometry
|
|
287
|
+
|
|
288
|
+
@property
|
|
289
|
+
def vertices(self):
|
|
290
|
+
"""Get a list of vertices for the face (in counter-clockwise order).
|
|
291
|
+
|
|
292
|
+
Note that these vertices only represent the outer boundary of the face
|
|
293
|
+
and do not account for holes cut in the face by apertures or doors.
|
|
294
|
+
"""
|
|
295
|
+
return self._geometry.vertices
|
|
296
|
+
|
|
297
|
+
@property
|
|
298
|
+
def punched_vertices(self):
|
|
299
|
+
"""Get a list of vertices with holes cut in it for apertures and doors.
|
|
300
|
+
|
|
301
|
+
Note that some vertices will be repeated since the vertices effectively
|
|
302
|
+
trace out a single boundary around the whole shape, winding inward to cut
|
|
303
|
+
out the holes. This property should be used when exporting to Radiance.
|
|
304
|
+
"""
|
|
305
|
+
return self.punched_geometry.vertices
|
|
306
|
+
|
|
307
|
+
@property
|
|
308
|
+
def upper_left_vertices(self):
|
|
309
|
+
"""Get a list of vertices starting from the upper-left corner.
|
|
310
|
+
|
|
311
|
+
This property obeys the same rules as the vertices property but always starts
|
|
312
|
+
from the upper-left-most vertex. This property should be used when exporting to
|
|
313
|
+
EnergyPlus / OpenStudio.
|
|
314
|
+
"""
|
|
315
|
+
return self._geometry.upper_left_counter_clockwise_vertices
|
|
316
|
+
|
|
317
|
+
@property
|
|
318
|
+
def normal(self):
|
|
319
|
+
"""Get a Vector3D for the direction in which the face is pointing.
|
|
320
|
+
"""
|
|
321
|
+
return self._geometry.normal
|
|
322
|
+
|
|
323
|
+
@property
|
|
324
|
+
def center(self):
|
|
325
|
+
"""Get a ladybug_geometry Point3D for the center of the face.
|
|
326
|
+
|
|
327
|
+
Note that this is the center of the bounding rectangle around this geometry
|
|
328
|
+
and not the area centroid.
|
|
329
|
+
"""
|
|
330
|
+
return self._geometry.center
|
|
331
|
+
|
|
332
|
+
@property
|
|
333
|
+
def area(self):
|
|
334
|
+
"""Get the area of the face."""
|
|
335
|
+
return self._geometry.area
|
|
336
|
+
|
|
337
|
+
@property
|
|
338
|
+
def perimeter(self):
|
|
339
|
+
"""Get the perimeter of the face. This includes the length of holes in the face.
|
|
340
|
+
"""
|
|
341
|
+
return self._geometry.perimeter
|
|
342
|
+
|
|
343
|
+
@property
|
|
344
|
+
def min(self):
|
|
345
|
+
"""Get a Point3D for the minimum of the bounding box around the object."""
|
|
346
|
+
all_geo = self._outdoor_shades + self._indoor_shades
|
|
347
|
+
all_geo.extend(self._apertures)
|
|
348
|
+
all_geo.extend(self._doors)
|
|
349
|
+
all_geo.append(self.geometry)
|
|
350
|
+
return self._calculate_min(all_geo)
|
|
351
|
+
|
|
352
|
+
@property
|
|
353
|
+
def max(self):
|
|
354
|
+
"""Get a Point3D for the maximum of the bounding box around the object."""
|
|
355
|
+
all_geo = self._outdoor_shades + self._indoor_shades
|
|
356
|
+
all_geo.extend(self._apertures)
|
|
357
|
+
all_geo.extend(self._doors)
|
|
358
|
+
all_geo.append(self.geometry)
|
|
359
|
+
return self._calculate_max(all_geo)
|
|
360
|
+
|
|
361
|
+
@property
|
|
362
|
+
def aperture_area(self):
|
|
363
|
+
"""Get the combined area of the face's apertures."""
|
|
364
|
+
return sum([ap.area for ap in self._apertures])
|
|
365
|
+
|
|
366
|
+
@property
|
|
367
|
+
def aperture_ratio(self):
|
|
368
|
+
"""Get a number between 0 and 1 for the area ratio of the apertures to the face.
|
|
369
|
+
"""
|
|
370
|
+
return self.aperture_area / self.area
|
|
371
|
+
|
|
372
|
+
@property
|
|
373
|
+
def tilt(self):
|
|
374
|
+
"""Get the tilt of the geometry between 0 (up) and 180 (down)."""
|
|
375
|
+
return math.degrees(self._geometry.tilt)
|
|
376
|
+
|
|
377
|
+
@property
|
|
378
|
+
def altitude(self):
|
|
379
|
+
"""Get the altitude of the geometry between +90 (up) and -90 (down)."""
|
|
380
|
+
return math.degrees(self._geometry.altitude)
|
|
381
|
+
|
|
382
|
+
@property
|
|
383
|
+
def azimuth(self):
|
|
384
|
+
"""Get the azimuth of the geometry, between 0 and 360.
|
|
385
|
+
|
|
386
|
+
Given Y-axis as North, 0 = North, 90 = East, 180 = South, 270 = West
|
|
387
|
+
This will be zero if the Face3D is perfectly horizontal.
|
|
388
|
+
"""
|
|
389
|
+
return math.degrees(self._geometry.azimuth)
|
|
390
|
+
|
|
391
|
+
@property
|
|
392
|
+
def is_exterior(self):
|
|
393
|
+
"""Get a boolean for whether this object has an Outdoors boundary condition.
|
|
394
|
+
"""
|
|
395
|
+
return isinstance(self.boundary_condition, Outdoors)
|
|
396
|
+
|
|
397
|
+
@property
|
|
398
|
+
def gbxml_type(self):
|
|
399
|
+
"""Get text for the type of object this is in gbXML schema.
|
|
400
|
+
|
|
401
|
+
This will always be one of the following.
|
|
402
|
+
|
|
403
|
+
* InteriorWall
|
|
404
|
+
* ExteriorWall
|
|
405
|
+
* UndergroundWall
|
|
406
|
+
* Roof
|
|
407
|
+
* Ceiling
|
|
408
|
+
* UndergroundCeiling
|
|
409
|
+
* InteriorFloor
|
|
410
|
+
* ExposedFloor
|
|
411
|
+
* UndergroundSlab
|
|
412
|
+
* SlabOnGrade
|
|
413
|
+
* Air
|
|
414
|
+
"""
|
|
415
|
+
if isinstance(self.type, AirBoundary):
|
|
416
|
+
return 'Air'
|
|
417
|
+
elif isinstance(self.type, Wall):
|
|
418
|
+
bc_type = 'Interior'
|
|
419
|
+
if isinstance(self.boundary_condition, Outdoors):
|
|
420
|
+
bc_type = 'Exterior'
|
|
421
|
+
elif isinstance(self.boundary_condition, Ground):
|
|
422
|
+
bc_type = 'Underground'
|
|
423
|
+
return bc_type + 'Wall'
|
|
424
|
+
elif isinstance(self.type, Floor):
|
|
425
|
+
if isinstance(self.boundary_condition, Ground):
|
|
426
|
+
if self.has_parent:
|
|
427
|
+
for f in self.parent.faces:
|
|
428
|
+
if isinstance(f.type, Wall) and \
|
|
429
|
+
isinstance(f.boundary_condition, Outdoors):
|
|
430
|
+
return 'SlabOnGrade'
|
|
431
|
+
return 'UndergroundSlab'
|
|
432
|
+
elif isinstance(self.boundary_condition, Outdoors):
|
|
433
|
+
return 'ExposedFloor'
|
|
434
|
+
else:
|
|
435
|
+
return 'InteriorFloor'
|
|
436
|
+
else:
|
|
437
|
+
if isinstance(self.boundary_condition, Outdoors):
|
|
438
|
+
return 'Roof'
|
|
439
|
+
elif isinstance(self.boundary_condition, Ground):
|
|
440
|
+
return 'UndergroundCeiling'
|
|
441
|
+
return 'Ceiling'
|
|
442
|
+
|
|
443
|
+
@property
|
|
444
|
+
def type_color(self):
|
|
445
|
+
"""Get a Color to be used in visualizations by type."""
|
|
446
|
+
ts = self.type.name if isinstance(self.boundary_condition, (Outdoors, Ground)) \
|
|
447
|
+
else 'Interior{}'.format(self.type.name)
|
|
448
|
+
return self.TYPE_COLORS[ts]
|
|
449
|
+
|
|
450
|
+
@property
|
|
451
|
+
def bc_color(self):
|
|
452
|
+
"""Get a Color to be used in visualizations by boundary condition."""
|
|
453
|
+
try:
|
|
454
|
+
return self.BC_COLORS[self.boundary_condition.name]
|
|
455
|
+
except KeyError: # extension boundary condition
|
|
456
|
+
return self.BC_COLORS['Other']
|
|
457
|
+
|
|
458
|
+
def horizontal_orientation(self, north_vector=Vector2D(0, 1)):
|
|
459
|
+
"""Get a number between 0 and 360 for the orientation of the face in degrees.
|
|
460
|
+
|
|
461
|
+
0 = North, 90 = East, 180 = South, 270 = West
|
|
462
|
+
|
|
463
|
+
Args:
|
|
464
|
+
north_vector: A ladybug_geometry Vector2D for the north direction.
|
|
465
|
+
Default is the Y-axis (0, 1).
|
|
466
|
+
"""
|
|
467
|
+
return math.degrees(
|
|
468
|
+
north_vector.angle_clockwise(Vector2D(self.normal.x, self.normal.y)))
|
|
469
|
+
|
|
470
|
+
def cardinal_direction(self, north_vector=Vector2D(0, 1), angle_tolerance=1):
|
|
471
|
+
"""Get text description for the cardinal direction that the face is pointing.
|
|
472
|
+
|
|
473
|
+
Will be one of the following: ('North', 'NorthEast', 'East', 'SouthEast',
|
|
474
|
+
'South', 'SouthWest', 'West', 'NorthWest', 'Up', 'Down').
|
|
475
|
+
|
|
476
|
+
Args:
|
|
477
|
+
north_vector: A ladybug_geometry Vector2D for the north direction.
|
|
478
|
+
Default is the Y-axis (0, 1).
|
|
479
|
+
angle_tolerance: The angle tolerance in degrees used to determine if
|
|
480
|
+
the Face is perfectly Up or Down. (Default: 1).
|
|
481
|
+
"""
|
|
482
|
+
tilt = self.tilt
|
|
483
|
+
if tilt < angle_tolerance:
|
|
484
|
+
return 'Up'
|
|
485
|
+
elif tilt > 180 - angle_tolerance:
|
|
486
|
+
return 'Down'
|
|
487
|
+
orient = self.horizontal_orientation(north_vector)
|
|
488
|
+
orient_text = ('North', 'NorthEast', 'East', 'SouthEast', 'South',
|
|
489
|
+
'SouthWest', 'West', 'NorthWest')
|
|
490
|
+
angles = (22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5)
|
|
491
|
+
for i, ang in enumerate(angles):
|
|
492
|
+
if orient < ang:
|
|
493
|
+
return orient_text[i]
|
|
494
|
+
return orient_text[0]
|
|
495
|
+
|
|
496
|
+
def cardinal_abbrev(self, north_vector=Vector2D(0, 1), angle_tolerance=1):
|
|
497
|
+
"""Get text abbreviation for the cardinal direction that the face is pointing.
|
|
498
|
+
|
|
499
|
+
Will be one of the following: ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW',
|
|
500
|
+
'Up', 'Down').
|
|
501
|
+
|
|
502
|
+
Args:
|
|
503
|
+
north_vector: A ladybug_geometry Vector2D for the north direction.
|
|
504
|
+
Default is the Y-axis (0, 1).
|
|
505
|
+
angle_tolerance: The angle tolerance in degrees used to determine if
|
|
506
|
+
the Face is perfectly Up or Down. (Default: 1).
|
|
507
|
+
"""
|
|
508
|
+
tilt = self.tilt
|
|
509
|
+
if tilt < angle_tolerance:
|
|
510
|
+
return 'Up'
|
|
511
|
+
elif tilt > 180 - angle_tolerance:
|
|
512
|
+
return 'Down'
|
|
513
|
+
orient = self.horizontal_orientation(north_vector)
|
|
514
|
+
orient_text = ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW')
|
|
515
|
+
angles = (22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5)
|
|
516
|
+
for i, ang in enumerate(angles):
|
|
517
|
+
if orient < ang:
|
|
518
|
+
return orient_text[i]
|
|
519
|
+
return orient_text[0]
|
|
520
|
+
|
|
521
|
+
def add_prefix(self, prefix):
|
|
522
|
+
"""Change the identifier of this object and child objects by inserting a prefix.
|
|
523
|
+
|
|
524
|
+
This is particularly useful in workflows where you duplicate and edit
|
|
525
|
+
a starting object and then want to combine it with the original object
|
|
526
|
+
into one Model (like making a model of repeated rooms) since all objects
|
|
527
|
+
within a Model must have unique identifiers.
|
|
528
|
+
|
|
529
|
+
Args:
|
|
530
|
+
prefix: Text that will be inserted at the start of this object's
|
|
531
|
+
(and child objects') identifier and display_name. It is recommended
|
|
532
|
+
that this prefix be short to avoid maxing out the 100 allowable
|
|
533
|
+
characters for honeybee identifiers.
|
|
534
|
+
"""
|
|
535
|
+
self._identifier = clean_string('{}_{}'.format(prefix, self.identifier))
|
|
536
|
+
self.display_name = '{}_{}'.format(prefix, self.display_name)
|
|
537
|
+
self.properties.add_prefix(prefix)
|
|
538
|
+
for ap in self._apertures:
|
|
539
|
+
ap.add_prefix(prefix)
|
|
540
|
+
for dr in self._doors:
|
|
541
|
+
dr.add_prefix(prefix)
|
|
542
|
+
self._add_prefix_shades(prefix)
|
|
543
|
+
if isinstance(self._boundary_condition, Surface):
|
|
544
|
+
new_bc_objs = (clean_string('{}_{}'.format(prefix, adj_name)) for adj_name
|
|
545
|
+
in self._boundary_condition._boundary_condition_objects)
|
|
546
|
+
self._boundary_condition = Surface(new_bc_objs, False)
|
|
547
|
+
|
|
548
|
+
def rename_by_attribute(
|
|
549
|
+
self,
|
|
550
|
+
format_str='{parent.display_name} - {gbxml_type} - {cardinal_direction}'
|
|
551
|
+
):
|
|
552
|
+
"""Set the display name of this Face using a format string with Face attributes.
|
|
553
|
+
|
|
554
|
+
Args:
|
|
555
|
+
format_str: Text string for the pattern with which the Face will be
|
|
556
|
+
renamed. Any property on this class may be used (eg. gbxml_str)
|
|
557
|
+
and each property should be put in curly brackets. Nested
|
|
558
|
+
properties can be specified by using "." to denote nesting levels
|
|
559
|
+
(eg. properties.energy.construction.display_name). Functions that
|
|
560
|
+
return string outputs can also be passed here as long as these
|
|
561
|
+
functions defaults specified for all arguments.
|
|
562
|
+
"""
|
|
563
|
+
matches = re.findall(r'{([^}]*)}', format_str)
|
|
564
|
+
attributes = [get_attr_nested(self, m, decimal_count=2) for m in matches]
|
|
565
|
+
for attr_name, attr_val in zip(matches, attributes):
|
|
566
|
+
format_str = format_str.replace('{{{}}}'.format(attr_name), attr_val)
|
|
567
|
+
self.display_name = format_str
|
|
568
|
+
return format_str
|
|
569
|
+
|
|
570
|
+
def remove_sub_faces(self):
|
|
571
|
+
"""Remove all apertures and doors from the face."""
|
|
572
|
+
self.remove_apertures()
|
|
573
|
+
self.remove_doors()
|
|
574
|
+
|
|
575
|
+
def remove_apertures(self):
|
|
576
|
+
"""Remove all apertures from the face."""
|
|
577
|
+
for aperture in self._apertures:
|
|
578
|
+
aperture._parent = None
|
|
579
|
+
self._apertures = []
|
|
580
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
581
|
+
|
|
582
|
+
def remove_doors(self):
|
|
583
|
+
"""Remove all doors from the face."""
|
|
584
|
+
for door in self._apertures:
|
|
585
|
+
door._parent = None
|
|
586
|
+
self._doors = []
|
|
587
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
588
|
+
|
|
589
|
+
def add_aperture(self, aperture):
|
|
590
|
+
"""Add an Aperture to this face.
|
|
591
|
+
|
|
592
|
+
This method does not check the co-planarity between this Face and the
|
|
593
|
+
Aperture or whether the Aperture has all vertices within the boundary of
|
|
594
|
+
this Face. To check this, the Face3D.is_sub_face() method can be used
|
|
595
|
+
with the Aperture and Face geometry before using this method or the
|
|
596
|
+
are_sub_faces_valid() method can be used afterwards.
|
|
597
|
+
|
|
598
|
+
Args:
|
|
599
|
+
aperture: An Aperture to add to this face.
|
|
600
|
+
"""
|
|
601
|
+
assert isinstance(aperture, Aperture), \
|
|
602
|
+
'Expected Aperture. Got {}.'.format(type(aperture))
|
|
603
|
+
self._acceptable_sub_face_check(Aperture)
|
|
604
|
+
aperture._parent = self
|
|
605
|
+
if self.normal.angle(aperture.normal) > math.pi / 2: # reversed normal
|
|
606
|
+
aperture._geometry = aperture._geometry.flip()
|
|
607
|
+
self._apertures.append(aperture)
|
|
608
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
609
|
+
|
|
610
|
+
def add_door(self, door):
|
|
611
|
+
"""Add a Door to this face.
|
|
612
|
+
|
|
613
|
+
This method does not check the co-planarity between this Face and the
|
|
614
|
+
Door or whether the Door has all vertices within the boundary of
|
|
615
|
+
this Face. To check this, the Face3D.is_sub_face() method can be used
|
|
616
|
+
with the Door and Face geometry before using this method or the
|
|
617
|
+
are_sub_faces_valid() method can be used afterwards.
|
|
618
|
+
|
|
619
|
+
Args:
|
|
620
|
+
door: A Door to add to this face.
|
|
621
|
+
"""
|
|
622
|
+
assert isinstance(door, Door), \
|
|
623
|
+
'Expected Door. Got {}.'.format(type(door))
|
|
624
|
+
self._acceptable_sub_face_check(Door)
|
|
625
|
+
door._parent = self
|
|
626
|
+
if self.normal.angle(door.normal) > math.pi / 2: # reversed normal
|
|
627
|
+
door._geometry = door._geometry.flip()
|
|
628
|
+
self._doors.append(door)
|
|
629
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
630
|
+
|
|
631
|
+
def add_sub_face(self, sub_face):
|
|
632
|
+
"""Add an Apertures or Doors to this face."""
|
|
633
|
+
if isinstance(sub_face, Aperture):
|
|
634
|
+
self.add_aperture(sub_face)
|
|
635
|
+
else:
|
|
636
|
+
self.add_door(sub_face)
|
|
637
|
+
|
|
638
|
+
def add_apertures(self, apertures):
|
|
639
|
+
"""Add a list of Apertures to this face."""
|
|
640
|
+
for aperture in apertures:
|
|
641
|
+
self.add_aperture(aperture)
|
|
642
|
+
|
|
643
|
+
def add_doors(self, doors):
|
|
644
|
+
"""Add a list of Doors to this face."""
|
|
645
|
+
for door in doors:
|
|
646
|
+
self.add_door(door)
|
|
647
|
+
|
|
648
|
+
def add_sub_faces(self, sub_faces):
|
|
649
|
+
"""Add a list of Apertures and/or Doors to this face."""
|
|
650
|
+
for sub_f in sub_faces:
|
|
651
|
+
self.add_sub_face(sub_f)
|
|
652
|
+
|
|
653
|
+
def replace_apertures(self, apertures):
|
|
654
|
+
"""Replace all sub-faces assigned to this Face with a new list of Apertures."""
|
|
655
|
+
self.remove_sub_faces()
|
|
656
|
+
self.add_apertures(apertures)
|
|
657
|
+
|
|
658
|
+
def set_adjacency(self, other_face, tolerance=0.01):
|
|
659
|
+
"""Set this face adjacent to another and set the other face adjacent to this one.
|
|
660
|
+
|
|
661
|
+
Note that this method does not verify whether the other_face geometry is
|
|
662
|
+
co-planar or compatible with this one so it is recommended that either the
|
|
663
|
+
Face3D.is_centered_adjacent() or the Face3D.is_geometrically_equivalent()
|
|
664
|
+
method be used with this face geometry and the other_face geometry
|
|
665
|
+
before using this method in order to verify these criteria.
|
|
666
|
+
|
|
667
|
+
However, this method will use the proximity of apertures and doors within
|
|
668
|
+
the input tolerance to determine which of the sub faces in the other_face
|
|
669
|
+
are adjacent to the ones in this face. An exception will be thrown if not
|
|
670
|
+
all sub-faces can be matched.
|
|
671
|
+
|
|
672
|
+
Args:
|
|
673
|
+
other_face: Another Face object to be set adjacent to this one.
|
|
674
|
+
tolerance: The minimum distance between the center of two aperture
|
|
675
|
+
geometries at which they are considered adjacent. Default: 0.01,
|
|
676
|
+
suitable for objects in meters.
|
|
677
|
+
|
|
678
|
+
Returns:
|
|
679
|
+
A dictionary of adjacency information with the following keys
|
|
680
|
+
|
|
681
|
+
- adjacent_apertures - A list of tuples with each tuple containing 2
|
|
682
|
+
objects for Apertures paired in the process of solving adjacency.
|
|
683
|
+
|
|
684
|
+
- adjacent_doors - A list of tuples with each tuple containing 2
|
|
685
|
+
objects for Doors paired in the process of solving adjacency.
|
|
686
|
+
"""
|
|
687
|
+
# check the inputs and the ability of the faces to be adjacent
|
|
688
|
+
assert isinstance(other_face, Face), \
|
|
689
|
+
'Expected honeybee Face. Got {}.'.format(type(other_face))
|
|
690
|
+
|
|
691
|
+
# set the boundary conditions of the faces
|
|
692
|
+
self._boundary_condition = boundary_conditions.surface(other_face)
|
|
693
|
+
other_face._boundary_condition = boundary_conditions.surface(self)
|
|
694
|
+
|
|
695
|
+
adj_info = {'adjacent_apertures': [], 'adjacent_doors': []}
|
|
696
|
+
|
|
697
|
+
# set the apertures to be adjacent to one another
|
|
698
|
+
if len(self._apertures) != len(other_face._apertures):
|
|
699
|
+
msg = 'Number of apertures does not match between {} and {}.'.format(
|
|
700
|
+
self.display_name, other_face.display_name)
|
|
701
|
+
if self.has_parent and other_face.has_parent:
|
|
702
|
+
msg = '{} Relevant rooms: {}, {}'.format(
|
|
703
|
+
msg, self.parent.display_name, other_face.parent.display_name)
|
|
704
|
+
raise AssertionError(msg)
|
|
705
|
+
if len(self._apertures) > 0:
|
|
706
|
+
found_adjacencies = 0
|
|
707
|
+
for aper_1 in self._apertures:
|
|
708
|
+
for aper_2 in other_face._apertures:
|
|
709
|
+
if aper_1.center.distance_to_point(aper_2.center) <= tolerance:
|
|
710
|
+
aper_1.set_adjacency(aper_2)
|
|
711
|
+
adj_info['adjacent_apertures'].append((aper_1, aper_2))
|
|
712
|
+
found_adjacencies += 1
|
|
713
|
+
break
|
|
714
|
+
if len(self._apertures) != found_adjacencies:
|
|
715
|
+
msg = 'Not all apertures of {} were found to be adjacent to ' \
|
|
716
|
+
'apertures in {}.'.format(self.display_name, other_face.display_name)
|
|
717
|
+
if self.has_parent and other_face.has_parent:
|
|
718
|
+
msg = '{} Relevant rooms: {}, {}'.format(
|
|
719
|
+
msg, self.parent.display_name, other_face.parent.display_name)
|
|
720
|
+
raise AssertionError(msg)
|
|
721
|
+
|
|
722
|
+
# set the doors to be adjacent to one another
|
|
723
|
+
assert len(self._doors) == len(other_face._doors), \
|
|
724
|
+
'Number of doors does not match between {} and {}.'.format(
|
|
725
|
+
self.display_name, other_face.display_name)
|
|
726
|
+
if len(self._doors) > 0:
|
|
727
|
+
found_adjacencies = 0
|
|
728
|
+
for door_1 in self._doors:
|
|
729
|
+
for door_2 in other_face._doors:
|
|
730
|
+
if door_1.center.distance_to_point(door_2.center) <= tolerance:
|
|
731
|
+
door_1.set_adjacency(door_2)
|
|
732
|
+
adj_info['adjacent_doors'].append((door_1, door_2))
|
|
733
|
+
found_adjacencies += 1
|
|
734
|
+
break
|
|
735
|
+
if len(self._doors) != found_adjacencies:
|
|
736
|
+
msg = 'Not all doors of {} were found to be adjacent to ' \
|
|
737
|
+
'doors in {}.'.format(self.display_name, other_face.display_name)
|
|
738
|
+
if self.has_parent and other_face.has_parent:
|
|
739
|
+
msg = '{} Relevant rooms: {}, {}'.format(
|
|
740
|
+
msg, self.parent.display_name, other_face.parent.display_name)
|
|
741
|
+
raise AssertionError(msg)
|
|
742
|
+
|
|
743
|
+
return adj_info
|
|
744
|
+
|
|
745
|
+
def rectangularize_apertures(
|
|
746
|
+
self, subdivision_distance=None, max_separation=None,
|
|
747
|
+
merge_all=False, tolerance=0.01, angle_tolerance=1.0):
|
|
748
|
+
"""Convert all Apertures on this Face to be rectangular.
|
|
749
|
+
|
|
750
|
+
This is useful when exporting to simulation engines that only accept
|
|
751
|
+
rectangular window geometry. This method will always result ing Rooms where
|
|
752
|
+
all Apertures are rectangular. However, if the subdivision_distance is not
|
|
753
|
+
set, some Apertures may extend past the parent Face or may collide with
|
|
754
|
+
one another.
|
|
755
|
+
|
|
756
|
+
Args:
|
|
757
|
+
subdivision_distance: A number for the resolution at which the
|
|
758
|
+
non-rectangular Apertures will be subdivided into smaller
|
|
759
|
+
rectangular units. Specifying a number here ensures that the
|
|
760
|
+
resulting rectangular Apertures do not extend past the parent
|
|
761
|
+
Face or collide with one another. If None, all non-rectangular
|
|
762
|
+
Apertures will be rectangularized by taking the bounding rectangle
|
|
763
|
+
around the Aperture. (Default: None).
|
|
764
|
+
max_separation: A number for the maximum distance between non-rectangular
|
|
765
|
+
Apertures at which point the Apertures will be merged into a single
|
|
766
|
+
rectangular geometry. This is often helpful when there are several
|
|
767
|
+
triangular Apertures that together make a rectangle when they are
|
|
768
|
+
merged across their frames. In such cases, this max_separation
|
|
769
|
+
should be set to a value that is slightly larger than the window frame.
|
|
770
|
+
If None, no merging of Apertures will happen before they are
|
|
771
|
+
converted to rectangles. (Default: None).
|
|
772
|
+
merge_all: Boolean to note whether all apertures should be merged before
|
|
773
|
+
they are rectangularized. If False, only non-rectangular apertures
|
|
774
|
+
will be merged before rectangularization. Note that this argument
|
|
775
|
+
has no effect when the max_separation is None. (Default: False).
|
|
776
|
+
tolerance: The maximum difference between point values for them to be
|
|
777
|
+
considered equivalent. (Default: 0.01, suitable for objects in meters).
|
|
778
|
+
angle_tolerance: The max angle in degrees that the corners of the
|
|
779
|
+
rectangle can differ from a right angle before it is not
|
|
780
|
+
considered a rectangle. (Default: 1).
|
|
781
|
+
|
|
782
|
+
Returns:
|
|
783
|
+
True if the Apertures were changed. False if they were unchanged.
|
|
784
|
+
"""
|
|
785
|
+
# sort the rectangular and non-rectangular apertures
|
|
786
|
+
apertures = self._apertures
|
|
787
|
+
if len(apertures) == 0:
|
|
788
|
+
return False
|
|
789
|
+
tol, ang_tol = tolerance, math.radians(angle_tolerance)
|
|
790
|
+
rect_aps, non_rect_aps, non_rect_geos = [], [], []
|
|
791
|
+
for aperture in apertures:
|
|
792
|
+
try:
|
|
793
|
+
clean_geo = aperture.geometry.remove_colinear_vertices(tol)
|
|
794
|
+
except AssertionError: # degenerate Aperture to be ignored
|
|
795
|
+
continue
|
|
796
|
+
if max_separation is None or not merge_all:
|
|
797
|
+
if clean_geo.polygon2d.is_rectangle(ang_tol):
|
|
798
|
+
rect_aps.append(aperture)
|
|
799
|
+
else:
|
|
800
|
+
non_rect_aps.append(aperture)
|
|
801
|
+
non_rect_geos.append(clean_geo)
|
|
802
|
+
else:
|
|
803
|
+
non_rect_aps.append(aperture)
|
|
804
|
+
non_rect_geos.append(clean_geo)
|
|
805
|
+
if not non_rect_geos: # nothing to be rectangularized
|
|
806
|
+
return False
|
|
807
|
+
|
|
808
|
+
# reset boundary conditions to outdoors so new apertures can be added
|
|
809
|
+
if not isinstance(self.boundary_condition, Outdoors):
|
|
810
|
+
self.boundary_condition = boundary_conditions.outdoors
|
|
811
|
+
for ap in rect_aps:
|
|
812
|
+
ap.boundary_condition = boundary_conditions.outdoors
|
|
813
|
+
edits_occurred = False
|
|
814
|
+
|
|
815
|
+
# try to merge the non-rectangular apertures if a max_separation is specified
|
|
816
|
+
ref_plane = self._reference_plane(ang_tol)
|
|
817
|
+
if max_separation is not None:
|
|
818
|
+
if merge_all or (not merge_all and len(non_rect_geos) > 1):
|
|
819
|
+
edits_occurred = True
|
|
820
|
+
if max_separation <= tol: # just join the Apertures at the tolerance
|
|
821
|
+
non_rect_geos = Face3D.join_coplanar_faces(non_rect_geos, tol)
|
|
822
|
+
else: # join the Apertures using the max_separation
|
|
823
|
+
# get polygons for the faces that all lie within the same plane
|
|
824
|
+
face_polys = []
|
|
825
|
+
for fg in non_rect_geos:
|
|
826
|
+
verts2d = tuple(ref_plane.xyz_to_xy(_v) for _v in fg.boundary)
|
|
827
|
+
face_polys.append(Polygon2D(verts2d))
|
|
828
|
+
if fg.has_holes:
|
|
829
|
+
for hole in fg.holes:
|
|
830
|
+
verts2d = tuple(ref_plane.xyz_to_xy(_v) for _v in hole)
|
|
831
|
+
face_polys.append(Polygon2D(verts2d))
|
|
832
|
+
# get the joined boundaries around the Polygon2D
|
|
833
|
+
joined_bounds = Polygon2D.gap_crossing_boundary(
|
|
834
|
+
face_polys, max_separation, tolerance)
|
|
835
|
+
# convert the boundary polygons back to Face3D
|
|
836
|
+
if len(joined_bounds) == 1: # can be represented with a single Face3D
|
|
837
|
+
verts3d = tuple(ref_plane.xy_to_xyz(_v) for _v in joined_bounds[0])
|
|
838
|
+
non_rect_geos = [Face3D(verts3d, plane=ref_plane)]
|
|
839
|
+
elif len(joined_bounds) == 0: # everything was invalid
|
|
840
|
+
non_rect_geos = []
|
|
841
|
+
else: # need to separate holes from distinct Face3Ds
|
|
842
|
+
bound_faces = []
|
|
843
|
+
for poly in joined_bounds:
|
|
844
|
+
verts3d = tuple(ref_plane.xy_to_xyz(_v) for _v in poly)
|
|
845
|
+
bound_faces.append(Face3D(verts3d, plane=ref_plane))
|
|
846
|
+
non_rect_geos = Face3D.merge_faces_to_holes(bound_faces, tolerance)
|
|
847
|
+
clean_aps = []
|
|
848
|
+
for ap_geo in non_rect_geos:
|
|
849
|
+
try:
|
|
850
|
+
clean_aps.append(ap_geo.remove_colinear_vertices(tol))
|
|
851
|
+
except AssertionError: # degenerate Aperture to be ignored
|
|
852
|
+
continue
|
|
853
|
+
non_rect_geos = clean_aps
|
|
854
|
+
|
|
855
|
+
# convert the remaining Aperture geometries to rectangles
|
|
856
|
+
if subdivision_distance is None: # just take the bounding rectangle
|
|
857
|
+
edits_occurred = True
|
|
858
|
+
# get the bounding rectangle around all of the geometries
|
|
859
|
+
ap_geos = []
|
|
860
|
+
for ap_geo in non_rect_geos:
|
|
861
|
+
if ap_geo.polygon2d.is_rectangle(ang_tol):
|
|
862
|
+
ap_geos.append(ap_geo) # catch rectangles found in merging
|
|
863
|
+
continue
|
|
864
|
+
geo_2d = Polygon2D([ref_plane.xyz_to_xy(v) for v in ap_geo.vertices])
|
|
865
|
+
g_min, g_max = geo_2d.min, geo_2d.max
|
|
866
|
+
base, hgt = g_max.x - g_min.x, g_max.y - g_min.y
|
|
867
|
+
bound_poly = Polygon2D.from_rectangle(g_min, Vector2D(0, 1), base, hgt)
|
|
868
|
+
geo_3d = Face3D([ref_plane.xy_to_xyz(v) for v in bound_poly.vertices])
|
|
869
|
+
ap_geos.append(geo_3d)
|
|
870
|
+
non_rect_geos = ap_geos
|
|
871
|
+
|
|
872
|
+
# create Aperture objects from all of the merged geometries
|
|
873
|
+
if not edits_occurred:
|
|
874
|
+
new_aps = non_rect_aps
|
|
875
|
+
else:
|
|
876
|
+
new_aps = []
|
|
877
|
+
for i, ap_face in enumerate(non_rect_geos):
|
|
878
|
+
exist_ap = None
|
|
879
|
+
for old_ap in non_rect_aps:
|
|
880
|
+
if old_ap.center.is_equivalent(ap_face.center, tolerance):
|
|
881
|
+
exist_ap = old_ap
|
|
882
|
+
break
|
|
883
|
+
if exist_ap is None: # could not be matched; just make a new aperture
|
|
884
|
+
new_ap = Aperture('{}_RG{}'.format(self.identifier, i), ap_face)
|
|
885
|
+
else:
|
|
886
|
+
new_ap = Aperture(exist_ap.identifier, ap_face,
|
|
887
|
+
is_operable=exist_ap.is_operable)
|
|
888
|
+
new_ap.display_name = '{}_{}'.format(exist_ap.display_name, i)
|
|
889
|
+
new_aps.append(new_ap)
|
|
890
|
+
|
|
891
|
+
# we can just add the apertures if there's no subdivision going on
|
|
892
|
+
if subdivision_distance is None:
|
|
893
|
+
# remove any Apertures that are overlapping
|
|
894
|
+
all_aps = rect_aps + new_aps
|
|
895
|
+
all_aps = self._remove_overlapping_sub_faces(all_aps, tolerance)
|
|
896
|
+
self.remove_apertures()
|
|
897
|
+
self.add_apertures(all_aps)
|
|
898
|
+
return True
|
|
899
|
+
|
|
900
|
+
# if distance is provided, subdivide the apertures into strips
|
|
901
|
+
new_ap_objs = []
|
|
902
|
+
for ap_obj in new_aps:
|
|
903
|
+
ap_geo = ap_obj.geometry
|
|
904
|
+
if ap_geo.polygon2d.is_rectangle(ang_tol):
|
|
905
|
+
new_ap_objs.append(ap_obj) # catch rectangles found in merging
|
|
906
|
+
continue
|
|
907
|
+
# create a mesh grid over the Aperture in the reference plane
|
|
908
|
+
geo_2d = Polygon2D([ref_plane.xyz_to_xy(v) for v in ap_geo.vertices])
|
|
909
|
+
try:
|
|
910
|
+
grid = Mesh2D.from_polygon_grid(
|
|
911
|
+
geo_2d, subdivision_distance, subdivision_distance, False)
|
|
912
|
+
except AssertionError: # Aperture smaller than resolution; ignore
|
|
913
|
+
continue
|
|
914
|
+
|
|
915
|
+
# group face by y value. All the rows will be merged together
|
|
916
|
+
vertices = grid.vertices
|
|
917
|
+
groups = {}
|
|
918
|
+
start_y = None
|
|
919
|
+
last_y = vertices[grid.faces[0][0]].y
|
|
920
|
+
for i, face in enumerate(grid.faces):
|
|
921
|
+
min_2d = vertices[face[0]]
|
|
922
|
+
for xy in groups:
|
|
923
|
+
if abs(min_2d.x - xy[0]) < tolerance and \
|
|
924
|
+
abs(min_2d.y - last_y) < tolerance:
|
|
925
|
+
groups[(xy[0], start_y)].append(face)
|
|
926
|
+
break
|
|
927
|
+
else:
|
|
928
|
+
start_y = min_2d.y
|
|
929
|
+
groups[(min_2d.x, start_y)] = [face]
|
|
930
|
+
last_y = vertices[face[3]].y
|
|
931
|
+
|
|
932
|
+
# get the max and min of each group
|
|
933
|
+
sorted_groups = []
|
|
934
|
+
for group in groups.values():
|
|
935
|
+
# find min_2d and max_2d for each group
|
|
936
|
+
min_2d = vertices[group[0][0]]
|
|
937
|
+
max_2d = vertices[group[-1][2]]
|
|
938
|
+
sorted_groups.append({'min': min_2d, 'max': max_2d})
|
|
939
|
+
|
|
940
|
+
def _get_last_row(groups, start=0):
|
|
941
|
+
"""An internal function to return the index for the last row that can be
|
|
942
|
+
merged with the start row that is passed to this function.
|
|
943
|
+
|
|
944
|
+
This function compares the min and max x and y values for each row to see
|
|
945
|
+
if they can be merged into a rectangle.
|
|
946
|
+
"""
|
|
947
|
+
for count, group in enumerate(groups[start:]):
|
|
948
|
+
next_group = groups[count + start + 1]
|
|
949
|
+
if abs(group['min'].y - next_group['min'].y) <= tolerance \
|
|
950
|
+
and abs(group['max'].y - next_group['max'].y) <= tolerance \
|
|
951
|
+
and abs(next_group['min'].x - group['max'].x) <= tolerance:
|
|
952
|
+
continue
|
|
953
|
+
else:
|
|
954
|
+
return start + count
|
|
955
|
+
|
|
956
|
+
return start + count + 1
|
|
957
|
+
|
|
958
|
+
# merge the rows if they have the same number of grid cells
|
|
959
|
+
sorted_groups.sort(key=lambda x: x['min'].x)
|
|
960
|
+
merged_groups = []
|
|
961
|
+
start_row = 0
|
|
962
|
+
last_row = -1
|
|
963
|
+
while last_row < len(sorted_groups):
|
|
964
|
+
try:
|
|
965
|
+
last_row = _get_last_row(sorted_groups, start=start_row)
|
|
966
|
+
except IndexError:
|
|
967
|
+
merged_groups.append(
|
|
968
|
+
{
|
|
969
|
+
'min': sorted_groups[start_row]['min'],
|
|
970
|
+
'max': sorted_groups[len(sorted_groups) - 1]['max']
|
|
971
|
+
}
|
|
972
|
+
)
|
|
973
|
+
break
|
|
974
|
+
else:
|
|
975
|
+
merged_groups.append(
|
|
976
|
+
{
|
|
977
|
+
'min': sorted_groups[start_row]['min'],
|
|
978
|
+
'max': sorted_groups[last_row]['max']
|
|
979
|
+
}
|
|
980
|
+
)
|
|
981
|
+
if last_row == start_row:
|
|
982
|
+
# the row was not grouped with anything else
|
|
983
|
+
start_row += 1
|
|
984
|
+
else:
|
|
985
|
+
start_row = last_row + 1
|
|
986
|
+
|
|
987
|
+
# convert the groups into rectangular strips
|
|
988
|
+
for i, group in enumerate(merged_groups):
|
|
989
|
+
min_2d = group['min']
|
|
990
|
+
max_2d = group['max']
|
|
991
|
+
base, hgt = max_2d.x - min_2d.x, max_2d.y - min_2d.y
|
|
992
|
+
bound_poly = Polygon2D.from_rectangle(min_2d, Vector2D(0, 1), base, hgt)
|
|
993
|
+
geo_3d = Face3D([ref_plane.xy_to_xyz(v) for v in bound_poly.vertices])
|
|
994
|
+
new_ap = Aperture(
|
|
995
|
+
'{}_Glz{}'.format(ap_obj.identifier, i),
|
|
996
|
+
geo_3d, is_operable=ap_obj.is_operable)
|
|
997
|
+
new_ap.display_name = '{}_{}'.format(ap_obj.display_name, i)
|
|
998
|
+
new_ap_objs.append(new_ap)
|
|
999
|
+
|
|
1000
|
+
# replace the apertures with the new ones
|
|
1001
|
+
self.remove_apertures()
|
|
1002
|
+
self.add_apertures(rect_aps + new_ap_objs)
|
|
1003
|
+
return True
|
|
1004
|
+
|
|
1005
|
+
def _reference_plane(self, angle_tolerance):
|
|
1006
|
+
"""Get a Plane for this Face geometry derived from the Face3D plane.
|
|
1007
|
+
|
|
1008
|
+
This will be oriented with the plane Y-Axis either aligned with the
|
|
1009
|
+
World Z or World Y, which is helpful in rectangularization.
|
|
1010
|
+
|
|
1011
|
+
Args:
|
|
1012
|
+
angle_tolerance: The max angle in radians that Face normal can differ
|
|
1013
|
+
from the World Z before the Face is treated as being in the
|
|
1014
|
+
World XY plane.
|
|
1015
|
+
"""
|
|
1016
|
+
parent_llc = self.geometry.lower_left_corner
|
|
1017
|
+
rel_plane = self.geometry.plane
|
|
1018
|
+
vertical = Vector3D(0, 0, 1)
|
|
1019
|
+
vert_ang = rel_plane.n.angle(vertical)
|
|
1020
|
+
if vert_ang <= angle_tolerance or vert_ang >= math.pi - angle_tolerance:
|
|
1021
|
+
proj_x = Vector3D(1, 0, 0)
|
|
1022
|
+
else:
|
|
1023
|
+
proj_y = vertical.project(rel_plane.n)
|
|
1024
|
+
proj_x = proj_y.rotate(rel_plane.n, math.pi / -2)
|
|
1025
|
+
|
|
1026
|
+
ref_plane = Plane(rel_plane.n, parent_llc, proj_x)
|
|
1027
|
+
return ref_plane
|
|
1028
|
+
|
|
1029
|
+
def offset_aperture_edges(self, offset_distance, tolerance=0.01):
|
|
1030
|
+
"""Offset the edges of all apertures by a certain distance.
|
|
1031
|
+
|
|
1032
|
+
This is useful for translating between interfaces that expect the window
|
|
1033
|
+
frame to be included within or excluded from the geometry of the Aperture.
|
|
1034
|
+
|
|
1035
|
+
Note that this operation can often create Apertures that collide with
|
|
1036
|
+
one another or extend past the parent Face. So it may be desirable
|
|
1037
|
+
to run the fix_invalid_sub_faces after using this method.
|
|
1038
|
+
|
|
1039
|
+
Args:
|
|
1040
|
+
offset_distance: Distance with which the edges of each Aperture will
|
|
1041
|
+
be offset from the original geometry. Positive values will
|
|
1042
|
+
offset the geometry outwards and negative values will offset the
|
|
1043
|
+
geometries inwards.
|
|
1044
|
+
tolerance: The minimum difference between point values for them to be
|
|
1045
|
+
considered the distinct. (Default: 0.01, suitable for objects
|
|
1046
|
+
in meters).
|
|
1047
|
+
"""
|
|
1048
|
+
# convert the apertures to polygons and offset them
|
|
1049
|
+
new_apertures = []
|
|
1050
|
+
prim_pl = self.geometry.plane
|
|
1051
|
+
for ap in self.apertures:
|
|
1052
|
+
try:
|
|
1053
|
+
verts_2d = tuple(prim_pl.xyz_to_xy(pt) for pt in ap.geometry.boundary)
|
|
1054
|
+
poly = Polygon2D(verts_2d).remove_colinear_vertices(tolerance)
|
|
1055
|
+
off_poly = poly.offset(-offset_distance, True)
|
|
1056
|
+
if off_poly is not None:
|
|
1057
|
+
verts_3d = tuple(prim_pl.xy_to_xyz(pt) for pt in off_poly)
|
|
1058
|
+
new_ap = ap.duplicate()
|
|
1059
|
+
new_ap._geometry = Face3D(verts_3d, prim_pl)
|
|
1060
|
+
new_apertures.append(new_ap)
|
|
1061
|
+
else:
|
|
1062
|
+
new_apertures.append(ap)
|
|
1063
|
+
except AssertionError: # degenerate geometry to ignore
|
|
1064
|
+
new_apertures.append(ap)
|
|
1065
|
+
# assign the new apertures
|
|
1066
|
+
self.remove_apertures()
|
|
1067
|
+
self.add_apertures(new_apertures)
|
|
1068
|
+
|
|
1069
|
+
def merge_neighboring_sub_faces(self, merge_distance=0.05, tolerance=0.01):
|
|
1070
|
+
"""Merge neighboring Apertures and/or Doors on this Face together.
|
|
1071
|
+
|
|
1072
|
+
This method is particularly useful for simplifying Apertures in concave
|
|
1073
|
+
Faces since trying to simplify such Apertures down to a ratio will
|
|
1074
|
+
produce a triangulated result that is not particularly clean.
|
|
1075
|
+
|
|
1076
|
+
Args:
|
|
1077
|
+
merge_distance: Distance between Apertures and/or Doors at which point they
|
|
1078
|
+
will be merged into a single Aperture. When this value is less than
|
|
1079
|
+
or equal to the tolerance, apertures will only be merged if they
|
|
1080
|
+
touch one another. (Default: 0.05, suitable for objects in meters).
|
|
1081
|
+
tolerance: The minimum difference between point values for them to be
|
|
1082
|
+
considered the distinct. (Default: 0.01, suitable for objects
|
|
1083
|
+
in meters).
|
|
1084
|
+
"""
|
|
1085
|
+
# first, check that there are Apertures to e merged
|
|
1086
|
+
sub_faces = self.sub_faces
|
|
1087
|
+
if len(sub_faces) <= 1: # no apertures to be merged
|
|
1088
|
+
return
|
|
1089
|
+
|
|
1090
|
+
# collect the sub-face geometries as polygons in the face plane
|
|
1091
|
+
clean_polys, original_objs, original_area = [], [], 0
|
|
1092
|
+
prim_pl = self.geometry.plane
|
|
1093
|
+
for sub_f in sub_faces:
|
|
1094
|
+
try:
|
|
1095
|
+
verts_2d = tuple(prim_pl.xyz_to_xy(pt) for pt in sub_f.geometry.boundary)
|
|
1096
|
+
poly = Polygon2D(verts_2d).remove_colinear_vertices(tolerance)
|
|
1097
|
+
clean_polys.append(poly)
|
|
1098
|
+
original_area += poly.area
|
|
1099
|
+
original_objs.append(sub_f)
|
|
1100
|
+
except AssertionError: # degenerate geometry to ignore
|
|
1101
|
+
pass
|
|
1102
|
+
original_polys = clean_polys[:]
|
|
1103
|
+
|
|
1104
|
+
# join the polygons together
|
|
1105
|
+
if merge_distance <= tolerance: # only join the polygons that touch one another
|
|
1106
|
+
clean_polys = Polygon2D.joined_intersected_boundary(clean_polys, tolerance)
|
|
1107
|
+
else:
|
|
1108
|
+
clean_polys = Polygon2D.gap_crossing_boundary(
|
|
1109
|
+
clean_polys, merge_distance, tolerance)
|
|
1110
|
+
|
|
1111
|
+
# assuming that the operations have edited the polygons, create new sub-faces
|
|
1112
|
+
new_area = sum(p.area for p in clean_polys)
|
|
1113
|
+
area_diff = abs(original_area - new_area)
|
|
1114
|
+
if len(clean_polys) != len(original_polys) or area_diff > tolerance:
|
|
1115
|
+
clean_polys = [poly.remove_colinear_vertices(tolerance)
|
|
1116
|
+
for poly in clean_polys]
|
|
1117
|
+
self.remove_sub_faces()
|
|
1118
|
+
for i, n_poly in enumerate(clean_polys):
|
|
1119
|
+
new_geo = Face3D([prim_pl.xy_to_xyz(pt) for pt in n_poly], prim_pl)
|
|
1120
|
+
for o_poly, o_obj in zip(original_polys, original_objs):
|
|
1121
|
+
if n_poly.is_point_inside_bound_rect(o_poly.center):
|
|
1122
|
+
orig_obj = o_obj
|
|
1123
|
+
break
|
|
1124
|
+
else: # could not be matched with any original object
|
|
1125
|
+
orig_obj = None
|
|
1126
|
+
if orig_obj is None:
|
|
1127
|
+
new_ap = Aperture('{}_{}'.format(self.identifier, i), new_geo)
|
|
1128
|
+
self.add_aperture(new_ap)
|
|
1129
|
+
elif isinstance(orig_obj, Aperture):
|
|
1130
|
+
new_ap = orig_obj.duplicate()
|
|
1131
|
+
new_ap._geometry = new_geo
|
|
1132
|
+
self.add_aperture(new_ap)
|
|
1133
|
+
elif isinstance(orig_obj, Door):
|
|
1134
|
+
new_door = orig_obj.duplicate()
|
|
1135
|
+
new_door._geometry = new_geo
|
|
1136
|
+
self.add_door(new_door)
|
|
1137
|
+
|
|
1138
|
+
def project_and_add_sub_face(self, sub_face, angle_tolerance=None):
|
|
1139
|
+
"""Project an Aperture or Door into this Face and add it to the Face.
|
|
1140
|
+
|
|
1141
|
+
Args:
|
|
1142
|
+
sub_face: An Aperture or Door to be projected into this Face and added
|
|
1143
|
+
to it.
|
|
1144
|
+
angle_tolerance: An optional angle tolerance in degrees to be
|
|
1145
|
+
used to check whether the plane of the sub-face is parallel
|
|
1146
|
+
with this Face before merging.If None, no check will be
|
|
1147
|
+
performed. (Default: None).
|
|
1148
|
+
"""
|
|
1149
|
+
parallel = True
|
|
1150
|
+
if angle_tolerance is not None:
|
|
1151
|
+
a_tol_min = math.radians(angle_tolerance)
|
|
1152
|
+
a_tol_max = math.pi - a_tol_min
|
|
1153
|
+
if a_tol_min < sub_face.normal.angle(self.normal) < a_tol_max:
|
|
1154
|
+
parallel = False
|
|
1155
|
+
if parallel:
|
|
1156
|
+
pl = self.geometry.plane
|
|
1157
|
+
geo = sub_face.geometry
|
|
1158
|
+
bound = [pl.project_point(pt) for pt in geo.boundary]
|
|
1159
|
+
holes = [[pl.project_point(pt) for pt in h] for h in geo.holes] \
|
|
1160
|
+
if geo.has_holes else None
|
|
1161
|
+
sub_face._geometry = Face3D(bound, pl, holes)
|
|
1162
|
+
self.add_sub_face(sub_face)
|
|
1163
|
+
|
|
1164
|
+
def fix_invalid_sub_faces(
|
|
1165
|
+
self, trim_with_parent=True, union_overlaps=True,
|
|
1166
|
+
offset_distance=0.05, tolerance=0.01):
|
|
1167
|
+
"""Fix invalid Apertures and Doors on this face by performing two operations.
|
|
1168
|
+
|
|
1169
|
+
First, sub-faces that extend past their parent Face are trimmed with the
|
|
1170
|
+
parent and will have their edges offset towards the inside of the Face.
|
|
1171
|
+
Second, any sub-faces that overlap or touch one another will be unioned
|
|
1172
|
+
into a single Aperture or Door.
|
|
1173
|
+
|
|
1174
|
+
Args:
|
|
1175
|
+
trim_with_parent: Boolean to note whether the fixing operation should
|
|
1176
|
+
check all sub-faces that extend past their parent and trim
|
|
1177
|
+
them, offsetting them towards the inside of the Face. (Default: True).
|
|
1178
|
+
union_overlaps: Boolean to note whether the fixing operation should
|
|
1179
|
+
check all sub-faces that overlap with one another and union any
|
|
1180
|
+
sub-faces together that overlap. (Default: True).
|
|
1181
|
+
offset_distance: Distance from the edge of the parent Face that the
|
|
1182
|
+
sub-faces will be offset to in order to make them valid. This
|
|
1183
|
+
should be larger than the tolerance. (Default: 0.05, suitable for
|
|
1184
|
+
objects in meters).
|
|
1185
|
+
tolerance: The minimum difference between point values for them to be
|
|
1186
|
+
considered the distinct. (Default: 0.01, suitable for objects
|
|
1187
|
+
in meters).
|
|
1188
|
+
"""
|
|
1189
|
+
# collect the sub-face geometries as polygons in the face plane
|
|
1190
|
+
clean_polys, original_objs, original_area = [], [], 0
|
|
1191
|
+
prim_pl = self.geometry.plane
|
|
1192
|
+
for sub_f in self.sub_faces:
|
|
1193
|
+
try:
|
|
1194
|
+
verts_2d = tuple(prim_pl.xyz_to_xy(pt) for pt in sub_f.geometry.boundary)
|
|
1195
|
+
poly = Polygon2D(verts_2d).remove_colinear_vertices(tolerance)
|
|
1196
|
+
clean_polys.append(poly)
|
|
1197
|
+
original_area += poly.area
|
|
1198
|
+
original_objs.append(sub_f)
|
|
1199
|
+
except AssertionError: # degenerate geometry to ignore
|
|
1200
|
+
pass
|
|
1201
|
+
original_polys = clean_polys[:]
|
|
1202
|
+
|
|
1203
|
+
# trim objects with the parent polygon if they extend past it
|
|
1204
|
+
if trim_with_parent:
|
|
1205
|
+
face_3d = self.geometry
|
|
1206
|
+
verts2d = tuple(prim_pl.xyz_to_xy(pt) for pt in face_3d.boundary)
|
|
1207
|
+
parent_poly, parent_holes = Polygon2D(verts2d), None
|
|
1208
|
+
if face_3d.has_holes:
|
|
1209
|
+
parent_holes = tuple(
|
|
1210
|
+
Polygon2D(prim_pl.xyz_to_xy(pt) for pt in hole)
|
|
1211
|
+
for hole in face_3d.holes
|
|
1212
|
+
)
|
|
1213
|
+
# loop through the polygons and offset them if they are not correctly bounded
|
|
1214
|
+
new_polygons = []
|
|
1215
|
+
for polygon in clean_polys:
|
|
1216
|
+
if not self._is_sub_polygon(polygon, parent_poly, parent_holes):
|
|
1217
|
+
# find the boolean intersection of the polygon with the room
|
|
1218
|
+
sub_face = Face3D([prim_pl.xy_to_xyz(pt) for pt in polygon])
|
|
1219
|
+
bool_int = Face3D.coplanar_intersection(
|
|
1220
|
+
face_3d, sub_face, tolerance, math.radians(1))
|
|
1221
|
+
if bool_int is None: # sub-face completely outside parent
|
|
1222
|
+
continue
|
|
1223
|
+
# offset the result of the boolean intersection from the edge
|
|
1224
|
+
parent_edges = face_3d.boundary_segments if face_3d.holes is None \
|
|
1225
|
+
else face_3d.boundary_segments + \
|
|
1226
|
+
tuple(seg for hole in face_3d.hole_segments for seg in hole)
|
|
1227
|
+
for new_f in bool_int:
|
|
1228
|
+
new_pts_2d = []
|
|
1229
|
+
for pt in new_f.boundary:
|
|
1230
|
+
for edge in parent_edges:
|
|
1231
|
+
close_pt = edge.closest_point(pt)
|
|
1232
|
+
if pt.distance_to_point(close_pt) < offset_distance:
|
|
1233
|
+
move_vec = edge.v.rotate(prim_pl.n, math.pi / 2)
|
|
1234
|
+
move_vec = move_vec.normalize() * offset_distance
|
|
1235
|
+
pt = pt.move(move_vec)
|
|
1236
|
+
new_pts_2d.append(prim_pl.xyz_to_xy(pt))
|
|
1237
|
+
new_polygons.append(Polygon2D(new_pts_2d))
|
|
1238
|
+
else:
|
|
1239
|
+
new_polygons.append(polygon)
|
|
1240
|
+
clean_polys = new_polygons
|
|
1241
|
+
|
|
1242
|
+
# union overlaps and merge sub-faces that are touching
|
|
1243
|
+
if union_overlaps:
|
|
1244
|
+
grouped_polys = Polygon2D.group_by_overlap(clean_polys, tolerance)
|
|
1245
|
+
# union any of the polygons that overlap
|
|
1246
|
+
if not all(len(g) == 1 for g in grouped_polys):
|
|
1247
|
+
clean_polys = []
|
|
1248
|
+
for p_group in grouped_polys:
|
|
1249
|
+
if len(p_group) == 1:
|
|
1250
|
+
clean_polys.append(p_group[0])
|
|
1251
|
+
else:
|
|
1252
|
+
union_poly = Polygon2D.boolean_union_all(p_group, tolerance)
|
|
1253
|
+
for new_poly in union_poly:
|
|
1254
|
+
clean_polys.append(
|
|
1255
|
+
new_poly.remove_colinear_vertices(tolerance))
|
|
1256
|
+
# join the polygons that touch one another
|
|
1257
|
+
clean_polys = Polygon2D.joined_intersected_boundary(clean_polys, tolerance)
|
|
1258
|
+
|
|
1259
|
+
# assuming that the operations have edited the polygons, create new sub-faces
|
|
1260
|
+
new_area = sum(p.area for p in clean_polys)
|
|
1261
|
+
area_diff = abs(original_area - new_area)
|
|
1262
|
+
if len(clean_polys) != len(original_polys) or area_diff > tolerance:
|
|
1263
|
+
self.remove_sub_faces()
|
|
1264
|
+
for i, n_poly in enumerate(clean_polys):
|
|
1265
|
+
new_geo = Face3D([prim_pl.xy_to_xyz(pt) for pt in n_poly], prim_pl)
|
|
1266
|
+
for o_poly, o_obj in zip(original_polys, original_objs):
|
|
1267
|
+
if n_poly.is_point_inside_bound_rect(o_poly.center):
|
|
1268
|
+
orig_obj = o_obj
|
|
1269
|
+
break
|
|
1270
|
+
else: # could not be matched with any original object
|
|
1271
|
+
orig_obj = None
|
|
1272
|
+
if orig_obj is None:
|
|
1273
|
+
new_ap = Aperture('{}_{}'.format(self.identifier, i), new_geo)
|
|
1274
|
+
self.add_aperture(new_ap)
|
|
1275
|
+
elif isinstance(orig_obj, Aperture):
|
|
1276
|
+
new_ap = orig_obj.duplicate()
|
|
1277
|
+
new_ap._geometry = new_geo
|
|
1278
|
+
self.add_aperture(new_ap)
|
|
1279
|
+
elif isinstance(orig_obj, Door):
|
|
1280
|
+
new_door = orig_obj.duplicate()
|
|
1281
|
+
new_door._geometry = new_geo
|
|
1282
|
+
self.add_door(new_door)
|
|
1283
|
+
|
|
1284
|
+
def apertures_by_ratio(self, ratio, tolerance=0.01, rect_split=True):
|
|
1285
|
+
"""Add apertures to this Face given a ratio of aperture area to face area.
|
|
1286
|
+
|
|
1287
|
+
Note that this method removes any existing apertures and doors on the Face.
|
|
1288
|
+
This method attempts to generate as few apertures as necessary to meet the ratio.
|
|
1289
|
+
|
|
1290
|
+
Args:
|
|
1291
|
+
ratio: A number between 0 and 1 (but not perfectly equal to 1)
|
|
1292
|
+
for the desired ratio between aperture area and face area.
|
|
1293
|
+
tolerance: The maximum difference between point values for them to be
|
|
1294
|
+
considered the same. This is used in the event that this face is
|
|
1295
|
+
concave and an attempt to subdivide the face into a rectangle is
|
|
1296
|
+
made. It does not affect the ability to produce apertures for
|
|
1297
|
+
convex Faces. Default: 0.01, suitable for objects in meters.
|
|
1298
|
+
rect_split: Boolean to note whether rectangular portions of base Face
|
|
1299
|
+
should be extracted before scaling them to create apertures. For
|
|
1300
|
+
gabled geometries, the resulting apertures will consist of one
|
|
1301
|
+
rectangle and one triangle, which can often look more realistic
|
|
1302
|
+
and is a better input for engines like EnergyPlus that cannot
|
|
1303
|
+
model windows with more than 4 vertices. However, if a single
|
|
1304
|
+
pentagonal window is desired for a gabled shape, this input can
|
|
1305
|
+
be set to False to produce such a result.
|
|
1306
|
+
|
|
1307
|
+
Usage:
|
|
1308
|
+
|
|
1309
|
+
.. code-block:: python
|
|
1310
|
+
|
|
1311
|
+
room = Room.from_box(3.0, 6.0, 3.2, 180)
|
|
1312
|
+
room.faces[1].apertures_by_ratio(0.4)
|
|
1313
|
+
"""
|
|
1314
|
+
assert 0 <= ratio < 1, 'Ratio must be between 0 and 1. Got {}'.format(ratio)
|
|
1315
|
+
self._acceptable_sub_face_check(Aperture)
|
|
1316
|
+
self.remove_sub_faces()
|
|
1317
|
+
if ratio == 0:
|
|
1318
|
+
return
|
|
1319
|
+
try:
|
|
1320
|
+
geo = self._geometry.remove_colinear_vertices(tolerance)
|
|
1321
|
+
except AssertionError: # degenerate face that should not have apertures
|
|
1322
|
+
return
|
|
1323
|
+
if rect_split:
|
|
1324
|
+
ap_faces = geo.sub_faces_by_ratio_rectangle(ratio, tolerance)
|
|
1325
|
+
else:
|
|
1326
|
+
ap_faces = geo.sub_faces_by_ratio(ratio)
|
|
1327
|
+
for i, ap_face in enumerate(ap_faces):
|
|
1328
|
+
aperture = Aperture('{}_Glz{}'.format(self.identifier, i), ap_face)
|
|
1329
|
+
self.add_aperture(aperture)
|
|
1330
|
+
|
|
1331
|
+
def apertures_by_ratio_rectangle(self, ratio, aperture_height, sill_height,
|
|
1332
|
+
horizontal_separation, vertical_separation=0,
|
|
1333
|
+
tolerance=0.01):
|
|
1334
|
+
"""Add apertures to this face given a ratio of aperture area to face area.
|
|
1335
|
+
|
|
1336
|
+
Note that this method removes any existing apertures on the Face.
|
|
1337
|
+
|
|
1338
|
+
This function is virtually equivalent to the apertures_by_ratio method but
|
|
1339
|
+
any rectangular portions of this face will produce customizable rectangular
|
|
1340
|
+
apertures using the other inputs (aperture_height, sill_height,
|
|
1341
|
+
horizontal_separation, vertical_separation).
|
|
1342
|
+
|
|
1343
|
+
Args:
|
|
1344
|
+
ratio: A number between 0 and 0.95 for the ratio between the area of
|
|
1345
|
+
the apertures and the area of this face.
|
|
1346
|
+
aperture_height: A number for the target height of the output apertures.
|
|
1347
|
+
Note that, if the ratio is too large for the height, the ratio will
|
|
1348
|
+
take precedence and the actual aperture_height will be larger
|
|
1349
|
+
than this value.
|
|
1350
|
+
sill_height: A number for the target height above the bottom edge of
|
|
1351
|
+
the rectangle to start the apertures. Note that, if the
|
|
1352
|
+
ratio is too large for the height, the ratio will take precedence
|
|
1353
|
+
and the sill_height will be smaller than this value.
|
|
1354
|
+
horizontal_separation: A number for the target separation between
|
|
1355
|
+
individual aperture center lines. If this number is larger than
|
|
1356
|
+
the parent rectangle base, only one aperture will be produced.
|
|
1357
|
+
vertical_separation: An optional number to create a single vertical
|
|
1358
|
+
separation between top and bottom apertures. The default is
|
|
1359
|
+
0 for no separation.
|
|
1360
|
+
tolerance: The maximum difference between point values for them to be
|
|
1361
|
+
considered a part of a rectangle. Default: 0.01, suitable for
|
|
1362
|
+
objects in meters.
|
|
1363
|
+
|
|
1364
|
+
Usage:
|
|
1365
|
+
|
|
1366
|
+
.. code-block:: python
|
|
1367
|
+
|
|
1368
|
+
room = Room.from_box(3.0, 6.0, 3.2, 180)
|
|
1369
|
+
room.faces[1].apertures_by_ratio_rectangle(0.4, 2, 0.9, 3)
|
|
1370
|
+
"""
|
|
1371
|
+
assert 0 <= ratio <= 0.95, \
|
|
1372
|
+
'Ratio must be between 0 and 0.95. Got {}'.format(ratio)
|
|
1373
|
+
self._acceptable_sub_face_check(Aperture)
|
|
1374
|
+
self.remove_sub_faces()
|
|
1375
|
+
if ratio == 0:
|
|
1376
|
+
return
|
|
1377
|
+
try:
|
|
1378
|
+
geo = self._geometry.remove_colinear_vertices(tolerance)
|
|
1379
|
+
except AssertionError: # degenerate face that should not have apertures
|
|
1380
|
+
return
|
|
1381
|
+
ap_faces = geo.sub_faces_by_ratio_sub_rectangle(
|
|
1382
|
+
ratio, aperture_height, sill_height, horizontal_separation,
|
|
1383
|
+
vertical_separation, tolerance)
|
|
1384
|
+
for i, ap_face in enumerate(ap_faces):
|
|
1385
|
+
aperture = Aperture('{}_Glz{}'.format(self.identifier, i), ap_face)
|
|
1386
|
+
self.add_aperture(aperture)
|
|
1387
|
+
|
|
1388
|
+
def apertures_by_ratio_gridded(self, ratio, x_dim, y_dim=None, tolerance=0.01):
|
|
1389
|
+
"""Add apertures to this face given a ratio of aperture area to face area.
|
|
1390
|
+
|
|
1391
|
+
Note that this method removes any existing apertures on the Face.
|
|
1392
|
+
|
|
1393
|
+
Apertures will be arranged in a grid derived from this face's plane.
|
|
1394
|
+
Because the x_dim and y_dim refer to dimensions within the X and Y
|
|
1395
|
+
coordinate system of this faces's plane, rotating this plane will
|
|
1396
|
+
result in rotated grid cells. This is particularly useful for generating
|
|
1397
|
+
skylights based on a glazing ratio.
|
|
1398
|
+
|
|
1399
|
+
If the x_dim and/or y_dim are too large for this face, this method will
|
|
1400
|
+
return essentially the same result as the apertures_by_ratio method.
|
|
1401
|
+
|
|
1402
|
+
Args:
|
|
1403
|
+
ratio: A number between 0 and 1 for the ratio between the area of
|
|
1404
|
+
the apertures and the area of this face.
|
|
1405
|
+
x_dim: The x dimension of the grid cells as a number.
|
|
1406
|
+
y_dim: The y dimension of the grid cells as a number. Default is None,
|
|
1407
|
+
which will assume the same cell dimension for y as is set for x.
|
|
1408
|
+
tolerance: The maximum difference between point values for them to be
|
|
1409
|
+
considered a part of a rectangle. Default: 0.01, suitable for
|
|
1410
|
+
objects in meters.
|
|
1411
|
+
|
|
1412
|
+
Usage:
|
|
1413
|
+
|
|
1414
|
+
.. code-block:: python
|
|
1415
|
+
|
|
1416
|
+
room = Room.from_box(3.0, 6.0, 3.2, 180)
|
|
1417
|
+
room.faces[-1].apertures_by_ratio_gridded(0.05, 3)
|
|
1418
|
+
"""
|
|
1419
|
+
assert 0 <= ratio < 1, 'Ratio must be between 0 and 1. Got {}'.format(ratio)
|
|
1420
|
+
self._acceptable_sub_face_check(Aperture)
|
|
1421
|
+
self.remove_sub_faces()
|
|
1422
|
+
if ratio == 0:
|
|
1423
|
+
return
|
|
1424
|
+
try:
|
|
1425
|
+
geo = self._geometry.remove_colinear_vertices(tolerance)
|
|
1426
|
+
except AssertionError: # degenerate face that should not have apertures
|
|
1427
|
+
return
|
|
1428
|
+
ap_faces = geo.sub_faces_by_ratio_gridded(ratio, x_dim, y_dim)
|
|
1429
|
+
for i, ap_face in enumerate(ap_faces):
|
|
1430
|
+
aperture = Aperture('{}_Glz{}'.format(self.identifier, i), ap_face)
|
|
1431
|
+
self.add_aperture(aperture)
|
|
1432
|
+
|
|
1433
|
+
def apertures_by_width_height_rectangle(self, aperture_height, aperture_width,
|
|
1434
|
+
sill_height, horizontal_separation,
|
|
1435
|
+
tolerance=0.01):
|
|
1436
|
+
"""Add repeating apertures to this face given the aperture width and height.
|
|
1437
|
+
|
|
1438
|
+
Note that this method removes any existing apertures on the Face.
|
|
1439
|
+
|
|
1440
|
+
Note that this method will effectively fill any rectangular portions of
|
|
1441
|
+
this Face with apertures at the specified width, height and separation.
|
|
1442
|
+
If no rectangular portion of this Face can be identified, no apertures
|
|
1443
|
+
will be added.
|
|
1444
|
+
|
|
1445
|
+
Args:
|
|
1446
|
+
aperture_height: A number for the target height of the apertures.
|
|
1447
|
+
aperture_width: A number for the target width of the apertures.
|
|
1448
|
+
sill_height: A number for the target height above the bottom edge of
|
|
1449
|
+
the rectangle to start the apertures. If the aperture_height
|
|
1450
|
+
is too large for the sill_height to fit within the rectangle,
|
|
1451
|
+
the aperture_height will take precedence.
|
|
1452
|
+
horizontal_separation: A number for the target separation between
|
|
1453
|
+
individual apertures center lines. If this number is larger than
|
|
1454
|
+
the parent rectangle base, only one aperture will be produced.
|
|
1455
|
+
tolerance: The maximum difference between point values for them to be
|
|
1456
|
+
considered a part of a rectangle. Default: 0.01, suitable for
|
|
1457
|
+
objects in meters.
|
|
1458
|
+
|
|
1459
|
+
Usage:
|
|
1460
|
+
|
|
1461
|
+
.. code-block:: python
|
|
1462
|
+
|
|
1463
|
+
room = Room.from_box(5.0, 10.0, 3.2, 180)
|
|
1464
|
+
room.faces[1].apertures_by_width_height_rectangle(1.5, 2, 0.8, 2.5)
|
|
1465
|
+
"""
|
|
1466
|
+
assert horizontal_separation > 0, \
|
|
1467
|
+
'horizontal_separation must be above 0. Got {}'.format(horizontal_separation)
|
|
1468
|
+
if aperture_height <= 0 or aperture_width <= 0:
|
|
1469
|
+
return
|
|
1470
|
+
self._acceptable_sub_face_check(Aperture)
|
|
1471
|
+
self.remove_sub_faces()
|
|
1472
|
+
try:
|
|
1473
|
+
geo = self._geometry.remove_colinear_vertices(tolerance)
|
|
1474
|
+
except AssertionError: # degenerate face that should not have apertures
|
|
1475
|
+
return
|
|
1476
|
+
ap_faces = geo.sub_faces_by_dimension_rectangle(
|
|
1477
|
+
aperture_height, aperture_width, sill_height, horizontal_separation,
|
|
1478
|
+
tolerance)
|
|
1479
|
+
for i, ap_face in enumerate(ap_faces):
|
|
1480
|
+
aperture = Aperture('{}_Glz{}'.format(self.identifier, i), ap_face)
|
|
1481
|
+
self.add_aperture(aperture)
|
|
1482
|
+
|
|
1483
|
+
def aperture_by_width_height(self, width, height, sill_height=1,
|
|
1484
|
+
aperture_identifier=None):
|
|
1485
|
+
"""Add a single rectangular aperture to the center of this Face.
|
|
1486
|
+
|
|
1487
|
+
A rectangular window with the input width and height will always be added
|
|
1488
|
+
by this method regardless of whether this parent Face contains a recognizable
|
|
1489
|
+
rectangular portion or not. Furthermore, this method preserves any existing
|
|
1490
|
+
apertures on the Face.
|
|
1491
|
+
|
|
1492
|
+
While the resulting aperture will always be in the plane of this Face,
|
|
1493
|
+
this method will not check to ensure that the aperture has all of its
|
|
1494
|
+
vertices completely within the boundary of this Face or that it does not
|
|
1495
|
+
intersect with other apertures in the Face. The are_sub_faces_valid()
|
|
1496
|
+
method can be used afterwards to check this.
|
|
1497
|
+
|
|
1498
|
+
Args:
|
|
1499
|
+
width: A number for the Aperture width.
|
|
1500
|
+
height: A number for the Aperture height.
|
|
1501
|
+
sill_height: A number for the sill height. (Default: 1).
|
|
1502
|
+
aperture_identifier: Optional string for the aperture identifier.
|
|
1503
|
+
If None, the default will follow the convention
|
|
1504
|
+
"[face_identifier]_Glz[count]" where [count] is one more than
|
|
1505
|
+
the current number of apertures in the face.
|
|
1506
|
+
|
|
1507
|
+
Returns:
|
|
1508
|
+
The new Aperture object that has been generated.
|
|
1509
|
+
|
|
1510
|
+
Usage:
|
|
1511
|
+
|
|
1512
|
+
.. code-block:: python
|
|
1513
|
+
|
|
1514
|
+
room = Room.from_box(3.0, 6.0, 3.2, 180)
|
|
1515
|
+
room[1].aperture_by_width_height(2, 2, .7) # aperture in front
|
|
1516
|
+
room[2].aperture_by_width_height(4, 1.5, .5) # aperture on right
|
|
1517
|
+
room[2].aperture_by_width_height(4, 0.5, 2.2) # aperture on right
|
|
1518
|
+
"""
|
|
1519
|
+
# Perform checks
|
|
1520
|
+
if width <= 0 or height <= 0:
|
|
1521
|
+
return
|
|
1522
|
+
self._acceptable_sub_face_check(Aperture)
|
|
1523
|
+
# Generate the aperture geometry
|
|
1524
|
+
origin = self._geometry.lower_left_counter_clockwise_vertices[0]
|
|
1525
|
+
face_plane = Plane(self._geometry.plane.n, origin)
|
|
1526
|
+
if face_plane.y.z < 0:
|
|
1527
|
+
face_plane = face_plane.rotate(face_plane.n, math.pi, face_plane.o)
|
|
1528
|
+
center2d = face_plane.xyz_to_xy(self._geometry.center)
|
|
1529
|
+
x_dist = width / 2
|
|
1530
|
+
lower_left = Point2D(center2d.x - x_dist, sill_height)
|
|
1531
|
+
lower_right = Point2D(center2d.x + x_dist, sill_height)
|
|
1532
|
+
upper_right = Point2D(center2d.x + x_dist, sill_height + height)
|
|
1533
|
+
upper_left = Point2D(center2d.x - x_dist, sill_height + height)
|
|
1534
|
+
ap_verts2d = (lower_left, lower_right, upper_right, upper_left)
|
|
1535
|
+
ap_verts3d = tuple(face_plane.xy_to_xyz(pt) for pt in ap_verts2d)
|
|
1536
|
+
ap_face = Face3D(ap_verts3d, self._geometry.plane)
|
|
1537
|
+
if self.normal.angle(ap_face.normal) > math.pi / 2: # reversed normal
|
|
1538
|
+
ap_face = ap_face.flip()
|
|
1539
|
+
|
|
1540
|
+
# Create the aperture and add it to this Face
|
|
1541
|
+
identifier = aperture_identifier or \
|
|
1542
|
+
'{}_Glz{}'.format(self.identifier, len(self.apertures))
|
|
1543
|
+
aperture = Aperture(identifier, ap_face)
|
|
1544
|
+
self.add_aperture(aperture)
|
|
1545
|
+
return aperture
|
|
1546
|
+
|
|
1547
|
+
def overhang(self, depth, angle=0, indoor=False, tolerance=0.01, base_name=None):
|
|
1548
|
+
"""Add an overhang to this Face.
|
|
1549
|
+
|
|
1550
|
+
Args:
|
|
1551
|
+
depth: A number for the overhang depth.
|
|
1552
|
+
angle: A number for the for an angle to rotate the overhang in degrees.
|
|
1553
|
+
Positive numbers indicate a downward rotation while negative numbers
|
|
1554
|
+
indicate an upward rotation. Default is 0 for no rotation.
|
|
1555
|
+
indoor: Boolean for whether the overhang should be generated facing the
|
|
1556
|
+
opposite direction of the aperture normal (typically meaning
|
|
1557
|
+
indoor geometry). Default: False.
|
|
1558
|
+
tolerance: An optional value to not add the overhang if it has a length less
|
|
1559
|
+
than the tolerance. Default: 0.01, suitable for objects in meters.
|
|
1560
|
+
base_name: Optional base identifier for the shade objects. If None,
|
|
1561
|
+
the default is InOverhang or OutOverhang depending on whether
|
|
1562
|
+
indoor is True.
|
|
1563
|
+
|
|
1564
|
+
Returns:
|
|
1565
|
+
A list of the new Shade objects that have been generated.
|
|
1566
|
+
"""
|
|
1567
|
+
if base_name is None:
|
|
1568
|
+
base_name = 'InOverhang' if indoor else 'OutOverhang'
|
|
1569
|
+
return self.louvers_by_count(1, depth, angle=angle, indoor=indoor,
|
|
1570
|
+
tolerance=tolerance, base_name=base_name)
|
|
1571
|
+
|
|
1572
|
+
def louvers(self, depth, louver_count=None, distance=None, offset=0, angle=0,
|
|
1573
|
+
contour_vector=Vector2D(0, 1), flip_start_side=False,
|
|
1574
|
+
indoor=False, tolerance=0.01, base_name=None):
|
|
1575
|
+
"""Add a series of louvered Shade objects over this Face.
|
|
1576
|
+
|
|
1577
|
+
If both louver_count and distance are None, this method will add a
|
|
1578
|
+
single louver shade following the other criteria.
|
|
1579
|
+
|
|
1580
|
+
Args:
|
|
1581
|
+
depth: A number for the depth to extrude the louvers.
|
|
1582
|
+
louver_count: A positive integer for the number of louvers to generate.
|
|
1583
|
+
If None, louvers will be generated to fill the Face at the
|
|
1584
|
+
specified distance. (Default: None).
|
|
1585
|
+
distance: A number for the approximate distance between each louver.
|
|
1586
|
+
If None, louvers will be generated to fill the Face at the
|
|
1587
|
+
specified louver_count. (Default: None).
|
|
1588
|
+
offset: A number for the distance to louvers from this Face.
|
|
1589
|
+
Default is 0 for no offset.
|
|
1590
|
+
angle: A number for the for an angle to rotate the louvers in degrees.
|
|
1591
|
+
Positive numbers indicate a downward rotation while negative numbers
|
|
1592
|
+
indicate an upward rotation. Default is 0 for no rotation.
|
|
1593
|
+
contour_vector: A Vector2D for the direction along which contours
|
|
1594
|
+
are generated. This 2D vector will be interpreted into a 3D vector
|
|
1595
|
+
within the plane of this Face. (0, 1) will usually generate
|
|
1596
|
+
horizontal contours in 3D space, (1, 0) will generate vertical
|
|
1597
|
+
contours, and (1, 1) will generate diagonal contours. Default: (0, 1).
|
|
1598
|
+
flip_start_side: Boolean to note whether the side the louvers start from
|
|
1599
|
+
should be flipped. Default is False to have louvers on top or right.
|
|
1600
|
+
Setting to True will start contours on the bottom or left.
|
|
1601
|
+
indoor: Boolean for whether louvers should be generated facing the
|
|
1602
|
+
opposite direction of the Face normal (typically meaning
|
|
1603
|
+
indoor geometry). Default: False.
|
|
1604
|
+
tolerance: An optional value to remove any louvers with a length less
|
|
1605
|
+
than the tolerance. Default: 0.01, suitable for objects in meters.
|
|
1606
|
+
base_name: Optional base identifier for the shade objects. If None,
|
|
1607
|
+
the default is InShd or OutShd depending on whether indoor is True.
|
|
1608
|
+
|
|
1609
|
+
Returns:
|
|
1610
|
+
A list of the new Shade objects that have been generated.
|
|
1611
|
+
"""
|
|
1612
|
+
if depth == 0 or louver_count == 0:
|
|
1613
|
+
return []
|
|
1614
|
+
elif louver_count is None and distance is None:
|
|
1615
|
+
return self.louvers_by_count(
|
|
1616
|
+
1, depth, offset, angle, contour_vector, flip_start_side, indoor,
|
|
1617
|
+
tolerance=tolerance, base_name=base_name)
|
|
1618
|
+
elif distance is None:
|
|
1619
|
+
return self.louvers_by_count(
|
|
1620
|
+
louver_count, depth, offset, angle, contour_vector,
|
|
1621
|
+
flip_start_side, indoor, tolerance=tolerance, base_name=base_name)
|
|
1622
|
+
else:
|
|
1623
|
+
return self.louvers_by_distance_between(
|
|
1624
|
+
distance, depth, offset, angle, contour_vector, flip_start_side, indoor,
|
|
1625
|
+
tolerance=tolerance, max_count=louver_count, base_name=base_name)
|
|
1626
|
+
|
|
1627
|
+
def louvers_by_count(self, louver_count, depth, offset=0, angle=0,
|
|
1628
|
+
contour_vector=Vector2D(0, 1), flip_start_side=False,
|
|
1629
|
+
indoor=False, tolerance=0.01, base_name=None):
|
|
1630
|
+
"""Add louvered Shade objects over this Face to hit a target louver_count.
|
|
1631
|
+
|
|
1632
|
+
Args:
|
|
1633
|
+
louver_count: A positive integer for the number of louvers to generate.
|
|
1634
|
+
depth: A number for the depth to extrude the louvers.
|
|
1635
|
+
offset: A number for the distance to louvers from this Face.
|
|
1636
|
+
Default is 0 for no offset.
|
|
1637
|
+
angle: A number for the for an angle to rotate the louvers in degrees.
|
|
1638
|
+
Positive numbers indicate a downward rotation while negative numbers
|
|
1639
|
+
indicate an upward rotation. Default is 0 for no rotation.
|
|
1640
|
+
contour_vector: A Vector2D for the direction along which contours
|
|
1641
|
+
are generated. This 2D vector will be interpreted into a 3D vector
|
|
1642
|
+
within the plane of this Face. (0, 1) will usually generate
|
|
1643
|
+
horizontal contours in 3D space, (1, 0) will generate vertical
|
|
1644
|
+
contours, and (1, 1) will generate diagonal contours. Default: (0, 1).
|
|
1645
|
+
flip_start_side: Boolean to note whether the side the louvers start from
|
|
1646
|
+
should be flipped. Default is False to have louvers on top or right.
|
|
1647
|
+
Setting to True will start contours on the bottom or left.
|
|
1648
|
+
indoor: Boolean for whether louvers should be generated facing the
|
|
1649
|
+
opposite direction of the Face normal (typically meaning
|
|
1650
|
+
indoor geometry). Default: False.
|
|
1651
|
+
tolerance: An optional value to remove any louvers with a length less
|
|
1652
|
+
than the tolerance. Default: 0.01, suitable for objects in meters.
|
|
1653
|
+
base_name: Optional base identifier for the shade objects. If None,
|
|
1654
|
+
the default is InShd or OutShd depending on whether indoor is True.
|
|
1655
|
+
|
|
1656
|
+
Returns:
|
|
1657
|
+
A list of the new Shade objects that have been generated.
|
|
1658
|
+
"""
|
|
1659
|
+
assert louver_count > 0, 'louver_count must be greater than 0.'
|
|
1660
|
+
angle = math.radians(angle)
|
|
1661
|
+
louvers = []
|
|
1662
|
+
face_geo = self.geometry if indoor is False else self.geometry.flip()
|
|
1663
|
+
if base_name is None:
|
|
1664
|
+
shd_name_base = '{}_InShd{}' if indoor else '{}_OutShd{}'
|
|
1665
|
+
else:
|
|
1666
|
+
shd_name_base = '{}_' + str(base_name) + '{}'
|
|
1667
|
+
shade_faces = face_geo.contour_fins_by_number(
|
|
1668
|
+
louver_count, depth, offset, angle,
|
|
1669
|
+
contour_vector, flip_start_side, tolerance)
|
|
1670
|
+
for i, shade_geo in enumerate(shade_faces):
|
|
1671
|
+
louvers.append(Shade(shd_name_base.format(self.identifier, i), shade_geo))
|
|
1672
|
+
if indoor:
|
|
1673
|
+
self.add_indoor_shades(louvers)
|
|
1674
|
+
else:
|
|
1675
|
+
self.add_outdoor_shades(louvers)
|
|
1676
|
+
return louvers
|
|
1677
|
+
|
|
1678
|
+
def louvers_by_distance_between(
|
|
1679
|
+
self, distance, depth, offset=0, angle=0, contour_vector=Vector2D(0, 1),
|
|
1680
|
+
flip_start_side=False, indoor=False, tolerance=0.01, max_count=None,
|
|
1681
|
+
base_name=None):
|
|
1682
|
+
"""Add louvered Shade objects over this Face to hit a target distance between.
|
|
1683
|
+
|
|
1684
|
+
Args:
|
|
1685
|
+
distance: A number for the approximate distance between each louver.
|
|
1686
|
+
depth: A number for the depth to extrude the louvers.
|
|
1687
|
+
offset: A number for the distance to louvers from this Face.
|
|
1688
|
+
Default is 0 for no offset.
|
|
1689
|
+
angle: A number for the for an angle to rotate the louvers in degrees.
|
|
1690
|
+
Positive numbers indicate a downward rotation while negative numbers
|
|
1691
|
+
indicate an upward rotation. Default is 0 for no rotation.
|
|
1692
|
+
contour_vector: A Vector2D for the direction along which contours
|
|
1693
|
+
are generated. This 2D vector will be interpreted into a 3D vector
|
|
1694
|
+
within the plane of this Face. (0, 1) will usually generate
|
|
1695
|
+
horizontal contours in 3D space, (1, 0) will generate vertical
|
|
1696
|
+
contours, and (1, 1) will generate diagonal contours. Default: (0, 1).
|
|
1697
|
+
flip_start_side: Boolean to note whether the side the louvers start from
|
|
1698
|
+
should be flipped. Default is False to have contours on top or right.
|
|
1699
|
+
Setting to True will start contours on the bottom or left.
|
|
1700
|
+
indoor: Boolean for whether louvers should be generated facing the
|
|
1701
|
+
opposite direction of the Face normal (typically meaning
|
|
1702
|
+
indoor geometry). Default: False.
|
|
1703
|
+
tolerance: An optional value to remove any louvers with a length less
|
|
1704
|
+
than the tolerance. Default: 0.01, suitable for objects in meters.
|
|
1705
|
+
max_count: Optional integer to set the maximum number of louvers that
|
|
1706
|
+
will be generated. If None, louvers will cover the entire face.
|
|
1707
|
+
base_name: Optional base identifier for the shade objects. If None, the
|
|
1708
|
+
default is InShd or OutShd depending on whether indoor is True.
|
|
1709
|
+
|
|
1710
|
+
Returns:
|
|
1711
|
+
A list of the new Shade objects that have been generated.
|
|
1712
|
+
"""
|
|
1713
|
+
# set defaults
|
|
1714
|
+
angle = math.radians(angle)
|
|
1715
|
+
face_geo = self.geometry if indoor is False else self.geometry.flip()
|
|
1716
|
+
if base_name is None:
|
|
1717
|
+
shd_name_base = '{}_InShd{}' if indoor else '{}_OutShd{}'
|
|
1718
|
+
else:
|
|
1719
|
+
shd_name_base = '{}_' + str(base_name) + '{}'
|
|
1720
|
+
|
|
1721
|
+
# generate shade geometries
|
|
1722
|
+
shade_faces = face_geo.contour_fins_by_distance_between(
|
|
1723
|
+
distance, depth, offset, angle, contour_vector, flip_start_side, tolerance)
|
|
1724
|
+
if max_count:
|
|
1725
|
+
try:
|
|
1726
|
+
shade_faces = shade_faces[:max_count]
|
|
1727
|
+
except IndexError: # fewer shades were generated than the max count
|
|
1728
|
+
pass
|
|
1729
|
+
|
|
1730
|
+
# create the shade objects
|
|
1731
|
+
louvers = []
|
|
1732
|
+
for i, shade_geo in enumerate(shade_faces):
|
|
1733
|
+
louvers.append(Shade(shd_name_base.format(self.identifier, i), shade_geo))
|
|
1734
|
+
if indoor:
|
|
1735
|
+
self.add_indoor_shades(louvers)
|
|
1736
|
+
else:
|
|
1737
|
+
self.add_outdoor_shades(louvers)
|
|
1738
|
+
return louvers
|
|
1739
|
+
|
|
1740
|
+
def move(self, moving_vec):
|
|
1741
|
+
"""Move this Face along a vector.
|
|
1742
|
+
|
|
1743
|
+
Args:
|
|
1744
|
+
moving_vec: A ladybug_geometry Vector3D with the direction and distance
|
|
1745
|
+
to move the face.
|
|
1746
|
+
"""
|
|
1747
|
+
self._geometry = self.geometry.move(moving_vec)
|
|
1748
|
+
for ap in self._apertures:
|
|
1749
|
+
ap.move(moving_vec)
|
|
1750
|
+
for dr in self._doors:
|
|
1751
|
+
dr.move(moving_vec)
|
|
1752
|
+
self.move_shades(moving_vec)
|
|
1753
|
+
self.properties.move(moving_vec)
|
|
1754
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1755
|
+
|
|
1756
|
+
def rotate(self, axis, angle, origin):
|
|
1757
|
+
"""Rotate this Face by a certain angle around an axis and origin.
|
|
1758
|
+
|
|
1759
|
+
Args:
|
|
1760
|
+
axis: A ladybug_geometry Vector3D axis representing the axis of rotation.
|
|
1761
|
+
angle: An angle for rotation in degrees.
|
|
1762
|
+
origin: A ladybug_geometry Point3D for the origin around which the
|
|
1763
|
+
object will be rotated.
|
|
1764
|
+
"""
|
|
1765
|
+
self._geometry = self.geometry.rotate(axis, math.radians(angle), origin)
|
|
1766
|
+
for ap in self._apertures:
|
|
1767
|
+
ap.rotate(axis, angle, origin)
|
|
1768
|
+
for dr in self._doors:
|
|
1769
|
+
dr.rotate(axis, angle, origin)
|
|
1770
|
+
self.rotate_shades(axis, angle, origin)
|
|
1771
|
+
self.properties.rotate(axis, angle, origin)
|
|
1772
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1773
|
+
|
|
1774
|
+
def rotate_xy(self, angle, origin):
|
|
1775
|
+
"""Rotate this Face counterclockwise in the world XY plane by a certain angle.
|
|
1776
|
+
|
|
1777
|
+
Args:
|
|
1778
|
+
angle: An angle in degrees.
|
|
1779
|
+
origin: A ladybug_geometry Point3D for the origin around which the
|
|
1780
|
+
object will be rotated.
|
|
1781
|
+
"""
|
|
1782
|
+
self._geometry = self.geometry.rotate_xy(math.radians(angle), origin)
|
|
1783
|
+
for ap in self._apertures:
|
|
1784
|
+
ap.rotate_xy(angle, origin)
|
|
1785
|
+
for dr in self._doors:
|
|
1786
|
+
dr.rotate_xy(angle, origin)
|
|
1787
|
+
self.rotate_xy_shades(angle, origin)
|
|
1788
|
+
self.properties.rotate_xy(angle, origin)
|
|
1789
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1790
|
+
|
|
1791
|
+
def reflect(self, plane):
|
|
1792
|
+
"""Reflect this Face across a plane.
|
|
1793
|
+
|
|
1794
|
+
Args:
|
|
1795
|
+
plane: A ladybug_geometry Plane across which the object will
|
|
1796
|
+
be reflected.
|
|
1797
|
+
"""
|
|
1798
|
+
self._geometry = self.geometry.reflect(plane.n, plane.o)
|
|
1799
|
+
for ap in self._apertures:
|
|
1800
|
+
ap.reflect(plane)
|
|
1801
|
+
for dr in self._doors:
|
|
1802
|
+
dr.reflect(plane)
|
|
1803
|
+
self.reflect_shades(plane)
|
|
1804
|
+
self.properties.reflect(plane)
|
|
1805
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1806
|
+
|
|
1807
|
+
def scale(self, factor, origin=None):
|
|
1808
|
+
"""Scale this Face by a factor from an origin point.
|
|
1809
|
+
|
|
1810
|
+
Args:
|
|
1811
|
+
factor: A number representing how much the object should be scaled.
|
|
1812
|
+
origin: A ladybug_geometry Point3D representing the origin from which
|
|
1813
|
+
to scale. If None, it will be scaled from the World origin (0, 0, 0).
|
|
1814
|
+
"""
|
|
1815
|
+
self._geometry = self.geometry.scale(factor, origin)
|
|
1816
|
+
for ap in self._apertures:
|
|
1817
|
+
ap.scale(factor, origin)
|
|
1818
|
+
for dr in self._doors:
|
|
1819
|
+
dr.scale(factor, origin)
|
|
1820
|
+
self.scale_shades(factor, origin)
|
|
1821
|
+
self.properties.scale(factor, origin)
|
|
1822
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1823
|
+
|
|
1824
|
+
def remove_colinear_vertices(self, tolerance=0.01):
|
|
1825
|
+
"""Remove all colinear and duplicate vertices from this object's geometry.
|
|
1826
|
+
|
|
1827
|
+
Note that this does not affect any assigned Apertures, Doors or Shades.
|
|
1828
|
+
|
|
1829
|
+
Args:
|
|
1830
|
+
tolerance: The minimum distance between a vertex and the boundary segments
|
|
1831
|
+
at which point the vertex is considered colinear. Default: 0.01,
|
|
1832
|
+
suitable for objects in meters.
|
|
1833
|
+
"""
|
|
1834
|
+
try:
|
|
1835
|
+
self._geometry = self.geometry.remove_colinear_vertices(tolerance)
|
|
1836
|
+
except AssertionError as e: # usually a sliver face of some kind
|
|
1837
|
+
raise ValueError(
|
|
1838
|
+
'Face "{}" is invalid with dimensions less than the '
|
|
1839
|
+
'tolerance.\n{}'.format(self.full_id, e))
|
|
1840
|
+
self._punched_geometry = None # reset so that it can be re-computed
|
|
1841
|
+
|
|
1842
|
+
def remove_degenerate_sub_faces(self, tolerance=0.01):
|
|
1843
|
+
"""Remove colinear vertices from sub-faces and eliminate degenerate ones.
|
|
1844
|
+
|
|
1845
|
+
Args:
|
|
1846
|
+
tolerance: The minimum distance between a vertex and the boundary segments
|
|
1847
|
+
at which point the vertex is considered colinear. Default: 0.01,
|
|
1848
|
+
suitable for objects in meters.
|
|
1849
|
+
"""
|
|
1850
|
+
# set up lists to track sub-faces to remove
|
|
1851
|
+
del_ap_i, del_dr_i = [], []
|
|
1852
|
+
# remove degenerate apertures
|
|
1853
|
+
for i, ap in enumerate(self._apertures):
|
|
1854
|
+
try:
|
|
1855
|
+
ap.remove_colinear_vertices(tolerance)
|
|
1856
|
+
except ValueError:
|
|
1857
|
+
del_ap_i.append(i)
|
|
1858
|
+
for del_i in reversed(del_ap_i):
|
|
1859
|
+
self._apertures.pop(del_i)
|
|
1860
|
+
# remove degenerate doors
|
|
1861
|
+
for i, dr in enumerate(self._doors):
|
|
1862
|
+
try:
|
|
1863
|
+
dr.remove_colinear_vertices(tolerance)
|
|
1864
|
+
except ValueError:
|
|
1865
|
+
del_dr_i.append(i)
|
|
1866
|
+
for del_i in reversed(del_dr_i):
|
|
1867
|
+
self._doors.pop(del_i)
|
|
1868
|
+
|
|
1869
|
+
def is_geo_equivalent(self, face, tolerance=0.01):
|
|
1870
|
+
"""Get a boolean for whether this object is geometrically equivalent to another.
|
|
1871
|
+
|
|
1872
|
+
This will also check all child Apertures and Doors for equivalency but not
|
|
1873
|
+
assigned shades.
|
|
1874
|
+
|
|
1875
|
+
Args:
|
|
1876
|
+
face: Another Face for which geometric equivalency will be tested.
|
|
1877
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
1878
|
+
vertices at which they can be considered geometrically equivalent.
|
|
1879
|
+
|
|
1880
|
+
Returns:
|
|
1881
|
+
True if geometrically equivalent. False if not geometrically equivalent.
|
|
1882
|
+
"""
|
|
1883
|
+
meta_1 = (self.display_name, self.type, self.boundary_condition)
|
|
1884
|
+
meta_2 = (face.display_name, face.type, face.boundary_condition)
|
|
1885
|
+
if meta_1 != meta_2:
|
|
1886
|
+
return False
|
|
1887
|
+
if abs(self.area - face.area) > tolerance * self.area:
|
|
1888
|
+
return False
|
|
1889
|
+
if not self.geometry.is_centered_adjacent(face.geometry, tolerance):
|
|
1890
|
+
return False
|
|
1891
|
+
if len(self._apertures) != len(face._apertures):
|
|
1892
|
+
return False
|
|
1893
|
+
if len(self._doors) != len(face._doors):
|
|
1894
|
+
return False
|
|
1895
|
+
for ap1, ap2 in zip(self._apertures, face._apertures):
|
|
1896
|
+
if not ap1.is_geo_equivalent(ap2, tolerance):
|
|
1897
|
+
return False
|
|
1898
|
+
for dr1, dr2 in zip(self._doors, face._doors):
|
|
1899
|
+
if not dr1.is_geo_equivalent(dr2, tolerance):
|
|
1900
|
+
return False
|
|
1901
|
+
if not self._are_shades_equivalent(face, tolerance):
|
|
1902
|
+
return False
|
|
1903
|
+
return True
|
|
1904
|
+
|
|
1905
|
+
def check_sub_faces_valid(self, tolerance=0.01, angle_tolerance=1,
|
|
1906
|
+
raise_exception=True, detailed=False):
|
|
1907
|
+
"""Check that sub-faces are co-planar with this Face within the Face boundary.
|
|
1908
|
+
|
|
1909
|
+
Note this does not check the planarity of the sub-faces themselves, whether
|
|
1910
|
+
they self-intersect, or whether they have a non-zero area.
|
|
1911
|
+
|
|
1912
|
+
Args:
|
|
1913
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
1914
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
1915
|
+
suitable for objects in meters.
|
|
1916
|
+
angle_tolerance: The max angle in degrees that the plane normals can
|
|
1917
|
+
differ from one another in order for them to be considered coplanar.
|
|
1918
|
+
Default: 1 degree.
|
|
1919
|
+
raise_exception: Boolean to note whether a ValueError should be raised
|
|
1920
|
+
if an sub-face is not valid.
|
|
1921
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
1922
|
+
dicts with error info or a string with a message. (Default: False).
|
|
1923
|
+
|
|
1924
|
+
Returns:
|
|
1925
|
+
A string with the message or a list with dictionaries if detailed is True.
|
|
1926
|
+
"""
|
|
1927
|
+
detailed = False if raise_exception else detailed
|
|
1928
|
+
ap = self.check_apertures_valid(tolerance, angle_tolerance, False, detailed)
|
|
1929
|
+
dr = self.check_doors_valid(tolerance, angle_tolerance, False, detailed)
|
|
1930
|
+
full_msgs = ap + dr if detailed else [m for m in (ap, dr) if m != '']
|
|
1931
|
+
if raise_exception and len(full_msgs) != 0:
|
|
1932
|
+
raise ValueError('\n'.join(full_msgs))
|
|
1933
|
+
return full_msgs if detailed else '\n'.join(full_msgs)
|
|
1934
|
+
|
|
1935
|
+
def check_apertures_valid(self, tolerance=0.01, angle_tolerance=1,
|
|
1936
|
+
raise_exception=True, detailed=False):
|
|
1937
|
+
"""Check that apertures are co-planar with this Face within the Face boundary.
|
|
1938
|
+
|
|
1939
|
+
Note this does not check the planarity of the apertures themselves, whether
|
|
1940
|
+
they self-intersect, or whether they have a non-zero area.
|
|
1941
|
+
|
|
1942
|
+
Args:
|
|
1943
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
1944
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
1945
|
+
suitable for objects in meters.
|
|
1946
|
+
angle_tolerance: The max angle in degrees that the plane normals can
|
|
1947
|
+
differ from one another in order for them to be considered coplanar.
|
|
1948
|
+
Default: 1 degree.
|
|
1949
|
+
raise_exception: Boolean to note whether a ValueError should be raised
|
|
1950
|
+
if an aperture is not valid.
|
|
1951
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
1952
|
+
dicts with error info or a string with a message. (Default: False).
|
|
1953
|
+
|
|
1954
|
+
Returns:
|
|
1955
|
+
A string with the message or a list with dictionaries if detailed is True.
|
|
1956
|
+
"""
|
|
1957
|
+
detailed = False if raise_exception else detailed
|
|
1958
|
+
angle_tolerance = math.radians(angle_tolerance)
|
|
1959
|
+
msgs = []
|
|
1960
|
+
for ap in self._apertures:
|
|
1961
|
+
if not self.geometry.is_sub_face(ap.geometry, tolerance, angle_tolerance):
|
|
1962
|
+
msg = 'Aperture "{}" is not coplanar or fully bounded by its parent ' \
|
|
1963
|
+
'Face "{}".'.format(ap.full_id, self.full_id)
|
|
1964
|
+
msg = self._validation_message_child(
|
|
1965
|
+
msg, ap, detailed, '000104', error_type='Invalid Sub-Face Geometry')
|
|
1966
|
+
msgs.append(msg)
|
|
1967
|
+
full_msg = msgs if detailed else '\n'.join(msgs)
|
|
1968
|
+
if raise_exception and len(msgs) != 0:
|
|
1969
|
+
raise ValueError(full_msg)
|
|
1970
|
+
return full_msg
|
|
1971
|
+
|
|
1972
|
+
def check_doors_valid(self, tolerance=0.01, angle_tolerance=1,
|
|
1973
|
+
raise_exception=True, detailed=False):
|
|
1974
|
+
"""Check that doors are co-planar with this Face within the Face boundary.
|
|
1975
|
+
|
|
1976
|
+
Note this does not check the planarity of the doors themselves, whether
|
|
1977
|
+
they self-intersect, or whether they have a non-zero area.
|
|
1978
|
+
|
|
1979
|
+
Args:
|
|
1980
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
1981
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
1982
|
+
suitable for objects in meters.
|
|
1983
|
+
angle_tolerance: The max angle in degrees that the plane normals can
|
|
1984
|
+
differ from one another in order for them to be considered coplanar.
|
|
1985
|
+
Default: 1 degree.
|
|
1986
|
+
raise_exception: Boolean to note whether a ValueError should be raised
|
|
1987
|
+
if an door is not valid.
|
|
1988
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
1989
|
+
dicts with error info or a string with a message. (Default: False).
|
|
1990
|
+
|
|
1991
|
+
Returns:
|
|
1992
|
+
A string with the message or a list with dictionaries if detailed is True.
|
|
1993
|
+
"""
|
|
1994
|
+
detailed = False if raise_exception else detailed
|
|
1995
|
+
angle_tolerance = math.radians(angle_tolerance)
|
|
1996
|
+
msgs = []
|
|
1997
|
+
for dr in self._doors:
|
|
1998
|
+
if not self.geometry.is_sub_face(dr.geometry, tolerance, angle_tolerance):
|
|
1999
|
+
msg = 'Door "{}" is not coplanar or fully bounded by its parent ' \
|
|
2000
|
+
'Face "{}".'.format(dr.full_id, self.full_id)
|
|
2001
|
+
msg = self._validation_message_child(
|
|
2002
|
+
msg, dr, detailed, '000104', error_type='Invalid Sub-Face Geometry')
|
|
2003
|
+
msgs.append(msg)
|
|
2004
|
+
full_msg = msgs if detailed else '\n'.join(msgs)
|
|
2005
|
+
if raise_exception and len(msgs) != 0:
|
|
2006
|
+
raise ValueError(full_msg)
|
|
2007
|
+
return full_msg
|
|
2008
|
+
|
|
2009
|
+
def check_sub_faces_overlapping(
|
|
2010
|
+
self, tolerance=0.01, raise_exception=True, detailed=False):
|
|
2011
|
+
"""Check that this Face's sub-faces do not overlap with one another.
|
|
2012
|
+
|
|
2013
|
+
Args:
|
|
2014
|
+
tolerance: The minimum distance that two sub-faces must overlap in order
|
|
2015
|
+
for them to be considered overlapping and invalid. (Default: 0.01,
|
|
2016
|
+
suitable for objects in meters).
|
|
2017
|
+
raise_exception: Boolean to note whether a ValueError should be raised
|
|
2018
|
+
if a sub-faces overlap with one another.
|
|
2019
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
2020
|
+
dicts with error info or a string with a message. (Default: False).
|
|
2021
|
+
|
|
2022
|
+
Returns:
|
|
2023
|
+
A string with the message or a list with dictionaries if detailed is True.
|
|
2024
|
+
"""
|
|
2025
|
+
sub_faces = self.sub_faces
|
|
2026
|
+
if len(sub_faces) == 0:
|
|
2027
|
+
return [] if detailed else ''
|
|
2028
|
+
sf_groups = self._group_sub_faces_by_overlap(sub_faces, tolerance)
|
|
2029
|
+
if not all(len(g) == 1 for g in sf_groups):
|
|
2030
|
+
base_msg = 'Face "{}" contains Apertures and/or ' \
|
|
2031
|
+
'Doors that overlap with each other.'.format(self.full_id)
|
|
2032
|
+
if raise_exception:
|
|
2033
|
+
raise ValueError(base_msg)
|
|
2034
|
+
if not detailed: # just give a message about the Face if not detailed
|
|
2035
|
+
return base_msg
|
|
2036
|
+
all_overlaps = []
|
|
2037
|
+
for sf_group in sf_groups:
|
|
2038
|
+
if len(sf_group) != 1:
|
|
2039
|
+
det_msg = 'The following sub-faces overlap with one another:' \
|
|
2040
|
+
'\n{}'.format('\n'.join([sf.full_id for sf in sf_group]))
|
|
2041
|
+
msg = '{}\n{}'.format(base_msg, det_msg)
|
|
2042
|
+
err_obj = self._validation_message_child(
|
|
2043
|
+
msg, sf_group[0], detailed, '000105',
|
|
2044
|
+
error_type='Overlapping Sub-Face Geometry')
|
|
2045
|
+
err_obj['element_type'] = 'SubFace'
|
|
2046
|
+
for ov_obj in sf_group[1:]:
|
|
2047
|
+
err_obj['element_id'].append(ov_obj.identifier)
|
|
2048
|
+
err_obj['element_name'].append(ov_obj.display_name)
|
|
2049
|
+
err_obj['parents'].append(err_obj['parents'][0])
|
|
2050
|
+
all_overlaps.append(err_obj)
|
|
2051
|
+
return all_overlaps
|
|
2052
|
+
return [] if detailed else ''
|
|
2053
|
+
|
|
2054
|
+
def check_upside_down(self, angle_tolerance=1, raise_exception=True, detailed=False):
|
|
2055
|
+
"""Check whether the face is pointing in the correct direction for the face type.
|
|
2056
|
+
|
|
2057
|
+
This method will only report Floors that are pointing upwards or RoofCeilings
|
|
2058
|
+
that are pointed downwards. These cases are likely modeling errors and are in
|
|
2059
|
+
danger of having their vertices flipped by EnergyPlus, causing them to
|
|
2060
|
+
not see the sun.
|
|
2061
|
+
|
|
2062
|
+
Args:
|
|
2063
|
+
angle_tolerance: The max angle in degrees that the Face normal can
|
|
2064
|
+
differ from up or down before it is considered a case of a downward
|
|
2065
|
+
pointing RoofCeiling or upward pointing Floor. Default: 1 degree.
|
|
2066
|
+
raise_exception: Boolean to note whether an ValueError should be
|
|
2067
|
+
raised if the Face is an an upward pointing Floor or a downward
|
|
2068
|
+
pointing RoofCeiling.
|
|
2069
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
2070
|
+
dicts with error info or a string with a message. (Default: False).
|
|
2071
|
+
|
|
2072
|
+
Returns:
|
|
2073
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
2074
|
+
"""
|
|
2075
|
+
msg = None
|
|
2076
|
+
if isinstance(self.type, Floor) and self.altitude > 90 - angle_tolerance:
|
|
2077
|
+
msg = 'Face "{}" is an upward-pointing Floor, which should be ' \
|
|
2078
|
+
'changed to a RoofCeiling.'.format(self.full_id)
|
|
2079
|
+
elif isinstance(self.type, RoofCeiling) and self.altitude < angle_tolerance - 90:
|
|
2080
|
+
msg = 'Face "{}" is an downward-pointing RoofCeiling, which should be ' \
|
|
2081
|
+
'changed to a Floor.'.format(self.full_id)
|
|
2082
|
+
if msg:
|
|
2083
|
+
full_msg = self._validation_message(
|
|
2084
|
+
msg, raise_exception, detailed, '000109',
|
|
2085
|
+
error_type='Upside Down Face')
|
|
2086
|
+
return full_msg
|
|
2087
|
+
return [] if detailed else ''
|
|
2088
|
+
|
|
2089
|
+
def check_planar(self, tolerance=0.01, raise_exception=True, detailed=False):
|
|
2090
|
+
"""Check whether all of the Face's vertices lie within the same plane.
|
|
2091
|
+
|
|
2092
|
+
Args:
|
|
2093
|
+
tolerance: The minimum distance between a given vertex and a the
|
|
2094
|
+
object's plane at which the vertex is said to lie in the plane.
|
|
2095
|
+
Default: 0.01, suitable for objects in meters.
|
|
2096
|
+
raise_exception: Boolean to note whether an ValueError should be
|
|
2097
|
+
raised if a vertex does not lie within the object's plane.
|
|
2098
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
2099
|
+
dicts with error info or a string with a message. (Default: False).
|
|
2100
|
+
|
|
2101
|
+
Returns:
|
|
2102
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
2103
|
+
"""
|
|
2104
|
+
try:
|
|
2105
|
+
self.geometry.check_planar(tolerance, raise_exception=True)
|
|
2106
|
+
except ValueError as e:
|
|
2107
|
+
msg = 'Face "{}" is not planar.\n{}'.format(self.full_id, e)
|
|
2108
|
+
full_msg = self._validation_message(
|
|
2109
|
+
msg, raise_exception, detailed, '000101',
|
|
2110
|
+
error_type='Non-Planar Geometry')
|
|
2111
|
+
if detailed: # add the out-of-plane points to helper_geometry
|
|
2112
|
+
help_pts = [
|
|
2113
|
+
p.to_dict() for p in self.geometry.non_planar_vertices(tolerance)
|
|
2114
|
+
]
|
|
2115
|
+
full_msg[0]['helper_geometry'] = help_pts
|
|
2116
|
+
return full_msg
|
|
2117
|
+
return [] if detailed else ''
|
|
2118
|
+
|
|
2119
|
+
def check_self_intersecting(self, tolerance=0.01, raise_exception=True,
|
|
2120
|
+
detailed=False):
|
|
2121
|
+
"""Check whether the edges of the Face intersect one another (like a bowtie).
|
|
2122
|
+
|
|
2123
|
+
Note that objects that have duplicate vertices will not be considered
|
|
2124
|
+
self-intersecting and are valid in honeybee.
|
|
2125
|
+
|
|
2126
|
+
Args:
|
|
2127
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
2128
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
2129
|
+
suitable for objects in meters.
|
|
2130
|
+
raise_exception: If True, a ValueError will be raised if the object
|
|
2131
|
+
intersects with itself. Default: True.
|
|
2132
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
2133
|
+
dicts with error info or a string with a message. (Default: False).
|
|
2134
|
+
|
|
2135
|
+
Returns:
|
|
2136
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
2137
|
+
"""
|
|
2138
|
+
if self.geometry.is_self_intersecting:
|
|
2139
|
+
msg = 'Face "{}" has self-intersecting edges.'.format(self.full_id)
|
|
2140
|
+
try: # see if it is self-intersecting because of a duplicate vertex
|
|
2141
|
+
new_geo = self.geometry.remove_duplicate_vertices(tolerance)
|
|
2142
|
+
if not new_geo.is_self_intersecting:
|
|
2143
|
+
return [] if detailed else '' # valid with removed dup vertex
|
|
2144
|
+
except AssertionError:
|
|
2145
|
+
pass # degenerate face; treat it as self-intersecting
|
|
2146
|
+
full_msg = self._validation_message(
|
|
2147
|
+
msg, raise_exception, detailed, '000102',
|
|
2148
|
+
error_type='Self-Intersecting Geometry')
|
|
2149
|
+
if detailed: # add the self-intersection points to helper_geometry
|
|
2150
|
+
help_pts = [p.to_dict() for p in self.geometry.self_intersection_points]
|
|
2151
|
+
full_msg[0]['helper_geometry'] = help_pts
|
|
2152
|
+
return full_msg
|
|
2153
|
+
return [] if detailed else ''
|
|
2154
|
+
|
|
2155
|
+
def check_degenerate(self, tolerance=0.01, raise_exception=True, detailed=False):
|
|
2156
|
+
"""Check whether the Face is degenerate with effectively zero area.
|
|
2157
|
+
|
|
2158
|
+
Note that, while the Face may have an area larger than the tolerance,
|
|
2159
|
+
removing colinear vertices within the tolerance would create a geometry
|
|
2160
|
+
smaller than the tolerance.
|
|
2161
|
+
|
|
2162
|
+
Args:
|
|
2163
|
+
tolerance: The minimum difference between the coordinate values of two
|
|
2164
|
+
vertices at which they can be considered equivalent. Default: 0.01,
|
|
2165
|
+
suitable for objects in meters.
|
|
2166
|
+
raise_exception: If True, a ValueError will be raised if the object
|
|
2167
|
+
intersects with itself. Default: True.
|
|
2168
|
+
detailed: Boolean for whether the returned object is a detailed list of
|
|
2169
|
+
dicts with error info or a string with a message. (Default: False).
|
|
2170
|
+
|
|
2171
|
+
Returns:
|
|
2172
|
+
A string with the message or a list with a dictionary if detailed is True.
|
|
2173
|
+
"""
|
|
2174
|
+
msg = 'Face "{}" is degenerate and should be deleted.'.format(self.full_id)
|
|
2175
|
+
try: # see if it is self-intersecting because of a duplicate vertex
|
|
2176
|
+
new_geo = self.geometry.remove_colinear_vertices(tolerance)
|
|
2177
|
+
if new_geo.area > tolerance:
|
|
2178
|
+
return [] if detailed else '' # valid
|
|
2179
|
+
except AssertionError:
|
|
2180
|
+
pass # degenerate face; treat it as degenerate
|
|
2181
|
+
full_msg = self._validation_message(
|
|
2182
|
+
msg, raise_exception, detailed, '000103',
|
|
2183
|
+
error_type='Zero-Area Geometry')
|
|
2184
|
+
return full_msg
|
|
2185
|
+
return [] if detailed else ''
|
|
2186
|
+
|
|
2187
|
+
def display_dict(self):
|
|
2188
|
+
"""Get a list of DisplayFace3D dictionaries for visualizing the object."""
|
|
2189
|
+
base = [self._display_face(self.punched_geometry, self.type_color)]
|
|
2190
|
+
for ap in self._apertures:
|
|
2191
|
+
base.extend(ap.display_dict())
|
|
2192
|
+
for dr in self._doors:
|
|
2193
|
+
base.extend(dr.display_dict())
|
|
2194
|
+
for shd in self.shades:
|
|
2195
|
+
base.extend(shd.display_dict())
|
|
2196
|
+
return base
|
|
2197
|
+
|
|
2198
|
+
@property
|
|
2199
|
+
def to(self):
|
|
2200
|
+
"""Face writer object.
|
|
2201
|
+
|
|
2202
|
+
Use this method to access Writer class to write the face in other formats.
|
|
2203
|
+
|
|
2204
|
+
Usage:
|
|
2205
|
+
|
|
2206
|
+
.. code-block:: python
|
|
2207
|
+
|
|
2208
|
+
face.to.idf(face) -> idf string.
|
|
2209
|
+
face.to.radiance(face) -> Radiance string.
|
|
2210
|
+
"""
|
|
2211
|
+
return writer
|
|
2212
|
+
|
|
2213
|
+
def to_dict(self, abridged=False, included_prop=None, include_plane=True):
|
|
2214
|
+
"""Return Face as a dictionary.
|
|
2215
|
+
|
|
2216
|
+
Args:
|
|
2217
|
+
abridged: Boolean to note whether the extension properties of the
|
|
2218
|
+
object (ie. materials, constructions) should be included in detail
|
|
2219
|
+
(False) or just referenced by identifier (True). (Default: False).
|
|
2220
|
+
included_prop: List of properties to filter keys that must be included in
|
|
2221
|
+
output dictionary. For example ['energy'] will include 'energy' key if
|
|
2222
|
+
available in properties to_dict. By default all the keys will be
|
|
2223
|
+
included. To exclude all the keys from extensions use an empty list.
|
|
2224
|
+
include_plane: Boolean to note wether the plane of the Face3D should be
|
|
2225
|
+
included in the output. This can preserve the orientation of the
|
|
2226
|
+
X/Y axes of the plane but is not required and can be removed to
|
|
2227
|
+
keep the dictionary smaller. (Default: True).
|
|
2228
|
+
"""
|
|
2229
|
+
base = {'type': 'Face'}
|
|
2230
|
+
base['identifier'] = self.identifier
|
|
2231
|
+
base['display_name'] = self.display_name
|
|
2232
|
+
base['properties'] = self.properties.to_dict(abridged, included_prop)
|
|
2233
|
+
enforce_upper_left = True if 'energy' in base['properties'] else False
|
|
2234
|
+
base['geometry'] = self._geometry.to_dict(include_plane, enforce_upper_left)
|
|
2235
|
+
|
|
2236
|
+
base['face_type'] = self.type.name
|
|
2237
|
+
if isinstance(self.boundary_condition, Outdoors) and \
|
|
2238
|
+
'energy' in base['properties']:
|
|
2239
|
+
base['boundary_condition'] = self.boundary_condition.to_dict(full=True)
|
|
2240
|
+
else:
|
|
2241
|
+
base['boundary_condition'] = self.boundary_condition.to_dict()
|
|
2242
|
+
|
|
2243
|
+
if self._apertures != []:
|
|
2244
|
+
base['apertures'] = [ap.to_dict(abridged, included_prop, include_plane)
|
|
2245
|
+
for ap in self._apertures]
|
|
2246
|
+
if self._doors != []:
|
|
2247
|
+
base['doors'] = [dr.to_dict(abridged, included_prop, include_plane)
|
|
2248
|
+
for dr in self._doors]
|
|
2249
|
+
self._add_shades_to_dict(base, abridged, included_prop, include_plane)
|
|
2250
|
+
if self.user_data is not None:
|
|
2251
|
+
base['user_data'] = self.user_data
|
|
2252
|
+
return base
|
|
2253
|
+
|
|
2254
|
+
def _acceptable_sub_face_check(self, sub_face_type=Aperture):
|
|
2255
|
+
"""Check whether the Face can accept sub-faces and raise an exception if not."""
|
|
2256
|
+
assert isinstance(self.boundary_condition, Outdoors), \
|
|
2257
|
+
'{} cannot be added to Face "{}" with a {} boundary condition.'.format(
|
|
2258
|
+
sub_face_type.__name__, self.full_id, self.boundary_condition)
|
|
2259
|
+
assert not isinstance(self.type, AirBoundary), \
|
|
2260
|
+
'{} cannot be added to AirBoundary Face "{}".'.format(
|
|
2261
|
+
sub_face_type.__name__, self.full_id)
|
|
2262
|
+
|
|
2263
|
+
@staticmethod
|
|
2264
|
+
def _remove_overlapping_sub_faces(sub_faces, tolerance):
|
|
2265
|
+
"""Get a list of Apertures and/or Doors with no overlaps.
|
|
2266
|
+
|
|
2267
|
+
Args:
|
|
2268
|
+
sub_faces: A list of Apertures or Doors to be checked for overlapping.
|
|
2269
|
+
tolerance: The minimum distance from the edge of a neighboring Face3D
|
|
2270
|
+
at which a point is considered to overlap with that Face3D.
|
|
2271
|
+
|
|
2272
|
+
Returns:
|
|
2273
|
+
A list of the input sub_faces with smaller overlapping geometries removed.
|
|
2274
|
+
"""
|
|
2275
|
+
# group the sub-faces according to the overlaps with one another
|
|
2276
|
+
grouped_sfs = Face._group_sub_faces_by_overlap(sub_faces, tolerance)
|
|
2277
|
+
# build a list of sub-faces without any overlaps
|
|
2278
|
+
clean_sub_faces = []
|
|
2279
|
+
for sf_group in grouped_sfs:
|
|
2280
|
+
if len(sf_group) == 1:
|
|
2281
|
+
clean_sub_faces.append(sf_group[0])
|
|
2282
|
+
else: # take the subface with the largest area
|
|
2283
|
+
sf_group.sort(key=lambda x: x.area, reverse=True)
|
|
2284
|
+
clean_sub_faces.append(sf_group[0])
|
|
2285
|
+
return clean_sub_faces
|
|
2286
|
+
|
|
2287
|
+
@staticmethod
|
|
2288
|
+
def _group_sub_faces_by_overlap(sub_faces, tolerance):
|
|
2289
|
+
"""Group a Apertures and/or Doors depending on whether they overlap one another.
|
|
2290
|
+
|
|
2291
|
+
Args:
|
|
2292
|
+
sub_faces: A list of Apertures or Doors to be checked for overlapping.
|
|
2293
|
+
tolerance: The minimum distance from the edge of a neighboring Face3D
|
|
2294
|
+
at which a point is considered to overlap with that Face3D.
|
|
2295
|
+
|
|
2296
|
+
Returns:
|
|
2297
|
+
A list of lists where each sub-list represents a group of Apertures and/or
|
|
2298
|
+
Doors that overlap with one another.
|
|
2299
|
+
"""
|
|
2300
|
+
# sort the sub-faces by area
|
|
2301
|
+
sub_faces = list(sorted(sub_faces, key=lambda x: x.area, reverse=True))
|
|
2302
|
+
# create polygons for all of the faces
|
|
2303
|
+
r_plane = sub_faces[0].geometry.plane
|
|
2304
|
+
polygons = [Polygon2D([r_plane.xyz_to_xy(pt) for pt in face.vertices])
|
|
2305
|
+
for face in sub_faces]
|
|
2306
|
+
# loop through the polygons and check to see if it overlaps with the others
|
|
2307
|
+
grouped_polys, grouped_sfs = [[polygons[0]]], [[sub_faces[0]]]
|
|
2308
|
+
for poly, face in zip(polygons[1:], sub_faces[1:]):
|
|
2309
|
+
group_found = False
|
|
2310
|
+
for poly_group, face_group in zip(grouped_polys, grouped_sfs):
|
|
2311
|
+
for oth_poly in poly_group:
|
|
2312
|
+
if poly.polygon_relationship(oth_poly, tolerance) >= 0:
|
|
2313
|
+
poly_group.append(poly)
|
|
2314
|
+
face_group.append(face)
|
|
2315
|
+
group_found = True
|
|
2316
|
+
break
|
|
2317
|
+
if group_found:
|
|
2318
|
+
break
|
|
2319
|
+
if not group_found: # the polygon does not overlap with any of the others
|
|
2320
|
+
grouped_polys.append([poly]) # make a new group for the polygon
|
|
2321
|
+
grouped_sfs.append([face]) # make a new group for the face
|
|
2322
|
+
return grouped_sfs
|
|
2323
|
+
|
|
2324
|
+
@staticmethod
|
|
2325
|
+
def _is_sub_polygon(sub_poly, parent_poly, parent_holes=None):
|
|
2326
|
+
"""Check if a sub-polygon is valid for a given assumed parent polygon.
|
|
2327
|
+
|
|
2328
|
+
Args:
|
|
2329
|
+
sub_poly: A sub-Polygon2D for which sub-face equivalency will be tested.
|
|
2330
|
+
parent_poly: A parent Polygon2D.
|
|
2331
|
+
parent_holes: An optional list of Polygon2D for any holes that may
|
|
2332
|
+
exist in the parent polygon. (Default: None).
|
|
2333
|
+
"""
|
|
2334
|
+
if parent_holes is None:
|
|
2335
|
+
return parent_poly.is_polygon_inside(sub_poly)
|
|
2336
|
+
else:
|
|
2337
|
+
if not parent_poly.is_polygon_inside(sub_poly):
|
|
2338
|
+
return False
|
|
2339
|
+
for hole_poly in parent_holes:
|
|
2340
|
+
if not hole_poly.is_polygon_outside(sub_poly):
|
|
2341
|
+
return False
|
|
2342
|
+
return True
|
|
2343
|
+
|
|
2344
|
+
def __copy__(self):
|
|
2345
|
+
new_f = Face(self.identifier, self.geometry, self.type, self.boundary_condition)
|
|
2346
|
+
new_f._display_name = self._display_name
|
|
2347
|
+
new_f._user_data = None if self.user_data is None else self.user_data.copy()
|
|
2348
|
+
new_f._apertures = [ap.duplicate() for ap in self._apertures]
|
|
2349
|
+
new_f._doors = [dr.duplicate() for dr in self._doors]
|
|
2350
|
+
for ap in new_f._apertures:
|
|
2351
|
+
ap._parent = new_f
|
|
2352
|
+
for dr in new_f._doors:
|
|
2353
|
+
dr._parent = new_f
|
|
2354
|
+
self._duplicate_child_shades(new_f)
|
|
2355
|
+
new_f._punched_geometry = self._punched_geometry
|
|
2356
|
+
new_f._properties._duplicate_extension_attr(self._properties)
|
|
2357
|
+
return new_f
|
|
2358
|
+
|
|
2359
|
+
def __repr__(self):
|
|
2360
|
+
return 'Face: %s' % self.display_name
|