I have a problem. I created a TriangleGrid using SkiaSharp. While I was drawing the grid I saved each triangle info in a Dictionary. The Dictionary looks like this:
public class TriangleRegistryObject
{
public float x1 { get; set; }
public float y1 { get; set; }
public float x2 { get; set; }
public float y2 { get; set; }
public float x3 { get; set; }
public float y3 { get; set; }
public bool Selected { get; set; }
public bool Visible { get; set; }
}
Now when I select a Triangle I set the boolean Selected
to true
. At the end I want to check if the Triangles I have selected are connected with eachother. I thought I could count the connected lines. Here is an example image:
Now I want to count the purple lines where Selected=true
.
I have every coordinate (x1, y1) (x2, y2) and (x3, y3).
UPDATE:
Here is the code I use that return 0 for me!
public static bool ValidLayout()
{
bool IsValid;
int sharedEdges;
int SelectedTriangles = TriangleRegistry.Count(tr => tr.Value.Selected.Equals(true));
var triangles = new List<TriangleRegistryList>();
foreach (KeyValuePair<string, TriangleRegistryObject> row in TriangleRegistry.Where(n => n.Value.Selected == true).ToList())
{
triangles.Add(new TriangleRegistryList { x1 = row.Value.x1,
y1 = row.Value.y1,
x2 = row.Value.x2,
y2 = row.Value.y2,
x3 = row.Value.x3,
y3 = row.Value.y3
});
}
sharedEdges = triangles.GetKCombs(2).Where(t => t.First().IsAdjacentTo(t.Skip(1).Take(1).Single())).Count();
if (sharedEdges >= (SelectedTriangles - 1))
{
IsValid = true;
}
else
{
IsValid = false;
}
return IsValid;
}
But I have no idea how I can compare the coordinates with each other, to count the connected lines!
Can someone help me?