⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 affinetransform.java

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* AffineTransform.java -- transform coordinates between two 2-D spaces   Copyright (C) 2000, 2001, 2002 Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.awt.geom;import java.awt.Shape;import java.io.IOException;import java.io.ObjectInputStream;import java.io.Serializable;/** * This class represents an affine transformation between two coordinate * spaces in 2 dimensions. Such a transform preserves the "straightness" * and "parallelness" of lines. The transform is built from a sequence of * translations, scales, flips, rotations, and shears. * * <p>The transformation can be represented using matrix math on a 3x3 array. * Given (x,y), the transformation (x',y') can be found by: * <pre> * [ x']   [ m00 m01 m02 ] [ x ]   [ m00*x + m01*y + m02 ] * [ y'] = [ m10 m11 m12 ] [ y ] = [ m10*x + m11*y + m12 ] * [ 1 ]   [  0   0   1  ] [ 1 ]   [          1          ] * </pre> * The bottom row of the matrix is constant, so a transform can be uniquely * represented (as in toString) by "[[m00, m01, m02], [m10, m11, m12]]". * * @author Tom Tromey <tromey@cygnus.com> * @author Eric Blake <ebb9@email.byu.edu> * @since 1.2 * @status partially updated to 1.4, still has some problems */public class AffineTransform implements Cloneable, Serializable{  /**   * Compatible with JDK 1.2+.   */  private static final long serialVersionUID = 1330973210523860834L;  /**   * The transformation is the identity (x' = x, y' = y). All other transforms   * have either a combination of the appropriate transform flag bits for   * their type, or the type GENERAL_TRANSFORM.   *   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #getType()   */  public static final int TYPE_IDENTITY = 0;  /**   * The transformation includes a translation - shifting in the x or y   * direction without changing length or angles.   *   * @see #TYPE_IDENTITY   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #getType()   */  public static final int TYPE_TRANSLATION = 1;  /**   * The transformation includes a uniform scale - length is scaled in both   * the x and y directions by the same amount, without affecting angles.   * This is mutually exclusive with TYPE_GENERAL_SCALE.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #TYPE_MASK_SCALE   * @see #getType()   */  public static final int TYPE_UNIFORM_SCALE = 2;  /**   * The transformation includes a general scale - length is scaled in either   * or both the x and y directions, but by different amounts; without   * affecting angles. This is mutually exclusive with TYPE_UNIFORM_SCALE.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #TYPE_MASK_SCALE   * @see #getType()   */  public static final int TYPE_GENERAL_SCALE = 4;  /**   * This constant checks if either variety of scale transform is performed.   *   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   */  public static final int TYPE_MASK_SCALE = 6;  /**   * The transformation includes a flip about an axis, swapping between   * right-handed and left-handed coordinate systems. In a right-handed   * system, the positive x-axis rotates counter-clockwise to the positive   * y-axis; in a left-handed system it rotates clockwise.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #getType()   */  public static final int TYPE_FLIP = 64;  /**   * The transformation includes a rotation of a multiple of 90 degrees (PI/2   * radians). Angles are rotated, but length is preserved. This is mutually   * exclusive with TYPE_GENERAL_ROTATION.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_GENERAL_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #TYPE_MASK_ROTATION   * @see #getType()   */  public static final int TYPE_QUADRANT_ROTATION = 8;  /**   * The transformation includes a rotation by an arbitrary angle. Angles are   * rotated, but length is preserved. This is mutually exclusive with   * TYPE_QUADRANT_ROTATION.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_TRANSFORM   * @see #TYPE_MASK_ROTATION   * @see #getType()   */  public static final int TYPE_GENERAL_ROTATION = 16;  /**   * This constant checks if either variety of rotation is performed.   *   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   */  public static final int TYPE_MASK_ROTATION = 24;  /**   * The transformation is an arbitrary conversion of coordinates which   * could not be decomposed into the other TYPEs.   *   * @see #TYPE_IDENTITY   * @see #TYPE_TRANSLATION   * @see #TYPE_UNIFORM_SCALE   * @see #TYPE_GENERAL_SCALE   * @see #TYPE_FLIP   * @see #TYPE_QUADRANT_ROTATION   * @see #TYPE_GENERAL_ROTATION   * @see #getType()   */  public static final int TYPE_GENERAL_TRANSFORM = 32;  /**   * The X coordinate scaling element of the transform matrix.   *   * @serial matrix[0,0]   */  private double m00;  /**   * The Y coordinate scaling element of the transform matrix.   *   * @serial matrix[1,0]   */  private double m10;  /**   * The X coordinate shearing element of the transform matrix.   *   * @serial matrix[0,1]   */  private double m01;  /**   * The Y coordinate shearing element of the transform matrix.   *   * @serial matrix[1,1]   */  private double m11;  /**   * The X coordinate translation element of the transform matrix.   *   * @serial matrix[0,2]   */  private double m02;  /**   * The Y coordinate translation element of the transform matrix.   *   * @serial matrix[1,2]   */  private double m12;  /** The type of this transform. */  private transient int type;  /**   * Construct a new identity transform:   * <pre>   * [ 1 0 0 ]   * [ 0 1 0 ]   * [ 0 0 1 ]   * </pre>   */  public AffineTransform()  {    m00 = m11 = 1;  }  /**   * Create a new transform which copies the given one.   *   * @param tx the transform to copy   * @throws NullPointerException if tx is null   */  public AffineTransform(AffineTransform tx)  {    setTransform(tx);  }  /**   * Construct a transform with the given matrix entries:   * <pre>   * [ m00 m01 m02 ]   * [ m10 m11 m12 ]   * [  0   0   1  ]   * </pre>   *   * @param m00 the x scaling component   * @param m10 the y shearing component   * @param m01 the x shearing component   * @param m11 the y scaling component   * @param m02 the x translation component   * @param m12 the y translation component   */  public AffineTransform(float m00, float m10,                         float m01, float m11,                         float m02, float m12)  {    this.m00 = m00;    this.m10 = m10;    this.m01 = m01;    this.m11 = m11;    this.m02 = m02;    this.m12 = m12;    updateType();  }  /**   * Construct a transform from a sequence of float entries. The array must   * have at least 4 entries, which has a translation factor of 0; or 6   * entries, for specifying all parameters:   * <pre>   * [ f[0] f[2] (f[4]) ]   * [ f[1] f[3] (f[5]) ]   * [  0     0    1    ]   * </pre>   *   * @param f the matrix to copy from, with at least 4 (6) entries   * @throws NullPointerException if f is null   * @throws ArrayIndexOutOfBoundsException if f is too small   */  public AffineTransform(float[] f)  {    m00 = f[0];    m10 = f[1];    m01 = f[2];    m11 = f[3];    if (f.length >= 6)      {        m02 = f[4];        m12 = f[5];      }    updateType();  }  /**   * Construct a transform with the given matrix entries:   * <pre>   * [ m00 m01 m02 ]   * [ m10 m11 m12 ]   * [  0   0   1  ]   * </pre>   *   * @param m00 the x scaling component   * @param m10 the y shearing component   * @param m01 the x shearing component   * @param m11 the y scaling component   * @param m02 the x translation component   * @param m12 the y translation component   */  public AffineTransform(double m00, double m10, double m01,                         double m11, double m02, double m12)  {    this.m00 = m00;    this.m10 = m10;    this.m01 = m01;    this.m11 = m11;    this.m02 = m02;    this.m12 = m12;    updateType();  }  /**   * Construct a transform from a sequence of double entries. The array must   * have at least 4 entries, which has a translation factor of 0; or 6   * entries, for specifying all parameters:   * <pre>   * [ d[0] d[2] (d[4]) ]   * [ d[1] d[3] (d[5]) ]   * [  0     0    1    ]   * </pre>   *   * @param d the matrix to copy from, with at least 4 (6) entries   * @throws NullPointerException if d is null   * @throws ArrayIndexOutOfBoundsException if d is too small   */  public AffineTransform(double[] d)  {    m00 = d[0];    m10 = d[1];    m01 = d[2];    m11 = d[3];    if (d.length >= 6)      {        m02 = d[4];        m12 = d[5];      }    updateType();  }  /**   * Returns a translation transform:   * <pre>   * [ 1 0 tx ]   * [ 0 1 ty ]   * [ 0 0 1  ]   * </pre>   *   * @param tx the x translation distance   * @param ty the y translation distance   * @return the translating transform   */  public static AffineTransform getTranslateInstance(double tx, double ty)  {    AffineTransform t = new AffineTransform();    t.setToTranslation(tx, ty);    return t;  }  /**   * Returns a rotation transform. A positive angle (in radians) rotates   * the positive x-axis to the positive y-axis:   * <pre>   * [ cos(theta) -sin(theta) 0 ]   * [ sin(theta)  cos(theta) 0 ]   * [     0           0      1 ]   * </pre>   *   * @param theta the rotation angle   * @return the rotating transform   */  public static AffineTransform getRotateInstance(double theta)  {    AffineTransform t = new AffineTransform();    t.setToRotation(theta);    return t;  }  /**   * Returns a rotation transform about a point. A positive angle (in radians)   * rotates the positive x-axis to the positive y-axis. This is the same   * as calling:   * <pre>   * AffineTransform tx = new AffineTransform();   * tx.setToTranslation(x, y);   * tx.rotate(theta);   * tx.translate(-x, -y);   * </pre>   *   * <p>The resulting matrix is:    * <pre>   * [ cos(theta) -sin(theta) x-x*cos+y*sin ]   * [ sin(theta)  cos(theta) y-x*sin-y*cos ]   * [     0           0            1       ]   * </pre>   *   * @param theta the rotation angle   * @param x the x coordinate of the pivot point   * @param y the y coordinate of the pivot point   * @return the rotating transform   */  public static AffineTransform getRotateInstance(double theta,                                                  double x, double y)  {    AffineTransform t = new AffineTransform();    t.setToTranslation(x, y);    t.rotate(theta);    t.translate(-x, -y);    return t;  }  /**   * Returns a scaling transform:   * <pre>   * [ sx 0  0 ]   * [ 0  sy 0 ]   * [ 0  0  1 ]   * </pre>   *   * @param sx the x scaling factor   * @param sy the y scaling factor   * @return the scaling transform   */  public static AffineTransform getScaleInstance(double sx, double sy)  {    AffineTransform t = new AffineTransform();    t.setToScale(sx, sy);    return t;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -