@@ -141,20 +141,21 @@ def from_dict(cls, data):
141
141
142
142
Args:
143
143
data: {
144
- "boundary": [{"x": 0, "y": 0, "z": 0}, {"x": 10, "y": 0, "z": 0},
145
- {"x": 0, "y": 10, "z": 0}],
146
- "plane": {"n": {"x": 0, "y": 0, "z": 1}, "o": {"x": 0, "y": 0, "z": 0},
147
- "x": {"x": 1, "y": 0, "z": 0}}
148
- "holes": [[{"x": 2, "y": 2, "z": 0}, {"x": 5, "y": 2, "z": 0},
149
- {"x": 2, "y": 5, "z": 0}]],
144
+ "type": "Face3D",
145
+ "boundary": [[0, 0, 0], [10, 0, 0], [0, 10, 0]],
146
+ "plane": {"n": [0, 0, 1], "o": [0, 0, 0], "x": [1, 0, 0]},
147
+ "holes": [[[2, 2, 0], [5, 2, 0], [2, 5, 0]]]
150
148
}
151
149
"""
152
150
holes = None
153
151
if 'holes' in data and data ['holes' ] is not None :
154
- holes = tuple (
155
- tuple (Point3D .from_dict (pt ) for pt in hole ) for hole in data ['holes' ])
156
- return cls (tuple (Point3D .from_dict (pt ) for pt in data ['boundary' ]),
157
- Plane .from_dict (data ['plane' ]), holes )
152
+ holes = tuple (tuple (
153
+ Point3D (pt [0 ], pt [1 ], pt [2 ]) for pt in hole ) for hole in data ['holes' ])
154
+ plane = None
155
+ if 'plane' in data and data ['plane' ] is not None :
156
+ plane = Plane .from_dict (data ['plane' ])
157
+ return cls (tuple (Point3D (pt [0 ], pt [1 ], pt [2 ]) for pt in data ['boundary' ]),
158
+ plane , holes )
158
159
159
160
@classmethod
160
161
def from_extrusion (cls , line_segment , extrusion_vector ):
@@ -1359,15 +1360,22 @@ def sub_rectangles_from_rectangle(base_plane, parent_base, parent_height, ratio,
1359
1360
base_plane )]
1360
1361
return final_faces
1361
1362
1362
- def to_dict (self ):
1363
- """Get Face3D as a dictionary."""
1364
- if not self .has_holes :
1365
- return {'boundary' : [pt .to_dict () for pt in self .boundary ],
1366
- 'plane' : self .plane .to_dict ()}
1367
- else :
1368
- return {'boundary' : [pt .to_dict () for pt in self .boundary ],
1369
- 'plane' : self .plane .to_dict (),
1370
- 'holes' : [[pt .to_dict () for pt in hole ] for hole in self .holes ]}
1363
+ def to_dict (self , include_plane = True ):
1364
+ """Get Face3D as a dictionary.
1365
+
1366
+ Args:
1367
+ include_plane: Set to True to include the Face3D plane in the
1368
+ dictionary, which will preserve the underlying orientation
1369
+ of the face plane. Default True.
1370
+ """
1371
+ base = {'type' : 'Face3D' ,
1372
+ 'boundary' : [(pt .x , pt .y , pt .z ) for pt in self .boundary ]}
1373
+ if include_plane :
1374
+ base ['plane' ] = self .plane .to_dict ()
1375
+ if self .has_holes :
1376
+ base ['holes' ] = [[(pt .x , pt .y , pt .z ) for pt in hole ]
1377
+ for hole in self .holes ]
1378
+ return base
1371
1379
1372
1380
def _check_vertices_input (self , vertices , loop_name = 'boundary' ):
1373
1381
if not isinstance (vertices , tuple ):
0 commit comments