Skip to content

Commit

Permalink
tighter bounding box calculation using FamilyInstance information
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytammik committed Jul 20, 2017
1 parent 3ed6b95 commit c4be469
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
35 changes: 18 additions & 17 deletions FamilyBoundingBox/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ BoundingBoxXYZ familyInstanceBoundingBox

/// <summary>
/// Compute the 'BoundingBoxXYZ' of <paramref name="familyInstance"/>.
///
/// Required because 'FamilyInstance.get_BoundingBox( null )' does not give
/// a tight 'BoundingBoxXYZ'.
/// Required because 'FamilyInstance.get_BoundingBox( null )'
/// does not give a tight bounding box.
/// </summary>
/// <param name="familyInstance">The 'FamilyInstance' to compute the
/// 'BoundingBoxXYZ' of.</param>
Expand All @@ -234,7 +233,9 @@ private static BoundingBoxXYZ ComputeFamilyInstanceBoundingBoxXyz(
Options options = new Options();
GeometryElement geometryElement
= familyInstance.get_Geometry( options );
foreach ( GeometryInstance geometryInstance in geometryElement )

foreach ( GeometryInstance geometryInstance
in geometryElement )
{
foreach ( GeometryObject geometryObject in
geometryInstance.GetInstanceGeometry() )
Expand Down Expand Up @@ -272,7 +273,7 @@ private static BoundingBoxXYZ ComputeBoundingBoxXYZFromPoints(
IEnumerable<XYZ> points)
{
BoundingBoxXYZ boundingBoxXYZ = null;
if ( points.Any() )
if( points.Any() )
{
double minX = Double.PositiveInfinity;
double minY = Double.PositiveInfinity;
Expand All @@ -299,27 +300,27 @@ private static BoundingBoxXYZ ComputeBoundingBoxXYZFromPoints(
}

/// <summary>
/// Merge <paramref name="boundingBoxXyz0"/> and
/// <paramref name="boundingBoxXyz1"/> into a new 'BoundingBoxXYZ'.
/// Merge <paramref name="a"/> and
/// <paramref name="b"/> into a new 'BoundingBoxXYZ'.
/// </summary>
/// <param name="boundingBoxXyz0">A 'BoundingBoxXYZ' to merge</param>
/// <param name="boundingBoxXyz1">A 'BoundingBoxXYZ' to merge</param>
/// <param name="a">A 'BoundingBoxXYZ' to merge</param>
/// <param name="b">A 'BoundingBoxXYZ' to merge</param>
/// <returns>The new merged 'BoundingBoxXYZ'.</returns>
static BoundingBoxXYZ MergeBoundingBoxXyz(
BoundingBoxXYZ boundingBoxXyz0,
BoundingBoxXYZ boundingBoxXyz1 )
BoundingBoxXYZ a,
BoundingBoxXYZ b )
{
BoundingBoxXYZ mergedResult = new BoundingBoxXYZ();

mergedResult.Min = new XYZ(
Math.Min( boundingBoxXyz0.Min.X, boundingBoxXyz1.Min.X ),
Math.Min( boundingBoxXyz0.Min.Y, boundingBoxXyz1.Min.Y ),
Math.Min( boundingBoxXyz0.Min.Z, boundingBoxXyz1.Min.Z ) );
Math.Min( a.Min.X, b.Min.X ),
Math.Min( a.Min.Y, b.Min.Y ),
Math.Min( a.Min.Z, b.Min.Z ) );

mergedResult.Max = new XYZ(
Math.Max( boundingBoxXyz0.Max.X, boundingBoxXyz1.Max.X ),
Math.Max( boundingBoxXyz0.Max.Y, boundingBoxXyz1.Max.Y ),
Math.Max( boundingBoxXyz0.Max.Z, boundingBoxXyz1.Max.Z ) );
Math.Max( a.Max.X, b.Max.X ),
Math.Max( a.Max.Y, b.Max.Y ),
Math.Max( a.Max.Z, b.Max.Z ) );

return mergedResult;
}
Expand Down
10 changes: 8 additions & 2 deletions FamilyBoundingBox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "2017.0.0.0" )]
[assembly: AssemblyFileVersion( "2017.0.0.0" )]
//
// History:
//
// 2017-03-15 2017.0.0.0 initial implementation
// 2017-07-20 2017.0.0.1 tighter bounding box calculation using FamilyInstance information
//
[assembly: AssemblyVersion( "2017.0.0.1" )]
[assembly: AssemblyFileVersion( "2017.0.0.1" )]

0 comments on commit c4be469

Please sign in to comment.