//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); }
//指定位置からのコピー 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)); } } }
//指定位置からのコピー 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)); } } }
//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; }
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)); } }