From b686d63958dbb7fa78d82775f84f4701eee8a66c Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Wed, 12 Jun 2024 15:04:33 +0200 Subject: [PATCH] attempt to fix #1484 --- Revit_Core_Engine/Query/GeometryPrimitives.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Revit_Core_Engine/Query/GeometryPrimitives.cs b/Revit_Core_Engine/Query/GeometryPrimitives.cs index 9447a9744..e9845d251 100644 --- a/Revit_Core_Engine/Query/GeometryPrimitives.cs +++ b/Revit_Core_Engine/Query/GeometryPrimitives.cs @@ -25,6 +25,7 @@ using Autodesk.Revit.DB.Mechanical; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base.Attributes; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -57,14 +58,24 @@ public static List GeometryPrimitives(this GeometryElement geome Transform geometryTransform = geometryInstance.Transform; if (transform != null) - { geometryTransform = geometryTransform.Multiply(transform.Inverse); - // This is an edge case fix where the transform origin lies very close to zero, but not exactly at it - // See #1330 for reference - double distanceFromZero = geometryTransform.Origin.DistanceTo(XYZ.Zero); - if (distanceFromZero != 0 && distanceFromZero < 1e-6) - geometryTransform.Origin = XYZ.Zero; + // This is an edge case fix where the transform origin lies very close to zero, but not exactly at it + // See #1330 for reference + double distanceFromZero = geometryTransform.Origin.DistanceTo(XYZ.Zero); + if (distanceFromZero != 0 && distanceFromZero < 1e-6) + geometryTransform.Origin = XYZ.Zero; + + if (!geometryTransform.IsConformal) + { + // This is an edge case related to numerical noise in identity matrix + // See #1484 for reference + XYZ x = geometryTransform.BasisX; + XYZ y = geometryTransform.BasisY; + XYZ z = geometryTransform.BasisZ; + geometryTransform.BasisX = new XYZ(Math.Round(x.X, 6), Math.Round(x.Y, 6), Math.Round(x.Z, 6)); + geometryTransform.BasisY = new XYZ(Math.Round(y.X, 6), Math.Round(y.Y, 6), Math.Round(y.Z, 6)); + geometryTransform.BasisZ = new XYZ(Math.Round(z.X, 6), Math.Round(z.Y, 6), Math.Round(z.Z, 6)); } GeometryElement geomElement = geometryInstance.GetInstanceGeometry(geometryTransform);