From 4579e06a4265fba412662ce752c5d3e8d0739949 Mon Sep 17 00:00:00 2001 From: James Bradley Date: Wed, 5 Jun 2024 11:06:34 -0400 Subject: [PATCH 1/2] handle tolerance gaps --- .../WallsLOD200.Dependencies.csproj | 6 ++-- .../WallsLOD200/src/WallsLOD200.cs | 35 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/LayoutFunctions/WallsLOD200/dependencies/WallsLOD200.Dependencies.csproj b/LayoutFunctions/WallsLOD200/dependencies/WallsLOD200.Dependencies.csproj index a58e7b7a..e8277aec 100644 --- a/LayoutFunctions/WallsLOD200/dependencies/WallsLOD200.Dependencies.csproj +++ b/LayoutFunctions/WallsLOD200/dependencies/WallsLOD200.Dependencies.csproj @@ -6,9 +6,9 @@ enable - - - + + + diff --git a/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs b/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs index 506c444d..4d051352 100644 --- a/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs +++ b/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs @@ -5,6 +5,7 @@ namespace WallsLOD200 { public static partial class WallsLOD200 { + public static double tolerance = 0.0001; /// /// The WallsLOD200 function. /// @@ -114,17 +115,31 @@ private static List MergeCollinearLines(List lines) { Line otherLine = mergedLines[j]; - if (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < 0.0001) + try { - // Merge collinear lines - Line mergedLine = line.MergedCollinearLine(otherLine); - - // Update the list with the merged line - mergedLines.RemoveAt(j); - mergedLines[i] = mergedLine; - - linesMerged = true; - break; // Exit the inner loop as we have merged the lines + if (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < tolerance) + { + // project lines within tolerance but further than epsilon + if (line.DistanceTo(otherLine) > double.Epsilon) + { + otherLine = otherLine.Projected(line); + } + // Merge collinear lines + Line mergedLine = line.MergedCollinearLine(otherLine); + + // Update the list with the merged line + mergedLines.RemoveAt(j); + mergedLines[i] = mergedLine; + + linesMerged = true; + break; // Exit the inner loop as we have merged the lines + } + } + catch (Exception e) + { + Console.WriteLine($"Failed to merge wall line {otherLine.Start} - {otherLine.End}."); + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); } } if (linesMerged) From f0c24361da9dcab7a7fc900dfd34770a1fd63273 Mon Sep 17 00:00:00 2001 From: James Bradley Date: Thu, 6 Jun 2024 14:17:46 -0400 Subject: [PATCH 2/2] don't catch --- .../WallsLOD200/src/WallsLOD200.cs | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs b/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs index 4d051352..c124252c 100644 --- a/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs +++ b/LayoutFunctions/WallsLOD200/src/WallsLOD200.cs @@ -115,31 +115,22 @@ private static List MergeCollinearLines(List lines) { Line otherLine = mergedLines[j]; - try + if (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < tolerance) { - if (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < tolerance) + // project lines within tolerance but further than epsilon + if (line.DistanceTo(otherLine) > double.Epsilon) { - // project lines within tolerance but further than epsilon - if (line.DistanceTo(otherLine) > double.Epsilon) - { - otherLine = otherLine.Projected(line); - } - // Merge collinear lines - Line mergedLine = line.MergedCollinearLine(otherLine); - - // Update the list with the merged line - mergedLines.RemoveAt(j); - mergedLines[i] = mergedLine; - - linesMerged = true; - break; // Exit the inner loop as we have merged the lines + otherLine = otherLine.Projected(line); } - } - catch (Exception e) - { - Console.WriteLine($"Failed to merge wall line {otherLine.Start} - {otherLine.End}."); - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); + // Merge collinear lines + Line mergedLine = line.MergedCollinearLine(otherLine); + + // Update the list with the merged line + mergedLines.RemoveAt(j); + mergedLines[i] = mergedLine; + + linesMerged = true; + break; // Exit the inner loop as we have merged the lines } } if (linesMerged)