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: Add check for null Space perimeter in the IsValid method #2960

Merged
merged 2 commits into from
Dec 2, 2022
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 .ci/Datasets/Environment_Engine/Query/IsValid.json

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions Environment_Engine/Query/IsValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static partial class Query
[MultiOutput(1, "selfIntersectingSpaces", "Returns list of invalid spaces due to the perimeter curve self intersecting.")]
[MultiOutput(2, "zeroPerimeterSpaces", "Returns list of invalid spaces due to perimeter length being zero.")]
[MultiOutput(3, "notClosedSpaces", "Returns list of invalid spaces due to not closed perimeter.")]
public static Output<List<Space>, List<Space>, List<Space>, List<Space>> IsValid(this List<Space> spaces, double intersectionTolerance = BH.oM.Geometry.Tolerance.Distance, double lengthTolerance = BH.oM.Geometry.Tolerance.Distance, double closedSpacesTolerance = BH.oM.Geometry.Tolerance.Distance)
[MultiOutput(4, "nullPerimeterSpaces", "Returns list of invalid spaces due to having a null perimeter.")]
public static Output<List<Space>, List<Space>, List<Space>, List<Space>, List<Space>> IsValid(this List<Space> spaces, double intersectionTolerance = BH.oM.Geometry.Tolerance.Distance, double lengthTolerance = BH.oM.Geometry.Tolerance.Distance, double closedSpacesTolerance = BH.oM.Geometry.Tolerance.Distance)
{
if(spaces == null)
{
Expand All @@ -57,10 +58,18 @@ public static Output<List<Space>, List<Space>, List<Space>, List<Space>> IsValid
List<Space> selfIntersectingSpaces = new List<Space>();
List<Space> zeroPerimeterSpaces = new List<Space>();
List<Space> notClosedSpaces = new List<Space>();
List<Space> nullPerimeterSpaces = new List<Space>();

foreach (Space space in spaces)
{
if(space == null)
continue;

if(space.Perimeter == null)
{
nullPerimeterSpaces.Add(space);
continue; //Don't run the rest of the loop and risk it crashing on the other checks if the perimeter is null
}

bool isvalid = true;
if (space.IsSelfIntersecting(intersectionTolerance))
Expand Down Expand Up @@ -88,7 +97,14 @@ public static Output<List<Space>, List<Space>, List<Space>, List<Space>> IsValid
}
}

return new Output<List<Space>, List<Space>, List<Space>, List<Space>>{Item1 = validSpaces, Item2 = selfIntersectingSpaces, Item3 = notClosedSpaces, Item4 = zeroPerimeterSpaces};
return new Output<List<Space>, List<Space>, List<Space>, List<Space>, List<Space>>
{
Item1 = validSpaces,
Item2 = selfIntersectingSpaces,
Item3 = zeroPerimeterSpaces,
Item4 = notClosedSpaces,
Item5 = nullPerimeterSpaces,
};
}
}
}