Algorithmix.Enumeration.Opposite C# (CSharp) Method

Opposite() public static method

Determine the Opposite direction Left/Right are opposites as are Up and Down
public static Opposite ( Direction direction ) : Direction
direction Direction Direction to be toggled
return Direction
        public static Direction Opposite(Direction direction)
        {
            // Default case
            Direction opposite = Direction.FromLeft;
            switch (direction)
            {
                case Direction.FromLeft:
                    opposite = Direction.FromRight;
                    break;
                case Direction.FromRight:
                    opposite = Direction.FromLeft;
                    break;
                case Direction.FromTop:
                    opposite = Direction.FromBottom;
                    break;
                case Direction.FromBottom:
                    opposite = Direction.FromTop;
                    break;
            }
            return opposite;
        }

Same methods

Enumeration::Opposite ( Orientation orientation ) : Orientation

Usage Example

示例#1
0
        /// <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));
        }
All Usage Examples Of Algorithmix.Enumeration::Opposite