X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Ftest%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fcommon%2FPerspectiveTransformTestCase.java;fp=core%2Ftest%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fcommon%2FPerspectiveTransformTestCase.java;h=5b5834dc6cafabfd257faf26e93e73cc4ca36716;hb=8b2ac51d63b9daf021376e1203ca31bf263e26ee;hp=0000000000000000000000000000000000000000;hpb=45c7cd5ff5fb1269d244ea2a4d232df50dd1efcd;p=zxing.git diff --git a/core/test/src/com/google/zxing/common/PerspectiveTransformTestCase.java b/core/test/src/com/google/zxing/common/PerspectiveTransformTestCase.java new file mode 100644 index 00000000..5b5834dc --- /dev/null +++ b/core/test/src/com/google/zxing/common/PerspectiveTransformTestCase.java @@ -0,0 +1,58 @@ +/* + * Copyright 2007 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.common; + +import junit.framework.TestCase; + +/** + * @author srowen@google.com (Sean Owen) + */ +public final class PerspectiveTransformTestCase extends TestCase { + + private static final float EPSILON = 0.0001f; + + public void testSquareToQuadrilateral() { + PerspectiveTransform pt = PerspectiveTransform.squareToQuadrilateral( + 2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f); + assertPointEquals(2.0f, 3.0f, 0.0f, 0.0f, pt); + assertPointEquals(10.0f, 4.0f, 1.0f, 0.0f, pt); + assertPointEquals(4.0f, 9.0f, 0.0f, 1.0f, pt); + assertPointEquals(16.0f, 15.0f, 1.0f, 1.0f, pt); + assertPointEquals(6.535211f, 6.8873234f, 0.5f, 0.5f, pt); + assertPointEquals(48.0f, 42.42857f, 1.5f, 1.5f, pt); + } + + public void testQuadrilateralToQuadrilateral() { + PerspectiveTransform pt = PerspectiveTransform.quadrilateralToQuadrilateral( + 2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f, + 103.0f, 110.0f, 300.0f, 120.0f, 290.0f, 270.0f, 150.0f, 280.0f); + assertPointEquals(103.0f, 110.0f, 2.0f, 3.0f, pt); + assertPointEquals(300.0f, 120.0f, 10.0f, 4.0f, pt); + assertPointEquals(290.0f, 270.0f, 16.0f, 15.0f, pt); + assertPointEquals(150.0f, 280.0f, 4.0f, 9.0f, pt); + assertPointEquals(7.1516876f, -64.60185f, 0.5f, 0.5f, pt); + assertPointEquals(328.09116f, 334.16385f, 50.0f, 50.0f, pt); + } + + private static void assertPointEquals(float expectedX, float expectedY, float sourceX, float sourceY, PerspectiveTransform pt) { + float[] points = new float[]{sourceX, sourceY}; + pt.transformPoints(points); + assertEquals(expectedX, points[0], EPSILON); + assertEquals(expectedY, points[1], EPSILON); + } + +} \ No newline at end of file