Skip to content

Commit

Permalink
check points for distance instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbradleym committed Jun 12, 2024
1 parent f0c2436 commit 53b00df
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions LayoutFunctions/WallsLOD200/src/WallsLOD200.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private static List<Line> MergeCollinearLines(List<Line> 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)
// project lines with points within tolerance of eachother but further than epsilon
if (LinesWithinTolerance(line, otherLine, tolerance))
{
otherLine = otherLine.Projected(line);
}
Expand All @@ -141,5 +141,28 @@ private static List<Line> MergeCollinearLines(List<Line> lines)
}
return merged;
}

public static bool LinesWithinTolerance(Line line1, Line line2, double tolerance)
{
// Calculate distances between all point pairs
var distances = new List<double>()
{
line1.Start.DistanceTo(line2.Start),
line1.Start.DistanceTo(line2.End),
line1.End.DistanceTo(line2.Start),
line1.End.DistanceTo(line2.End)
};

// Check if any distance is within the tolerance but larger than double.Epsilon
foreach (var distance in distances)
{
if (distance > double.Epsilon && distance <= tolerance)
{
return true;
}
}

return false;
}
}
}

0 comments on commit 53b00df

Please sign in to comment.