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

Environment_Engine: Panels by level filter #1106

Merged
merged 3 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Environment_Engine/Compute/MergeBuildingElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static Panel MergePanels(this Panel panel1, Panel panel2)
List<string> connectedSpaces = panel1.ConnectedSpaces;
connectedSpaces.AddRange(panel2.ConnectedSpaces);
connectedSpaces = connectedSpaces.Where(x => !x.Equals("-1")).ToList();
connectedSpaces = connectedSpaces.Distinct().ToList();

rtnPanel.ConnectedSpaces = new List<string>(connectedSpaces);

Expand Down
2 changes: 1 addition & 1 deletion Environment_Engine/Query/IsContaining.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static bool IsContaining(this List<List<Panel>> 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<Point> 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")]
Expand Down
4 changes: 2 additions & 2 deletions Environment_Engine/Query/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down
73 changes: 73 additions & 0 deletions Environment_Engine/Query/Panels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,5 +193,76 @@ public static Panel PanelByGuid(this List<Panel> 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<Panel> PanelsByLevel(this List<Panel> 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<Panel> PanelsByLevel(this List<Panel> panels, double searchLevel)
{
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<Panel> PanelsByMinimumLevel(this List<Panel> 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<Panel> PanelsByMinimumLevel(this List<Panel> 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<Panel> PanelsByMaximumLevel(this List<Panel> 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<Panel> PanelsByMaximumLevel(this List<Panel> 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")]
public static List<List<Panel>> FindDuplicatePanels(this List<Panel> panels)
{
List<List<Panel>> duplicates = new List<List<Panel>>();

foreach (Panel p in panels)
{
List<Panel> found = panels.Where(x => x.IsIdentical(p)).ToList();
if (found.Count > 1)
duplicates.Add(found);
}

return duplicates;
}
}
}