Esempio n. 1
0
 /// <summary>
 /// affine�s��ɕ��s�ړ��ϊ�������B
 /// ���Ȃ킿�Aa.Matrix + a.Point + p�ł���B
 /// Compose(Affine2D a, Point p)�Ƃ͉Š��ł͂Ȃ����Ƃɒ��ӁI
 /// </summary>
 /// <param name="a"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public static Affine2D Compose(Point p, Affine2D a)
 {
     return new Affine2D(a.Matrix, a.Point + p);
 }
Esempio n. 2
0
 /// <summary>
 /// ���s�ړ��ϊ�p��affine�ϊ�a�̍����ϊ�����߂�B
 /// ���Ȃ킿�Aa.Matrix + (A.Matrix * p + A.Point)
 /// Compose(Point p,Affine2D a)�Ƃ͉Š��ł͂Ȃ����Ƃɒ��ӁI
 /// </summary>
 /// <param name="a"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public static Affine2D Compose(Affine2D a, Point p)
 {
     return new Affine2D(a.Matrix, a.Matrix * a.Point + p);
 }
Esempio n. 3
0
        /// <summary>
        /// 設定された各変換に基づいて
        /// SrcRectが変換される先を求める。
        /// 詳しくは、このクラス自体の説明を読むべし。
        /// </summary>
        /// <returns>転送先矩形が空集合の場合は
        /// YanesdkResult.InvalidParameterが返る。
        /// </returns>
        public YanesdkResult Calc()
        {
            // 転送元矩形の確定
            if (SrcWidth <= 0 || SrcHeight <= 0)
                return YanesdkResult.PreconditionError;

            Rect r = SrcRect != null
                ? SrcRect.Clone() : new Rect(0, 0, SrcWidth, SrcHeight);

            // 右下の点は含まないのでそのための補正も行なう。
            // とは言ってもあえてその点を除外する必要はない。
            //	(理由はsubpixelを考えるとわかる。詳しくは割愛。)

            BltLayoutHelper bltLayout = new BltLayoutHelper();
            bltLayout.Rect1 = r;
            bltLayout.Layout = Layout;
            bltLayout.Update();
            Point layoutPoint = bltLayout.LayoutPoint;

            // 合成変換を求める。
            Affine2D a;
            if ((Trans0 == Trans0_ && Trans == Trans_))
            {
                // 前回計算した結果と同じなので計算する必要なし
                a = A_;
            }
            else
            {
                // 計算すると同時に計算結果をcacheしておく。
                a = A_ = Trans * Trans0;
                Trans0_ = Trans0;
                Trans_ = Trans;
            }

            // 転送先でのサイズが指定されているのか?
            if (DstSize != null)
            {
                //	このサイズに合わせて拡大縮小する変換が必要である。
                a = new Affine2D(DstSize.Cx/SrcWidth,DstSize.Cy/SrcHeight)*a;
            }

            // 合成変換 = DstPoint平行移動変換×DstSize変換×Trans×Trans0× -LayoutPoint平行移動変換
            //	A = { DstSize変換×Trans×Trans0 }
            a = Affine2D.Compose(DstPoint,
                    Affine2D.Compose(a,-layoutPoint));

            // 正常に計算できたのでこの変換を保存しておく。
            TransAll = a;

            /*
            // 転送元でのclipping処理
            SrcPoints = new Point[4];
            SrcPoints[0] = new Point(left, top);
            SrcPoints[1] = new Point(right, top);
            SrcPoints[2] = new Point(right, bottom);
            SrcPoints[3] = new Point(left, bottom);

            DstPoints = new Point[4];

            // これらの点がはみ出ていれば押し戻して転送先の点を求める
            for (int i = 0; i < 4; ++i)
            {
                // affine変換を用いているので転送先のclippingが容易である
                Point p = SrcPoints[i];
                if (p.X < 0)
                    p.X = 0;

                if (SrcWidth < p.X)
                    p.X = SrcWidth;

                if (p.Y < 0)
                    p.Y = 0;

                if (SrcHeight < p.Y)
                    p.Y = SrcHeight;

                // これだけで転送先が求まる!
                DstPoints[i] = a * p;

                // テクスチャ座標に変換しておく必要がある。
                SrcPoints[i] = p * TextureRate;
            }
            */

            return YanesdkResult.NoError;
        }
Esempio n. 4
0
        /// <summary>
        /// 設定された各変換に基づいて
        /// SrcRectが変換される先を求める。
        /// 詳しくは、このクラス自体の説明を読むべし。
        /// </summary>
        /// <returns>転送先矩形が空集合の場合は
        /// YanesdkResult.InvalidParameterが返る。
        /// </returns>
        public YanesdkResult Calc()
        {
            // 転送元矩形の確定
            if (SrcWidth <= 0 || SrcHeight <= 0)
            {
                return(YanesdkResult.PreconditionError);
            }

            Rect r = SrcRect != null
                                ? SrcRect.Clone() : new Rect(0, 0, SrcWidth, SrcHeight);

            // 右下の点は含まないのでそのための補正も行なう。
            // とは言ってもあえてその点を除外する必要はない。
            //	(理由はsubpixelを考えるとわかる。詳しくは割愛。)

            BltLayoutHelper bltLayout = new BltLayoutHelper();

            bltLayout.Rect1  = r;
            bltLayout.Layout = Layout;
            bltLayout.Update();
            Point layoutPoint = bltLayout.LayoutPoint;


            // 合成変換を求める。
            Affine2D a;

            if ((Trans0 == Trans0_ && Trans == Trans_))
            {
                // 前回計算した結果と同じなので計算する必要なし
                a = A_;
            }
            else
            {
                // 計算すると同時に計算結果をcacheしておく。
                a       = A_ = Trans * Trans0;
                Trans0_ = Trans0;
                Trans_  = Trans;
            }

            // 転送先でのサイズが指定されているのか?
            if (DstSize != null)
            {
                //	このサイズに合わせて拡大縮小する変換が必要である。
                a = new Affine2D(DstSize.Cx / SrcWidth, DstSize.Cy / SrcHeight) * a;
            }

            // 合成変換 = DstPoint平行移動変換×DstSize変換×Trans×Trans0× -LayoutPoint平行移動変換
            //	A = { DstSize変換×Trans×Trans0 }
            a = Affine2D.Compose(DstPoint,
                                 Affine2D.Compose(a, -layoutPoint));

            // 正常に計算できたのでこの変換を保存しておく。
            TransAll = a;

            /*
             * // 転送元でのclipping処理
             * SrcPoints = new Point[4];
             * SrcPoints[0] = new Point(left, top);
             * SrcPoints[1] = new Point(right, top);
             * SrcPoints[2] = new Point(right, bottom);
             * SrcPoints[3] = new Point(left, bottom);
             *
             * DstPoints = new Point[4];
             *
             * // これらの点がはみ出ていれば押し戻して転送先の点を求める
             * for (int i = 0; i < 4; ++i)
             * {
             *      // affine変換を用いているので転送先のclippingが容易である
             *      Point p = SrcPoints[i];
             *      if (p.X < 0)
             *              p.X = 0;
             *
             *      if (SrcWidth < p.X)
             *              p.X = SrcWidth;
             *
             *      if (p.Y < 0)
             *              p.Y = 0;
             *
             *      if (SrcHeight < p.Y)
             *              p.Y = SrcHeight;
             *
             *      // これだけで転送先が求まる!
             *      DstPoints[i] = a * p;
             *
             *      // テクスチャ座標に変換しておく必要がある。
             *      SrcPoints[i] = p * TextureRate;
             * }
             */

            return(YanesdkResult.NoError);
        }
Esempio n. 5
0
 /// <summary>
 /// affine行列に平行移動変換を合成。
 /// すなわち、a.Matrix + a.Point + pである。
 /// Compose(Affine2D a, Point p)とは可換ではないことに注意!
 /// </summary>
 /// <param name="a"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public static Affine2D Compose(Point p, Affine2D a)
 {
     return(new Affine2D(a.Matrix, a.Point + p));
 }
Esempio n. 6
0
 /// <summary>
 /// 平行移動変換pとaffine変換aの合成変換を求める。
 /// すなわち、a.Matrix + (A.Matrix * p + A.Point)
 /// Compose(Point p,Affine2D a)とは可換ではないことに注意!
 /// </summary>
 /// <param name="a"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public static Affine2D Compose(Affine2D a, Point p)
 {
     return(new Affine2D(a.Matrix, a.Matrix * a.Point + p));
 }