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

Geometry_Engine: Split bugs fixed and OutlinesFromLines method added #3283

Merged
merged 28 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6e88f44
1st iteration of tweaking Split and adding OutlinesFromLines
pawelbaran Feb 13, 2024
0e1a2fd
Performance of ClusterCollinear tweaked
pawelbaran Feb 13, 2024
0e35f2d
attempt to tweak ClusterCollinear reverted
pawelbaran Feb 13, 2024
ccb589a
RemoveOutliers made back private
pawelbaran Feb 13, 2024
19ba2f8
generation of outlines from lines optimised and bugfixed
pawelbaran Feb 14, 2024
1fe517e
descriptions tweaked
pawelbaran Feb 14, 2024
89acac8
versioning added
pawelbaran Feb 14, 2024
c389b10
null checks added
pawelbaran Feb 14, 2024
133e81b
more safety added
pawelbaran Feb 14, 2024
9f2e34f
#3284 fixed
pawelbaran Feb 15, 2024
2079c19
zero length curve edge case fixed
pawelbaran Feb 15, 2024
785b070
edge case with nodes not ideally overlapping fixed
pawelbaran Feb 15, 2024
d430308
#3285 fixed
pawelbaran Feb 15, 2024
9086d2b
stack overflow in FitLine fixed
pawelbaran Feb 15, 2024
3d03358
another attempt to fix #3284
pawelbaran Feb 15, 2024
81b8b42
reverting attempts to improve collinearity checks
pawelbaran Feb 15, 2024
4c9e50e
IsCollinear made more precise
pawelbaran Feb 17, 2024
069c0a4
projection moved to occur per cluster
pawelbaran Feb 17, 2024
3527f39
call to BooleanUnion that may mess up the final result replaced with …
pawelbaran Feb 17, 2024
896267b
comments by @FraserGreenroyd addressed
pawelbaran Feb 17, 2024
0a01b16
code comment tweaked following @FraserGreenroyd's suggestion
pawelbaran Feb 19, 2024
92e47d0
copyright year upticked
pawelbaran Feb 19, 2024
737c445
fixed case of cutting lines with at least 1 node of valence 1 (#3289)
pawelbaran Feb 21, 2024
c793723
Robustness increased by force snapping the points together
pawelbaran Feb 21, 2024
044429d
final code comments
pawelbaran Feb 22, 2024
25f9a6e
IsNull overload for a collection added, null check code cleaned up a bit
pawelbaran Feb 23, 2024
aa2b6fe
safety checks added to Split method
pawelbaran Feb 23, 2024
5dc09da
order of descriptions fixed
pawelbaran Feb 23, 2024
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
21 changes: 7 additions & 14 deletions Architecture_Engine/Compute/CeilingTiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,26 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using BH.oM.Architecture.Elements;

using BH.oM.Geometry;
using BH.Engine.Geometry;
using System.Runtime.InteropServices;

using BH.oM.Architecture.Elements;
using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Architecture
{
public static partial class Compute
{
[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)")]
[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.")]
[Input("ceiling", "Ceiling object which provides the outer perimeter of the ceiling tiles")]

Check warning on line 37 in Architecture_Engine/Compute/CeilingTiles.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Architecture_Engine/Compute/CeilingTiles.cs#L37

Documentation attribute should end with grammatically correct punctuation (., !, or ?) - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/AttributeHasEndingPunctuation
[Input("ceilingTileLines", "The lines across the ceiling which will be used to cut the ceiling into individual tiles.")]
[Input("angleTolerance", "Tolerance used for angle calculations. Default set to BH.oM.Geometry.Tolerance.Angle.")]
[Input("distanceTolerance", "Tolerance used for distance calculations. Default set to BH.oM.Geometry.Tolerance.Distance")]

Check warning on line 40 in Architecture_Engine/Compute/CeilingTiles.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Architecture_Engine/Compute/CeilingTiles.cs#L40

Documentation attribute should end with grammatically correct punctuation (., !, or ?) - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/AttributeHasEndingPunctuation
[Input("decimalPlaces", "All coordinates of the geometry will be rounded to the number of decimal places specified. Default 6.")]
[Output("ceilingTiles", "Closed Ceiling Tile regions contained within the Ceiling.")]
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)
public static List<CeilingTile> CeilingTiles(Ceiling ceiling, List<Line> ceilingTileLines, double angleTolerance = BH.oM.Geometry.Tolerance.Angle, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance)
{
if(ceiling == null)
{
Expand All @@ -60,7 +53,7 @@

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,60 @@ public static partial class Query
/**** Public Methods ****/
/***************************************************/

[Description("Checks if a List is null and outputs relevant error message.")]
[Input("list", "The List to test for null.")]
[Description("Checks if a collection is null or empty and outputs relevant error message.")]
[Input("collection", "The collection to test for null value or emptiness.")]
[Input("msg", "Optional message to be returned in addition to the generated error message.")]
[Input("methodName", "The name of the method to reference in the error message.")]
[Output("isNull", "True if the collection is null or empty.")]
public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection, string msg = "", [CallerMemberName] string methodName = "")
{
return collection.NullCheckCollection(true, msg, methodName);
}

/***************************************************/

[Description("Checks if a collection is null and outputs relevant error message.")]
[Input("collection", "The collection to test for null value.")]
[Input("msg", "Optional message to be returned in addition to the generated error message.")]
[Output("isNull", "True if the List or its elements are null.")]
public static bool IsNullOrEmpty<T>(this IEnumerable<T> list, string msg = "", [CallerMemberName] string methodName = "")
[Input("methodName", "The name of the method to reference in the error message.")]
[Output("isNull", "True if the collection is null.")]
public static bool IsNull<T>(this IEnumerable<T> collection, string msg = "", [CallerMemberName] string methodName = "")
{
if (list == null)
return collection.NullCheckCollection(false, msg, methodName);
}


/***************************************************/
/**** Private Methods ****/
/***************************************************/

private static bool NullCheckCollection<T>(this IEnumerable<T> collection, bool checkForEmpty, string msg, string methodName)
{
if (collection == null)
{
if (string.IsNullOrEmpty(methodName))
{
methodName = "Method";
}
Base.Compute.RecordError($"Cannot evaluate {methodName} because the List failed a null check. {msg}");
Base.Compute.RecordError($"Cannot evaluate {methodName} because the input collection failed a null check. {msg}");

return true;
}
else if (!list.Any())
else if (checkForEmpty && !collection.Any())
{
if (string.IsNullOrEmpty(methodName))
{
methodName = "Method";
}
Base.Compute.RecordError($"Cannot evaluate {methodName} because the List is empty. {msg}");
Base.Compute.RecordError($"Cannot evaluate {methodName} because the input collection is empty. {msg}");

return true;
}

return false;
}

/***************************************************/
}
}

Expand Down
14 changes: 7 additions & 7 deletions Geometry_Engine/Compute/BooleanUnion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
[Input("refLine", "Second line to union.")]
[Input("tolerance", "Tolerance used for checking colinearity and proximity of the lines.", typeof(Length))]
[Output("union", "Boolean union of the lines.")]
public static List<Line> BooleanUnion(this Line line, Line refLine, double tolerance = Tolerance.Distance, bool keepIntermediatePoints = false)

Check warning on line 45 in Geometry_Engine/Compute/BooleanUnion.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Geometry_Engine/Compute/BooleanUnion.cs#L45

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
double sqTol = tolerance * tolerance;
List<Line> result = new Line[] { line, refLine }.Where(x => x != null && x.SquareLength() > sqTol).ToList();
Expand All @@ -59,7 +59,7 @@
[Input("lines", "Lines to union.")]
[Input("tolerance", "Tolerance used for checking colinearity and proximity of the lines.", typeof(Length))]
[Output("union", "Boolean union of the lines.")]
public static List<Line> BooleanUnion(this List<Line> lines, double tolerance = Tolerance.Distance, bool keepIntermediatePoints = false)

Check warning on line 62 in Geometry_Engine/Compute/BooleanUnion.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Geometry_Engine/Compute/BooleanUnion.cs#L62

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
double sqTol = tolerance * tolerance;
return lines.Where(x => x != null && x.SquareLength() > sqTol)
Expand Down Expand Up @@ -488,20 +488,20 @@
extraSteps.Add(0, new List<double>());
foreach (double step in steps)
{
while (step - mergedRanges[i].Item2 > tolerance)
{
i++;
extraSteps.Add(i, new List<double>());
}

if (step - mergedRanges[i].Item1 > tolerance)
{

if (mergedRanges[i].Item2 - step > tolerance && extraSteps[i].All(x => Math.Abs(x - step) > tolerance))
extraSteps[i].Add(step);
else
{
i++;
extraSteps.Add(i, new List<double>());
}
}
}

extraSteps.Remove(i);

List<(double, double)> mergedMerged = new List<(double, double)>();
foreach (int j in extraSteps.Keys.OrderBy(x => x))
{
Expand Down
Loading