Skip to content

Commit 3f0be7a

Browse files
authored
Geometry_Engine: Split bugs fixed and OutlinesFromLines method added (#3283)
2 parents 9cc40cd + 5dc09da commit 3f0be7a

File tree

6 files changed

+557
-151
lines changed

6 files changed

+557
-151
lines changed

Architecture_Engine/Compute/CeilingTiles.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,26 @@
2020
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
2121
*/
2222

23-
using System;
24-
using System.Collections.Generic;
25-
using System.Linq;
26-
using System.Text;
27-
using System.Threading.Tasks;
28-
29-
using BH.oM.Architecture.Elements;
30-
31-
using BH.oM.Geometry;
3223
using BH.Engine.Geometry;
33-
using System.Runtime.InteropServices;
34-
24+
using BH.oM.Architecture.Elements;
3525
using BH.oM.Base.Attributes;
26+
using BH.oM.Geometry;
27+
using System.Collections.Generic;
3628
using System.ComponentModel;
29+
using System.Linq;
3730

3831
namespace BH.Engine.Architecture
3932
{
4033
public static partial class Compute
4134
{
35+
[PreviousVersion("7.1", "BH.Engine.Architecture.Compute.CeilingTiles(BH.oM.Architecture.Elements.Ceiling, System.Collections.Generic.List<BH.oM.Geometry.Line>, System.Double, System.Double, System.Int32)")]
4236
[Description("Generate a collection of Ceiling Tile objects that can sit within the given ceiling. Uses the BH.Engine.Geometry.Compute.Split(Polyline, List<Line>) method for its core.")]
4337
[Input("ceiling", "Ceiling object which provides the outer perimeter of the ceiling tiles")]
4438
[Input("ceilingTileLines", "The lines across the ceiling which will be used to cut the ceiling into individual tiles.")]
4539
[Input("angleTolerance", "Tolerance used for angle calculations. Default set to BH.oM.Geometry.Tolerance.Angle.")]
4640
[Input("distanceTolerance", "Tolerance used for distance calculations. Default set to BH.oM.Geometry.Tolerance.Distance")]
47-
[Input("decimalPlaces", "All coordinates of the geometry will be rounded to the number of decimal places specified. Default 6.")]
4841
[Output("ceilingTiles", "Closed Ceiling Tile regions contained within the Ceiling.")]
49-
public static List<CeilingTile> CeilingTiles(Ceiling ceiling, List<Line> ceilingTileLines, double angleTolerance = BH.oM.Geometry.Tolerance.Angle, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance, int decimalPlaces = 6)
42+
public static List<CeilingTile> CeilingTiles(Ceiling ceiling, List<Line> ceilingTileLines, double angleTolerance = BH.oM.Geometry.Tolerance.Angle, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance)
5043
{
5144
if(ceiling == null)
5245
{
@@ -60,7 +53,7 @@ public static List<CeilingTile> CeilingTiles(Ceiling ceiling, List<Line> ceiling
6053

6154
Polyline outerPerimeter = ceiling.Surface.IExternalEdges().Select(x => x.ICollapseToPolyline(angleTolerance)).ToList().Join()[0];
6255

63-
List<Polyline> regions = BH.Engine.Geometry.Compute.Split(outerPerimeter, ceilingTileLines, distanceTolerance, decimalPlaces);
56+
List<Polyline> regions = BH.Engine.Geometry.Compute.Split(outerPerimeter, ceilingTileLines, distanceTolerance);
6457

6558
List<CeilingTile> tiles = new List<CeilingTile>();
6659

BHoM_Engine/Query/IsNullOrEmpty.cs renamed to BHoM_Engine/Query/IsNull.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,60 @@ public static partial class Query
3737
/**** Public Methods ****/
3838
/***************************************************/
3939

40-
[Description("Checks if a List is null and outputs relevant error message.")]
41-
[Input("list", "The List to test for null.")]
40+
[Description("Checks if a collection is null or empty and outputs relevant error message.")]
41+
[Input("collection", "The collection to test for null value or emptiness.")]
42+
[Input("msg", "Optional message to be returned in addition to the generated error message.")]
4243
[Input("methodName", "The name of the method to reference in the error message.")]
44+
[Output("isNull", "True if the collection is null or empty.")]
45+
public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection, string msg = "", [CallerMemberName] string methodName = "")
46+
{
47+
return collection.NullCheckCollection(true, msg, methodName);
48+
}
49+
50+
/***************************************************/
51+
52+
[Description("Checks if a collection is null and outputs relevant error message.")]
53+
[Input("collection", "The collection to test for null value.")]
4354
[Input("msg", "Optional message to be returned in addition to the generated error message.")]
44-
[Output("isNull", "True if the List or its elements are null.")]
45-
public static bool IsNullOrEmpty<T>(this IEnumerable<T> list, string msg = "", [CallerMemberName] string methodName = "")
55+
[Input("methodName", "The name of the method to reference in the error message.")]
56+
[Output("isNull", "True if the collection is null.")]
57+
public static bool IsNull<T>(this IEnumerable<T> collection, string msg = "", [CallerMemberName] string methodName = "")
4658
{
47-
if (list == null)
59+
return collection.NullCheckCollection(false, msg, methodName);
60+
}
61+
62+
63+
/***************************************************/
64+
/**** Private Methods ****/
65+
/***************************************************/
66+
67+
private static bool NullCheckCollection<T>(this IEnumerable<T> collection, bool checkForEmpty, string msg, string methodName)
68+
{
69+
if (collection == null)
4870
{
4971
if (string.IsNullOrEmpty(methodName))
5072
{
5173
methodName = "Method";
5274
}
53-
Base.Compute.RecordError($"Cannot evaluate {methodName} because the List failed a null check. {msg}");
75+
Base.Compute.RecordError($"Cannot evaluate {methodName} because the input collection failed a null check. {msg}");
5476

5577
return true;
5678
}
57-
else if (!list.Any())
79+
else if (checkForEmpty && !collection.Any())
5880
{
5981
if (string.IsNullOrEmpty(methodName))
6082
{
6183
methodName = "Method";
6284
}
63-
Base.Compute.RecordError($"Cannot evaluate {methodName} because the List is empty. {msg}");
85+
Base.Compute.RecordError($"Cannot evaluate {methodName} because the input collection is empty. {msg}");
6486

6587
return true;
6688
}
6789

6890
return false;
6991
}
7092

93+
/***************************************************/
7194
}
7295
}
7396

Geometry_Engine/Compute/BooleanUnion.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,20 +488,20 @@ private static List<Line> BooleanUnionCollinear(this List<Line> lines, double to
488488
extraSteps.Add(0, new List<double>());
489489
foreach (double step in steps)
490490
{
491+
while (step - mergedRanges[i].Item2 > tolerance)
492+
{
493+
i++;
494+
extraSteps.Add(i, new List<double>());
495+
}
496+
491497
if (step - mergedRanges[i].Item1 > tolerance)
492498
{
499+
493500
if (mergedRanges[i].Item2 - step > tolerance && extraSteps[i].All(x => Math.Abs(x - step) > tolerance))
494501
extraSteps[i].Add(step);
495-
else
496-
{
497-
i++;
498-
extraSteps.Add(i, new List<double>());
499-
}
500502
}
501503
}
502504

503-
extraSteps.Remove(i);
504-
505505
List<(double, double)> mergedMerged = new List<(double, double)>();
506506
foreach (int j in extraSteps.Keys.OrderBy(x => x))
507507
{

0 commit comments

Comments
 (0)