Algorithmix.MatchData.IsMatch C# (CSharp) Method

IsMatch() private static method

IsMatch determines if two shreds can be placed next to each other and thus matched. It returns a match.inverted or match.noninverted if possible or match.impossible if not. You shouldn't need to call IsMatch, rather use the safe ClusterNodes() method which will do it for you
private static IsMatch ( MatchData matchData, INode firstRoot, INode secondRoot ) : ClusterData
matchData MatchData
firstRoot INode
secondRoot INode
return ClusterData
        private static ClusterData IsMatch(MatchData matchData, INode firstRoot, INode secondRoot)
        {
            Side first = matchData.First;
            Side second = matchData.Second;
            Tuple<Match, Direction> firstFit;
            Tuple<Match, Direction> secondFit;
            // Cannot match when you have the same root
            if (firstRoot == secondRoot)
            {
                return null;
            }

            firstFit = IsFit(firstRoot, first.Shred, first);
            if (firstFit.Item1 == Match.Impossible)
            {
                return null;
            }
            secondFit = IsFit(secondRoot, second.Shred, second);
            if (secondFit.Item1 == Match.Impossible)
            {
                return null;
            }

            //if (firstFit.Item1 == Match.Inverted && secondFit.Item1 == Match.Inverted)
            //{
            //    return new ClusterData(Match.NonInverted, secondFit.Item2, firstFit.Item2);
            //}
            //else if (firstFit.Item1 == Match.NonInverted && secondFit.Item1 == Match.NonInverted)
            if (firstFit.Item1 == secondFit.Item1)
            {
                return new ClusterData(Match.NonInverted, firstFit.Item2, secondFit.Item2);
            }
            else if (firstFit.Item1 == Match.Inverted && secondFit.Item1 == Match.NonInverted ||
                     firstFit.Item1 == Match.NonInverted && secondFit.Item1 == Match.Inverted)
            {
                return new ClusterData(Match.Inverted, firstFit.Item2, secondFit.Item2);
            }

            return null;
        }