-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPolygonGraph.cs
49 lines (42 loc) · 1.36 KB
/
PolygonGraph.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections.Generic;
using System.Linq;
using lib;
namespace SquareConstructor
{
public class PolygonGraph
{
public Node[] Nodes { get; }
public PolygonGraph(Polygon[] polygons)
{
Nodes = polygons.Select(p => new Node(p)).ToArray();
foreach (var currentNode in Nodes)
{
foreach (var neightbourNode in Nodes)
{
if (currentNode.Equals(neightbourNode))
continue;
foreach (var segment in currentNode.Polygon.GetCommonSegments(neightbourNode.Polygon))
{
if(!currentNode.Neightbours.ContainsKey(segment))
currentNode.Neightbours[segment] = new List<Node>();
currentNode.Neightbours[segment].Add(neightbourNode);
}
}
}
}
public class Node
{
public Polygon Polygon { get; private set; }
public Dictionary<Segment, List<Node>> Neightbours { get; private set; }
public Node(Polygon polygon)
{
Polygon = polygon;
Neightbours = new Dictionary<Segment, List<Node>>();
}
public List<Node> GetNeightbours(Segment segment)
{
return Neightbours[segment];
}
}
}
}