jdk/src/share/classes/java/awt/geom/AffineTransform.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 21244 7c2ac5ca05a2
child 21957 97758de70fbd
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
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>
21244
7c2ac5ca05a2 8026021: more fix of javadoc errors and warnings reported by doclint, see the description
cl
parents: 20451
diff changeset
    50
 * <h4><a name="quadrantapproximation">Handling 90-Degree Rotations</a></h4>
2
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
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   528
     * entries or the 6 specifiable entries of the 3x3 transformation
2
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
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   718
     * point according to a rotation vector.
2
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
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   848
     * appropriate flag bits.
2
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
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
   879
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    private void calculateType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        int ret = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        boolean sgn0, sgn1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        double M0, M1, M2, M3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if ((M0 = m00) * (M2 = m01) + (M3 = m10) * (M1 = m11) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                // Transformed unit vectors are not perpendicular...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                this.type = TYPE_GENERAL_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            sgn0 = (M0 >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            sgn1 = (M1 >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            if (sgn0 == sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                // sgn(M0) == sgn(M1) therefore sgn(M2) == -sgn(M3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                // This is the "unflipped" (right-handed) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                if (M0 != M1 || M2 != -M3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                } else if (M0 * M1 - M2 * M3 != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    ret |= TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                // sgn(M0) == -sgn(M1) therefore sgn(M2) == sgn(M3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                // This is the "flipped" (left-handed) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                if (M0 != -M1 || M2 != M3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    ret |= (TYPE_GENERAL_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                            TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                } else if (M0 * M1 - M2 * M3 != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    ret |= (TYPE_GENERAL_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                            TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    ret |= (TYPE_GENERAL_ROTATION | TYPE_FLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            sgn0 = ((M0 = m01) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            sgn1 = ((M1 = m10) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            if (sgn0 != sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                // Different signs - simple 90 degree rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                if (M0 != -M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                    ret |= (TYPE_QUADRANT_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                } else if (M0 != 1.0 && M0 != -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    ret |= (TYPE_QUADRANT_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    ret |= TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                // Same signs - 90 degree rotation plus an axis flip too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                if (M0 == M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    ret |= (TYPE_QUADRANT_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                            TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                    ret |= (TYPE_QUADRANT_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                            TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                            TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            sgn0 = ((M0 = m00) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            sgn1 = ((M1 = m11) >= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            if (sgn0 == sgn1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                if (sgn0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                    // Both scaling factors non-negative - simple scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    // Note: APPLY_SCALE implies M0, M1 are not both 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    if (M0 == M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                        ret |= TYPE_UNIFORM_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                        ret |= TYPE_GENERAL_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    // Both scaling factors negative - 180 degree rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    if (M0 != M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                        ret |= (TYPE_QUADRANT_ROTATION | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    } else if (M0 != -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                        ret |= (TYPE_QUADRANT_ROTATION | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                        ret |= TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                // Scaling factor signs different - flip about some axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                if (M0 == -M1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                    if (M0 == 1.0 || M0 == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                        ret |= TYPE_FLIP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                        ret |= (TYPE_FLIP | TYPE_UNIFORM_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    ret |= (TYPE_FLIP | TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            ret = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        this.type = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Returns the determinant of the matrix representation of the transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * The determinant is useful both to determine if the transform can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * be inverted and to get a single value representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * combined X and Y scaling of the transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * If the determinant is non-zero, then this transform is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * invertible and the various methods that depend on the inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * transform do not need to throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * {@link NoninvertibleTransformException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * If the determinant is zero then this transform can not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * inverted since the transform maps all input coordinates onto
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * a line or a point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * If the determinant is near enough to zero then inverse transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * operations might not carry enough precision to produce meaningful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * If this transform represents a uniform scale, as indicated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * the <code>getType</code> method then the determinant also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * represents the square of the uniform scale factor by which all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * the points are expanded from or contracted towards the origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * If this transform represents a non-uniform scale or more general
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * transform then the determinant is not likely to represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * value useful for any purpose other than determining if inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * transforms are possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * Mathematically, the determinant is calculated using the formula:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *          |  m00  m01  m02  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     *          |  m10  m11  m12  |  =  m00 * m11 - m01 * m10
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *          |   0    0    1   |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @return the determinant of the matrix used to transform the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @see #getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @see #createInverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @see #inverseTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @see #TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  1042
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    public double getDeterminant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            return m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            return -(m01 * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            return m00 * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            return 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * Manually recalculates the state of the transform when the matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * changes too much to predict the effects on the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * The following table specifies what the various settings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * state field say about the values of the corresponding matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * element fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * Note that the rules governing the SCALE fields are slightly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * different depending on whether the SHEAR flag is also set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *                     SCALE            SHEAR          TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *                    m00/m11          m01/m10          m02/m12
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * IDENTITY             1.0              0.0              0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * TRANSLATE (TR)       1.0              0.0          not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * SCALE (SC)       not both 1.0         0.0              0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * TR | SC          not both 1.0         0.0          not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * SHEAR (SH)           0.0          not both 0.0         0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * TR | SH              0.0          not both 0.0     not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * SC | SH          not both 0.0     not both 0.0         0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * TR | SC | SH     not both 0.0     not both 0.0     not both 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    void updateState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if (m01 == 0.0 && m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                    state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    state = (APPLY_SCALE | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            if (m00 == 0.0 && m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                    state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    state = (APPLY_SHEAR | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    state = (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                    state = (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                    type = TYPE_UNKNOWN;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * Convenience method used internally to throw exceptions when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * a case was forgotten in a switch statement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    private void stateError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        throw new InternalError("missing case in transform state switch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * Retrieves the 6 specifiable values in the 3x3 affine transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * matrix and places them into an array of double precisions values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * The values are stored in the array as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;m02&nbsp;m12&nbsp;}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * An array of 4 doubles can also be specified, in which case only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * first four elements representing the non-transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * parts of the array are retrieved and the values are stored into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * the array as {&nbsp;m00&nbsp;m10&nbsp;m01&nbsp;m11&nbsp;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @param flatmatrix the double array used to store the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @see #getScaleX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @see #getScaleY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @see #getShearX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @see #getShearY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @see #getTranslateX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @see #getTranslateY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    public void getMatrix(double[] flatmatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        flatmatrix[0] = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        flatmatrix[1] = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        flatmatrix[2] = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        flatmatrix[3] = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        if (flatmatrix.length > 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            flatmatrix[4] = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            flatmatrix[5] = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Returns the X coordinate scaling element (m00) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @return a double value that is the X coordinate of the scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    public double getScaleX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        return m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * Returns the Y coordinate scaling element (m11) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @return a double value that is the Y coordinate of the scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    public double getScaleY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        return m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * Returns the X coordinate shearing element (m01) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * @return a double value that is the X coordinate of the shearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    public double getShearX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        return m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * Returns the Y coordinate shearing element (m10) of the 3x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * @return a double value that is the Y coordinate of the shearing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    public double getShearY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        return m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * Returns the X coordinate of the translation element (m02) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @return a double value that is the X coordinate of the translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    public double getTranslateX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        return m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * Returns the Y coordinate of the translation element (m12) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * 3x3 affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * @return a double value that is the Y coordinate of the translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     *  element of the affine transformation matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * @see #getMatrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    public double getTranslateY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        return m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * Concatenates this transform with a translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * This is equivalent to calling concatenate(T), where T is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @param tx the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @param ty the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    public void translate(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  1255
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            m02 = tx * m00 + ty * m01 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            m12 = tx * m10 + ty * m11 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            m02 = tx * m00 + ty * m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            m12 = tx * m10 + ty * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                state = APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            m02 = ty * m01 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            m12 = tx * m10 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            m02 = ty * m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            m12 = tx * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            m02 = tx * m00 + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            m12 = ty * m11 + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                if (type != TYPE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    type -= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            m02 = tx * m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            m12 = ty * m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                state = APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            m02 = tx + m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            m12 = ty + m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            m02 = tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            m12 = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            if (tx != 0.0 || ty != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    // Utility methods to optimize rotate methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    // These tables translate the flags during predictable quadrant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    // rotations where the shear and scale values are swapped and negated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    private static final int rot90conversion[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        /* IDENTITY => */        APPLY_SHEAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        /* TRANSLATE (TR) => */  APPLY_SHEAR | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        /* SCALE (SC) => */      APPLY_SHEAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        /* SC | TR => */         APPLY_SHEAR | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        /* SHEAR (SH) => */      APPLY_SCALE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        /* SH | TR => */         APPLY_SCALE | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        /* SH | SC => */         APPLY_SHEAR | APPLY_SCALE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        /* SH | SC | TR => */    APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    private final void rotate90() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        double M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        m00 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        m01 = -M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        m10 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        m11 = -M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        int state = rot90conversion[this.state];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        if ((state & (APPLY_SHEAR | APPLY_SCALE)) == APPLY_SCALE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            m00 == 1.0 && m11 == 1.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            state -= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    private final void rotate180() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        m00 = -m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        m11 = -m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        if ((state & (APPLY_SHEAR)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            // If there was a shear, then this rotation has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            // effect on the state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            m01 = -m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            m10 = -m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            // No shear means the SCALE state may toggle when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            // m00 and m11 are negated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                this.state = state & ~APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    private final void rotate270() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        double M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        m00 = -m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        m01 = M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        m10 = -m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        m11 = M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        int state = rot90conversion[this.state];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        if ((state & (APPLY_SHEAR | APPLY_SCALE)) == APPLY_SCALE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            m00 == 1.0 && m11 == 1.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            state -= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Concatenates this transform with a rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * This is equivalent to calling concatenate(R), where R is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    public void rotate(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        double sin = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        if (sin == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        } else if (sin == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            double cos = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            if (cos == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            } else if (cos != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                m00 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                m01 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                m10 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                m11 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * coordinates around an anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * This operation is equivalent to translating the coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * that the anchor point is at the origin (S1), then rotating them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * about the new origin (S2), and finally translating so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * intermediate origin is restored to the coordinates of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * anchor point (S3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * This operation is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     *     translate(anchorx, anchory);      // S3: final translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     *     rotate(theta);                    // S2: rotate around anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     *     translate(-anchorx, -anchory);    // S1: translate anchor to origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    public void rotate(double theta, double anchorx, double anchory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        // REMIND: Simple for now - optimize later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        translate(anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        rotate(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        translate(-anchorx, -anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * coordinates according to a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * All coordinates rotate about the origin by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * no additional rotation is added to this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     *          rotate(Math.atan2(vecy, vecx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    public void rotate(double vecx, double vecy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        if (vecy == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            if (vecx < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            // If vecx > 0.0 - no rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            // If vecx == 0.0 - undefined rotation - treat as no rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        } else if (vecx == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            if (vecy > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            } else {  // vecy must be < 0.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            double len = Math.sqrt(vecx * vecx + vecy * vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            double sin = vecy / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            double cos = vecx / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            m00 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            m01 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            m10 =  cos * M0 + sin * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            m11 = -sin * M0 + cos * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * coordinates around an anchor point according to a rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * All coordinates rotate about the specified anchor coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     * the transform is not modified in any way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     *     rotate(Math.atan2(vecy, vecx), anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    public void rotate(double vecx, double vecy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                       double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        // REMIND: Simple for now - optimize later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        translate(anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        rotate(vecx, vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        translate(-anchorx, -anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * coordinates by the specified number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * This is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     *     rotate(numquadrants * Math.PI / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    public void quadrantRotate(int numquadrants) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * Concatenates this transform with a transform that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * coordinates by the specified number of quadrants around
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * the specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     *     rotate(numquadrants * Math.PI / 2.0, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    public void quadrantRotate(int numquadrants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                               double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            m02 += anchorx * (m00 - m01) + anchory * (m01 + m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
            m12 += anchorx * (m10 - m11) + anchory * (m11 + m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            rotate90();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            m02 += anchorx * (m00 + m00) + anchory * (m01 + m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            m12 += anchorx * (m10 + m10) + anchory * (m11 + m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            rotate180();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            m02 += anchorx * (m00 + m01) + anchory * (m01 - m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            m12 += anchorx * (m10 + m11) + anchory * (m11 - m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
            rotate270();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            state &= ~APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * Concatenates this transform with a scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * This is equivalent to calling concatenate(S), where S is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * @param sx the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * @param sy the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  1637
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    public void scale(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            m00 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            m11 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            m01 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            m10 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            if (m01 == 0 && m10 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                state &= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    this.type = (state == APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                                 ? TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                                 : TYPE_TRANSLATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                    state |= APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                    this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                this.state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            m00 *= sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            m11 *= sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            if (m00 == 1.0 && m11 == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                this.state = (state &= APPLY_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                this.type = (state == APPLY_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                             ? TYPE_IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                             : TYPE_TRANSLATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            m00 = sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            m11 = sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            if (sx != 1.0 || sy != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * Concatenates this transform with a shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * This is equivalent to calling concatenate(SH), where SH is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * <code>AffineTransform</code> represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @param shx the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * direction of the positive X axis as a factor of their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * @param shy the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * direction of the positive Y axis as a factor of their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
    public void shear(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  1712
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            m00 = M0 + M1 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            m01 = M0 * shx + M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
            m10 = M0 + M1 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            m11 = M0 * shx + M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            m00 = m01 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            m11 = m10 * shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            if (m00 != 0.0 || m11 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                this.state = state | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            m01 = m00 * shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            m10 = m11 * shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            if (m01 != 0.0 || m10 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                this.state = state | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            m01 = shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            m10 = shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            if (m01 != 0.0 || m10 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                this.state = state | APPLY_SCALE | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                this.type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * Resets this transform to the Identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    public void setToIdentity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        m00 = m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        m10 = m01 = m02 = m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * Sets this transform to a translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * @param tx the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * @param ty the distance by which coordinates are translated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    public void setToTranslation(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        m02 = tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        m12 = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        if (tx != 0.0 || ty != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            state = APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            type = TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * Sets this transform to a rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    public void setToRotation(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        double sin = Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        double cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        if (sin == 1.0 || sin == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            cos = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            cos = Math.cos(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            if (cos == -1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            } else if (cos == 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                type = TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        m00 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        m10 =  sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        m01 = -sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        m11 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * Sets this transform to a translated rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * This operation is equivalent to translating the coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * that the anchor point is at the origin (S1), then rotating them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * about the new origin (S2), and finally translating so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * intermediate origin is restored to the coordinates of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * anchor point (S3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * This operation is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     *     setToTranslation(anchorx, anchory); // S3: final translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     *     rotate(theta);                      // S2: rotate around anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     *     translate(-anchorx, -anchory);      // S1: translate anchor to origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *          [   cos(theta)    -sin(theta)    x-x*cos+y*sin  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *          [   sin(theta)     cos(theta)    y-x*sin-y*cos  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     *          [       0              0               1        ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * Rotating by a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * Note also the discussion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * <a href="#quadrantapproximation">Handling 90-Degree Rotations</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @param theta the angle of rotation measured in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    public void setToRotation(double theta, double anchorx, double anchory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        setToRotation(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        double sin = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        double oneMinusCos = 1.0 - m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        m02 = anchorx * oneMinusCos + anchory * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        m12 = anchory * oneMinusCos - anchorx * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * coordinates according to a rotation vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * All coordinates rotate about the origin by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * the transform is set to an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     *     setToRotation(Math.atan2(vecy, vecx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    public void setToRotation(double vecx, double vecy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        double sin, cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        if (vecy == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            sin = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            if (vecx < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                cos = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                cos = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        } else if (vecx == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            cos = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            sin = (vecy > 0.0) ? 1.0 : -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            double len = Math.sqrt(vecx * vecx + vecy * vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            cos = vecx / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            sin = vecy / len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            state = APPLY_SHEAR | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            type = TYPE_GENERAL_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        m00 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        m10 =  sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        m01 = -sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        m11 =  cos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * coordinates around an anchor point according to a rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * All coordinates rotate about the specified anchor coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * by the same amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * The amount of rotation is such that coordinates along the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * positive X axis will subsequently align with the vector pointing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * from the origin to the specified vector coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * If both <code>vecx</code> and <code>vecy</code> are 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * the transform is set to an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     *     setToTranslation(Math.atan2(vecy, vecx), anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * @param vecx the X coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * @param vecy the Y coordinate of the rotation vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    public void setToRotation(double vecx, double vecy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                              double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        setToRotation(vecx, vecy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        double sin = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        double oneMinusCos = 1.0 - m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        m02 = anchorx * oneMinusCos + anchory * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        m12 = anchory * oneMinusCos - anchorx * sin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        if (m02 != 0.0 || m12 != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            state |= APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * Sets this transform to a rotation transformation that rotates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * coordinates by the specified number of quadrants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     *     setToRotation(numquadrants * Math.PI / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    public void setToQuadrantRotation(int numquadrants) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            m00 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            m11 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            m10 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
            m01 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            m00 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            m11 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            m10 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            m01 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * Sets this transform to a translated rotation transformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * that rotates coordinates by the specified number of quadrants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * around the specified anchor point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * This operation is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     *     setToRotation(numquadrants * Math.PI / 2.0, anchorx, anchory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * Rotating by a positive number of quadrants rotates points on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * the positive X axis toward the positive Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * @param numquadrants the number of 90 degree arcs to rotate by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * @param anchorx the X coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * @param anchory the Y coordinate of the rotation anchor point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
    public void setToQuadrantRotation(int numquadrants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                                      double anchorx, double anchory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        switch (numquadrants & 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            m00 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            m11 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            m02 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            m12 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            m10 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            m01 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            m02 =  anchorx + anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            m12 =  anchory - anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            m00 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            m10 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            m01 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
            m11 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            m02 =  anchorx + anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            m12 =  anchory + anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                state = APPLY_SCALE | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
            m00 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            m10 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
            m01 =  1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            m11 =  0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            m02 =  anchorx - anchory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            m12 =  anchory + anchorx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            if (m02 == 0.0 && m12 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                state = APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                type = TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                state = APPLY_SHEAR | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                type = TYPE_QUADRANT_ROTATION | TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * Sets this transform to a scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * @param sx the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * X axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * @param sy the factor by which coordinates are scaled along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * Y axis direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    public void setToScale(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        m00 = sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        m11 = sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
        m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        if (sx != 1.0 || sy != 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            state = APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * Sets this transform to a shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     * The matrix representing this transform becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * @param shx the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * direction of the positive X axis as a factor of their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * @param shy the multiplier by which coordinates are shifted in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * direction of the positive Y axis as a factor of their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    public void setToShear(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        m01 = shx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        m10 = shy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        if (shx != 0.0 || shy != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            state = (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            state = APPLY_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            type = TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * Sets this transform to a copy of the transform in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     * @param Tx the <code>AffineTransform</code> object from which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * copy the transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    public void setTransform(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        this.m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        this.m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        this.m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
        this.m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        this.m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        this.m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        this.state = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        this.type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * Sets this transform to the matrix specified by the 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * double precision values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * @param m00 the X coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @param m10 the Y coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * @param m01 the X coordinate shearing element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * @param m11 the Y coordinate scaling element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * @param m02 the X coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * @param m12 the Y coordinate translation element of the 3x3 matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    public void setTransform(double m00, double m10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                             double m01, double m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                             double m02, double m12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        this.m00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        this.m10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        this.m01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
        this.m11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
        this.m02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        this.m12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * Concatenates an <code>AffineTransform</code> <code>Tx</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * this <code>AffineTransform</code> Cx in the most commonly useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * way to provide a new user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * that is mapped to the former user space by <code>Tx</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * Cx is updated to perform the combined transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * Transforming a point p by the updated transform Cx' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * equivalent to first transforming p by <code>Tx</code> and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * transforming the result by the original transform Cx like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * Cx'(p) = Cx(Tx(p))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * In matrix notation, if this transform Cx is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * represented by the matrix [this] and <code>Tx</code> is represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * by the matrix [Tx] then this method does the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     *          [this] = [this] x [Tx]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * @param Tx the <code>AffineTransform</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * concatenated with this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * @see #preConcatenate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2232
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    public void concatenate(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        double T00, T01, T10, T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        double T02, T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        int mystate = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        int txstate = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        switch ((txstate << HI_SHIFT) | mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
            /* ---------- Tx == IDENTITY cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
        case (HI_IDENTITY | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        case (HI_IDENTITY | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        case (HI_IDENTITY | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        case (HI_IDENTITY | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
        case (HI_IDENTITY | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
            /* ---------- this == IDENTITY cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        case (HI_SHEAR | HI_SCALE | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        case (HI_SCALE | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        case (HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
        case (HI_SHEAR | HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        case (HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
            m00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            m11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        case (HI_SHEAR | HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        case (HI_SHEAR | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            m00 = m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
            state = txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            type = Tx.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
            /* ---------- Tx == TRANSLATE cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        case (HI_TRANSLATE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        case (HI_TRANSLATE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        case (HI_TRANSLATE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        case (HI_TRANSLATE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            translate(Tx.m02, Tx.m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
            /* ---------- Tx == SCALE cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        case (HI_SCALE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        case (HI_SCALE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        case (HI_SCALE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        case (HI_SCALE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        case (HI_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            scale(Tx.m00, Tx.m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            /* ---------- Tx == SHEAR cases ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            T01 = Tx.m01; T10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            m00 = m01 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            m01 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            m10 = m11 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            m11 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        case (HI_SHEAR | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        case (HI_SHEAR | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            m00 = m01 * Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
            m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
            m11 = m10 * Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            state = mystate ^ (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        case (HI_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        case (HI_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            m01 = m00 * Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
            m10 = m11 * Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            state = mystate ^ (APPLY_SHEAR | APPLY_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        case (HI_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            m01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            m10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            state = APPLY_TRANSLATE | APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
        // If Tx has more than one attribute, it is not worth optimizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        // all of those cases...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        T00 = Tx.m00; T01 = Tx.m01; T02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
        T10 = Tx.m10; T11 = Tx.m11; T12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        switch (mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            state = mystate | txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            M1 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            m00  = T00 * M0 + T10 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            m01  = T01 * M0 + T11 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            m02 += T02 * M0 + T12 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            m10  = T00 * M0 + T10 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            m11  = T01 * M0 + T11 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            m12 += T02 * M0 + T12 * M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            m00  = T10 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            m01  = T11 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
            m02 += T12 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            m10  = T00 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            m11  = T01 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            m12 += T02 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            m00  = T00 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            m01  = T01 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            m02 += T02 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
            M0 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            m10  = T10 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            m11  = T11 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            m12 += T12 * M0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            m00  = T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            m01  = T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            m02 += T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
            m10  = T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
            m11  = T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
            m12 += T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
            state = txstate | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * Concatenates an <code>AffineTransform</code> <code>Tx</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * this <code>AffineTransform</code> Cx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * in a less commonly used way such that <code>Tx</code> modifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * coordinate transformation relative to the absolute pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * space rather than relative to the existing user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * Cx is updated to perform the combined transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     * Transforming a point p by the updated transform Cx' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * equivalent to first transforming p by the original transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * Cx and then transforming the result by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     * <code>Tx</code> like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     * Cx'(p) = Tx(Cx(p))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     * In matrix notation, if this transform Cx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
     * is represented by the matrix [this] and <code>Tx</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
     * represented by the matrix [Tx] then this method does the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
     *          [this] = [Tx] x [this]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
     * @param Tx the <code>AffineTransform</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
     * concatenated with this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
     * @see #concatenate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2441
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    public void preConcatenate(AffineTransform Tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        double M0, M1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        double T00, T01, T10, T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        double T02, T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        int mystate = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        int txstate = Tx.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        switch ((txstate << HI_SHIFT) | mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        case (HI_IDENTITY | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
        case (HI_IDENTITY | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        case (HI_IDENTITY | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        case (HI_IDENTITY | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        case (HI_IDENTITY | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        case (HI_IDENTITY | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            // Tx is IDENTITY...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        case (HI_TRANSLATE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        case (HI_TRANSLATE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        case (HI_TRANSLATE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            // Tx is TRANSLATE, this has no TRANSLATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
            m02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
            m12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            state = mystate | APPLY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            type |= TYPE_TRANSLATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        case (HI_TRANSLATE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        case (HI_TRANSLATE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        case (HI_TRANSLATE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
            // Tx is TRANSLATE, this has one too
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            m02 = m02 + Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
            m12 = m12 + Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        case (HI_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        case (HI_SCALE | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
            // Only these two existing states need a new state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            state = mystate | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        case (HI_SCALE | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        case (HI_SCALE | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        case (HI_SCALE | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        case (HI_SCALE | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        case (HI_SCALE | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            // Tx is SCALE, this is anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            T00 = Tx.m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
            T11 = Tx.m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
            if ((mystate & APPLY_SHEAR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                m01 = m01 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                m10 = m10 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                if ((mystate & APPLY_SCALE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                    m00 = m00 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                    m11 = m11 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                m00 = m00 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                m11 = m11 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
            if ((mystate & APPLY_TRANSLATE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                m02 = m02 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                m12 = m12 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        case (HI_SHEAR | APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        case (HI_SHEAR | APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
            mystate = mystate | APPLY_SCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
        case (HI_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        case (HI_SHEAR | APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
        case (HI_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        case (HI_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
            state = mystate ^ APPLY_SHEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        case (HI_SHEAR | APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            // Tx is SHEAR, this is anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            T01 = Tx.m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            T10 = Tx.m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            m00 = m10 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            m10 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            m01 = m11 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            m11 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            m02 = m12 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
            m12 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        // If Tx has more than one attribute, it is not worth optimizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        // all of those cases...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        T00 = Tx.m00; T01 = Tx.m01; T02 = Tx.m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        T10 = Tx.m10; T11 = Tx.m11; T12 = Tx.m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
        switch (mystate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            M1 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            m00 = M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            m10 = M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            M1 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
            m01 = M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            m11 = M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            M0 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
            m00 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            m10 = M0 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            M0 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            m01 = M0 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
            m11 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
            M0 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
            m00 = M0 * T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
            m10 = M0 * T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
            M0 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            m01 = M0 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
            m11 = M0 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
            M0 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
            M1 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
            T02 += M0 * T00 + M1 * T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
            T12 += M0 * T10 + M1 * T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
            m02 = T02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
            m12 = T12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            m00 = T00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            m10 = T10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            m01 = T01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
            m11 = T11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
            state = mystate | txstate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
            type = TYPE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * Returns an <code>AffineTransform</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * inverse transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * The inverse transform Tx' of this transform Tx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * maps coordinates transformed by Tx back
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * to their original coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     * If this transform maps all coordinates onto a point or a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * then it will not have an inverse, since coordinates that do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * not lie on the destination point or line will not have an inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * The <code>getDeterminant</code> method can be used to determine if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     * transform has no inverse, in which case an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * thrown if the <code>createInverse</code> method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
     * @return a new <code>AffineTransform</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
     * inverse transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     * @see #getDeterminant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     * @exception NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     * if the matrix cannot be inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
    public AffineTransform createInverse()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2665
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
            return new AffineTransform( m11 / det, -m10 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                                       -m01 / det,  m00 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                                       (m01 * m12 - m11 * m02) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                                       (m10 * m02 - m00 * m12) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                                       (APPLY_SHEAR |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                                        APPLY_SCALE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                                        APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
            return new AffineTransform( m11 / det, -m10 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
                                       -m01 / det,  m00 / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
                                        0.0,        0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
                                       (APPLY_SHEAR | APPLY_SCALE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        case (APPLY_SHEAR | APPLY_TRANSLATE):
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
                                       -m12 / m10, -m02 / m01,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
                                       (APPLY_SHEAR | APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            if (m01 == 0.0 || m10 == 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(0.0,       1.0 / m01,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                                       1.0 / m10, 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                                       0.0,       0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                                       (APPLY_SHEAR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
        case (APPLY_SCALE | APPLY_TRANSLATE):
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
                                       -m02 / m00, -m12 / m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
                                       (APPLY_SCALE | APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
            if (m00 == 0.0 || m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            return new AffineTransform(1.0 / m00, 0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                                       0.0,       1.0 / m11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
                                       0.0,       0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
                                       (APPLY_SCALE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
            return new AffineTransform( 1.0,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
                                        0.0,  1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                                       -m02, -m12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                                       (APPLY_TRANSLATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            return new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * Sets this transform to the inverse of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * The inverse transform Tx' of this transform Tx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * maps coordinates transformed by Tx back
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * to their original coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * If this transform maps all coordinates onto a point or a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * then it will not have an inverse, since coordinates that do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * not lie on the destination point or line will not have an inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     * mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     * The <code>getDeterminant</code> method can be used to determine if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     * transform has no inverse, in which case an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     * thrown if the <code>invert</code> method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     * @see #getDeterminant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     * @exception NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * if the matrix cannot be inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
    public void invert()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        double M00, M01, M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        double M10, M11, M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2762
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            m00 =  M11 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            m10 = -M10 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            m01 = -M01 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
            m11 =  M00 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
            m02 = (M01 * M12 - M11 * M02) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
            m12 = (M10 * M02 - M00 * M12) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            m00 =  M11 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            m10 = -M10 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            m01 = -M01 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
            m11 =  M00 / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            // m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            m10 = 1.0 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            m01 = 1.0 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            // m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            m02 = -M12 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            m12 = -M02 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            // m00 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            m10 = 1.0 / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            m01 = 1.0 / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            // m11 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            m00 = 1.0 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            m11 = 1.0 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
            m02 = -M02 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            m12 = -M12 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            M00 = m00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            m00 = 1.0 / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            m11 = 1.0 / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
            // m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            // m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            m02 = -m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
            m12 = -m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
            // m00 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
            // m10 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
            // m01 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
            // m11 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
            // m02 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
            // m12 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
     * Transforms the specified <code>ptSrc</code> and stores the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
     * in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * If <code>ptDst</code> is <code>null</code>, a new {@link Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * object is allocated and then the result of the transformation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     * In either case, <code>ptDst</code>, which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * transformed point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * If <code>ptSrc</code> and <code>ptDst</code> are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     * object, the input point is correctly overwritten with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
     * the transformed point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     * @param ptSrc the specified <code>Point2D</code> to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
     * @param ptDst the specified <code>Point2D</code> that stores the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
     * result of transforming <code>ptSrc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
     * @return the <code>ptDst</code> after transforming
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
  2879
     * <code>ptSrc</code> and storing the result in <code>ptDst</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    public Point2D transform(Point2D ptSrc, Point2D ptDst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2897
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
            ptDst.setLocation(x * m00 + y * m01 + m02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                              x * m10 + y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            ptDst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            ptDst.setLocation(y * m01 + m02, x * m10 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            ptDst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            ptDst.setLocation(x * m00 + m02, y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
            ptDst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            ptDst.setLocation(x + m02, y + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     * Transforms an array of point objects by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * If any element of the <code>ptDst</code> array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * <code>null</code>, a new <code>Point2D</code> object is allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     * and stored into that element before storing the results of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     * transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     * Note that this method does not take any precautions to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     * avoid problems caused by storing results into <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * objects that will be used as the source for calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     * further down the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
     * This method does guarantee that if a specified <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * object is both the source and destination for the same single point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     * transform operation then the results will not be stored until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
     * the calculations are complete to avoid storing the results on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     * top of the operands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     * If, however, the destination <code>Point2D</code> object for one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * operation is the same object as the source <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * object for another operation further down the source array then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * the original coordinates in that point are overwritten before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     * they can be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     * @param ptSrc the array containing the source point objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
     * @param ptDst the array into which the transform point objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
     * @param srcOff the offset to the first point object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
     * transformed in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
     * transformed point object that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
    public void transform(Point2D[] ptSrc, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
                          Point2D[] ptDst, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
        int state = this.state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
            // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            Point2D src = ptSrc[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            double x = src.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            double y = src.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            Point2D dst = ptDst[dstOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                if (src instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
                    dst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                    dst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
                ptDst[dstOff - 1] = dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
                stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
                /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  2981
                return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
                dst.setLocation(x * m00 + y * m01 + m02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
                                x * m10 + y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
            case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                dst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
            case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                dst.setLocation(y * m01 + m02, x * m10 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
            case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                dst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
            case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                dst.setLocation(x * m00 + m02, y * m11 + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
            case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                dst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
            case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                dst.setLocation(x + m02, y + m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
            case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
                dst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * Transforms an array of floating point coordinates by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * This method ensures that no source coordinates are overwritten by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     * @param dstPts the array into which the transformed point coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * are returned.  Each point is stored as a pair of x,&nbsp;y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * @param numPts the number of points to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
    public void transform(float[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
                          float[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3057
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
                dstPts[dstOff++] = (float) (M00 * x + M01 * y + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
                dstPts[dstOff++] = (float) (M10 * x + M11 * y + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
                dstPts[dstOff++] = (float) (M00 * x + M01 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                dstPts[dstOff++] = (float) (M10 * x + M11 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
                dstPts[dstOff++] = (float) (M10 * x + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
                dstPts[dstOff++] = (float) (M10 * x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     * Transforms an array of double precision coordinates by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     * The coordinates are stored in the arrays starting at the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
    public void transform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
                          double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3172
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
                dstPts[dstOff++] = M00 * x + M01 * y + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
                dstPts[dstOff++] = M10 * x + M11 * y + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
                dstPts[dstOff++] = M00 * x + M01 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                dstPts[dstOff++] = M10 * x + M11 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
                dstPts[dstOff++] = M01 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
                dstPts[dstOff++] = M10 * x + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
                dstPts[dstOff++] = M01 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
                dstPts[dstOff++] = M10 * x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
                dstPts[dstOff++] = M00 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
                dstPts[dstOff++] = M11 * srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
                dstPts[dstOff++] = M00 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                dstPts[dstOff++] = M11 * srcPts[srcOff++];
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
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                dstPts[dstOff++] = srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                dstPts[dstOff++] = srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * Transforms an array of floating point coordinates by this transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     * and stores the results into an array of doubles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
     * @param dstPts the array into which the transformed point coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
     * are returned.  Each point is stored as a pair of x,&nbsp;y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
     * @param numPts the number of points to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
    public void transform(float[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                          double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3268
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
                dstPts[dstOff++] = M00 * x + M01 * y + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                dstPts[dstOff++] = M10 * x + M11 * y + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                dstPts[dstOff++] = M00 * x + M01 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                dstPts[dstOff++] = M10 * x + M11 * y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
                dstPts[dstOff++] = M01 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                dstPts[dstOff++] = M10 * x + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
                dstPts[dstOff++] = M01 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                dstPts[dstOff++] = M10 * x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                dstPts[dstOff++] = M00 * srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                dstPts[dstOff++] = M11 * 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_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                dstPts[dstOff++] = M00 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
                dstPts[dstOff++] = M11 * srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                dstPts[dstOff++] = srcPts[srcOff++] + M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                dstPts[dstOff++] = srcPts[srcOff++] + M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                dstPts[dstOff++] = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
                dstPts[dstOff++] = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * Transforms an array of double precision coordinates by this transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * and stores the results into an array of floats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
    public void transform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
                          float[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
                          int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3364
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
                dstPts[dstOff++] = (float) (M00 * x + M01 * y + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
                dstPts[dstOff++] = (float) (M10 * x + M11 * y + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
                dstPts[dstOff++] = (float) (M00 * x + M01 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
                dstPts[dstOff++] = (float) (M10 * x + M11 * y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
                dstPts[dstOff++] = (float) (M10 * x + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
                dstPts[dstOff++] = (float) (M01 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
                dstPts[dstOff++] = (float) (M10 * x);
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_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                dstPts[dstOff++] = (float) (M00 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                dstPts[dstOff++] = (float) (M11 * srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
                dstPts[dstOff++] = (float) (srcPts[srcOff++] + M12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
                dstPts[dstOff++] = (float) (srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
                dstPts[dstOff++] = (float) (srcPts[srcOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * Inverse transforms the specified <code>ptSrc</code> and stores the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     * result in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * If <code>ptDst</code> is <code>null</code>, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * <code>Point2D</code> object is allocated and then the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     * transform is stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     * In either case, <code>ptDst</code>, which contains the transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     * If <code>ptSrc</code> and <code>ptDst</code> are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     * object, the input point is correctly overwritten with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     * transformed point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
     * @param ptSrc the point to be inverse transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     * @param ptDst the resulting transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     * @return <code>ptDst</code>, which contains the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * inverse transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * @exception NoninvertibleTransformException  if the matrix cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     *                                         inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3454
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
    public Point2D inverseTransform(Point2D ptSrc, Point2D ptDst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
            /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
            double det = m00 * m11 - m01 * m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
            ptDst.setLocation((x * m11 - y * m01) / det,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                              (y * m00 - x * m10) / det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            if (m01 == 0.0 || m10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
            ptDst.setLocation(y / m10, x / m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
            x -= m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
            y -= m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
            /* NOBREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
            if (m00 == 0.0 || m11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
            ptDst.setLocation(x / m00, y / m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
            ptDst.setLocation(x - m02, y - m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
     * Inverse transforms an array of double precision coordinates by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
     * this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
     * The coordinates are stored in the arrays starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
     * @param srcPts the array containing the source point coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * Each point is stored as a pair of x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * @param dstPts the array into which the transformed point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * coordinates are returned.  Each point is stored as a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
     * @param srcOff the offset to the first point to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
     * transformed point that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
     * @param numPts the number of point objects to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
     * @exception NoninvertibleTransformException  if the matrix cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
     *                                         inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
    public void inverseTransform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
                                 double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
                                 int numPts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
        throws NoninvertibleTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
        double M00, M01, M02, M10, M11, M12;    // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
        double det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3566
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
            M00 = m00; M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
            M10 = m10; M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                double x = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                double y = srcPts[srcOff++] - M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
                dstPts[dstOff++] = (x * M11 - y * M01) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                dstPts[dstOff++] = (y * M00 - x * M10) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
            det = M00 * M11 - M01 * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
            if (Math.abs(det) <= Double.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
                throw new NoninvertibleTransformException("Determinant is "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                                                          det);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
                dstPts[dstOff++] = (x * M11 - y * M01) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
                dstPts[dstOff++] = (y * M00 - x * M10) / det;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
            M01 = m01; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
            M10 = m10; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
                double x = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
                dstPts[dstOff++] = (srcPts[srcOff++] - M12) / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
                dstPts[dstOff++] = x / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
            if (M01 == 0.0 || M10 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                dstPts[dstOff++] = srcPts[srcOff++] / M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                dstPts[dstOff++] = x / M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
            M00 = m00; M02 = m02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            M11 = m11; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
                dstPts[dstOff++] = (srcPts[srcOff++] - M02) / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
                dstPts[dstOff++] = (srcPts[srcOff++] - M12) / M11;
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_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
            if (M00 == 0.0 || M11 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                throw new NoninvertibleTransformException("Determinant is 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
                dstPts[dstOff++] = srcPts[srcOff++] / M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
                dstPts[dstOff++] = srcPts[srcOff++] / M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
            M02 = m02; M12 = m12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
                dstPts[dstOff++] = srcPts[srcOff++] - M02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
                dstPts[dstOff++] = srcPts[srcOff++] - M12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
     * Transforms the relative distance vector specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
     * <code>ptSrc</code> and stores the result in <code>ptDst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
     * A relative distance vector is transformed without applying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * translation components of the affine transformation matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     * using the following equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
     *  [  x' ]   [  m00  m01 (m02) ] [  x  ]   [ m00x + m01y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
     *  [  y' ] = [  m10  m11 (m12) ] [  y  ] = [ m10x + m11y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
     *  [ (1) ]   [  (0)  (0) ( 1 ) ] [ (1) ]   [     (1)     ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
     * If <code>ptDst</code> is <code>null</code>, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
     * <code>Point2D</code> object is allocated and then the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
     * transform is stored in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
     * In either case, <code>ptDst</code>, which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
     * transformed point, is returned for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
     * If <code>ptSrc</code> and <code>ptDst</code> are the same object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
     * the input point is correctly overwritten with the transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     * point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     * @param ptSrc the distance vector to be delta transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * @param ptDst the resulting transformed distance vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * @return <code>ptDst</code>, which contains the result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     * transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
    public Point2D deltaTransform(Point2D ptSrc, Point2D ptDst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
        if (ptDst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
            if (ptSrc instanceof Point2D.Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
                ptDst = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
                ptDst = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
        // Copy source coords into local variables in case src == dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
        double x = ptSrc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
        double y = ptSrc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3699
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
            ptDst.setLocation(x * m00 + y * m01, x * m10 + y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
            ptDst.setLocation(y * m01, x * m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
            ptDst.setLocation(x * m00, y * m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
            ptDst.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
            return ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     * Transforms an array of relative distance vectors by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     * transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
     * A relative distance vector is transformed without applying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     * translation components of the affine transformation matrix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
     * using the following equations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
     *  [  x' ]   [  m00  m01 (m02) ] [  x  ]   [ m00x + m01y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
     *  [  y' ] = [  m10  m11 (m12) ] [  y  ] = [ m10x + m11y ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
     *  [ (1) ]   [  (0)  (0) ( 1 ) ] [ (1) ]   [     (1)     ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
     * The two coordinate array sections can be exactly the same or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
     * can be overlapping sections of the same array without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
     * validity of the results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
     * This method ensures that no source coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
     * overwritten by a previous operation before they can be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
     * The coordinates are stored in the arrays starting at the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
     * offset in the order <code>[x0, y0, x1, y1, ..., xn, yn]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
     * @param srcPts the array containing the source distance vectors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
     * Each vector is stored as a pair of relative x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
     * @param dstPts the array into which the transformed distance vectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
     * are returned.  Each vector is stored as a pair of relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
     * x,&nbsp;y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
     * @param srcOff the offset to the first vector to be transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
     * in the source array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
     * @param dstOff the offset to the location of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
     * transformed vector that is stored in the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
     * @param numPts the number of vector coordinate pairs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
     * transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
    public void deltaTransform(double[] srcPts, int srcOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
                               double[] dstPts, int dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
                               int numPts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
        double M00, M01, M10, M11;      // For caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
        if (dstPts == srcPts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
            dstOff > srcOff && dstOff < srcOff + numPts * 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
            // If the arrays overlap partially with the destination higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
            // than the source and we transform the coordinates normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
            // we would overwrite some of the later source coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
            // with results of previous transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
            // To get around this we use arraycopy to copy the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
            // to their final destination with correct overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
            // handling and then transform them in place in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
            // safer location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
            System.arraycopy(srcPts, srcOff, dstPts, dstOff, numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
            // srcPts = dstPts;         // They are known to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
            srcOff = dstOff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
            stateError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
            /* NOTREACHED */
15994
5c8a3d840366 8007295: Reduce number of warnings in awt classes
mcherkas
parents: 10419
diff changeset
  3775
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
        case (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
        case (APPLY_SHEAR | APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
            M00 = m00; M01 = m01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
            M10 = m10; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
                double y = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
                dstPts[dstOff++] = x * M00 + y * M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                dstPts[dstOff++] = x * M10 + y * M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
        case (APPLY_SHEAR | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
        case (APPLY_SHEAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
            M01 = m01; M10 = m10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
                double x = srcPts[srcOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                dstPts[dstOff++] = srcPts[srcOff++] * M01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
                dstPts[dstOff++] = x * M10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
        case (APPLY_SCALE | APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
        case (APPLY_SCALE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
            M00 = m00; M11 = m11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
            while (--numPts >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
                dstPts[dstOff++] = srcPts[srcOff++] * M00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                dstPts[dstOff++] = srcPts[srcOff++] * M11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
        case (APPLY_TRANSLATE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
        case (APPLY_IDENTITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
            if (srcPts != dstPts || srcOff != dstOff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
                System.arraycopy(srcPts, srcOff, dstPts, dstOff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                                 numPts * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
        /* NOTREACHED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
     * Returns a new {@link Shape} object defined by the geometry of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
     * specified <code>Shape</code> after it has been transformed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
     * this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
     * @param pSrc the specified <code>Shape</code> object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
     * transformed by this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
     * @return a new <code>Shape</code> object that defines the geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
     * of the transformed <code>Shape</code>, or null if {@code pSrc} is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
    public Shape createTransformedShape(Shape pSrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
        if (pSrc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
        return new Path2D.Double(pSrc, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
    // Round values to sane precision for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
    // Note that Math.sin(Math.PI) has an error of about 10^-16
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
    private static double _matround(double matval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
        return Math.rint(matval * 1E15) / 1E15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
     * Returns a <code>String</code> that represents the value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
     * {@link Object}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
     * @return a <code>String</code> representing the value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
     * <code>Object</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        return ("AffineTransform[["
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
                + _matround(m00) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
                + _matround(m01) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
                + _matround(m02) + "], ["
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
                + _matround(m10) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
                + _matround(m11) + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
                + _matround(m12) + "]]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
     * Returns <code>true</code> if this <code>AffineTransform</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
     * an identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
     * @return <code>true</code> if this <code>AffineTransform</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
     * an identity transform; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
    public boolean isIdentity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
        return (state == APPLY_IDENTITY || (getType() == TYPE_IDENTITY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
     * Returns a copy of this <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
     * @return an <code>Object</code> that is a copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
     * <code>AffineTransform</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
            // this shouldn't happen, since we are Cloneable
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 7006
diff changeset
  3878
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
     * Returns the hashcode for this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
     * @return      a hash code for this transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
        long bits = Double.doubleToLongBits(m00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
        bits = bits * 31 + Double.doubleToLongBits(m01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
        bits = bits * 31 + Double.doubleToLongBits(m02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
        bits = bits * 31 + Double.doubleToLongBits(m10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
        bits = bits * 31 + Double.doubleToLongBits(m11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
        bits = bits * 31 + Double.doubleToLongBits(m12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
        return (((int) bits) ^ ((int) (bits >> 32)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
     * Returns <code>true</code> if this <code>AffineTransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
     * represents the same affine coordinate transform as the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
     * argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
     * @param obj the <code>Object</code> to test for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
     * <code>AffineTransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
     * @return <code>true</code> if <code>obj</code> equals this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
     * <code>AffineTransform</code> object; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
        if (!(obj instanceof AffineTransform)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
        AffineTransform a = (AffineTransform)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
        return ((m00 == a.m00) && (m01 == a.m01) && (m02 == a.m02) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
                (m10 == a.m10) && (m11 == a.m11) && (m12 == a.m12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
    /* Serialization support.  A readObject method is neccessary because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
     * the state field is part of the implementation of this particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
     * AffineTransform and not part of the public specification.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
     * state variable's value needs to be recalculated on the fly by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
     * readObject method as it is in the 6-argument matrix constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
     * JDK 1.2 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
    private static final long serialVersionUID = 1330973210523860834L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
        updateState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
}