Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbradleym committed Apr 23, 2024
1 parent 8586f84 commit 2c989e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
22 changes: 22 additions & 0 deletions LayoutFunctions/WallsLOD200/dependencies/LineEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Elements.Geometry;

namespace WallsLOD200
{

public class LineEqualityComparer : IEqualityComparer<Line>
{
public bool Equals(Line? x, Line? y)
{
if (x != null && y != null)
{
return (x.Start.IsAlmostEqualTo(y.Start) && x.End.IsAlmostEqualTo(y.End)) || (x.Start.IsAlmostEqualTo(y.End) && x.End.IsAlmostEqualTo(y.Start));
}
return false;
}

public int GetHashCode(Line obj)
{
return obj.GetHashCode();
}
}
}
25 changes: 2 additions & 23 deletions LayoutFunctions/WallsLOD200/src/WallsLOD200.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static List<Line> UnifyLines(List<Line> lines)

private static List<Line> RemoveDuplicateLines(List<Line> lines)
{
HashSet<Line> uniqueLines = new HashSet<Line>(new LineEqualityComparer());
HashSet<Line> uniqueLines = new(new LineEqualityComparer());

foreach (Line line in lines)
{
Expand Down Expand Up @@ -114,7 +114,7 @@ private static List<Line> MergeCollinearLines(List<Line> lines)
{
Line otherLine = mergedLines[j];

if (line.IsCollinear(otherLine) && (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < 0.0001))
if (line.TryGetOverlap(otherLine, out var overlap) || line.DistanceTo(otherLine) < 0.0001)
{
// Merge collinear lines
Line mergedLine = line.MergedCollinearLine(otherLine);
Expand All @@ -135,26 +135,5 @@ private static List<Line> MergeCollinearLines(List<Line> lines)
}
return merged;
}

private class LineEqualityComparer : IEqualityComparer<Line>
{
public bool Equals(Line x, Line y)
{
// Check if start and end points of lines are equal
return (x.Start == y.Start && x.End == y.End) || (x.Start == y.End && x.End == y.Start);
}

public int GetHashCode(Line obj)
{
// Compute hash code based on start and end points
unchecked
{
int hash = 17;
hash = hash * 23 + obj.Start.GetHashCode();
hash = hash * 23 + obj.End.GetHashCode();
return hash;
}
}
}
}
}

0 comments on commit 2c989e6

Please sign in to comment.