Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CenterPoint and Bounds methods #1387

Merged
merged 10 commits into from
Jul 31, 2023
25 changes: 23 additions & 2 deletions Revit_Core_Engine/Query/Bounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static partial class Query
/**** Public methods ****/
/***************************************************/

[Description("Returns the combined bounding box of a given colection of volumetric solids.")]
[Description("Returns the combined bounding box of a given collection of volumetric solids.")]
[Input("solids", "A collection of solids to find the bounds for.")]
[Input("transform", "Optional transform of the bounding box's coordinate system.")]
[Output("bounds", "Combined bounding box of the input colection of volumetric solids.")]
[Output("bounds", "Combined bounding box of the input collection of volumetric solids.")]
public static BoundingBoxXYZ Bounds(this IEnumerable<Solid> solids, Transform transform = null)
{
solids = solids?.Where(x => x != null && x.Volume > 1e-6).ToList();
Expand Down Expand Up @@ -81,6 +81,27 @@ public static BoundingBoxXYZ Bounds(this IEnumerable<Solid> solids, Transform tr
}

/***************************************************/

[Description("Returns the combined outline of the given outlines.")]
[Input("outlines", "A list of outlines to combine.")]
[Output("bounds", "Combined outline of the given outlines.")]
public static Outline Bounds(this List<Outline> outlines)
michal-pekacki marked this conversation as resolved.
Show resolved Hide resolved
{
michal-pekacki marked this conversation as resolved.
Show resolved Hide resolved
if (outlines == null || !outlines.Any())
return null;
michal-pekacki marked this conversation as resolved.
Show resolved Hide resolved

Outline newOutline = new Outline(outlines[0]);

foreach (Outline outline in outlines.Skip(1))
{
newOutline.AddPoint(outline.MinimumPoint);
newOutline.AddPoint(outline.MaximumPoint);
}

return newOutline;
}

/***************************************************/
}
}

46 changes: 46 additions & 0 deletions Revit_Core_Engine/Query/CenterPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using Autodesk.Revit.DB;
using BH.oM.Base.Attributes;
using System.ComponentModel;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/

[Description("Returns the center point of the outline.")]
[Input("outline", "Outline to get the center point from.")]
[Output("point", "Center point of the outline.")]
public static XYZ CenterPoint(this Outline outline)
{
return (outline.MinimumPoint + outline.MaximumPoint) / 2;
}

/***************************************************/
}
}