private static void RequirePortalMorph(Morph.Id morph, string paramName)
        {
            switch (morph)
            {
                case Morph.Portal.Down:
                case Morph.Portal.Left:
                case Morph.Portal.Right:
                case Morph.Portal.Up:
                    break;

                default:
                    throw new ArgumentException("The given morph is not a portal morph.", paramName);
            }
        }
        public static Direction PerformPortalTransformation(this Direction direction, Morph.Id sourcePortalMorph,
            Morph.Id targetPortalMorph)
        {
            RequirePortalMorph(sourcePortalMorph, nameof(sourcePortalMorph));
            RequirePortalMorph(targetPortalMorph, nameof(targetPortalMorph));

            var source = (int) sourcePortalMorph;
            var target = (int) targetPortalMorph;

            // No transformation required if morphs are same for both portals
            if (source == target)
                return direction;

            if (source < target)
                source += 4;

            var dir = source - target;

            switch (dir)
            {
                case 1:
                    return direction.RotatedClockWise();
                case 2:
                    return direction.Flipped();
                case 3:
                    return direction.RotatedCounterClockWise();

                default:
                    return direction;
            }
        }