BHoM / BHoM_Engine

Internal manipulation of the BHoM
GNU Lesser General Public License v3.0
26 stars 12 forks source link

Geometry_Engine: PlanarSurface throws unhelpful errors on some geometries #3322

Open Tom-Kingstone opened 4 months ago

Tom-Kingstone commented 4 months ago

Description:

Coming up in testing IES and XML toolkits, There are multiple panels which have geometry similar to this: image where an internal curve (as an opening) meets the external curve. When these curves are input into PlanarSurface, it causes this error to be raised:

1. This component failed to run properly.
- Error: Sequence contains more than one element
- Occured in  BH.Engine.Geometry.Create.PlanarSurface(ICurve externalBoundary, List`1 internalBoundaries, Double tolerance)
     called from BH.UI.Base.Caller.Run(List`1 inputs)
- Are you sure you have the correct type of inputs? Check their description for more details.

This was introduced a few years back in creating planar surfaces when multiple try/catches were removed, and some of the logic was changed. The error is thrown here:https://github.com/BHoM/BHoM_Engine/blob/aed0d0617bb80b49519fec32e548610c02ba8aab/Geometry_Engine/Create/PlanarSurface.cs#L139 caused by BooleanDifference returning a list with more than one element due to there being more than one region returned from boolean difference.

Steps to reproduce:

Use Create.PlanarSurface(externalBoundary, internalBoundaries, tolerance) with geometry similar to that of the image below.

Expected behaviour:

Not sure how to describe it, but it should create a surface that looks like this: image

Test file(s):

Tom-Kingstone commented 3 months ago

After some discussion, @jamesramsden-bh suggested that we simply catch the error and provide a more user-friendly error when this exception is thrown. Something like one of the internal boundaries splits the planar surface into two, ensure that internal boundaries do not span the width of the planar surface.

Tom-Kingstone commented 3 months ago

The overarching issue of Panels having invalid geometry for a planar surface (even when the panels' geometry is nominally valid) has a solution in this branch: https://github.com/BHoM/BHoM_Engine/tree/Analytical_Engine-%233322-PanelGeometryFix The issue with PlanarSurface not having a useful error message has a solution on this branch: https://github.com/BHoM/BHoM_Engine/tree/Geometry_Engine-%233322-ImprovePlanarSurfaceErrors