Source code: com/arranger/jarl/test/TransformTest1.java
1 package com.arranger.jarl.test;
2
3 import junit.framework.TestCase;
4
5 import java.awt.*;
6 import java.awt.geom.*;
7 import java.awt.image.BufferedImage;
8
9 /**
10 * TransformTest1 created on Feb 28, 2003
11 */
12 public class TransformTest1 extends TestCase {
13
14 protected int m_imageHeight = 480;
15 protected int m_imageWidth = 640;
16
17 public void testTransform() throws Exception {
18
19 /*Image image = createImage();
20 Graphics2D graphics2D = (Graphics2D)image.getGraphics();
21
22 Shape sourceShape = getSourceShape();
23 Shape transformShape = getTransformShape();
24
25 graphics2D.setColor(Color.white);
26 graphics2D.draw(centerShape(sourceShape));
27
28 Point2D[] sourcePoints = WidgetUtil.getPoints(sourceShape, 1);
29 Point2D[] transformPoints = WidgetUtil.getPoints(transformShape, 1);
30 Point2D[] resultPoints = WidgetUtil.transformPoints(sourcePoints, transformPoints);
31 Shape shape = WidgetUtil.pointsToShape(resultPoints, false);
32
33 graphics2D.setColor(Color.blue);
34 graphics2D.draw(centerShape(shape));
35
36 IOUtil.save(image, new File("transformTest.bmp"));*/
37 }
38
39 protected Shape centerShape(Shape shape) {
40 Point2D centerPoint = new Point2D.Double(m_imageWidth / 2.0, m_imageHeight / 2.0);
41 Rectangle2D rectangle2D = shape.getBounds2D();
42 double x = centerPoint.getX() - (rectangle2D.getWidth() / 2.0) - rectangle2D.getX();
43 double y = centerPoint.getY() - (rectangle2D.getHeight() / 2.0) - rectangle2D.getY();
44 AffineTransform affineTransform = AffineTransform.getTranslateInstance(x, y);
45 return affineTransform.createTransformedShape(shape);
46 }
47
48 protected Shape getSourceShape() {
49 /*return new Line2D.Double(
50 0 + m_imageWidth * .25,
51 0 + m_imageHeight * .25,
52 0 - m_imageWidth * .25,
53 0 - m_imageHeight * .25);*/ //36work
54 return new Line2D.Double(
55 0 + m_imageWidth * .25,
56 0 - m_imageHeight * .25,
57 0 - m_imageWidth * .25,
58 0 + m_imageHeight * .25); //216NoWork
59 /*return new Line2D.Double(
60 0 - m_imageWidth * .25,
61 0 + m_imageHeight * .25,
62 0 + m_imageWidth * .25,
63 0 - m_imageHeight * .25);*/
64 /*return new Line2D.Double( //-216Work
65 0 - m_imageWidth * .25,
66 0 - m_imageHeight * .25,
67 0 + m_imageWidth * .25,
68 0 + m_imageHeight * .25);*/ //-36NoWork
69
70
71 //-36 & -36
72 /*GeneralPath generalPath = new GeneralPath();
73 generalPath.moveTo((float)(0 - m_imageWidth * .25), (float)(0 - m_imageHeight * .25));
74 generalPath.lineTo((float)(0 - m_imageWidth * 0), (float)(0 - m_imageHeight * 0));
75 generalPath.lineTo((float)(0 + m_imageWidth * .25), (float)(0 + m_imageHeight * .25));
76 return generalPath;*/
77
78 //-36 & -216
79 /*GeneralPath generalPath = new GeneralPath();
80 generalPath.moveTo((float)(0 - m_imageWidth * .25), (float)(0 - m_imageHeight * .25));
81 generalPath.lineTo((float)(0 - m_imageWidth * 0), (float)(0 - m_imageHeight * 0));
82 generalPath.lineTo((float)(0 + m_imageWidth * .25), (float)(0 - m_imageHeight * .25));
83 return generalPath;*/
84
85 //return new Arc2D.Double(0, 0, m_imageWidth / 2, m_imageHeight / 2, 270, 90, Arc2D.OPEN);
86
87 /*GeneralPath generalPath = new GeneralPath();
88 generalPath.moveTo(0, 20);
89 generalPath.lineTo(m_imageWidth / 2, 20);
90 generalPath.lineTo(m_imageWidth / 4, 0);
91 return generalPath;*/
92
93 /*GeneralPath generalPath = new GeneralPath();
94 generalPath.moveTo(20, 20);
95 generalPath.quadTo(m_imageWidth / 4, m_imageWidth / 4, m_imageWidth / 2, 0);
96 return generalPath;*/
97
98 //return new Ellipse2D.Double(0, 0, m_imageWidth / 2, m_imageHeight / 2);
99 //return new Rectangle2D.Double(0, 0, m_imageWidth / 2, m_imageHeight / 2);
100 }
101
102 protected Shape getTransformShape() {
103 float height = 5;
104 float width = 10;
105
106 GeneralPath generalPath = new GeneralPath();
107 generalPath.moveTo(0, 0);
108 generalPath.lineTo(.25f * width, 1f * height);
109 generalPath.lineTo(.5f * width, 0f * height);
110 generalPath.lineTo(.75f * width, -1f * height);
111 generalPath.lineTo(1f * width, -0f * height);
112 return generalPath;
113 }
114
115 protected Image createImage() {
116 Image image = new BufferedImage(m_imageWidth,
117 m_imageHeight,
118 BufferedImage.TYPE_INT_RGB);
119 return image;
120 }
121 }