Skip to content

Commit

Permalink
Null handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
enarhi committed Jul 29, 2021
1 parent d3d31d1 commit 13d2c61
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Facade_Engine/Compute/ComponentAreas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static partial class Compute
[MultiOutput(1, "frameArea", "Adjacent Elements per adjacent edge")]
public static Output<double, double> ComponentAreas(this Opening opening)
{
if (opening == null)
return null;

IGeometry frameGeo = opening.FrameGeometry2D();
double frameArea = 0;

Expand Down
7 changes: 3 additions & 4 deletions Facade_Engine/Compute/EdgeAdjacencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ public static partial class Compute
[MultiOutput(1, "adjacentElems", "Adjacent Elements per adjacent edge.")]
public static Output<List<IElement1D>, List<IElement2D>> EdgeAdjacencies(this IElement1D edge, IEnumerable<IElement2D> elements, double tolerance = Tolerance.Distance)
{
if (edge == null || elements.Count() == 0)
return null;

List<IElement1D> adjEdges = new List<IElement1D>();
List<IElement2D> adjElems = new List<IElement2D>();

//List<IElement2D> adjFullElems = AdjacentElements(edge, elems);
PolyCurve edgeGeo = edge.ElementCurves().IJoin()[0];
Vector edgeDir = edge.IGeometry().IEndDir();

foreach (IElement2D elem in elements)
{
List<IElement1D> edges = elem.IOutlineElements1D();
Expand Down
3 changes: 3 additions & 0 deletions Facade_Engine/Compute/UValueOpeningCAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static partial class Compute
[Output("effectiveUValue", "Effective U-value result of opening calculated using CAM.")]
public static OverallUValue UValueOpeningCAM(this Opening opening)
{
if (opening == null)
return null;

double glassArea = opening.ComponentAreas().Item1;

List<IFragment> glassUValues = opening.GetAllFragments(typeof(UValueGlassCentre));
Expand Down
3 changes: 3 additions & 0 deletions Facade_Engine/Compute/UValueOpeningSAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static partial class Compute
[Output("effectiveUValue", "Effective U-value result of opening caclulated using SAM.")]
public static OverallUValue UValueOpeningSAM(this Opening opening)
{
if (opening == null)
return null;

double area = opening.Area();

List<IFragment> uValues = opening.GetAllFragments(typeof(UValueGlassCentre));
Expand Down
6 changes: 4 additions & 2 deletions Facade_Engine/Query/FrameGeometry2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static partial class Query

public static IGeometry FrameGeometry2D(this Opening opening)
{
if (opening == null)
return null;

PolyCurve extCrv = opening.Geometry();
List<double> widths = new List<double>();

Expand All @@ -59,8 +62,7 @@ public static IGeometry FrameGeometry2D(this Opening opening)
BH.Engine.Reflection.Compute.RecordWarning("This method only works on planar curves. Opening " + opening.BHoM_Guid + " has non-planar curves and will be ignored.");
return null;
}

Plane openingPlane = extCrv.FitPlane();

foreach (FrameEdge edge in opening.Edges)
{
double width = edge.FrameEdgeProperty.WidthIntoOpening();
Expand Down
47 changes: 46 additions & 1 deletion Facade_Engine/Query/IsAdjacent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public static bool IsAdjacentApprox(this Line curve1, Line curve2, double tolera

public static bool IsAdjacent(this Line curve1, Polyline curve2, double tolerance = Tolerance.Distance)
{
if (curve1 == null || curve2 == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the adjacency of two curves if either curve is null.");
return false;
}

foreach (Line crv in curve2.SubParts())
if (crv.IsAdjacent(curve2, tolerance))
return true;
Expand All @@ -166,6 +172,12 @@ public static bool IsAdjacent(this Line curve1, Polyline curve2, double toleranc

public static bool IsAdjacent(this Polyline curve1, Line curve2, double tolerance = Tolerance.Distance)
{
if (curve1 == null || curve2 == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the adjacency of a PolyLine and a Curve if either is null.");
return false;
}

foreach (Line crv in curve1.SubParts())
if (crv.IsAdjacent(curve2, tolerance))
return true;
Expand All @@ -182,7 +194,13 @@ public static bool IsAdjacent(this Polyline curve1, Line curve2, double toleranc

public static bool IsAdjacent(this Polyline curve1, Polyline curve2, double tolerance = Tolerance.Distance)
{
foreach (Line crv2 in curve2.SubParts())
if (curve1 == null || curve2 == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the adjacency of two PolyLines if either PolyLine is null.");
return false;
}

foreach (Line crv2 in curve2.SubParts())
if (curve1.IsAdjacent(crv2, tolerance))
return true;
return false;
Expand All @@ -201,6 +219,12 @@ public static bool IsAdjacent(this Polyline curve1, Polyline curve2, double tole

public static bool IIsAdjacent (this ICurve curve1, ICurve curve2, double tolerance = Tolerance.Distance)
{
if (curve1 == null || curve2 == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the adjacency of two ICurves if either ICurve is null.");
return false;
}

return IsAdjacent(new Polyline { ControlPoints = curve1.IControlPoints() } as dynamic, new Polyline { ControlPoints = curve2.IControlPoints() } as dynamic);
}

Expand All @@ -212,6 +236,12 @@ public static bool IIsAdjacent (this ICurve curve1, ICurve curve2, double tolera

public static bool IIsAdjacent(this IElement1D elem1, IElement1D elem2, double tolerance = Tolerance.Distance)
{
if (elem1 == null || elem2 == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the adjacency of two IElement1Ds if either is null.");
return false;
}

return IsAdjacent(elem1 as dynamic, elem2 as dynamic);
}

Expand Down Expand Up @@ -245,6 +275,11 @@ private static bool IsAdjacent(this IElement1D elem1, IElement1D elem2, double t
[Output("bool", "True if provided lines are adjacent.")]
private static bool IsAdjacent(this IEdge edge1, IEdge edge2, double tolerance = Tolerance.Distance)
{
if (edge1 == null || edge2 == null)
{
return false;
}

ICurve crv1 = edge1.Curve;
ICurve crv2 = edge2.Curve;

Expand All @@ -263,6 +298,11 @@ private static bool IsAdjacent(this IEdge edge1, IEdge edge2, double tolerance =
[Output("bool", "True if provided lines are adjacent.")]
private static bool IsAdjacent(this IEdge edge1, ICurve crv2, double tolerance = Tolerance.Distance)
{
if (edge1 == null || crv2 == null)
{
return false;
}

ICurve crv1 = edge1.Curve;

if (crv1 != null && crv2 != null)
Expand All @@ -280,6 +320,11 @@ private static bool IsAdjacent(this IEdge edge1, ICurve crv2, double tolerance =
[Output("bool", "True if provided lines are adjacent.")]
private static bool IsAdjacent(this ICurve crv1, IEdge edge2, double tolerance = Tolerance.Distance)
{
if (crv1 == null || edge2 == null)
{
return false;
}

ICurve crv2 = edge2.Curve;

if (crv1 != null && crv2 != null)
Expand Down
6 changes: 6 additions & 0 deletions Facade_Engine/Query/PrimaryPropertyName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static partial class Query
[Output("propName", "The name of the element's construction property")]
public static string IPrimaryPropertyName(this IElement2D elem)
{
if (elem == null)
return null;

return PrimaryPropertyName(elem as dynamic);
}

Expand All @@ -58,6 +61,9 @@ public static string IPrimaryPropertyName(this IElement2D elem)
[Output("propName", "The name of the element's construction property")]
public static string IPrimaryPropertyName(this IElement1D elem)
{
if (elem == null)
return null;

return PrimaryPropertyName(elem as dynamic);
}

Expand Down

0 comments on commit 13d2c61

Please sign in to comment.