jdk/src/share/classes/java/awt/geom/AffineTransform.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 7006 05505fff1342
child 15994 5c8a3d840366
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Shape;
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
    29
import java.beans.ConstructorProperties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * The <code>AffineTransform</code> class represents a 2D affine transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * that performs a linear mapping from 2D coordinates to other 2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * coordinates that preserves the "straightness" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * "parallelness" of lines.  Affine transformations can be constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * using sequences of translations, scales, flips, rotations, and shears.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Such a coordinate transformation can be represented by a 3 row by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * 3 column matrix with an implied last row of [ 0 0 1 ].  This matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * transforms source coordinates {@code (x,y)} into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * destination coordinates {@code (x',y')} by considering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * them to be a column vector and multiplying the coordinate vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * by the matrix according to the following process:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      [ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <a name="quadrantapproximation"><h4>Handling 90-Degree Rotations</h4></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * In some variations of the <code>rotate</code> methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>AffineTransform</code> class, a double-precision argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * specifies the angle of rotation in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * These methods have special handling for rotations of approximately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * 90 degrees (including multiples such as 180, 270, and 360 degrees),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * so that the common case of quadrant rotation is handled more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * efficiently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * This special handling can cause angles very close to multiples of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * 90 degrees to be treated as if they were exact multiples of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * 90 degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * For small multiples of 90 degrees the range of angles treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * as a quadrant rotation is approximately 0.00000121 degrees wide.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * This section explains why such special care is needed and how
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * it is implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Since 90 degrees is represented as <code>PI/2</code> in radians,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * and since PI is a transcendental (and therefore irrational) number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * it is not possible to exactly represent a multiple of 90 degrees as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * an exact double precision value measured in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * As a result it is theoretically impossible to describe quadrant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * rotations (90, 180, 270 or 360 degrees) using these values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Double precision floating point values can get very close to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * non-zero multiples of <code>PI/2</code> but never close enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * for the sine or cosine to be exactly 0.0, 1.0 or -1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * The implementations of <code>Math.sin()</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <code>Math.cos()</code> correspondingly never return 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * for any case other than <code>Math.sin(0.0)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * These same implementations do, however, return exactly 1.0 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * -1.0 for some range of numbers around each multiple of 90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * degrees since the correct answer is so close to 1.0 or -1.0 that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the double precision significand cannot represent the difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * as accurately as it can for numbers that are near 0.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * The net result of these issues is that if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <code>Math.sin()</code> and <code>Math.cos()</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * are used to directly generate the values for the matrix modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * during these radian-based rotation operations then the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * transform is never strictly classifiable as a quadrant rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * even for a simple case like <code>rotate(Math.PI/2.0)</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * due to minor variations in the matrix caused by the non-0.0 values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * obtained for the sine and cosine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * If these transforms are not classified as quadrant rotations then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * subsequent code which attempts to optimize further operations based
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * upon the type of the transform will be relegated to its most general
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Because quadrant rotations are fairly common,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * this class should handle these cases reasonably quickly, both in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * applying the rotations to the transform and in applying the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * transform to the coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * To facilitate this optimal handling, the methods which take an angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * of rotation measured in radians attempt to detect angles that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * intended to be quadrant rotations and treat them as such.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * These methods therefore treat an angle <em>theta</em> as a quadrant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * rotation if either <code>Math.sin(<em>theta</em>)</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <code>Math.cos(<em>theta</em>)</code> returns exactly 1.0 or -1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * As a rule of thumb, this property holds true for a range of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * approximately 0.0000000211 radians (or 0.00000121 degrees) around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * small multiples of <code>Math.PI/2.0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @author Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
public class AffineTransform implements Cloneable, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * This constant is only useful for the cached type field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * It indicates that the type has been decached and must be recalculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final int TYPE_UNKNOWN = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * This constant indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * is an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * An identity transform is one in which the output coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * always the same as the input coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * If this transform is anything other than the identity transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * the type will either be the constant GENERAL_TRANSFORM or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * combination of the appropriate flag bits for the various coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * conversions that this transform performs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static final int TYPE_IDENTITY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * performs a translation in addition to the conversions indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * A translation moves the coordinates by a constant amount in x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * and y without changing the length or angle of vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static final int TYPE_TRANSLATION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * performs a uniform scale in addition to the conversions indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * A uniform scale multiplies the length of vectors by the same amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * in both the x and y directions without changing the angle between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * This flag bit is mutually exclusive with the TYPE_GENERAL_SCALE flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public static final int TYPE_UNIFORM_SCALE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * performs a general scale in addition to the conversions indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * A general scale multiplies the length of vectors by different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * amounts in the x and y directions without changing the angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * between perpendicular vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * This flag bit is mutually exclusive with the TYPE_UNIFORM_SCALE flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public static final int TYPE_GENERAL_SCALE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This constant is a bit mask for any of the scale flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final int TYPE_MASK_SCALE = (TYPE_UNIFORM_SCALE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                               TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * performs a mirror image flip about some axis which changes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * normally right handed coordinate system into a left handed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * system in addition to the conversions indicated by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * A right handed coordinate system is one where the positive X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * axis rotates counterclockwise to overlay the positive Y axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * similar to the direction that the fingers on your right hand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * curl when you stare end on at your thumb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * A left handed coordinate system is one where the positive X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * axis rotates clockwise to overlay the positive Y axis similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * to the direction that the fingers on your left hand curl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * There is no mathematical way to determine the angle of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * original flipping or mirroring transformation since all angles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * of flip are identical given an appropriate adjusting rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static final int TYPE_FLIP = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /* NOTE: TYPE_FLIP was added after GENERAL_TRANSFORM was in public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * circulation and the flag bits could no longer be conveniently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * renumbered without introducing binary incompatibility in outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * performs a quadrant rotation by some multiple of 90 degrees in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * addition to the conversions indicated by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * A rotation changes the angles of vectors by the same amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * regardless of the original direction of the vector and without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * changing the length of the vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * This flag bit is mutually exclusive with the TYPE_GENERAL_ROTATION flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public static final int TYPE_QUADRANT_ROTATION = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * This flag bit indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * performs a rotation by an arbitrary angle in addition to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * conversions indicated by other flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * A rotation changes the angles of vectors by the same amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * regardless of the original direction of the vector and without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * changing the length of the vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * This flag bit is mutually exclusive with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * TYPE_QUADRANT_ROTATION flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static final int TYPE_GENERAL_ROTATION = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * This constant is a bit mask for any of the rotation flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public static final int TYPE_MASK_ROTATION = (TYPE_QUADRANT_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                  TYPE_GENERAL_ROTATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * This constant indicates that the transform defined by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * performs an arbitrary conversion of the input coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * If this transform can be classified by any of the above constants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * the type will either be the constant TYPE_IDENTITY or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * combination of the appropriate flag bits for the various coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * conversions that this transform performs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public static final int TYPE_GENERAL_TRANSFORM = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * This constant is used for the internal state variable to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * that no calculations need to be performed and that the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * coordinates only need to be copied to their destinations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * complete the transformation equation of this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @see #APPLY_TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @see #APPLY_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @see #APPLY_SHEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    static final int APPLY_IDENTITY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * This constant is used for the internal state variable to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * that the translation components of the matrix (m02 and m12) need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * to be added to complete the transformation equation of this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see #APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see #APPLY_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #APPLY_SHEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @see #state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    static final int APPLY_TRANSLATE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * This constant is used for the internal state variable to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * that the scaling components of the matrix (m00 and m11) need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * to be factored in to complete the transformation equation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * this transform.  If the APPLY_SHEAR bit is also set then it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * indicates that the scaling components are not both 0.0.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * APPLY_SHEAR bit is not also set then it indicates that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * scaling components are not both 1.0.  If neither the APPLY_SHEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * nor the APPLY_SCALE bits are set then the scaling components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * are both 1.0, which means that the x and y components contribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * to the transformed coordinate, but they are not multiplied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * any scaling factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see #APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see #APPLY_TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @see #APPLY_SHEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see #state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    static final int APPLY_SCALE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * This constant is used for the internal state variable to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * that the shearing components of the matrix (m01 and m10) need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * to be factored in to complete the transformation equation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * transform.  The presence of this bit in the state variable changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * the interpretation of the APPLY_SCALE bit as indicated in its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see #APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see #APPLY_TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @see #APPLY_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see #state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    static final int APPLY_SHEAR = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * For methods which combine together the state of two separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * transforms and dispatch based upon the combination, these constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * specify how far to shift one of the states so that the two states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * are mutually non-interfering and provide constants for testing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * bits of the shifted (HI) state.  The methods in this class use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the convention that the state of "this" transform is unshifted and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * the state of the "other" or "argument" transform is shifted (HI).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private static final int HI_SHIFT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    private static final int HI_IDENTITY = APPLY_IDENTITY << HI_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private static final int HI_TRANSLATE = APPLY_TRANSLATE << HI_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private static final int HI_SCALE = APPLY_SCALE << HI_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    private static final int HI_SHEAR = APPLY_SHEAR << HI_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * The X coordinate scaling element of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    double m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * The Y coordinate shearing element of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     double m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * The X coordinate shearing element of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     double m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * The Y coordinate scaling element of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     double m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * The X coordinate of the translation element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     double m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * The Y coordinate of the translation element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     double m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * This field keeps track of which components of the matrix need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * be applied when performing a transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #APPLY_TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see #APPLY_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #APPLY_SHEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    transient int state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * This field caches the current transformation type of the matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see #TYPE_FLIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see #TYPE_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    private transient int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    private AffineTransform(double m00, double m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                            double m01, double m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            double m02, double m12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                            int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        this.m00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        this.m10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        this.m01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        this.m11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        this.m02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        this.m12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Constructs a new <code>AffineTransform</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Identity transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public AffineTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        m00 = m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // m01 = m10 = m02 = m12 = 0.0;         /* Not needed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // state = APPLY_IDENTITY;              /* Not needed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // type = TYPE_IDENTITY;                /* Not needed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Constructs a new <code>AffineTransform</code> that is a copy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * the specified <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @param Tx the <code>AffineTransform</code> object to copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public AffineTransform(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        this.m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        this.m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        this.m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        this.m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        this.m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        this.m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        this.state = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        this.type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Constructs a new <code>AffineTransform</code> from 6 floating point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * values representing the 6 specifiable entries of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @param m00 the X coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param m10 the Y coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param m01 the X coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @param m11 the Y coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @param m02 the X coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @param m12 the Y coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
   512
    @ConstructorProperties({ "scaleX", "shearY", "shearX", "scaleY", "translateX", "translateY" })
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public AffineTransform(float m00, float m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                           float m01, float m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                           float m02, float m12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        this.m00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        this.m10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        this.m01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        this.m11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        this.m02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        this.m12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Constructs a new <code>AffineTransform</code> from an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * floating point values representing either the 4 non-translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * enries or the 6 specifiable entries of the 3x3 transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * matrix.  The values are retrieved from the array as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;[m02&nbsp;m12]}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param flatmatrix the float array containing the values to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * in the new <code>AffineTransform</code> object. The length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * array is assumed to be at least 4. If the length of the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * less than 6, only the first 4 values are taken. If the length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * the array is greater than 6, the first 6 values are taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public AffineTransform(float[] flatmatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        m00 = flatmatrix[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        m10 = flatmatrix[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        m01 = flatmatrix[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        m11 = flatmatrix[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (flatmatrix.length > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            m02 = flatmatrix[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            m12 = flatmatrix[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Constructs a new <code>AffineTransform</code> from 6 double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * precision values representing the 6 specifiable entries of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @param m00 the X coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param m10 the Y coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @param m01 the X coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @param m11 the Y coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param m02 the X coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param m12 the Y coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public AffineTransform(double m00, double m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                           double m01, double m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                           double m02, double m12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        this.m00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        this.m10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        this.m01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        this.m11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        this.m02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        this.m12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Constructs a new <code>AffineTransform</code> from an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * double precision values representing either the 4 non-translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * entries or the 6 specifiable entries of the 3x3 transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * matrix. The values are retrieved from the array as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;[m02&nbsp;m12]}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @param flatmatrix the double array containing the values to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * in the new <code>AffineTransform</code> object. The length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * array is assumed to be at least 4. If the length of the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * less than 6, only the first 4 values are taken. If the length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * the array is greater than 6, the first 6 values are taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public AffineTransform(double[] flatmatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        m00 = flatmatrix[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        m10 = flatmatrix[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        m01 = flatmatrix[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        m11 = flatmatrix[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if (flatmatrix.length > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            m02 = flatmatrix[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            m12 = flatmatrix[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns a transform representing a translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * The matrix representing the returned transform is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param tx the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param ty the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @return an <code>AffineTransform</code> object that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *  translation transformation, created with the specified vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public static AffineTransform getTranslateInstance(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        Tx.setToTranslation(tx, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * Returns a transform representing a rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * The matrix representing the returned transform is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @return an <code>AffineTransform</code> object that is a rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *  transformation, created with the specified angle of rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    public static AffineTransform getRotateInstance(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        Tx.setToRotation(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Returns a transform that rotates coordinates around an anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * This operation is equivalent to translating the coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * that the anchor point is at the origin (S1), then rotating them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * about the new origin (S2), and finally translating so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * intermediate origin is restored to the coordinates of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * anchor point (S3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * This operation is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *     AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *     Tx.translate(anchorx, anchory);    // S3: final translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *     Tx.rotate(theta);                  // S2: rotate around anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *     Tx.translate(-anchorx, -anchory);  // S1: translate anchor to origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * The matrix representing the returned transform is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *          [   cos(theta)    -sin(theta)    x-x*cos+y*sin  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *          [   sin(theta)     cos(theta)    y-x*sin-y*cos  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *          [       0              0               1        ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @return an <code>AffineTransform</code> object that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *  coordinates around the specified point by the specified angle of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *  rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public static AffineTransform getRotateInstance(double theta,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                                    double anchorx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                                    double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        Tx.setToRotation(theta, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Returns a transform that rotates coordinates according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * All coordinates rotate about the origin by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * an identity transform is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *     AffineTransform.getRotateInstance(Math.atan2(vecy, vecx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @return an <code>AffineTransform</code> object that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *  coordinates according to the specified rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public static AffineTransform getRotateInstance(double vecx, double vecy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        Tx.setToRotation(vecx, vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Returns a transform that rotates coordinates around an anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * point accordinate to a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * All coordinates rotate about the specified anchor coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * an identity transform is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *     AffineTransform.getRotateInstance(Math.atan2(vecy, vecx),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *                                       anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @return an <code>AffineTransform</code> object that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *  coordinates around the specified point according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *  specified rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public static AffineTransform getRotateInstance(double vecx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                                                    double vecy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                                    double anchorx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                                    double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        Tx.setToRotation(vecx, vecy, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Returns a transform that rotates coordinates by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *     AffineTransform.getRotateInstance(numquadrants * Math.PI / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @return an <code>AffineTransform</code> object that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *  coordinates by the specified number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    public static AffineTransform getQuadrantRotateInstance(int numquadrants) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        Tx.setToQuadrantRotation(numquadrants);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * Returns a transform that rotates coordinates by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * number of quadrants around the specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *     AffineTransform.getRotateInstance(numquadrants * Math.PI / 2.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *                                       anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return an <code>AffineTransform</code> object that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *  coordinates by the specified number of quadrants around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *  specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    public static AffineTransform getQuadrantRotateInstance(int numquadrants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                                                            double anchorx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                                            double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        Tx.setToQuadrantRotation(numquadrants, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Returns a transform representing a scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * The matrix representing the returned transform is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @param sx the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @param sy the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @return an <code>AffineTransform</code> object that scales
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     *  coordinates by the specified factors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    public static AffineTransform getScaleInstance(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        Tx.setToScale(sx, sy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Returns a transform representing a shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * The matrix representing the returned transform is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * @param shx the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * direction of the positive X axis as a factor of their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param shy the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * direction of the positive Y axis as a factor of their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @return an <code>AffineTransform</code> object that shears
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *  coordinates by the specified multipliers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    public static AffineTransform getShearInstance(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        AffineTransform Tx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        Tx.setToShear(shx, shy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        return Tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Retrieves the flag bits describing the conversion properties of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * The return value is either one of the constants TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * or TYPE_GENERAL_TRANSFORM, or a combination of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * appriopriate flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * A valid combination of flag bits is an exclusive OR operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * that can combine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * the TYPE_TRANSLATION flag bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * in addition to either of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * TYPE_UNIFORM_SCALE or TYPE_GENERAL_SCALE flag bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * as well as either of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * TYPE_QUADRANT_ROTATION or TYPE_GENERAL_ROTATION flag bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @return the OR combination of any of the indicated flags that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * apply to this transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see #TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @see #TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @see #TYPE_GENERAL_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @see #TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @see #TYPE_GENERAL_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @see #TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (type == TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            calculateType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * This is the utility function to calculate the flag bits when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * they have not been cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    private void calculateType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        int ret = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        boolean sgn0, sgn1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        double M0, M1, M2, M3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if ((M0 = m00) * (M2 = m01) + (M3 = m10) * (M1 = m11) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                // Transformed unit vectors are not perpendicular...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                this.type = TYPE_GENERAL_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            sgn0 = (M0 >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            sgn1 = (M1 >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (sgn0 == sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                // sgn(M0) == sgn(M1) therefore sgn(M2) == -sgn(M3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                // This is the "unflipped" (right-handed) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                if (M0 != M1 || M2 != -M3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                } else if (M0 * M1 - M2 * M3 != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                    ret |= TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                // sgn(M0) == -sgn(M1) therefore sgn(M2) == sgn(M3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                // This is the "flipped" (left-handed) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                if (M0 != -M1 || M2 != M3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                    ret |= (TYPE_GENERAL_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                            TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                } else if (M0 * M1 - M2 * M3 != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    ret |= (TYPE_GENERAL_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                            TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_FLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            sgn0 = ((M0 = m01) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            sgn1 = ((M1 = m10) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            if (sgn0 != sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                // Different signs - simple 90 degree rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                if (M0 != -M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                    ret |= (TYPE_QUADRANT_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                } else if (M0 != 1.0 && M0 != -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    ret |= (TYPE_QUADRANT_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    ret |= TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                // Same signs - 90 degree rotation plus an axis flip too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                if (M0 == M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    ret |= (TYPE_QUADRANT_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                            TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    ret |= (TYPE_QUADRANT_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                            TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            sgn0 = ((M0 = m00) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            sgn1 = ((M1 = m11) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            if (sgn0 == sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                if (sgn0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    // Both scaling factors non-negative - simple scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                    // Note: APPLY_SCALE implies M0, M1 are not both 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    if (M0 == M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                        ret |= TYPE_UNIFORM_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                        ret |= TYPE_GENERAL_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    // Both scaling factors negative - 180 degree rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    if (M0 != M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                        ret |= (TYPE_QUADRANT_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    } else if (M0 != -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        ret |= (TYPE_QUADRANT_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                        ret |= TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                // Scaling factor signs different - flip about some axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                if (M0 == -M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    if (M0 == 1.0 || M0 == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                        ret |= TYPE_FLIP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                        ret |= (TYPE_FLIP | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    ret |= (TYPE_FLIP | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        this.type = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * Returns the determinant of the matrix representation of the transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * The determinant is useful both to determine if the transform can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * be inverted and to get a single value representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * combined X and Y scaling of the transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * If the determinant is non-zero, then this transform is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * invertible and the various methods that depend on the inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * transform do not need to throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * {@link NoninvertibleTransformException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * If the determinant is zero then this transform can not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * inverted since the transform maps all input coordinates onto
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * a line or a point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * If the determinant is near enough to zero then inverse transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * operations might not carry enough precision to produce meaningful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * If this transform represents a uniform scale, as indicated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * the <code>getType</code> method then the determinant also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * represents the square of the uniform scale factor by which all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * the points are expanded from or contracted towards the origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * If this transform represents a non-uniform scale or more general
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * transform then the determinant is not likely to represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * value useful for any purpose other than determining if inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * transforms are possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Mathematically, the determinant is calculated using the formula:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *          |  m00  m01  m02  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *          |  m10  m11  m12  |  =  m00 * m11 - m01 * m10
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     *          |   0    0    1   |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @return the determinant of the matrix used to transform the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @see #createInverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @see #inverseTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public double getDeterminant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            return m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            return -(m01 * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            return m00 * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            return 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * Manually recalculates the state of the transform when the matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * changes too much to predict the effects on the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * The following table specifies what the various settings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * state field say about the values of the corresponding matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * element fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * Note that the rules governing the SCALE fields are slightly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * different depending on whether the SHEAR flag is also set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     *                     SCALE            SHEAR          TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *                    m00/m11          m01/m10          m02/m12
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * IDENTITY             1.0              0.0              0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * TRANSLATE (TR)       1.0              0.0          not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * SCALE (SC)       not both 1.0         0.0              0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * TR | SC          not both 1.0         0.0          not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * SHEAR (SH)           0.0          not both 0.0         0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * TR | SH              0.0          not both 0.0     not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * SC | SH          not both 0.0     not both 0.0         0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * TR | SC | SH     not both 0.0     not both 0.0     not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    void updateState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        if (m01 == 0.0 && m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                    type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                    state = (APPLY_SCALE | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            if (m00 == 0.0 && m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                    state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    state = (APPLY_SHEAR | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    state = (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    state = (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * Convenience method used internally to throw exceptions when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * a case was forgotten in a switch statement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    private void stateError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        throw new InternalError("missing case in transform state switch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Retrieves the 6 specifiable values in the 3x3 affine transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * matrix and places them into an array of double precisions values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * The values are stored in the array as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;m02&nbsp;m12&nbsp;}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * An array of 4 doubles can also be specified, in which case only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * first four elements representing the non-transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * parts of the array are retrieved and the values are stored into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * the array as {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @param flatmatrix the double array used to store the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @see #getScaleX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @see #getScaleY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @see #getShearX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @see #getShearY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @see #getTranslateX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @see #getTranslateY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    public void getMatrix(double[] flatmatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        flatmatrix[0] = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        flatmatrix[1] = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        flatmatrix[2] = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        flatmatrix[3] = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if (flatmatrix.length > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            flatmatrix[4] = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            flatmatrix[5] = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * Returns the X coordinate scaling element (m00) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @return a double value that is the X coordinate of the scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    public double getScaleX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        return m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * Returns the Y coordinate scaling element (m11) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @return a double value that is the Y coordinate of the scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    public double getScaleY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        return m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * Returns the X coordinate shearing element (m01) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @return a double value that is the X coordinate of the shearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public double getShearX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        return m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * Returns the Y coordinate shearing element (m10) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * @return a double value that is the Y coordinate of the shearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    public double getShearY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        return m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * Returns the X coordinate of the translation element (m02) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * @return a double value that is the X coordinate of the translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    public double getTranslateX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        return m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * Returns the Y coordinate of the translation element (m12) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * @return a double value that is the Y coordinate of the translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    public double getTranslateY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        return m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * Concatenates this transform with a translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * This is equivalent to calling concatenate(T), where T is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @param tx the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @param ty the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    public void translate(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            m02 = tx * m00 + ty * m01 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            m12 = tx * m10 + ty * m11 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            m02 = tx * m00 + ty * m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            m12 = tx * m10 + ty * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                state = APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            m02 = ty * m01 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            m12 = tx * m10 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            m02 = ty * m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            m12 = tx * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            m02 = tx * m00 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            m12 = ty * m11 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            m02 = tx * m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            m12 = ty * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                state = APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            m02 = tx + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            m12 = ty + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            m02 = tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            m12 = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            if (tx != 0.0 || ty != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    // Utility methods to optimize rotate methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    // These tables translate the flags during predictable quadrant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    // rotations where the shear and scale values are swapped and negated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    private static final int rot90conversion[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        /* IDENTITY => */        APPLY_SHEAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        /* TRANSLATE (TR) => */  APPLY_SHEAR | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        /* SCALE (SC) => */      APPLY_SHEAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        /* SC | TR => */         APPLY_SHEAR | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        /* SHEAR (SH) => */      APPLY_SCALE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        /* SH | TR => */         APPLY_SCALE | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        /* SH | SC => */         APPLY_SHEAR | APPLY_SCALE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        /* SH | SC | TR => */    APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    private final void rotate90() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        double M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        m00 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        m01 = -M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        m10 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        m11 = -M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        int state = rot90conversion[this.state];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        if ((state & (APPLY_SHEAR | APPLY_SCALE)) == APPLY_SCALE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            m00 == 1.0 && m11 == 1.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            state -= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    private final void rotate180() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        m00 = -m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        m11 = -m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        if ((state & (APPLY_SHEAR)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            // If there was a shear, then this rotation has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            // effect on the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            m01 = -m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            m10 = -m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            // No shear means the SCALE state may toggle when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            // m00 and m11 are negated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                this.state = state & ~APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    private final void rotate270() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        double M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        m00 = -m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        m01 = M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        m10 = -m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        m11 = M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        int state = rot90conversion[this.state];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        if ((state & (APPLY_SHEAR | APPLY_SCALE)) == APPLY_SCALE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            m00 == 1.0 && m11 == 1.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            state -= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * Concatenates this transform with a rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * This is equivalent to calling concatenate(R), where R is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    public void rotate(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        double sin = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        if (sin == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        } else if (sin == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            double cos = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            if (cos == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            } else if (cos != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                m00 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                m01 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                m10 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                m11 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * coordinates around an anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * This operation is equivalent to translating the coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * that the anchor point is at the origin (S1), then rotating them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * about the new origin (S2), and finally translating so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * intermediate origin is restored to the coordinates of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * anchor point (S3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * This operation is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     *     translate(anchorx, anchory);      // S3: final translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     *     rotate(theta);                    // S2: rotate around anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     *     translate(-anchorx, -anchory);    // S1: translate anchor to origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    public void rotate(double theta, double anchorx, double anchory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        // REMIND: Simple for now - optimize later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        translate(anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        rotate(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        translate(-anchorx, -anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * coordinates according to a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * All coordinates rotate about the origin by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * no additional rotation is added to this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     *          rotate(Math.atan2(vecy, vecx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    public void rotate(double vecx, double vecy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        if (vecy == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            if (vecx < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            // If vecx > 0.0 - no rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            // If vecx == 0.0 - undefined rotation - treat as no rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        } else if (vecx == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            if (vecy > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            } else {  // vecy must be < 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            double len = Math.sqrt(vecx * vecx + vecy * vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            double sin = vecy / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            double cos = vecx / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            m00 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            m01 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            m10 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            m11 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * coordinates around an anchor point according to a rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * All coordinates rotate about the specified anchor coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * the transform is not modified in any way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     *     rotate(Math.atan2(vecy, vecx), anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    public void rotate(double vecx, double vecy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                       double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        // REMIND: Simple for now - optimize later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        translate(anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        rotate(vecx, vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        translate(-anchorx, -anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * coordinates by the specified number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * This is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     *     rotate(numquadrants * Math.PI / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    public void quadrantRotate(int numquadrants) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * coordinates by the specified number of quadrants around
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * the specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     *     rotate(numquadrants * Math.PI / 2.0, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    public void quadrantRotate(int numquadrants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                               double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            m02 += anchorx * (m00 - m01) + anchory * (m01 + m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            m12 += anchorx * (m10 - m11) + anchory * (m11 + m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            m02 += anchorx * (m00 + m00) + anchory * (m01 + m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            m12 += anchorx * (m10 + m10) + anchory * (m11 + m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            m02 += anchorx * (m00 + m01) + anchory * (m01 - m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            m12 += anchorx * (m10 + m11) + anchory * (m11 - m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            state &= ~APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * Concatenates this transform with a scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * This is equivalent to calling concatenate(S), where S is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     * @param sx the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * @param sy the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    public void scale(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            m00 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            m11 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            m01 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            m10 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            if (m01 == 0 && m10 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                state &= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    this.type = (state == APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                                 ? TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                                 : TYPE_TRANSLATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    state |= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                    this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            m00 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            m11 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                this.state = (state &= APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                this.type = (state == APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                             ? TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                             : TYPE_TRANSLATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            m00 = sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            m11 = sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            if (sx != 1.0 || sy != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * Concatenates this transform with a shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * This is equivalent to calling concatenate(SH), where SH is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * @param shx the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * direction of the positive X axis as a factor of their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * @param shy the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * direction of the positive Y axis as a factor of their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    public void shear(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            m00 = M0 + M1 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            m01 = M0 * shx + M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            m10 = M0 + M1 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            m11 = M0 * shx + M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            m00 = m01 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            m11 = m10 * shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            if (m00 != 0.0 || m11 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            m01 = m00 * shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            m10 = m11 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            if (m01 != 0.0 || m10 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                this.state = state | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            m01 = shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            m10 = shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            if (m01 != 0.0 || m10 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                this.state = state | APPLY_SCALE | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * Resets this transform to the Identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public void setToIdentity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        m00 = m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        m10 = m01 = m02 = m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * Sets this transform to a translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * @param tx the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * @param ty the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    public void setToTranslation(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        m02 = tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        m12 = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        if (tx != 0.0 || ty != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * Sets this transform to a rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    public void setToRotation(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        double sin = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        double cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        if (sin == 1.0 || sin == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            cos = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
            cos = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            if (cos == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            } else if (cos == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                type = TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        m00 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        m10 =  sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        m01 = -sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        m11 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * Sets this transform to a translated rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * This operation is equivalent to translating the coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * that the anchor point is at the origin (S1), then rotating them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * about the new origin (S2), and finally translating so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * intermediate origin is restored to the coordinates of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * anchor point (S3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * This operation is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     *     setToTranslation(anchorx, anchory); // S3: final translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     *     rotate(theta);                      // S2: rotate around anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *     translate(-anchorx, -anchory);      // S1: translate anchor to origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     *          [   cos(theta)    -sin(theta)    x-x*cos+y*sin  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     *          [   sin(theta)     cos(theta)    y-x*sin-y*cos  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     *          [       0              0               1        ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
    public void setToRotation(double theta, double anchorx, double anchory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        setToRotation(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        double sin = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        double oneMinusCos = 1.0 - m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        m02 = anchorx * oneMinusCos + anchory * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        m12 = anchory * oneMinusCos - anchorx * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     * coordinates according to a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * All coordinates rotate about the origin by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * the transform is set to an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     *     setToRotation(Math.atan2(vecy, vecx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    public void setToRotation(double vecx, double vecy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        double sin, cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        if (vecy == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            if (vecx < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                cos = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                cos = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        } else if (vecx == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            cos = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            sin = (vecy > 0.0) ? 1.0 : -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            double len = Math.sqrt(vecx * vecx + vecy * vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            cos = vecx / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            sin = vecy / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            type = TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        m00 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        m10 =  sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        m01 = -sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        m11 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * coordinates around an anchor point according to a rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * All coordinates rotate about the specified anchor coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * the transform is set to an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     *     setToTranslation(Math.atan2(vecy, vecx), anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    public void setToRotation(double vecx, double vecy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                              double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        setToRotation(vecx, vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        double sin = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        double oneMinusCos = 1.0 - m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        m02 = anchorx * oneMinusCos + anchory * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        m12 = anchory * oneMinusCos - anchorx * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * coordinates by the specified number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     *     setToRotation(numquadrants * Math.PI / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    public void setToQuadrantRotation(int numquadrants) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            m00 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            m11 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            m10 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            m01 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            m00 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            m11 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            m10 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            m01 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * Sets this transform to a translated rotation transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * that rotates coordinates by the specified number of quadrants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * around the specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     *     setToRotation(numquadrants * Math.PI / 2.0, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    public void setToQuadrantRotation(int numquadrants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                                      double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            m00 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            m11 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            m10 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            m01 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            m02 =  anchorx + anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            m12 =  anchory - anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            m00 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            m11 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
            m02 =  anchorx + anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            m12 =  anchory + anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                state = APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            m10 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            m01 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            m02 =  anchorx - anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
            m12 =  anchory + anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * Sets this transform to a scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * @param sx the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @param sy the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    public void setToScale(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        m00 = sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        m11 = sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        if (sx != 1.0 || sy != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * Sets this transform to a shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     * @param shx the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     * direction of the positive X axis as a factor of their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * @param shy the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * direction of the positive Y axis as a factor of their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
    public void setToShear(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        m01 = shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        m10 = shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        if (shx != 0.0 || shy != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            state = (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * Sets this transform to a copy of the transform in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * @param Tx the <code>AffineTransform</code> object from which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * copy the transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
    public void setTransform(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        this.m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        this.m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        this.m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        this.m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        this.m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        this.m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        this.state = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        this.type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     * Sets this transform to the matrix specified by the 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * double precision values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * @param m00 the X coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * @param m10 the Y coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * @param m01 the X coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * @param m11 the Y coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @param m02 the X coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * @param m12 the Y coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    public void setTransform(double m00, double m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                             double m01, double m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                             double m02, double m12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        this.m00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        this.m10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        this.m01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        this.m11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        this.m02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        this.m12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * Concatenates an <code>AffineTransform</code> <code>Tx</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * this <code>AffineTransform</code> Cx in the most commonly useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * way to provide a new user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * that is mapped to the former user space by <code>Tx</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * Cx is updated to perform the combined transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * Transforming a point p by the updated transform Cx' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * equivalent to first transforming p by <code>Tx</code> and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * transforming the result by the original transform Cx like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * Cx'(p) = Cx(Tx(p))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * In matrix notation, if this transform Cx is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * represented by the matrix [this] and <code>Tx</code> is represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * by the matrix [Tx] then this method does the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     *          [this] = [this] x [Tx]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * @param Tx the <code>AffineTransform</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * concatenated with this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @see #preConcatenate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    public void concatenate(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        double T00, T01, T10, T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
        double T02, T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        int mystate = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        int txstate = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        switch ((txstate << HI_SHIFT) | mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            /* ---------- Tx == IDENTITY cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        case (HI_IDENTITY | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        case (HI_IDENTITY | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        case (HI_IDENTITY | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        case (HI_IDENTITY | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
        case (HI_IDENTITY | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            /* ---------- this == IDENTITY cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        case (HI_SHEAR | HI_SCALE | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        case (HI_SCALE | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
            m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
            m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        case (HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        case (HI_SHEAR | HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        case (HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
            m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        case (HI_SHEAR | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        case (HI_SHEAR | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            m00 = m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
            /* ---------- Tx == TRANSLATE cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        case (HI_TRANSLATE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        case (HI_TRANSLATE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        case (HI_TRANSLATE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        case (HI_TRANSLATE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
            translate(Tx.m02, Tx.m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
            /* ---------- Tx == SCALE cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        case (HI_SCALE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        case (HI_SCALE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        case (HI_SCALE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        case (HI_SCALE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        case (HI_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
            scale(Tx.m00, Tx.m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            /* ---------- Tx == SHEAR cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            T01 = Tx.m01; T10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            m00 = m01 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            m01 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            m10 = m11 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            m11 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        case (HI_SHEAR | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        case (HI_SHEAR | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            m00 = m01 * Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
            m11 = m10 * Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            state = mystate ^ (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        case (HI_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        case (HI_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            m01 = m00 * Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            m10 = m11 * Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            state = mystate ^ (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        case (HI_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
            m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            state = APPLY_TRANSLATE | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        // If Tx has more than one attribute, it is not worth optimizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
        // all of those cases...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        T00 = Tx.m00; T01 = Tx.m01; T02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
        T10 = Tx.m10; T11 = Tx.m11; T12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        switch (mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
            state = mystate | txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            m00  = T00 * M0 + T10 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            m01  = T01 * M0 + T11 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            m02 += T02 * M0 + T12 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            m10  = T00 * M0 + T10 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            m11  = T01 * M0 + T11 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            m12 += T02 * M0 + T12 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            m00  = T10 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            m01  = T11 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            m02 += T12 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            m10  = T00 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            m11  = T01 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            m12 += T02 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            m00  = T00 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            m01  = T01 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
            m02 += T02 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            M0 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            m10  = T10 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            m11  = T11 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            m12 += T12 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            m00  = T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            m01  = T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            m02 += T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            m10  = T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
            m11  = T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            m12 += T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            state = txstate | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * Concatenates an <code>AffineTransform</code> <code>Tx</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     * this <code>AffineTransform</code> Cx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * in a less commonly used way such that <code>Tx</code> modifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * coordinate transformation relative to the absolute pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * space rather than relative to the existing user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     * Cx is updated to perform the combined transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * Transforming a point p by the updated transform Cx' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * equivalent to first transforming p by the original transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * Cx and then transforming the result by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * <code>Tx</code> like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * Cx'(p) = Tx(Cx(p))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * In matrix notation, if this transform Cx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     * is represented by the matrix [this] and <code>Tx</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * represented by the matrix [Tx] then this method does the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     *          [this] = [Tx] x [this]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
     * @param Tx the <code>AffineTransform</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
     * concatenated with this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
     * @see #concatenate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    public void preConcatenate(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        double T00, T01, T10, T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        double T02, T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        int mystate = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        int txstate = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        switch ((txstate << HI_SHIFT) | mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        case (HI_IDENTITY | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        case (HI_IDENTITY | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        case (HI_IDENTITY | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        case (HI_IDENTITY | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        case (HI_IDENTITY | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            // Tx is IDENTITY...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        case (HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        case (HI_TRANSLATE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        case (HI_TRANSLATE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            // Tx is TRANSLATE, this has no TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            state = mystate | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        case (HI_TRANSLATE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        case (HI_TRANSLATE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            // Tx is TRANSLATE, this has one too
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            m02 = m02 + Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
            m12 = m12 + Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        case (HI_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        case (HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
            // Only these two existing states need a new state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            state = mystate | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        case (HI_SCALE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        case (HI_SCALE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        case (HI_SCALE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        case (HI_SCALE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            // Tx is SCALE, this is anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            T00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
            T11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            if ((mystate & APPLY_SHEAR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
                m01 = m01 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                m10 = m10 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
                if ((mystate & APPLY_SCALE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                    m00 = m00 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                    m11 = m11 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                m00 = m00 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                m11 = m11 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            if ((mystate & APPLY_TRANSLATE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                m02 = m02 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                m12 = m12 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
        case (HI_SHEAR | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        case (HI_SHEAR | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
            mystate = mystate | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        case (HI_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        case (HI_SHEAR | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        case (HI_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        case (HI_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            state = mystate ^ APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
            // Tx is SHEAR, this is anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
            T01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
            T10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            m00 = m10 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            m10 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            m01 = m11 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
            m11 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            m02 = m12 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            m12 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
        // If Tx has more than one attribute, it is not worth optimizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        // all of those cases...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
        T00 = Tx.m00; T01 = Tx.m01; T02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        T10 = Tx.m10; T11 = Tx.m11; T12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        switch (mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            M1 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            m00 = M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            m10 = M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            m01 = M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            m11 = M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            m00 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
            m10 = M0 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            m01 = M0 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
            m11 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            m00 = M0 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            m10 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            M0 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
            m01 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
            m11 = M0 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
            m00 = T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
            m10 = T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
            m01 = T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
            m11 = T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
            state = mystate | txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * Returns an <code>AffineTransform</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     * inverse transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     * The inverse transform Tx' of this transform Tx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     * maps coordinates transformed by Tx back
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     * to their original coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * If this transform maps all coordinates onto a point or a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * then it will not have an inverse, since coordinates that do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * not lie on the destination point or line will not have an inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * The <code>getDeterminant</code> method can be used to determine if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * transform has no inverse, in which case an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * thrown if the <code>createInverse</code> method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     * @return a new <code>AffineTransform</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * inverse transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * @see #getDeterminant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * @exception NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * if the matrix cannot be inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    public AffineTransform createInverse()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
            det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            return new AffineTransform( m11 / det, -m10 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
                                       -m01 / det,  m00 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
                                       (m01 * m12 - m11 * m02) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
                                       (m10 * m02 - m00 * m12) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
                                       (APPLY_SHEAR |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                                        APPLY_SCALE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                                        APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
            det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
            return new AffineTransform( m11 / det, -m10 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                                       -m01 / det,  m00 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                                        0.0,        0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                                       (APPLY_SHEAR | APPLY_SCALE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
            if (m01 == 0.0 || m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
            return new AffineTransform( 0.0,        1.0 / m01,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
                                        1.0 / m10,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
                                       -m12 / m10, -m02 / m01,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
                                       (APPLY_SHEAR | APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
            if (m01 == 0.0 || m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            return new AffineTransform(0.0,       1.0 / m01,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
                                       1.0 / m10, 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
                                       0.0,       0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
                                       (APPLY_SHEAR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            if (m00 == 0.0 || m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
            return new AffineTransform( 1.0 / m00,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                                        0.0,        1.0 / m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                                       -m02 / m00, -m12 / m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                                       (APPLY_SCALE | APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            if (m00 == 0.0 || m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            return new AffineTransform(1.0 / m00, 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
                                       0.0,       1.0 / m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
                                       0.0,       0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
                                       (APPLY_SCALE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
            return new AffineTransform( 1.0,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
                                        0.0,  1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                                       -m02, -m12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                                       (APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            return new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
     * Sets this transform to the inverse of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     * The inverse transform Tx' of this transform Tx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * maps coordinates transformed by Tx back
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     * to their original coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     * In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * If this transform maps all coordinates onto a point or a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * then it will not have an inverse, since coordinates that do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * not lie on the destination point or line will not have an inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * The <code>getDeterminant</code> method can be used to determine if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * transform has no inverse, in which case an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * thrown if the <code>invert</code> method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * @see #getDeterminant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * @exception NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * if the matrix cannot be inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
    public void invert()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
        double M00, M01, M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
        double M10, M11, M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
            m00 =  M11 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            m10 = -M10 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
            m01 = -M01 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            m11 =  M00 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            m02 = (M01 * M12 - M11 * M02) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            m12 = (M10 * M02 - M00 * M12) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            m00 =  M11 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
            m10 = -M10 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            m01 = -M01 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            m11 =  M00 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            // m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
            m10 = 1.0 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            m01 = 1.0 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            // m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            m02 = -M12 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            m12 = -M02 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            // m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            m10 = 1.0 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            m01 = 1.0 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            // m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            m00 = 1.0 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
            m11 = 1.0 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            m02 = -M02 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            m12 = -M12 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
            M00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
            m00 = 1.0 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
            m11 = 1.0 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            // m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            // m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            m02 = -m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
            m12 = -m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            // m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            // m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
     * Transforms the specified <code>ptSrc</code> and stores the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     * in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     * If <code>ptDst</code> is <code>null</code>, a new {@link Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     * object is allocated and then the result of the transformation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
     * stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
     * In either case, <code>ptDst</code>, which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     * transformed point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
     * If <code>ptSrc</code> and <code>ptDst</code> are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
     * object, the input point is correctly overwritten with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
     * the transformed point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
     * @param ptSrc the specified <code>Point2D</code> to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * @param ptDst the specified <code>Point2D</code> that stores the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * result of transforming <code>ptSrc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * @return the <code>ptDst</code> after transforming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     * <code>ptSrc</code> and stroring the result in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
    public Point2D transform(Point2D ptSrc, Point2D ptDst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
            ptDst.setLocation(x * m00 + y * m01 + m02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                              x * m10 + y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            ptDst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
            ptDst.setLocation(y * m01 + m02, x * m10 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
            ptDst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
            ptDst.setLocation(x * m00 + m02, y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            ptDst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
            ptDst.setLocation(x + m02, y + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     * Transforms an array of point objects by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     * If any element of the <code>ptDst</code> array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     * <code>null</code>, a new <code>Point2D</code> object is allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     * and stored into that element before storing the results of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     * transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     * Note that this method does not take any precautions to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * avoid problems caused by storing results into <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * objects that will be used as the source for calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     * further down the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     * This method does guarantee that if a specified <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * object is both the source and destination for the same single point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * transform operation then the results will not be stored until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     * the calculations are complete to avoid storing the results on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     * top of the operands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     * If, however, the destination <code>Point2D</code> object for one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     * operation is the same object as the source <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     * object for another operation further down the source array then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * the original coordinates in that point are overwritten before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     * they can be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
     * @param ptSrc the array containing the source point objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * @param ptDst the array into which the transform point objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
     * @param srcOff the offset to the first point object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     * transformed in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * transformed point object that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
    public void transform(Point2D[] ptSrc, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
                          Point2D[] ptDst, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            Point2D src = ptSrc[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            double x = src.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            double y = src.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
            Point2D dst = ptDst[dstOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
                if (src instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
                    dst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
                    dst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
                ptDst[dstOff - 1] = dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
                stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                dst.setLocation(x * m00 + y * m01 + m02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                                x * m10 + y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                dst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
                dst.setLocation(y * m01 + m02, x * m10 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
                dst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                dst.setLocation(x * m00 + m02, y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
            case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                dst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
            case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                dst.setLocation(x + m02, y + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
            case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                dst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
     * Transforms an array of floating point coordinates by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     * This method ensures that no source coordinates are overwritten by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
     * previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * @param dstPts the array into which the transformed point coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * are returned.  Each point is stored as a pair of x,&nbsp;y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * @param numPts the number of points to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
    public void transform(float[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                          float[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
                dstPts[dstOff++] = (float) (M00 * x + M01 * y + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                dstPts[dstOff++] = (float) (M10 * x + M11 * y + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
                dstPts[dstOff++] = (float) (M00 * x + M01 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
                dstPts[dstOff++] = (float) (M10 * x + M11 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
                dstPts[dstOff++] = (float) (M10 * x + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
                dstPts[dstOff++] = (float) (M10 * x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * Transforms an array of double precision coordinates by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * The coordinates are stored in the arrays starting at the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
    public void transform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
                          double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
                dstPts[dstOff++] = M00 * x + M01 * y + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
                dstPts[dstOff++] = M10 * x + M11 * y + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
                dstPts[dstOff++] = M00 * x + M01 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
                dstPts[dstOff++] = M10 * x + M11 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
                dstPts[dstOff++] = M01 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
                dstPts[dstOff++] = M10 * x + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                dstPts[dstOff++] = M01 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                dstPts[dstOff++] = M10 * x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
                dstPts[dstOff++] = M00 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
                dstPts[dstOff++] = M11 * srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
                dstPts[dstOff++] = M00 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
                dstPts[dstOff++] = M11 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
                dstPts[dstOff++] = srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
                dstPts[dstOff++] = srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
     * Transforms an array of floating point coordinates by this transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
     * and stores the results into an array of doubles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * @param dstPts the array into which the transformed point coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * are returned.  Each point is stored as a pair of x,&nbsp;y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * @param numPts the number of points to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
    public void transform(float[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                          double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                dstPts[dstOff++] = M00 * x + M01 * y + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                dstPts[dstOff++] = M10 * x + M11 * y + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                dstPts[dstOff++] = M00 * x + M01 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                dstPts[dstOff++] = M10 * x + M11 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
                dstPts[dstOff++] = M01 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
                dstPts[dstOff++] = M10 * x + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                dstPts[dstOff++] = M01 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
                dstPts[dstOff++] = M10 * x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                dstPts[dstOff++] = M00 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                dstPts[dstOff++] = M11 * srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                dstPts[dstOff++] = M00 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
                dstPts[dstOff++] = M11 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                dstPts[dstOff++] = srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                dstPts[dstOff++] = srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
                dstPts[dstOff++] = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                dstPts[dstOff++] = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
     * Transforms an array of double precision coordinates by this transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
     * and stores the results into an array of floats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
    public void transform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                          float[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
                dstPts[dstOff++] = (float) (M00 * x + M01 * y + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
                dstPts[dstOff++] = (float) (M10 * x + M11 * y + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                dstPts[dstOff++] = (float) (M00 * x + M01 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
                dstPts[dstOff++] = (float) (M10 * x + M11 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
                dstPts[dstOff++] = (float) (M10 * x + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                dstPts[dstOff++] = (float) (M10 * x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                dstPts[dstOff++] = (float) (srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                dstPts[dstOff++] = (float) (srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
     * Inverse transforms the specified <code>ptSrc</code> and stores the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * result in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * If <code>ptDst</code> is <code>null</code>, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * <code>Point2D</code> object is allocated and then the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * transform is stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     * In either case, <code>ptDst</code>, which contains the transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * If <code>ptSrc</code> and <code>ptDst</code> are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * object, the input point is correctly overwritten with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * transformed point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * @param ptSrc the point to be inverse transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     * @param ptDst the resulting transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @return <code>ptDst</code>, which contains the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * inverse transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     * @exception NoninvertibleTransformException  if the matrix cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     *                                         inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
    public Point2D inverseTransform(Point2D ptSrc, Point2D ptDst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
            double det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
            ptDst.setLocation((x * m11 - y * m01) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                              (y * m00 - x * m10) / det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            if (m01 == 0.0 || m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
            ptDst.setLocation(y / m10, x / m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            if (m00 == 0.0 || m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
            ptDst.setLocation(x / m00, y / m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            ptDst.setLocation(x - m02, y - m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
     * Inverse transforms an array of double precision coordinates by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
     * this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
     * @exception NoninvertibleTransformException  if the matrix cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
     *                                         inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
    public void inverseTransform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                                 double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                                 int numPts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
                double x = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
                double y = srcPts[srcOff++] - M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                dstPts[dstOff++] = (x * M11 - y * M01) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                dstPts[dstOff++] = (y * M00 - x * M10) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                dstPts[dstOff++] = (x * M11 - y * M01) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                dstPts[dstOff++] = (y * M00 - x * M10) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
                double x = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                dstPts[dstOff++] = (srcPts[srcOff++] - M12) / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
                dstPts[dstOff++] = x / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
                dstPts[dstOff++] = srcPts[srcOff++] / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
                dstPts[dstOff++] = x / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
                dstPts[dstOff++] = (srcPts[srcOff++] - M02) / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
                dstPts[dstOff++] = (srcPts[srcOff++] - M12) / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
                dstPts[dstOff++] = srcPts[srcOff++] / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                dstPts[dstOff++] = srcPts[srcOff++] / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
                dstPts[dstOff++] = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
                dstPts[dstOff++] = srcPts[srcOff++] - M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
     * Transforms the relative distance vector specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
     * <code>ptSrc</code> and stores the result in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
     * A relative distance vector is transformed without applying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
     * translation components of the affine transformation matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
     * using the following equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
     *  [  x' ]   [  m00  m01 (m02) ] [  x  ]   [ m00x + m01y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
     *  [  y' ] = [  m10  m11 (m12) ] [  y  ] = [ m10x + m11y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
     *  [ (1) ]   [  (0)  (0) ( 1 ) ] [ (1) ]   [     (1)     ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     * If <code>ptDst</code> is <code>null</code>, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     * <code>Point2D</code> object is allocated and then the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
     * transform is stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
     * In either case, <code>ptDst</code>, which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
     * transformed point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
     * If <code>ptSrc</code> and <code>ptDst</code> are the same object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
     * the input point is correctly overwritten with the transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
     * point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
     * @param ptSrc the distance vector to be delta transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
     * @param ptDst the resulting transformed distance vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * @return <code>ptDst</code>, which contains the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     * transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
    public Point2D deltaTransform(Point2D ptSrc, Point2D ptDst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
            ptDst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            ptDst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
            ptDst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
     * Transforms an array of relative distance vectors by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
     * transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
     * A relative distance vector is transformed without applying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
     * translation components of the affine transformation matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
     * using the following equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
     *  [  x' ]   [  m00  m01 (m02) ] [  x  ]   [ m00x + m01y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
     *  [  y' ] = [  m10  m11 (m12) ] [  y  ] = [ m10x + m11y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
     *  [ (1) ]   [  (0)  (0) ( 1 ) ] [ (1) ]   [     (1)     ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
     * The coordinates are stored in the arrays starting at the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
     * @param srcPts the array containing the source distance vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     * Each vector is stored as a pair of relative x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     * @param dstPts the array into which the transformed distance vectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
     * are returned.  Each vector is stored as a pair of relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
     * @param srcOff the offset to the first vector to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
     * transformed vector that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
     * @param numPts the number of vector coordinate pairs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
     * transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
    public void deltaTransform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
                               double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                               int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
        double M00, M01, M10, M11;      // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
                dstPts[dstOff++] = x * M00 + y * M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
                dstPts[dstOff++] = x * M10 + y * M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
                dstPts[dstOff++] = srcPts[srcOff++] * M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
                dstPts[dstOff++] = x * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
                dstPts[dstOff++] = srcPts[srcOff++] * M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
                dstPts[dstOff++] = srcPts[srcOff++] * M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
     * Returns a new {@link Shape} object defined by the geometry of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
     * specified <code>Shape</code> after it has been transformed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
     * this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
     * @param pSrc the specified <code>Shape</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
     * transformed by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
     * @return a new <code>Shape</code> object that defines the geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
     * of the transformed <code>Shape</code>, or null if {@code pSrc} is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
    public Shape createTransformedShape(Shape pSrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
        if (pSrc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
        return new Path2D.Double(pSrc, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
    // Round values to sane precision for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
    // Note that Math.sin(Math.PI) has an error of about 10^-16
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
    private static double _matround(double matval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
        return Math.rint(matval * 1E15) / 1E15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
     * Returns a <code>String</code> that represents the value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
     * {@link Object}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
     * @return a <code>String</code> representing the value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
     * <code>Object</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
        return ("AffineTransform[["
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                + _matround(m00) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                + _matround(m01) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                + _matround(m02) + "], ["
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                + _matround(m10) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                + _matround(m11) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                + _matround(m12) + "]]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
     * Returns <code>true</code> if this <code>AffineTransform</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
     * an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
     * @return <code>true</code> if this <code>AffineTransform</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
     * an identity transform; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
    public boolean isIdentity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
        return (state == APPLY_IDENTITY || (getType() == TYPE_IDENTITY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
     * Returns a copy of this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
     * @return an <code>Object</code> that is a copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
     * <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
            // this shouldn't happen, since we are Cloneable
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 7006
diff changeset
  3859
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
     * Returns the hashcode for this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
     * @return      a hash code for this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
        long bits = Double.doubleToLongBits(m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        bits = bits * 31 + Double.doubleToLongBits(m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
        bits = bits * 31 + Double.doubleToLongBits(m02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
        bits = bits * 31 + Double.doubleToLongBits(m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        bits = bits * 31 + Double.doubleToLongBits(m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        bits = bits * 31 + Double.doubleToLongBits(m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
        return (((int) bits) ^ ((int) (bits >> 32)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
     * Returns <code>true</code> if this <code>AffineTransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
     * represents the same affine coordinate transform as the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
     * argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
     * @param obj the <code>Object</code> to test for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
     * <code>AffineTransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
     * @return <code>true</code> if <code>obj</code> equals this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
     * <code>AffineTransform</code> object; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
        if (!(obj instanceof AffineTransform)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
        AffineTransform a = (AffineTransform)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
        return ((m00 == a.m00) && (m01 == a.m01) && (m02 == a.m02) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                (m10 == a.m10) && (m11 == a.m11) && (m12 == a.m12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
    /* Serialization support.  A readObject method is neccessary because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
     * the state field is part of the implementation of this particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
     * AffineTransform and not part of the public specification.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
     * state variable's value needs to be recalculated on the fly by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
     * readObject method as it is in the 6-argument matrix constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
     * JDK 1.2 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
    private static final long serialVersionUID = 1330973210523860834L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
}