From f11960e0d7bf1318d28f7d43befefa12c7f4617d Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Fri, 19 Jul 2019 14:51:44 +0100 Subject: [PATCH 1/3] #1105 - panels by level filter Sneaky fix to minimum and maximum levels rounding to 3dp --- Environment_Engine/Query/Level.cs | 4 ++-- Environment_Engine/Query/Panels.cs | 37 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Environment_Engine/Query/Level.cs b/Environment_Engine/Query/Level.cs index 781e9b561..8b569d0ce 100644 --- a/Environment_Engine/Query/Level.cs +++ b/Environment_Engine/Query/Level.cs @@ -66,7 +66,7 @@ public static double MinimumLevel(this Panel panel) foreach (Point p in crvPts) min = Math.Min(min, p.Z); - return min; + return Math.Round(min, 3); } [Description("Returns the maximum level of the given panel based on the z axis")] @@ -80,7 +80,7 @@ public static double MaximumLevel(this Panel panel) foreach (Point p in crvPts) max = Math.Max(max, p.Z); - return max; + return Math.Round(max, 3); } [Description("Returns the Architecture Level that the Environment Panel resides on")] diff --git a/Environment_Engine/Query/Panels.cs b/Environment_Engine/Query/Panels.cs index 7ec73fbbe..6656c3d13 100644 --- a/Environment_Engine/Query/Panels.cs +++ b/Environment_Engine/Query/Panels.cs @@ -36,6 +36,8 @@ using BH.oM.Reflection.Attributes; using System.ComponentModel; +using BH.oM.Architecture.Elements; + namespace BH.Engine.Environment { public static partial class Query @@ -191,5 +193,40 @@ public static Panel PanelByGuid(this List panels, Guid guid) { return panels.Where(x => x.BHoM_Guid == guid).FirstOrDefault(); } + + [Description("Returns a collection of Environment Panels that sit entirely on a given levels elevation")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The Architecture level to search by")] + [Output("panels", "A collection of Environment Panels which match the given level")] + public static List PanelsByLevel(this List panels, Level searchLevel) + { + return panels.PanelsByLevel(searchLevel.Elevation); + } + + [Description("Returns a collection of Environment Panels that sit entirely on a given levels elevation")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The level to search by")] + [Output("panels", "A collection of Environment Panels which match the given level")] + public static List PanelsByLevel(this List panels, double searchLevel) + { + return panels.Where(x => x.MinimumLevel() == searchLevel && x.MaximumLevel() == searchLevel).ToList(); + } + + [Description("Returns a collection of Environment Panels that contain duplicates in the given collection")] + [Input("panels", "A collection of Environment Panels to search in")] + [Output("panels", "A nested collection of Environment Panels that are duplicates")] + public static List> FindDuplicatePanels(this List panels) + { + List> duplicates = new List>(); + + foreach (Panel p in panels) + { + List found = panels.Where(x => x.IsIdentical(p)).ToList(); + if (found.Count > 1) + duplicates.Add(found); + } + + return duplicates; + } } } \ No newline at end of file From f14830f2456826a720a42323fb07a9a4386936db Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Fri, 19 Jul 2019 15:06:26 +0100 Subject: [PATCH 2/3] Add more level filters for panels --- Environment_Engine/Query/Panels.cs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Environment_Engine/Query/Panels.cs b/Environment_Engine/Query/Panels.cs index 6656c3d13..463f74e2f 100644 --- a/Environment_Engine/Query/Panels.cs +++ b/Environment_Engine/Query/Panels.cs @@ -212,6 +212,42 @@ public static List PanelsByLevel(this List panels, double searchLe return panels.Where(x => x.MinimumLevel() == searchLevel && x.MaximumLevel() == searchLevel).ToList(); } + [Description("Returns a collection of Environment Panels where the minimum level of the panel matches the elevation of the given search level")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The Architecture level to search by")] + [Output("panels", "A collection of Environment Panels where the minimum level meets the search level")] + public static List PanelsByMinimumLevel(this List panels, Level searchLevel) + { + return panels.PanelsByMinimumLevel(searchLevel.Elevation); + } + + [Description("Returns a collection of Environment Panels where the minimum level of the panel matches the elevation of the given search level")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The level to search by")] + [Output("panels", "A collection of Environment Panels where the minimum level meets the search level")] + public static List PanelsByMinimumLevel(this List panels, double searchLevel) + { + return panels.Where(x => x.MinimumLevel() == searchLevel).ToList(); + } + + [Description("Returns a collection of Environment Panels where the maximum level of the panel matches the elevation of the given search level")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The Architecture level to search by")] + [Output("panels", "A collection of Environment Panels where the maximum level meets the search level")] + public static List PanelsByMaximumLevel(this List panels, Level searchLevel) + { + return panels.PanelsByMaximumLevel(searchLevel.Elevation); + } + + [Description("Returns a collection of Environment Panels where the maximum level of the panel matches the elevation of the given search level")] + [Input("panels", "A collection of Environment Panels to filter")] + [Input("searchLevel", "The level to search by")] + [Output("panels", "A collection of Environment Panels where the maximum level meets the search level")] + public static List PanelsByMaximumLevel(this List panels, double searchLevel) + { + return panels.Where(x => x.MaximumLevel() == searchLevel).ToList(); + } + [Description("Returns a collection of Environment Panels that contain duplicates in the given collection")] [Input("panels", "A collection of Environment Panels to search in")] [Output("panels", "A nested collection of Environment Panels that are duplicates")] From a4aa8f261bd602ebb99a8cf92dd334d3ac922fb9 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Fri, 19 Jul 2019 16:29:17 +0100 Subject: [PATCH 3/3] Fixes for Rhino -> BHoM workflow --- Environment_Engine/Compute/MergeBuildingElements.cs | 1 + Environment_Engine/Query/IsContaining.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Environment_Engine/Compute/MergeBuildingElements.cs b/Environment_Engine/Compute/MergeBuildingElements.cs index 3bb133de3..28c6aa0ff 100644 --- a/Environment_Engine/Compute/MergeBuildingElements.cs +++ b/Environment_Engine/Compute/MergeBuildingElements.cs @@ -51,6 +51,7 @@ public static Panel MergePanels(this Panel panel1, Panel panel2) List connectedSpaces = panel1.ConnectedSpaces; connectedSpaces.AddRange(panel2.ConnectedSpaces); connectedSpaces = connectedSpaces.Where(x => !x.Equals("-1")).ToList(); + connectedSpaces = connectedSpaces.Distinct().ToList(); rtnPanel.ConnectedSpaces = new List(connectedSpaces); diff --git a/Environment_Engine/Query/IsContaining.cs b/Environment_Engine/Query/IsContaining.cs index bec37cc08..62b907ec6 100644 --- a/Environment_Engine/Query/IsContaining.cs +++ b/Environment_Engine/Query/IsContaining.cs @@ -62,7 +62,7 @@ public static bool IsContaining(this List> panelsAsSpaces, Panel pan [Output("isContaining", "True if the point is contained within the list, false if it is not")] public static bool IsContaining(this List pts, Point pt) { - return (pts.Where(point => point.X == pt.X && point.Y == pt.Y && point.Z == pt.Z).FirstOrDefault() != null); + return (pts.Where(point => Math.Round(point.X, 3) == Math.Round(pt.X, 3) && Math.Round(point.Y, 3) == Math.Round(pt.Y, 3) && Math.Round(point.Z, 3) == Math.Round(pt.Z, 3)).FirstOrDefault() != null); } [Description("Defines whether an Environment Panel contains a provided point")]