Skip to content

Commit

Permalink
Conformal transformation bug fixed in geometry primitives query (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelbaran authored Jun 12, 2024
2 parents 1d4c71c + b686d63 commit 3bb620d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Revit_Core_Engine/Query/GeometryPrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,14 +58,24 @@ public static List<GeometryObject> 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);
Expand Down

0 comments on commit 3bb620d

Please sign in to comment.