예제 #1
0
        /*
         * public void serializeTest()
         * {
         *  string name = "gridMesh";
         *  LDGridTransform src = new LDGridTransform(0, 0, 100, 100, 2, 2));
         *
         *  //シリアライズ
         *  SerializeHelper.writeBoostXml(name, src);
         *
         *  //デシリアライズ
         *  var dst = SerializeHelper.readBoostXml<LDGridTransform>(name);
         *
         *  TestUtil.VERIFY(dst->getGridPoints() == src->getGridPoints());
         * }
         */
        public void simpleTransformTest()
        {
            LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 1, 1);

            {
                LDPoint src = new LDPoint(0.5f, 0.5f);

                LDPoint dst;

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.x(), 40.0);
                TestUtil.COMPARE(dst.y(), 40.0);
            }

            {
                LDPointList src = new LDPointList();
                src.add(new LDPoint(0.25f, 0.25f)).add(new LDPoint(0.75f, 0.75f));

                LDPointList dst;

                dst = grid.transform(src);

                TestUtil.VERIFY(dst.length() == 2);
                TestUtil.COMPARE(dst[0], new LDPoint(30.0f, 30));
                TestUtil.COMPARE(dst[1], new LDPoint(50.0f, 50));
            }

            {
                LDGridTransform src = new LDGridTransform(0.5f, 0.5f, 0.5f, 0.5f, 1, 1);

                LDGridTransform dst = new LDGridTransform();

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.getPoint(0, 0), new LDPoint(40, 40));
                TestUtil.COMPARE(dst.getPoint(0, 1), new LDPoint(60, 40));
                TestUtil.COMPARE(dst.getPoint(1, 1), new LDPoint(60, 60));
                TestUtil.COMPARE(dst.getPoint(1, 0), new LDPoint(40, 60));
            }

            {
                LDAffineTransform src = new LDAffineTransform();
                src.translate(0.5f, 0.5f);
                src.rotate(30);
                src.scale(2, 2);

                LDAffineTransform dst = new LDAffineTransform();

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.getTranslate(), new LDPoint(40, 40));
            }
        }
예제 #2
0
        //Grid自体を変換した結果を返す。基本0..1の範囲
        public LDGridTransform transform(LDGridTransform grid, bool clip = false)
        {
            LDGridTransform result = grid;

            for (int i = 0; i < grid.getRow() + 1; i++)
            {
                for (int j = 0; j < grid.getColumn() + 1; ++j)
                {
                    LDPoint newPt = transform(grid.getPoint(i, j), clip);
                    result.setPoint(i, j, newPt);
                }
            }

            return(result);
        }
예제 #3
0
 //指定位置からのコピー
 public void copyFrom(LDGridTransform src, int row, int col)
 {
     for (int i = row; i < getRow() + 1; ++i)
     {
         if (src.getRow() < i)
         {
             continue;
         }
         for (int j = col; j < getColumn() + 1; ++j)
         {
             if (src.getColumn() < j)
             {
                 continue;
             }
             setPoint(j, i, src.getPoint(j - col, i - row));
         }
     }
 }
예제 #4
0
        /*
        public void serializeTest()
        {
            string name = "gridMesh";
            LDGridTransform src = new LDGridTransform(0, 0, 100, 100, 2, 2));

            //シリアライズ
            SerializeHelper.writeBoostXml(name, src);

            //デシリアライズ
            var dst = SerializeHelper.readBoostXml<LDGridTransform>(name);

            TestUtil.VERIFY(dst->getGridPoints() == src->getGridPoints());
        }
        */
        public void simpleTransformTest()
        {
            LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 1, 1);

            {
                LDPoint src = new LDPoint(0.5f, 0.5f);

                LDPoint dst;

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.x(), 40.0);
                TestUtil.COMPARE(dst.y(), 40.0);
            }

            {
                LDPointList src = new LDPointList();
                src.add(new LDPoint(0.25f, 0.25f)).add(new LDPoint(0.75f, 0.75f));

                LDPointList dst;

                dst = grid.transform(src);

                TestUtil.VERIFY(dst.length() == 2);
                TestUtil.COMPARE(dst[0], new LDPoint(30.0f, 30));
                TestUtil.COMPARE(dst[1], new LDPoint(50.0f, 50));
            }

            {
                LDGridTransform src = new LDGridTransform(0.5f, 0.5f, 0.5f, 0.5f, 1, 1);

                LDGridTransform dst = new LDGridTransform();

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.getPoint(0, 0),new LDPoint(40, 40));
                TestUtil.COMPARE(dst.getPoint(0, 1),new LDPoint(60, 40));
                TestUtil.COMPARE(dst.getPoint(1, 1),new LDPoint(60, 60));
                TestUtil.COMPARE(dst.getPoint(1, 0),new LDPoint(40, 60));
            }

            {
                LDAffineTransform src = new LDAffineTransform();
                src.translate(0.5f, 0.5f);
                src.rotate(30);
                src.scale(2, 2);

                LDAffineTransform dst = new LDAffineTransform();

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.getTranslate(), new LDPoint(40, 40));
            }
        }
예제 #5
0
        //Grid自体を変換した結果を返す。基本0..1の範囲
        public LDGridTransform transform(LDGridTransform grid, bool clip = false)
        {
            LDGridTransform result = grid;

            for (int i = 0; i < grid.getRow() + 1; i++)
            {
                for (int j = 0; j < grid.getColumn() + 1; ++j)
                {
                    LDPoint newPt = transform(grid.getPoint(i, j), clip);
                    result.setPoint(i, j, newPt);
                }
            }

            return result;
        }
예제 #6
0
 //指定位置からのコピー
 public void copyFrom(LDGridTransform src, int row, int col)
 {
     for (int i = row; i < getRow() + 1; ++i)
     {
         if (src.getRow() < i)
         {
             continue;
         }
         for (int j = col; j < getColumn() + 1; ++j)
         {
             if (src.getColumn() < j)
             {
                 continue;
             }
             setPoint(j, i, src.getPoint(j - col, i - row));
         }
     }
 }
예제 #7
0
        public void extendedTransformTest()
        {
            {
                //拡張したGridの取得
                LDGridTransform src = new LDGridTransform(20, 20, 40, 40, 3, 3);
                LDGridTransform dst = src.createExtendedGrid();

                TestUtil.COMPARE(dst.getRow(), 4);
                TestUtil.COMPARE(dst.getColumn(), 4);
                TestUtil.COMPARE(dst.getPoint(0, 0), new LDPoint(-20, -20));
                TestUtil.COMPARE(dst.getPoint(0, 1), new LDPoint(10, -20));
                TestUtil.COMPARE(dst.getPoint(0, 2), new LDPoint(40, -20));
                TestUtil.COMPARE(dst.getPoint(0, 3), new LDPoint(70, -20));
                TestUtil.COMPARE(dst.getPoint(0, 4), new LDPoint(100, -20));
                TestUtil.COMPARE(dst.getPoint(1, 1), new LDPoint(20, 20));
            }

            {
                //範囲外 順変換 クリッピング
                LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 1, 1);
                LDPoint         src  = new LDPoint(-1, -1);

                LDPoint dst;

                dst = grid.transform(src, true);

                TestUtil.COMPARE(dst.x(), 20.0);
                TestUtil.COMPARE(dst.y(), 20.0);
            }
            {
                //範囲外 順変換
                LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 1, 1);
                LDPoint         src  = new LDPoint(-1, -1);

                LDPoint dst;

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.x(), -20.0);
                TestUtil.COMPARE(dst.y(), -20.0);
            }
            {
                //範囲外 順変換
                LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 1, 1);
                LDPoint         src  = new LDPoint(-10, -10);

                LDPoint dst;

                dst = grid.transform(src);

                TestUtil.COMPARE(dst.x(), -380.0);
                TestUtil.COMPARE(dst.y(), -380.0);
            }
            {
                //範囲外 逆変換 クリッピング
                LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 2, 2);
                LDPoint         src  = new LDPoint(-20, -20);

                LDPoint dst;

                dst = grid.inverseTransform(src, true);

                TestUtil.COMPARE(dst.x(), 0.0);
                TestUtil.COMPARE(dst.y(), 0.0);
            }
            {
                //範囲外 逆変換
                LDGridTransform grid = new LDGridTransform(20, 20, 40, 40, 2, 2);
                LDPoint         src  = new LDPoint(-20, -20);

                LDPoint dst;

                dst = grid.inverseTransform(src);

                TestUtil.COMPARE(dst.x(), -1.0);
                TestUtil.COMPARE(dst.y(), -1.0);
            }

            {
                LDGridTransform grid = new LDGridTransform(
                    new LDPoint(20.53125f, 20.62423f)
                    , new  LDPoint(40.53125f, 20.62423f)
                    , new  LDPoint(45.53125f, 45.62423f)
                    , new LDPoint(20.614312f, 40.94645f), 2, 2);
                LDGridTransform src = new LDGridTransform(3425.0134623f, 2412.9143f, 5252 - 2412.090023f, 5212 - 2451.00001f, 2, 8);

                LDGridTransform dst = src;

                var points = grid.inverseTransform(src.toForm());
                var rest   = grid.transform(points);

                dst.setForm(points);
                TestUtil.VERIFY(LDMathUtil.fuzzyCompare(rest, src.toForm(), 0.0000001f));
            }
            {
                LDGridTransform grid = new LDGridTransform(
                    new LDPoint(2012.53125f, 2051.62423f)
                    , new LDPoint(4097.53125f, 2033.62423f)
                    , new LDPoint(4575.53125f, 4566.62423f)
                    , new LDPoint(2062.614312f, 4000.94645f), 2, 2);
                LDGridTransform src = new LDGridTransform(34.0134623f, 24.9143f, 52 - 24.090023f, 52 - 24.00001f, 8, 2);

                LDGridTransform dst = src;

                var points = grid.inverseTransform(src.toForm());
                var rest   = grid.transform(points);

                dst.setForm(points);
                TestUtil.VERIFY(LDMathUtil.fuzzyCompare(rest, src.toForm(), 0.0000001f));
            }
        }