Ejemplo n.º 1
0
        protected virtual RotationDegree GetRotationDegreeFromRotationDirection(RotationDirection rotationDirection)
        {
            RotationDegree degreeCalculation = Rotation;

            switch (rotationDirection)
            {
            case RotationDirection.Clockwise:
                if (Rotation == RotationDegree.TwoSeventyFive)
                {
                    degreeCalculation = RotationDegree.Zero;
                }
                else
                {
                    degreeCalculation += 1;
                }
                break;

            case RotationDirection.CounterClockwise:
                if (Rotation == RotationDegree.Zero)
                {
                    degreeCalculation = RotationDegree.TwoSeventyFive;
                }
                else
                {
                    degreeCalculation -= 1;
                }
                break;
            }

            return(degreeCalculation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rotates the straight block CounterClockwise 90 degrees
        /// </summary>
        private void RotateStraightPieceCCW()
        {
            //All the block have the same Y
            int pivotY = BlockCells[0].CellLocationY;

            //The new highest Y value is +2 away from the pivot point
            pivotY += 2;
            //Find the Highest X value
            int pivotX = 0;

            foreach (var item in BlockCells)
            {
                if (item.CellLocationX > pivotX)
                {
                    pivotX = item.CellLocationX;
                }
            }
            //The pivot block is -1 from the pivot point
            pivotX -= 1;
            foreach (var item in BlockCells)
            {
                item.CellLocationY = pivotY;
                pivotY--;
                item.CellLocationX = pivotX;
            }
            RotationPoint = RotationDegree.threeSixty;
        }
Ejemplo n.º 3
0
            public static byte Rotate(byte b, RotationDegree rotDeg)
            {
                var l = (int)rotDeg << 1;
                var r = 8 - l;

                return((byte)(b << l | b >> r));
            }
Ejemplo n.º 4
0
        public static char Rotate(this char b, RotationDegree rotDeg)
        {
            var l = (int)rotDeg << 1;
            var r = 8 - l;

            return((char)(b << l | b >> r));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Rotates the straight block Clockwise 90 degrees
        /// </summary>
        private void RotateStraightPieceCW()
        {
            //All the block have the same X
            int pivotX = BlockCells[0].CellLocationX;

            //The new highest X value is +1 away from the pivot point
            pivotX += 1;
            //Find the Highest Y value
            int pivotY = 0;

            foreach (var item in BlockCells)
            {
                if (item.CellLocationY > pivotY)
                {
                    pivotY = item.CellLocationY;
                }
            }
            //The pivot block is -2 away from the highest block
            pivotY -= 2;
            foreach (var item in BlockCells)
            {
                item.CellLocationX = pivotX;
                pivotX--;
                item.CellLocationY = pivotY;
            }
            RotationPoint = RotationDegree.ninety;
        }
Ejemplo n.º 6
0
        public override List <Point> GetRotationTranslationCandidate(RotationDirection rotationDirection)
        {
            Point          pivot = PieceGridPositionList[PivotIndex];
            List <Point>   rotateCandidateList = new List <Point>();
            RotationDegree candidateDegree     = GetRotationDegreeFromRotationDirection(rotationDirection);

            // NOTE: rotationDirection matters not for this piece; it's just a toggle.
            // So, we'll just ignore it.
            switch (candidateDegree)
            {
            case RotationDegree.Zero:
                rotateCandidateList.Add(new Point(pivot.X - 1, pivot.Y));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X + 1, pivot.Y));
                rotateCandidateList.Add(new Point(pivot.X + 2, pivot.Y));
                break;

            case RotationDegree.Ninety:
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y - 1));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y + 1));
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y + 2));
                break;
            }

            return(rotateCandidateList);
        }
Ejemplo n.º 7
0
        public static byte Rotate(this byte b, RotationDegree rotDeg)
        {
            unchecked {
                var l = (byte)((byte)rotDeg << 1);
                var r = (byte)(8 - l);

                return(unchecked ((byte)(b << l | b >> r)));
            }
        }
Ejemplo n.º 8
0
        protected override RotationDegree GetRotationDegreeFromRotationDirection(RotationDirection rotationDirection)
        {
            RotationDegree degreeCalculation = Rotation;

            // This piece has, basically, two rotation states; simply toggle them.
            if (Rotation == RotationDegree.Zero)
            {
                degreeCalculation = RotationDegree.Ninety;
            }
            else if (Rotation == RotationDegree.Ninety)
            {
                degreeCalculation = RotationDegree.Zero;
            }

            return(degreeCalculation);
        }
Ejemplo n.º 9
0
        public override List <Point> GetRotationTranslationCandidate(RotationDirection rotationDirection)
        {
            Point          pivot = PieceGridPositionList[PivotIndex];
            List <Point>   rotateCandidateList = new List <Point>();
            RotationDegree candidateDegree     = GetRotationDegreeFromRotationDirection(rotationDirection);

            switch (candidateDegree)
            {
            case RotationDegree.Zero:
                rotateCandidateList.Add(new Point(pivot.X - 1, pivot.Y));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X + 1, pivot.Y));
                rotateCandidateList.Add(new Point(pivot.X + 1, pivot.Y + 1));
                break;

            case RotationDegree.Ninety:
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y + 1));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y - 1));
                rotateCandidateList.Add(new Point(pivot.X + 1, pivot.Y - 1));
                break;

            case RotationDegree.OneEighty:
                rotateCandidateList.Add(new Point(pivot.X + 1, pivot.Y));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X - 1, pivot.Y));
                rotateCandidateList.Add(new Point(pivot.X - 1, pivot.Y - 1));
                break;

            case RotationDegree.TwoSeventyFive:
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y - 1));
                rotateCandidateList.Add(pivot);
                rotateCandidateList.Add(new Point(pivot.X, pivot.Y + 1));
                rotateCandidateList.Add(new Point(pivot.X - 1, pivot.Y + 1));
                break;
            }

            return(rotateCandidateList);
        }
Ejemplo n.º 10
0
    /*
  input kernel area naming convention:
  -------------
  | A | B | C |
  ----|---|---|
  | D | E | F | //input pixel is at position E
  ----|---|---|
  | G | H | I |
  -------------
  */

    private static void _ScalePixel(
      IScaler scaler,
      RotationDegree rotDeg,
      Kernel_3X3 ker,
      sPixel[] trg,
      int trgi,
      int trgWidth,
      byte blendInfo,//result of preprocessing all four corners of pixel "e"
      IColorEq scalePixelColorEq,
      IColorDist scalePixelColorDist,
      OutputMatrix outputMatrix
      ) {
      //int a = kernel._[Rot._[(0 << 2) + rotDeg]];
      var b = ker._[Rot._[(1 << 2) + (int)rotDeg]];
      var c = ker._[Rot._[(2 << 2) + (int)rotDeg]];
      var d = ker._[Rot._[(3 << 2) + (int)rotDeg]];
      var e = ker._[Rot._[(4 << 2) + (int)rotDeg]];
      var f = ker._[Rot._[(5 << 2) + (int)rotDeg]];
      var g = ker._[Rot._[(6 << 2) + (int)rotDeg]];
      var h = ker._[Rot._[(7 << 2) + (int)rotDeg]];
      var i = ker._[Rot._[(8 << 2) + (int)rotDeg]];

      var blend = BlendInfo.Rotate(blendInfo, rotDeg);

      if (BlendInfo.GetBottomR(blend) == BlendType.BlendNone)
        return;

      var eq = scalePixelColorEq;
      var dist = scalePixelColorDist;

      bool doLineBlend;

      if (BlendInfo.GetBottomR(blend) >= BlendType.BlendDominant)
        doLineBlend = true;

        //make sure there is no second blending in an adjacent
      //rotation for this pixel: handles insular pixels, mario eyes
      //but support double-blending for 90? corners
      else if (BlendInfo.GetTopR(blend) != BlendType.BlendNone && !eq._(e, g))
        doLineBlend = false;

      else if (BlendInfo.GetBottomL(blend) != BlendType.BlendNone && !eq._(e, c))
        doLineBlend = false;

        //no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
      else if (eq._(g, h) && eq._(h, i) && eq._(i, f) && eq._(f, c) && !eq._(e, i))
        doLineBlend = false;

      else
        doLineBlend = true;

      //choose most similar color
      var px = dist._(e, f) <= dist._(e, h) ? f : h;

      var output = outputMatrix;
      output.Move(rotDeg, trgi);

      if (!doLineBlend) {
        scaler.BlendCorner(px, output);
        return;
      }

      //test sample: 70% of values max(fg, hc) / min(fg, hc)
      //are between 1.1 and 3.7 with median being 1.9
      var fg = dist._(f, g);
      var hc = dist._(h, c);

      var haveShallowLine = _CONFIGURATION.steepDirectionThreshold * fg <= hc && e != g && d != g;
      var haveSteepLine = _CONFIGURATION.steepDirectionThreshold * hc <= fg && e != c && b != c;

      if (haveShallowLine) {
        if (haveSteepLine)
          scaler.BlendLineSteepAndShallow(px, output);
        else
          scaler.BlendLineShallow(px, output);
      } else {
        if (haveSteepLine)
          scaler.BlendLineSteep(px, output);
        else
          scaler.BlendLineDiagonal(px, output);
      }
    }
Ejemplo n.º 11
0
 public void Move(RotationDegree rotDeg, int outi) {
   this._nr = this._n + (int)rotDeg * _MAX_SCALE_SQUARED;
   this._outi = outi;
 }
Ejemplo n.º 12
0
 internal void Move(RotationDegree rotDeg, int outIndex)
 {
     NRow  = N + (int)rotDeg * MaxScaleSquared;
     Index = outIndex;
 }
Ejemplo n.º 13
0
 public void Move(RotationDegree rotDeg, int outi)
 {
     this._nr   = this._n + (int)rotDeg * _MAX_SCALE_SQUARED;
     this._outi = outi;
 }
Ejemplo n.º 14
0
 public void Move(RotationDegree rotDeg, int outi)
 {
     _nr   = _n + (int)rotDeg * MaxScaleSquared;
     _outi = outi;
 }
Ejemplo n.º 15
0
        /*
         * input kernel area naming convention:
         * -------------
         | A | B | C |
         | ----|---|---|
         | D | E | F | //input pixel is at position E
         | ----|---|---|
         | G | H | I |
         | -------------
         */

        private static void _ScalePixel(
            IScaler scaler,
            RotationDegree rotDeg,
            Kernel_3X3 ker,
            sPixel[] trg,
            int trgi,
            int trgWidth,
            byte blendInfo,      //result of preprocessing all four corners of pixel "e"
            IColorEq scalePixelColorEq,
            IColorDist scalePixelColorDist,
            OutputMatrix outputMatrix
            )
        {
            //int a = kernel._[Rot._[(0 << 2) + rotDeg]];
            var b = ker._[Rot._[(1 << 2) + (int)rotDeg]];
            var c = ker._[Rot._[(2 << 2) + (int)rotDeg]];
            var d = ker._[Rot._[(3 << 2) + (int)rotDeg]];
            var e = ker._[Rot._[(4 << 2) + (int)rotDeg]];
            var f = ker._[Rot._[(5 << 2) + (int)rotDeg]];
            var g = ker._[Rot._[(6 << 2) + (int)rotDeg]];
            var h = ker._[Rot._[(7 << 2) + (int)rotDeg]];
            var i = ker._[Rot._[(8 << 2) + (int)rotDeg]];

            var blend = BlendInfo.Rotate(blendInfo, rotDeg);

            if (BlendInfo.GetBottomR(blend) == BlendType.BlendNone)
            {
                return;
            }

            var eq   = scalePixelColorEq;
            var dist = scalePixelColorDist;

            bool doLineBlend;

            if (BlendInfo.GetBottomR(blend) >= BlendType.BlendDominant)
            {
                doLineBlend = true;
            }

            //make sure there is no second blending in an adjacent
            //rotation for this pixel: handles insular pixels, mario eyes
            //but support double-blending for 90? corners
            else if (BlendInfo.GetTopR(blend) != BlendType.BlendNone && !eq._(e, g))
            {
                doLineBlend = false;
            }

            else if (BlendInfo.GetBottomL(blend) != BlendType.BlendNone && !eq._(e, c))
            {
                doLineBlend = false;
            }

            //no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
            else if (eq._(g, h) && eq._(h, i) && eq._(i, f) && eq._(f, c) && !eq._(e, i))
            {
                doLineBlend = false;
            }

            else
            {
                doLineBlend = true;
            }

            //choose most similar color
            var px = dist._(e, f) <= dist._(e, h) ? f : h;

            var output = outputMatrix;

            output.Move(rotDeg, trgi);

            if (!doLineBlend)
            {
                scaler.BlendCorner(px, output);
                return;
            }

            //test sample: 70% of values max(fg, hc) / min(fg, hc)
            //are between 1.1 and 3.7 with median being 1.9
            var fg = dist._(f, g);
            var hc = dist._(h, c);

            var haveShallowLine = _CONFIGURATION.steepDirectionThreshold * fg <= hc && e != g && d != g;
            var haveSteepLine   = _CONFIGURATION.steepDirectionThreshold * hc <= fg && e != c && b != c;

            if (haveShallowLine)
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteepAndShallow(px, output);
                }
                else
                {
                    scaler.BlendLineShallow(px, output);
                }
            }
            else
            {
                if (haveSteepLine)
                {
                    scaler.BlendLineSteep(px, output);
                }
                else
                {
                    scaler.BlendLineDiagonal(px, output);
                }
            }
        }
Ejemplo n.º 16
0
      public static byte Rotate(byte b, RotationDegree rotDeg) {
        var l = (int)rotDeg << 1;
        var r = 8 - l;

        return (byte)(b << l | b >> r);
      }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a New Falling Block
        /// </summary>
        /// <param name="blockType">The Type of Block that is Created</param>
        public FallingBlock(TypeOfBlock blockType)
        {
            BlockCells    = new List <Cells>();
            IsItFalling   = true;
            BlockType     = blockType;
            RotationPoint = RotationDegree.threeSixty;
            switch (blockType)
            {
            case TypeOfBlock.Straight:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(5, 3));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Cyan;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.LeftL:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(6, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Orange;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.LeftZ:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(6, 1));
                BlockCells.Add(new Cells(6, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Lime;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.RightL:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(4, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Blue;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.RightZ:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(4, 1));
                BlockCells.Add(new Cells(4, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Red;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.Square:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(6, 0));
                BlockCells.Add(new Cells(6, 1));
                BlockCells.Add(new Cells(5, 1));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Yellow;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.TBlock:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(4, 1));
                BlockCells.Add(new Cells(6, 1));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Purple;
                    item.Filled    = true;
                }
                break;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Rotates the left "L" block CounterClockwise 90 degrees
        /// </summary>
        private void RotateLeftLCCW()
        {
            //The Third block in the list is the pivot block
            int pivotY = BlockCells[2].CellLocationY;
            int pivotX = BlockCells[2].CellLocationX;

            switch (RotationPoint)
            {
            case RotationDegree.ninety:
                BlockCells[0].CellLocationX = pivotX;
                BlockCells[0].CellLocationY = pivotY - 2;

                BlockCells[1].CellLocationX = pivotX;
                BlockCells[1].CellLocationY = pivotY - 1;

                BlockCells[3].CellLocationX = pivotX + 1;
                BlockCells[3].CellLocationY = pivotY;

                RotationPoint = RotationDegree.oneEighty;
                break;

            case RotationDegree.oneEighty:
                BlockCells[0].CellLocationX = pivotX + 2;
                BlockCells[0].CellLocationY = pivotY;

                BlockCells[1].CellLocationX = pivotX + 1;
                BlockCells[1].CellLocationY = pivotY;

                BlockCells[3].CellLocationX = pivotX;
                BlockCells[3].CellLocationY = pivotY + 1;

                RotationPoint = RotationDegree.twoSeventy;
                break;

            case RotationDegree.twoSeventy:
                BlockCells[0].CellLocationX = pivotX;
                BlockCells[0].CellLocationY = pivotY + 2;

                BlockCells[1].CellLocationX = pivotX;
                BlockCells[1].CellLocationY = pivotY + 1;

                BlockCells[3].CellLocationX = pivotX - 1;
                BlockCells[3].CellLocationY = pivotY;

                RotationPoint = RotationDegree.threeSixty;
                break;

            case RotationDegree.threeSixty:
                BlockCells[0].CellLocationX = pivotX - 2;
                BlockCells[0].CellLocationY = pivotY;

                BlockCells[1].CellLocationX = pivotX - 1;
                BlockCells[1].CellLocationY = pivotY;

                BlockCells[3].CellLocationX = pivotX;
                BlockCells[3].CellLocationY = pivotY - 1;

                RotationPoint = RotationDegree.ninety;
                break;

            default:
                break;
            }
        }