From 4d8b130f2df17ca3d85ce619f62e0acbc0181d02 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 30 Jun 2020 21:24:08 +1000 Subject: [PATCH] Fix IfcPatch ResetAbsoluteCoordinates recipe to account for coordinate lists --- .../recipes/ResetAbsoluteCoordinates.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py b/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py index 98eebf0b58..ae55dea468 100644 --- a/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py +++ b/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py @@ -8,6 +8,22 @@ class Patcher: # 12D can have some funky coordinates out of any sensible range. This # method will not work all the time, but will catch most issues. offset_point = None + for point_list in self.file.by_type('IfcCartesianPointList3D'): + coord_list = [None] * len(point_list.CoordList) + for i, point in enumerate(point_list.CoordList): + if len(point) == 2 or not self.is_point_far_away(point): + coord_list[i] = point + continue + if not offset_point: + offset_point = (point[0], point[1], point[2]) + self.logger.info(f'Resetting absolute coordinates by {point}') + point = ( + point[0] - offset_point[0], + point[1] - offset_point[1], + point[2] - offset_point[2] + ) + coord_list[i] = point + point_list.CoordList = coord_list for point in self.file.by_type('IfcCartesianPoint'): if len(point.Coordinates) == 2 or not self.is_point_far_away(point): continue @@ -22,6 +38,10 @@ class Patcher: def is_point_far_away(self, point): # Arbitrary threshold based on experience - return abs(point.Coordinates[0]) > 1000000 \ - or abs(point.Coordinates[1]) > 1000000 \ - or abs(point.Coordinates[2]) > 1000000 + if hasattr(point, 'Coordinates'): + return abs(point.Coordinates[0]) > 1000000 \ + or abs(point.Coordinates[1]) > 1000000 \ + or abs(point.Coordinates[2]) > 1000000 + return abs(point[0]) > 1000000 \ + or abs(point[1]) > 1000000 \ + or abs(point[2]) > 1000000