File: getBounds2D.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (123 lines) | stat: -rw-r--r-- 4,607 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* getBounds2D.java -- some checks for the getBounds2D() method of the
              AffineTransformOp class.
   Copyright (C) 2006 Francis Kung <fkung@redhat.com>
This file is part of Mauve.

Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

Mauve is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/

// Tags: JDK1.2

package gnu.testlet.java.awt.image.AffineTransformOp;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

/**
 * Checks the getBounds2D method in the
 * {@link AffineTransformOp} class.
 */
public class getBounds2D implements Testlet 
{

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted). 
   */
  public void test(TestHarness harness)      
  {
    testIdentity(harness);
    testRotation(harness);
    testScale(harness);
    testShear(harness);
    testTranslation(harness);
  }
  
  private void testIdentity(TestHarness harness)
  {
    harness.checkPoint("testIdentity");

    AffineTransform xform = new AffineTransform();
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    BufferedImage img = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(0, 0, 30, 40));
  }
  
  private void testRotation(TestHarness harness)
  {
    harness.checkPoint("testRotation");

    AffineTransform xform = AffineTransform.getRotateInstance(Math.PI / 2);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    BufferedImage img = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(-40, 0, 40, 30));

    // Do it again, but result in a diamond (not another level rectangle)
    xform.rotate(Math.PI / 3);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(-45.980762f,
                                                             -34.641018f, 
                                                             45.980762f,
                                                             49.641018f));
    
    // Rotation about a point
    xform.setToIdentity();
    xform.rotate(Math.PI / 2, 10, 15);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(-15, 5, 40, 30));
  }
  
  private void testScale(TestHarness harness)
  {
    harness.checkPoint("testScale");
    
    AffineTransform xform = AffineTransform.getScaleInstance(1.0, 1.0);
    BufferedImage img = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(0, 0, 30, 40));
    
    xform.scale(2.5, 4.75);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(0, 0, 75, 190));   
  }
  
  private void testShear(TestHarness harness)
  {
    harness.checkPoint("testHarness");
    
    AffineTransform xform = AffineTransform.getShearInstance(1.5, 3.25);
    BufferedImage img = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(0, 0, 90, 137.5f));
  }
  
  private void testTranslation(TestHarness harness)
  {
    harness.checkPoint("testTranslation");

    AffineTransform xform = AffineTransform.getTranslateInstance(75, 50);
    BufferedImage img = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getBounds2D(img), new Rectangle2D.Float(75, 50, 30, 40));
  }
}