/// <summary>
/// This Method ensures a match is possible and if so clusters two nodes
/// </summary>
/// <param name="matchData"> MatchData Object </param>
/// <returns> </returns>
public static Cluster ClusterNodes(MatchData matchData)
{
INode firstRoot = matchData.First.Shred.Root();
INode secondRoot = matchData.Second.Shred.Root();
ClusterData result = IsMatch(matchData, firstRoot, secondRoot);
if (result == null)
{
return(null);
}
// Mirror the smaller object if need be
if (result.Match == Match.Inverted)
{
if (firstRoot.Size() < secondRoot.Size())
{
firstRoot.Mirror();
result.FirstDirection = Enumeration.Opposite(result.FirstDirection);
}
else
{
secondRoot.Mirror();
result.SecondDirection = Enumeration.Opposite(result.SecondDirection);
}
}
// If the FirstNode's Edge is on the Right, it should go on the LEFT (make sense? )
if (result.FirstDirection == Direction.FromRight && result.SecondDirection == Direction.FromLeft)
{
return(new Cluster(firstRoot, secondRoot, result.Match, matchData));
}
return(new Cluster(secondRoot, firstRoot, result.Match, matchData));
}