diff options
Diffstat (limited to 'awt/java/awt/geom')
-rw-r--r-- | awt/java/awt/geom/AffineTransform.java | 1267 | ||||
-rw-r--r-- | awt/java/awt/geom/Arc2D.java | 1157 | ||||
-rw-r--r-- | awt/java/awt/geom/Area.java | 330 | ||||
-rw-r--r-- | awt/java/awt/geom/CubicCurve2D.java | 1047 | ||||
-rw-r--r-- | awt/java/awt/geom/Dimension2D.java | 83 | ||||
-rw-r--r-- | awt/java/awt/geom/Ellipse2D.java | 458 | ||||
-rw-r--r-- | awt/java/awt/geom/FlatteningPathIterator.java | 358 | ||||
-rw-r--r-- | awt/java/awt/geom/GeneralPath.java | 624 | ||||
-rw-r--r-- | awt/java/awt/geom/IllegalPathStateException.java | 55 | ||||
-rw-r--r-- | awt/java/awt/geom/Line2D.java | 948 | ||||
-rw-r--r-- | awt/java/awt/geom/NoninvertibleTransformException.java | 48 | ||||
-rw-r--r-- | awt/java/awt/geom/PathIterator.java | 146 | ||||
-rw-r--r-- | awt/java/awt/geom/Point2D.java | 323 | ||||
-rw-r--r-- | awt/java/awt/geom/QuadCurve2D.java | 918 | ||||
-rw-r--r-- | awt/java/awt/geom/Rectangle2D.java | 824 | ||||
-rw-r--r-- | awt/java/awt/geom/RectangularShape.java | 297 | ||||
-rw-r--r-- | awt/java/awt/geom/RoundRectangle2D.java | 635 | ||||
-rw-r--r-- | awt/java/awt/geom/package.html | 8 |
18 files changed, 0 insertions, 9526 deletions
diff --git a/awt/java/awt/geom/AffineTransform.java b/awt/java/awt/geom/AffineTransform.java deleted file mode 100644 index 8a6938c..0000000 --- a/awt/java/awt/geom/AffineTransform.java +++ /dev/null @@ -1,1267 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Shape; -import java.io.IOException; -import java.io.Serializable; - -import org.apache.harmony.awt.internal.nls.Messages; -import org.apache.harmony.misc.HashCode; - -/** - * The Class AffineTransform represents a linear transformation (rotation, - * scaling, or shear) followed by a translation that acts on a coordinate space. - * It preserves collinearity of points and ratios of distances between collinear - * points: so if A, B, and C are on a line, then after the space has been - * transformed via the affine transform, the images of the three points will - * still be on a line, and the ratio of the distance from A to B with the - * distance from B to C will be the same as the corresponding ratio in the image - * space. - * - * @since Android 1.0 - */ -public class AffineTransform implements Cloneable, Serializable { - - /** - * The Constant serialVersionUID. - */ - private static final long serialVersionUID = 1330973210523860834L; - - /** - * The Constant TYPE_IDENTITY. - */ - public static final int TYPE_IDENTITY = 0; - - /** - * The Constant TYPE_TRANSLATION. - */ - public static final int TYPE_TRANSLATION = 1; - - /** - * The Constant TYPE_UNIFORM_SCALE. - */ - public static final int TYPE_UNIFORM_SCALE = 2; - - /** - * The Constant TYPE_GENERAL_SCALE. - */ - public static final int TYPE_GENERAL_SCALE = 4; - - /** - * The Constant TYPE_QUADRANT_ROTATION. - */ - public static final int TYPE_QUADRANT_ROTATION = 8; - - /** - * The Constant TYPE_GENERAL_ROTATION. - */ - public static final int TYPE_GENERAL_ROTATION = 16; - - /** - * The Constant TYPE_GENERAL_TRANSFORM. - */ - public static final int TYPE_GENERAL_TRANSFORM = 32; - - /** - * The Constant TYPE_FLIP. - */ - public static final int TYPE_FLIP = 64; - - /** - * The Constant TYPE_MASK_SCALE. - */ - public static final int TYPE_MASK_SCALE = TYPE_UNIFORM_SCALE | TYPE_GENERAL_SCALE; - - /** - * The Constant TYPE_MASK_ROTATION. - */ - public static final int TYPE_MASK_ROTATION = TYPE_QUADRANT_ROTATION | TYPE_GENERAL_ROTATION; - - /** - * The <code>TYPE_UNKNOWN</code> is an initial type value. - */ - static final int TYPE_UNKNOWN = -1; - - /** - * The min value equivalent to zero. If absolute value less then ZERO it - * considered as zero. - */ - static final double ZERO = 1E-10; - - /** - * The values of transformation matrix. - */ - double m00; - - /** - * The m10. - */ - double m10; - - /** - * The m01. - */ - double m01; - - /** - * The m11. - */ - double m11; - - /** - * The m02. - */ - double m02; - - /** - * The m12. - */ - double m12; - - /** - * The transformation <code>type</code>. - */ - transient int type; - - /** - * Instantiates a new affine transform of type <code>TYPE_IDENTITY</code> - * (which leaves coordinates unchanged). - */ - public AffineTransform() { - type = TYPE_IDENTITY; - m00 = m11 = 1.0; - m10 = m01 = m02 = m12 = 0.0; - } - - /** - * Instantiates a new affine transform that has the same data as the given - * AffineTransform. - * - * @param t - * the transform to copy. - */ - public AffineTransform(AffineTransform t) { - this.type = t.type; - this.m00 = t.m00; - this.m10 = t.m10; - this.m01 = t.m01; - this.m11 = t.m11; - this.m02 = t.m02; - this.m12 = t.m12; - } - - /** - * Instantiates a new affine transform by specifying the values of the 2x3 - * transformation matrix as floats. The type is set to the default type: - * <code>TYPE_UNKNOWN</code> - * - * @param m00 - * the m00 entry in the transformation matrix. - * @param m10 - * the m10 entry in the transformation matrix. - * @param m01 - * the m01 entry in the transformation matrix. - * @param m11 - * the m11 entry in the transformation matrix. - * @param m02 - * the m02 entry in the transformation matrix. - * @param m12 - * the m12 entry in the transformation matrix. - */ - public AffineTransform(float m00, float m10, float m01, float m11, float m02, float m12) { - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - /** - * Instantiates a new affine transform by specifying the values of the 2x3 - * transformation matrix as doubles. The type is set to the default type: - * <code>TYPE_UNKNOWN</code> - * - * @param m00 - * the m00 entry in the transformation matrix. - * @param m10 - * the m10 entry in the transformation matrix. - * @param m01 - * the m01 entry in the transformation matrix. - * @param m11 - * the m11 entry in the transformation matrix. - * @param m02 - * the m02 entry in the transformation matrix. - * @param m12 - * the m12 entry in the transformation matrix. - */ - public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) { - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - /** - * Instantiates a new affine transform by reading the values of the - * transformation matrix from an array of floats. The mapping from the array - * to the matrix starts with <code>matrix[0]</code> giving the top-left - * entry of the matrix and proceeds with the usual left-to-right and - * top-down ordering. - * <p> - * If the array has only four entries, then the two entries of the last row - * of the transformation matrix default to zero. - * - * @param matrix - * the array of four or six floats giving the values of the - * matrix. - * @throws ArrayIndexOutOfBoundsException - * if the size of the array is 0, 1, 2, 3, or 5. - */ - public AffineTransform(float[] matrix) { - this.type = TYPE_UNKNOWN; - m00 = matrix[0]; - m10 = matrix[1]; - m01 = matrix[2]; - m11 = matrix[3]; - if (matrix.length > 4) { - m02 = matrix[4]; - m12 = matrix[5]; - } - } - - /** - * Instantiates a new affine transform by reading the values of the - * transformation matrix from an array of doubles. The mapping from the - * array to the matrix starts with <code>matrix[0]</code> giving the - * top-left entry of the matrix and proceeds with the usual left-to-right - * and top-down ordering. - * <p> - * If the array has only four entries, then the two entries of the last row - * of the transformation matrix default to zero. - * - * @param matrix - * the array of four or six doubles giving the values of the - * matrix. - * @throws ArrayIndexOutOfBoundsException - * if the size of the array is 0, 1, 2, 3, or 5. - */ - public AffineTransform(double[] matrix) { - this.type = TYPE_UNKNOWN; - m00 = matrix[0]; - m10 = matrix[1]; - m01 = matrix[2]; - m11 = matrix[3]; - if (matrix.length > 4) { - m02 = matrix[4]; - m12 = matrix[5]; - } - } - - /** - * Returns type of the affine transformation. - * <p> - * The type is computed as follows: Label the entries of the transformation - * matrix as three rows (m00, m01), (m10, m11), and (m02, m12). Then if the - * original basis vectors are (1, 0) and (0, 1), the new basis vectors after - * transformation are given by (m00, m01) and (m10, m11), and the - * translation vector is (m02, m12). - * <p> - * The types are classified as follows: <br/> TYPE_IDENTITY - no change<br/> - * TYPE_TRANSLATION - The translation vector isn't zero<br/> - * TYPE_UNIFORM_SCALE - The new basis vectors have equal length<br/> - * TYPE_GENERAL_SCALE - The new basis vectors dont' have equal length<br/> - * TYPE_FLIP - The new basis vector orientation differs from the original - * one<br/> TYPE_QUADRANT_ROTATION - The new basis is a rotation of the - * original by 90, 180, 270, or 360 degrees<br/> TYPE_GENERAL_ROTATION - The - * new basis is a rotation of the original by an arbitrary angle<br/> - * TYPE_GENERAL_TRANSFORM - The transformation can't be inverted.<br/> - * <p> - * Note that multiple types are possible, thus the types can be combined - * using bitwise combinations. - * - * @return the type of the Affine Transform. - */ - public int getType() { - if (type != TYPE_UNKNOWN) { - return type; - } - - int type = 0; - - if (m00 * m01 + m10 * m11 != 0.0) { - type |= TYPE_GENERAL_TRANSFORM; - return type; - } - - if (m02 != 0.0 || m12 != 0.0) { - type |= TYPE_TRANSLATION; - } else if (m00 == 1.0 && m11 == 1.0 && m01 == 0.0 && m10 == 0.0) { - type = TYPE_IDENTITY; - return type; - } - - if (m00 * m11 - m01 * m10 < 0.0) { - type |= TYPE_FLIP; - } - - double dx = m00 * m00 + m10 * m10; - double dy = m01 * m01 + m11 * m11; - if (dx != dy) { - type |= TYPE_GENERAL_SCALE; - } else if (dx != 1.0) { - type |= TYPE_UNIFORM_SCALE; - } - - if ((m00 == 0.0 && m11 == 0.0) || (m10 == 0.0 && m01 == 0.0 && (m00 < 0.0 || m11 < 0.0))) { - type |= TYPE_QUADRANT_ROTATION; - } else if (m01 != 0.0 || m10 != 0.0) { - type |= TYPE_GENERAL_ROTATION; - } - - return type; - } - - /** - * Gets the scale x entry of the transformation matrix (the upper left - * matrix entry). - * - * @return the scale x value. - */ - public double getScaleX() { - return m00; - } - - /** - * Gets the scale y entry of the transformation matrix (the lower right - * entry of the linear transformation). - * - * @return the scale y value. - */ - public double getScaleY() { - return m11; - } - - /** - * Gets the shear x entry of the transformation matrix (the upper right - * entry of the linear transformation). - * - * @return the shear x value. - */ - public double getShearX() { - return m01; - } - - /** - * Gets the shear y entry of the transformation matrix (the lower left entry - * of the linear transformation). - * - * @return the shear y value. - */ - public double getShearY() { - return m10; - } - - /** - * Gets the x coordinate of the translation vector. - * - * @return the x coordinate of the translation vector. - */ - public double getTranslateX() { - return m02; - } - - /** - * Gets the y coordinate of the translation vector. - * - * @return the y coordinate of the translation vector. - */ - public double getTranslateY() { - return m12; - } - - /** - * Checks if the AffineTransformation is the identity. - * - * @return true, if the AffineTransformation is the identity. - */ - public boolean isIdentity() { - return getType() == TYPE_IDENTITY; - } - - /** - * Writes the values of the transformation matrix into the given array of - * doubles. If the array has length 4, only the linear transformation part - * will be written into it. If it has length greater than 4, the translation - * vector will be included as well. - * - * @param matrix - * the array to fill with the values of the matrix. - * @throws ArrayIndexOutOfBoundsException - * if the size of the array is 0, 1, 2, 3, or 5. - */ - public void getMatrix(double[] matrix) { - matrix[0] = m00; - matrix[1] = m10; - matrix[2] = m01; - matrix[3] = m11; - if (matrix.length > 4) { - matrix[4] = m02; - matrix[5] = m12; - } - } - - /** - * Gets the determinant of the linear transformation matrix. - * - * @return the determinant of the linear transformation matrix. - */ - public double getDeterminant() { - return m00 * m11 - m01 * m10; - } - - /** - * Sets the transform in terms of a list of double values. - * - * @param m00 - * the m00 coordinate of the transformation matrix. - * @param m10 - * the m10 coordinate of the transformation matrix. - * @param m01 - * the m01 coordinate of the transformation matrix. - * @param m11 - * the m11 coordinate of the transformation matrix. - * @param m02 - * the m02 coordinate of the transformation matrix. - * @param m12 - * the m12 coordinate of the transformation matrix. - */ - public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12) { - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - /** - * Sets the transform's data to match the data of the transform sent as a - * parameter. - * - * @param t - * the transform that gives the new values. - */ - public void setTransform(AffineTransform t) { - type = t.type; - setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12); - } - - /** - * Sets the transform to the identity transform. - */ - public void setToIdentity() { - type = TYPE_IDENTITY; - m00 = m11 = 1.0; - m10 = m01 = m02 = m12 = 0.0; - } - - /** - * Sets the transformation to a translation alone. Sets the linear part of - * the transformation to identity and the translation vector to the values - * sent as parameters. Sets the type to <code>TYPE_IDENTITY</code> if the - * resulting AffineTransformation is the identity transformation, otherwise - * sets it to <code>TYPE_TRANSLATION</code>. - * - * @param mx - * the distance to translate in the x direction. - * @param my - * the distance to translate in the y direction. - */ - public void setToTranslation(double mx, double my) { - m00 = m11 = 1.0; - m01 = m10 = 0.0; - m02 = mx; - m12 = my; - if (mx == 0.0 && my == 0.0) { - type = TYPE_IDENTITY; - } else { - type = TYPE_TRANSLATION; - } - } - - /** - * Sets the transformation to being a scale alone, eliminating rotation, - * shear, and translation elements. Sets the type to - * <code>TYPE_IDENTITY</code> if the resulting AffineTransformation is the - * identity transformation, otherwise sets it to <code>TYPE_UNKNOWN</code>. - * - * @param scx - * the scaling factor in the x direction. - * @param scy - * the scaling factor in the y direction. - */ - public void setToScale(double scx, double scy) { - m00 = scx; - m11 = scy; - m10 = m01 = m02 = m12 = 0.0; - if (scx != 1.0 || scy != 1.0) { - type = TYPE_UNKNOWN; - } else { - type = TYPE_IDENTITY; - } - } - - /** - * Sets the transformation to being a shear alone, eliminating rotation, - * scaling, and translation elements. Sets the type to - * <code>TYPE_IDENTITY</code> if the resulting AffineTransformation is the - * identity transformation, otherwise sets it to <code>TYPE_UNKNOWN</code>. - * - * @param shx - * the shearing factor in the x direction. - * @param shy - * the shearing factor in the y direction. - */ - public void setToShear(double shx, double shy) { - m00 = m11 = 1.0; - m02 = m12 = 0.0; - m01 = shx; - m10 = shy; - if (shx != 0.0 || shy != 0.0) { - type = TYPE_UNKNOWN; - } else { - type = TYPE_IDENTITY; - } - } - - /** - * Sets the transformation to being a rotation alone, eliminating shearing, - * scaling, and translation elements. Sets the type to - * <code>TYPE_IDENTITY</code> if the resulting AffineTransformation is the - * identity transformation, otherwise sets it to <code>TYPE_UNKNOWN</code>. - * - * @param angle - * the angle of rotation in radians. - */ - public void setToRotation(double angle) { - double sin = Math.sin(angle); - double cos = Math.cos(angle); - if (Math.abs(cos) < ZERO) { - cos = 0.0; - sin = sin > 0.0 ? 1.0 : -1.0; - } else if (Math.abs(sin) < ZERO) { - sin = 0.0; - cos = cos > 0.0 ? 1.0 : -1.0; - } - m00 = m11 = cos; - m01 = -sin; - m10 = sin; - m02 = m12 = 0.0; - type = TYPE_UNKNOWN; - } - - /** - * Sets the transformation to being a rotation followed by a translation. - * Sets the type to <code>TYPE_UNKNOWN</code>. - * - * @param angle - * the angle of rotation in radians. - * @param px - * the distance to translate in the x direction. - * @param py - * the distance to translate in the y direction. - */ - public void setToRotation(double angle, double px, double py) { - setToRotation(angle); - m02 = px * (1.0 - m00) + py * m10; - m12 = py * (1.0 - m00) - px * m10; - type = TYPE_UNKNOWN; - } - - /** - * Creates a new AffineTransformation that is a translation alone with the - * translation vector given by the values sent as parameters. The new - * transformation's type is <code>TYPE_IDENTITY</code> if the - * AffineTransformation is the identity transformation, otherwise it's - * <code>TYPE_TRANSLATION</code>. - * - * @param mx - * the distance to translate in the x direction. - * @param my - * the distance to translate in the y direction. - * @return the new AffineTransformation. - */ - public static AffineTransform getTranslateInstance(double mx, double my) { - AffineTransform t = new AffineTransform(); - t.setToTranslation(mx, my); - return t; - } - - /** - * Creates a new AffineTransformation that is a scale alone. The new - * transformation's type is <code>TYPE_IDENTITY</code> if the - * AffineTransformation is the identity transformation, otherwise it's - * <code>TYPE_UNKNOWN</code>. - * - * @param scx - * the scaling factor in the x direction. - * @param scY - * the scaling factor in the y direction. - * @return the new AffineTransformation. - */ - public static AffineTransform getScaleInstance(double scx, double scY) { - AffineTransform t = new AffineTransform(); - t.setToScale(scx, scY); - return t; - } - - /** - * Creates a new AffineTransformation that is a shear alone. The new - * transformation's type is <code>TYPE_IDENTITY</code> if the - * AffineTransformation is the identity transformation, otherwise it's - * <code>TYPE_UNKNOWN</code>. - * - * @param shx - * the shearing factor in the x direction. - * @param shy - * the shearing factor in the y direction. - * @return the new AffineTransformation. - */ - public static AffineTransform getShearInstance(double shx, double shy) { - AffineTransform m = new AffineTransform(); - m.setToShear(shx, shy); - return m; - } - - /** - * Creates a new AffineTransformation that is a rotation alone. The new - * transformation's type is <code>TYPE_IDENTITY</code> if the - * AffineTransformation is the identity transformation, otherwise it's - * <code>TYPE_UNKNOWN</code>. - * - * @param angle - * the angle of rotation in radians. - * @return the new AffineTransformation. - */ - public static AffineTransform getRotateInstance(double angle) { - AffineTransform t = new AffineTransform(); - t.setToRotation(angle); - return t; - } - - /** - * Creates a new AffineTransformation that is a rotation followed by a - * translation. Sets the type to <code>TYPE_UNKNOWN</code>. - * - * @param angle - * the angle of rotation in radians. - * @param x - * the distance to translate in the x direction. - * @param y - * the distance to translate in the y direction. - * @return the new AffineTransformation. - */ - public static AffineTransform getRotateInstance(double angle, double x, double y) { - AffineTransform t = new AffineTransform(); - t.setToRotation(angle, x, y); - return t; - } - - /** - * Applies a translation to this AffineTransformation. - * - * @param mx - * the distance to translate in the x direction. - * @param my - * the distance to translate in the y direction. - */ - public void translate(double mx, double my) { - concatenate(AffineTransform.getTranslateInstance(mx, my)); - } - - /** - * Applies a scaling transformation to this AffineTransformation. - * - * @param scx - * the scaling factor in the x direction. - * @param scy - * the scaling factor in the y direction. - */ - public void scale(double scx, double scy) { - concatenate(AffineTransform.getScaleInstance(scx, scy)); - } - - /** - * Applies a shearing transformation to this AffineTransformation. - * - * @param shx - * the shearing factor in the x direction. - * @param shy - * the shearing factor in the y direction. - */ - public void shear(double shx, double shy) { - concatenate(AffineTransform.getShearInstance(shx, shy)); - } - - /** - * Applies a rotation transformation to this AffineTransformation. - * - * @param angle - * the angle of rotation in radians. - */ - public void rotate(double angle) { - concatenate(AffineTransform.getRotateInstance(angle)); - } - - /** - * Applies a rotation and translation transformation to this - * AffineTransformation. - * - * @param angle - * the angle of rotation in radians. - * @param px - * the distance to translate in the x direction. - * @param py - * the distance to translate in the y direction. - */ - public void rotate(double angle, double px, double py) { - concatenate(AffineTransform.getRotateInstance(angle, px, py)); - } - - /** - * Multiplies the matrix representations of two AffineTransform objects. - * - * @param t1 - * - the AffineTransform object is a multiplicand - * @param t2 - * - the AffineTransform object is a multiplier - * @return an AffineTransform object that is the result of t1 multiplied by - * the matrix t2. - */ - AffineTransform multiply(AffineTransform t1, AffineTransform t2) { - return new AffineTransform(t1.m00 * t2.m00 + t1.m10 * t2.m01, // m00 - t1.m00 * t2.m10 + t1.m10 * t2.m11, // m01 - t1.m01 * t2.m00 + t1.m11 * t2.m01, // m10 - t1.m01 * t2.m10 + t1.m11 * t2.m11, // m11 - t1.m02 * t2.m00 + t1.m12 * t2.m01 + t2.m02, // m02 - t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12);// m12 - } - - /** - * Applies the given AffineTransform to this AffineTransform via matrix - * multiplication. - * - * @param t - * the AffineTransform to apply to this AffineTransform. - */ - public void concatenate(AffineTransform t) { - setTransform(multiply(t, this)); - } - - /** - * Changes the current AffineTransform the one obtained by taking the - * transform t and applying this AffineTransform to it. - * - * @param t - * the AffineTransform that this AffineTransform is multiplied - * by. - */ - public void preConcatenate(AffineTransform t) { - setTransform(multiply(this, t)); - } - - /** - * Creates an AffineTransform that is the inverse of this transform. - * - * @return the affine transform that is the inverse of this AffineTransform. - * @throws NoninvertibleTransformException - * if this AffineTransform cannot be inverted (the determinant - * of the linear transformation part is zero). - */ - public AffineTransform createInverse() throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ - } - return new AffineTransform(m11 / det, // m00 - -m10 / det, // m10 - -m01 / det, // m01 - m00 / det, // m11 - (m01 * m12 - m11 * m02) / det, // m02 - (m10 * m02 - m00 * m12) / det // m12 - ); - } - - /** - * Apply the current AffineTransform to the point. - * - * @param src - * the original point. - * @param dst - * Point2D object to be filled with the destination coordinates - * (where the original point is sent by this AffineTransform). - * May be null. - * @return the point in the AffineTransform's image space where the original - * point is sent. - */ - public Point2D transform(Point2D src, Point2D dst) { - if (dst == null) { - if (src instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } - } - - double x = src.getX(); - double y = src.getY(); - - dst.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); - return dst; - } - - /** - * Applies this AffineTransform to an array of points. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length > src.length</code> or - * <code>dstOff + length > dst.length</code>. - */ - public void transform(Point2D[] src, int srcOff, Point2D[] dst, int dstOff, int length) { - while (--length >= 0) { - Point2D srcPoint = src[srcOff++]; - double x = srcPoint.getX(); - double y = srcPoint.getY(); - Point2D dstPoint = dst[dstOff]; - if (dstPoint == null) { - if (srcPoint instanceof Point2D.Double) { - dstPoint = new Point2D.Double(); - } else { - dstPoint = new Point2D.Float(); - } - } - dstPoint.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); - dst[dstOff++] = dstPoint; - } - } - - /** - * Applies this AffineTransform to a set of points given as an array of - * double values where every two values in the array give the coordinates of - * a point; the even-indexed values giving the x coordinates and the - * odd-indexed values giving the y coordinates. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - */ - public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length) { - int step = 2; - if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { - srcOff = srcOff + length * 2 - 2; - dstOff = dstOff + length * 2 - 2; - step = -2; - } - while (--length >= 0) { - double x = src[srcOff + 0]; - double y = src[srcOff + 1]; - dst[dstOff + 0] = x * m00 + y * m01 + m02; - dst[dstOff + 1] = x * m10 + y * m11 + m12; - srcOff += step; - dstOff += step; - } - } - - /** - * Applies this AffineTransform to a set of points given as an array of - * float values where every two values in the array give the coordinates of - * a point; the even-indexed values giving the x coordinates and the - * odd-indexed values giving the y coordinates. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - */ - public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) { - int step = 2; - if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { - srcOff = srcOff + length * 2 - 2; - dstOff = dstOff + length * 2 - 2; - step = -2; - } - while (--length >= 0) { - float x = src[srcOff + 0]; - float y = src[srcOff + 1]; - dst[dstOff + 0] = (float)(x * m00 + y * m01 + m02); - dst[dstOff + 1] = (float)(x * m10 + y * m11 + m12); - srcOff += step; - dstOff += step; - } - } - - /** - * Applies this AffineTransform to a set of points given as an array of - * float values where every two values in the array give the coordinates of - * a point; the even-indexed values giving the x coordinates and the - * odd-indexed values giving the y coordinates. The destination coordinates - * are given as values of type <code>double</code>. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - */ - public void transform(float[] src, int srcOff, double[] dst, int dstOff, int length) { - while (--length >= 0) { - float x = src[srcOff++]; - float y = src[srcOff++]; - dst[dstOff++] = x * m00 + y * m01 + m02; - dst[dstOff++] = x * m10 + y * m11 + m12; - } - } - - /** - * Applies this AffineTransform to a set of points given as an array of - * double values where every two values in the array give the coordinates of - * a point; the even-indexed values giving the x coordinates and the - * odd-indexed values giving the y coordinates. The destination coordinates - * are given as values of type <code>float</code>. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - */ - public void transform(double[] src, int srcOff, float[] dst, int dstOff, int length) { - while (--length >= 0) { - double x = src[srcOff++]; - double y = src[srcOff++]; - dst[dstOff++] = (float)(x * m00 + y * m01 + m02); - dst[dstOff++] = (float)(x * m10 + y * m11 + m12); - } - } - - /** - * Transforms the point according to the linear transformation part of this - * AffineTransformation (without applying the translation). - * - * @param src - * the original point. - * @param dst - * the point object where the result of the delta transform is - * written. - * @return the result of applying the delta transform (linear part only) to - * the original point. - */ - // TODO: is this right? if dst is null, we check what it's an - // instance of? Shouldn't it be src instanceof Point2D.Double? - public Point2D deltaTransform(Point2D src, Point2D dst) { - if (dst == null) { - if (dst instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } - } - - double x = src.getX(); - double y = src.getY(); - - dst.setLocation(x * m00 + y * m01, x * m10 + y * m11); - return dst; - } - - /** - * Applies the linear transformation part of this AffineTransform (ignoring - * the translation part) to a set of points given as an array of double - * values where every two values in the array give the coordinates of a - * point; the even-indexed values giving the x coordinates and the - * odd-indexed values giving the y coordinates. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the delta transformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - */ - public void deltaTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) { - while (--length >= 0) { - double x = src[srcOff++]; - double y = src[srcOff++]; - dst[dstOff++] = x * m00 + y * m01; - dst[dstOff++] = x * m10 + y * m11; - } - } - - /** - * Transforms the point according to the inverse of this - * AffineTransformation. - * - * @param src - * the original point. - * @param dst - * the point object where the result of the inverse transform is - * written (may be null). - * @return the result of applying the inverse transform. Inverse transform. - * @throws NoninvertibleTransformException - * if this AffineTransform cannot be inverted (the determinant - * of the linear transformation part is zero). - */ - public Point2D inverseTransform(Point2D src, Point2D dst) - throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ - } - - if (dst == null) { - if (src instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } - } - - double x = src.getX() - m02; - double y = src.getY() - m12; - - dst.setLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det); - return dst; - } - - /** - * Applies the inverse of this AffineTransform to a set of points given as - * an array of double values where every two values in the array give the - * coordinates of a point; the even-indexed values giving the x coordinates - * and the odd-indexed values giving the y coordinates. - * - * @param src - * the array of points to be transformed. - * @param srcOff - * the offset in the source point array of the first point to be - * transformed. - * @param dst - * the point array where the images of the points (after applying - * the inverse of the AffineTransformation) should be placed. - * @param dstOff - * the offset in the destination array where the new values - * should be written. - * @param length - * the number of points to transform. - * @throws ArrayIndexOutOfBoundsException - * if <code>srcOff + length*2 > src.length</code> or - * <code>dstOff + length*2 > dst.length</code>. - * @throws NoninvertibleTransformException - * if this AffineTransform cannot be inverted (the determinant - * of the linear transformation part is zero). - */ - public void inverseTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) - throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ - } - - while (--length >= 0) { - double x = src[srcOff++] - m02; - double y = src[srcOff++] - m12; - dst[dstOff++] = (x * m11 - y * m01) / det; - dst[dstOff++] = (y * m00 - x * m10) / det; - } - } - - /** - * Creates a new shape whose data is given by applying this AffineTransform - * to the specified shape. - * - * @param src - * the original shape whose data is to be transformed. - * @return the new shape found by applying this AffineTransform to the - * original shape. - */ - public Shape createTransformedShape(Shape src) { - if (src == null) { - return null; - } - if (src instanceof GeneralPath) { - return ((GeneralPath)src).createTransformedShape(this); - } - PathIterator path = src.getPathIterator(this); - GeneralPath dst = new GeneralPath(path.getWindingRule()); - dst.append(path, false); - return dst; - } - - @Override - public String toString() { - return getClass().getName() + "[[" + m00 + ", " + m01 + ", " + m02 + "], [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + m10 + ", " + m11 + ", " + m12 + "]]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - - @Override - public int hashCode() { - HashCode hash = new HashCode(); - hash.append(m00); - hash.append(m01); - hash.append(m02); - hash.append(m10); - hash.append(m11); - hash.append(m12); - return hash.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof AffineTransform) { - AffineTransform t = (AffineTransform)obj; - return m00 == t.m00 && m01 == t.m01 && m02 == t.m02 && m10 == t.m10 && m11 == t.m11 - && m12 == t.m12; - } - return false; - } - - /** - * Writes the AffineTrassform object to the output steam. - * - * @param stream - * - the output stream. - * @throws IOException - * - if there are I/O errors while writing to the output stream. - */ - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - } - - /** - * Read the AffineTransform object from the input stream. - * - * @param stream - * - the input stream. - * @throws IOException - * - if there are I/O errors while reading from the input - * stream. - * @throws ClassNotFoundException - * - if class could not be found. - */ - private void readObject(java.io.ObjectInputStream stream) throws IOException, - ClassNotFoundException { - stream.defaultReadObject(); - type = TYPE_UNKNOWN; - } - -} diff --git a/awt/java/awt/geom/Arc2D.java b/awt/java/awt/geom/Arc2D.java deleted file mode 100644 index 56f5cd3..0000000 --- a/awt/java/awt/geom/Arc2D.java +++ /dev/null @@ -1,1157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class Arc2D represents a segment of a curve inscribed in a rectangle. The - * curve is defined by a start angle and an extent angle (the end angle minus - * the start angle) as a pie wedge whose point is in the center of the - * rectangle. The Arc2D as a shape may be either OPEN (including nothing but the - * curved arc segment itself), CHORD (the curved arc segment closed by a - * connecting segment from the end to the beginning of the arc, or PIE (the - * segments from the end of the arc to the center of the rectangle and from the - * center of the rectangle back to the arc's start point are included). - * - * @since Android 1.0 - */ -public abstract class Arc2D extends RectangularShape { - - /** - * The arc type OPEN indicates that the shape includes only the curved arc - * segment. - */ - public final static int OPEN = 0; - - /** - * The arc type CHORD indicates that as a shape the connecting segment from - * the end point of the curved arc to the beginning point is included. - */ - public final static int CHORD = 1; - - /** - * The arc type PIE indicates that as a shape the two segments from the - * arc's endpoint to the center of the rectangle and from the center of the - * rectangle to the arc's endpoint are included. - */ - public final static int PIE = 2; - - /** - * The Class Float is a subclass of Arc2D in which all of the data values - * are given as floats. - * - * @see Arc2D.Double - * @since Android 1.0 - */ - public static class Float extends Arc2D { - - /** - * The x coordinate of the upper left corner of the rectangle that - * contains the arc. - */ - public float x; - - /** - * The y coordinate of the upper left corner of the rectangle that - * contains the arc. - */ - public float y; - - /** - * The width of the rectangle that contains the arc. - */ - public float width; - - /** - * The height of the rectangle that contains the arc. - */ - public float height; - - /** - * The start angle of the arc in degrees. - */ - public float start; - - /** - * The width angle of the arc in degrees. - */ - public float extent; - - /** - * Instantiates a new Arc2D of type OPEN with float values. - */ - public Float() { - super(OPEN); - } - - /** - * Instantiates a new Arc2D of the specified type with float values. - * - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Float(int type) { - super(type); - } - - /** - * Instantiates a Arc2D with the specified float-valued data. - * - * @param x - * the x coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param y - * the y coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param width - * the width of the rectangle that contains the arc. - * @param height - * the height of the rectangle that contains the arc. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the width angle of the arc in degrees. - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Float(float x, float y, float width, float height, float start, float extent, - int type) { - super(type); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.start = start; - this.extent = extent; - } - - /** - * Instantiates a new Angle2D with the specified float-valued data and - * the bounding rectangle given by the parameter bounds. - * - * @param bounds - * the bounding rectangle of the Angle2D. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the width angle of the arc in degrees. - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Float(Rectangle2D bounds, float start, float extent, int type) { - super(type); - this.x = (float)bounds.getX(); - this.y = (float)bounds.getY(); - this.width = (float)bounds.getWidth(); - this.height = (float)bounds.getHeight(); - this.start = start; - this.extent = extent; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public double getAngleStart() { - return start; - } - - @Override - public double getAngleExtent() { - return extent; - } - - @Override - public boolean isEmpty() { - return width <= 0.0f || height <= 0.0f; - } - - @Override - public void setArc(double x, double y, double width, double height, double start, - double extent, int type) { - this.setArcType(type); - this.x = (float)x; - this.y = (float)y; - this.width = (float)width; - this.height = (float)height; - this.start = (float)start; - this.extent = (float)extent; - } - - @Override - public void setAngleStart(double start) { - this.start = (float)start; - } - - @Override - public void setAngleExtent(double extent) { - this.extent = (float)extent; - } - - @Override - protected Rectangle2D makeBounds(double x, double y, double width, double height) { - return new Rectangle2D.Float((float)x, (float)y, (float)width, (float)height); - } - - } - - /** - * The Class Double is a subclass of Arc2D in which all of the data values - * are given as doubles. - * - * @see Arc2D.Float - * @since Android 1.0 - */ - public static class Double extends Arc2D { - - /** - * The x coordinate of the upper left corner of the rectangle that - * contains the arc. - */ - public double x; - - /** - * The y coordinate of the upper left corner of the rectangle that - * contains the arc. - */ - public double y; - - /** - * The width of the rectangle that contains the arc. - */ - public double width; - - /** - * The height of the rectangle that contains the arc. - */ - public double height; - - /** - * The start angle of the arc in degrees. - */ - public double start; - - /** - * The width angle of the arc in degrees. - */ - public double extent; - - /** - * Instantiates a new Arc2D of type OPEN with double values. - */ - public Double() { - super(OPEN); - } - - /** - * Instantiates a new Arc2D of the specified type with double values. - * - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Double(int type) { - super(type); - } - - /** - * Instantiates a Arc2D with the specified double-valued data. - * - * @param x - * the x coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param y - * the y coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param width - * the width of the rectangle that contains the arc. - * @param height - * the height of the rectangle that contains the arc. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the width angle of the arc in degrees. - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Double(double x, double y, double width, double height, double start, double extent, - int type) { - super(type); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.start = start; - this.extent = extent; - } - - /** - * Instantiates a new Angle2D with the specified float-valued data and - * the bounding rectangle given by the parameter bounds. - * - * @param bounds - * the bounding rectangle of the Angle2D. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the width angle of the arc in degrees. - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public Double(Rectangle2D bounds, double start, double extent, int type) { - super(type); - this.x = bounds.getX(); - this.y = bounds.getY(); - this.width = bounds.getWidth(); - this.height = bounds.getHeight(); - this.start = start; - this.extent = extent; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public double getAngleStart() { - return start; - } - - @Override - public double getAngleExtent() { - return extent; - } - - @Override - public boolean isEmpty() { - return width <= 0.0 || height <= 0.0; - } - - @Override - public void setArc(double x, double y, double width, double height, double start, - double extent, int type) { - this.setArcType(type); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.start = start; - this.extent = extent; - } - - @Override - public void setAngleStart(double start) { - this.start = start; - } - - @Override - public void setAngleExtent(double extent) { - this.extent = extent; - } - - @Override - protected Rectangle2D makeBounds(double x, double y, double width, double height) { - return new Rectangle2D.Double(x, y, width, height); - } - - } - - /** - * The Class Iterator is the subclass of PathIterator that is used to - * traverse the boundary of a shape of type Arc2D. - */ - class Iterator implements PathIterator { - - /** - * The x coordinate of the center of the arc's bounding rectangle. - */ - double x; - - /** - * The y coordinate of the center of the arc's bounding rectangle. - */ - double y; - - /** - * Half of the width of the arc's bounding rectangle (the radius in the - * case of a circular arc). - */ - double width; - - /** - * Half of the height of the arc's bounding rectangle (the radius in the - * case of a circular arc). - */ - double height; - - /** - * The start angle of the arc in degrees. - */ - double angle; - - /** - * The angle extent in degrees. - */ - double extent; - - /** - * The closure type of the arc. - */ - int type; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * The number of arc segments the source arc subdivided to be - * approximated by Bezier curves. Depends on extent value. - */ - int arcCount; - - /** - * The number of line segments. Depends on closure type. - */ - int lineCount; - - /** - * The step to calculate next arc subdivision point. - */ - double step; - - /** - * The temporary value of cosinus of the current angle. - */ - double cos; - - /** - * The temporary value of sinus of the current angle. - */ - double sin; - - /** The coefficient to calculate control points of Bezier curves. */ - double k; - - /** - * The temporary value of x coordinate of the Bezier curve control - * vector. - */ - double kx; - - /** - * The temporary value of y coordinate of the Bezier curve control - * vector. - */ - double ky; - - /** - * The x coordinate of the first path point (MOVE_TO). - */ - double mx; - - /** - * The y coordinate of the first path point (MOVE_TO). - */ - double my; - - /** - * Constructs a new Arc2D.Iterator for given line and transformation - * - * @param a - * the source Arc2D object. - * @param t - * the AffineTransformation. - */ - Iterator(Arc2D a, AffineTransform t) { - if (width < 0 || height < 0) { - arcCount = 0; - lineCount = 0; - index = 1; - return; - } - - this.width = a.getWidth() / 2.0; - this.height = a.getHeight() / 2.0; - this.x = a.getX() + width; - this.y = a.getY() + height; - this.angle = -Math.toRadians(a.getAngleStart()); - this.extent = -a.getAngleExtent(); - this.type = a.getArcType(); - this.t = t; - - if (Math.abs(extent) >= 360.0) { - arcCount = 4; - k = 4.0 / 3.0 * (Math.sqrt(2.0) - 1.0); - step = Math.PI / 2.0; - if (extent < 0.0) { - step = -step; - k = -k; - } - } else { - arcCount = (int)Math.rint(Math.abs(extent) / 90.0); - step = Math.toRadians(extent / arcCount); - k = 4.0 / 3.0 * (1.0 - Math.cos(step / 2.0)) / Math.sin(step / 2.0); - } - - lineCount = 0; - if (type == Arc2D.CHORD) { - lineCount++; - } else if (type == Arc2D.PIE) { - lineCount += 2; - } - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > arcCount + lineCount; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - count = 1; - cos = Math.cos(angle); - sin = Math.sin(angle); - kx = k * width * sin; - ky = k * height * cos; - coords[0] = mx = x + cos * width; - coords[1] = my = y + sin * height; - } else if (index <= arcCount) { - type = SEG_CUBICTO; - count = 3; - coords[0] = mx - kx; - coords[1] = my + ky; - angle += step; - cos = Math.cos(angle); - sin = Math.sin(angle); - kx = k * width * sin; - ky = k * height * cos; - coords[4] = mx = x + cos * width; - coords[5] = my = y + sin * height; - coords[2] = mx + kx; - coords[3] = my - ky; - } else if (index == arcCount + lineCount) { - type = SEG_CLOSE; - count = 0; - } else { - type = SEG_LINETO; - count = 1; - coords[0] = x; - coords[1] = y; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - count = 1; - cos = Math.cos(angle); - sin = Math.sin(angle); - kx = k * width * sin; - ky = k * height * cos; - coords[0] = (float)(mx = x + cos * width); - coords[1] = (float)(my = y + sin * height); - } else if (index <= arcCount) { - type = SEG_CUBICTO; - count = 3; - coords[0] = (float)(mx - kx); - coords[1] = (float)(my + ky); - angle += step; - cos = Math.cos(angle); - sin = Math.sin(angle); - kx = k * width * sin; - ky = k * height * cos; - coords[4] = (float)(mx = x + cos * width); - coords[5] = (float)(my = y + sin * height); - coords[2] = (float)(mx + kx); - coords[3] = (float)(my - ky); - } else if (index == arcCount + lineCount) { - type = SEG_CLOSE; - count = 0; - } else { - type = SEG_LINETO; - count = 1; - coords[0] = (float)x; - coords[1] = (float)y; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - } - - /** - * The closure type of the arc. - */ - private int type; - - /** - * Instantiates a new arc2D. - * - * @param type - * the closure type. - */ - protected Arc2D(int type) { - setArcType(type); - } - - /** - * Takes the double-valued data and creates the corresponding Rectangle2D - * object with values either of type float or of type double depending on - * whether this Arc2D instance is of type Float or Double. - * - * @param x - * the x coordinate of the upper left corner of the bounding - * rectangle. - * @param y - * the y coordinate of the upper left corner of the bounding - * rectangle. - * @param width - * the width of the bounding rectangle. - * @param height - * the height of the bounding rectangle. - * @return the corresponding Rectangle2D object. - */ - protected abstract Rectangle2D makeBounds(double x, double y, double width, double height); - - /** - * Gets the start angle. - * - * @return the start angle. - */ - public abstract double getAngleStart(); - - /** - * Gets the width angle. - * - * @return the width angle. - */ - public abstract double getAngleExtent(); - - /** - * Sets the start angle. - * - * @param start - * the new start angle. - */ - public abstract void setAngleStart(double start); - - /** - * Sets the width angle. - * - * @param extent - * the new width angle. - */ - public abstract void setAngleExtent(double extent); - - /** - * Sets the data values that define the arc. - * - * @param x - * the x coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param y - * the y coordinate of the upper left corner of the rectangle - * that contains the arc. - * @param width - * the width of the rectangle that contains the arc. - * @param height - * the height of the rectangle that contains the arc. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the width angle of the arc in degrees. - * @param type - * the type of the new Arc2D, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public abstract void setArc(double x, double y, double width, double height, double start, - double extent, int type); - - /** - * Gets the arc type, either {@link Arc2D#OPEN}, {@link Arc2D#CHORD}, or - * {@link Arc2D#PIE}. - * - * @return the arc type. - */ - public int getArcType() { - return type; - } - - /** - * Sets the arc type, either {@link Arc2D#OPEN}, {@link Arc2D#CHORD}, or - * {@link Arc2D#PIE}. - * - * @param type - * the new arc type. - */ - public void setArcType(int type) { - if (type != OPEN && type != CHORD && type != PIE) { - // awt.205=Invalid type of Arc: {0} - throw new IllegalArgumentException(Messages.getString("awt.205", type)); //$NON-NLS-1$ - } - this.type = type; - } - - /** - * Gets the start point of the arc as a Point2D. - * - * @return the start point of the curved arc segment. - */ - public Point2D getStartPoint() { - double a = Math.toRadians(getAngleStart()); - return new Point2D.Double(getX() + (1.0 + Math.cos(a)) * getWidth() / 2.0, getY() - + (1.0 - Math.sin(a)) * getHeight() / 2.0); - } - - /** - * Gets the end point of the arc as a Point2D. - * - * @return the end point of the curved arc segment. - */ - public Point2D getEndPoint() { - double a = Math.toRadians(getAngleStart() + getAngleExtent()); - return new Point2D.Double(getX() + (1.0 + Math.cos(a)) * getWidth() / 2.0, getY() - + (1.0 - Math.sin(a)) * getHeight() / 2.0); - } - - public Rectangle2D getBounds2D() { - if (isEmpty()) { - return makeBounds(getX(), getY(), getWidth(), getHeight()); - } - double rx1 = getX(); - double ry1 = getY(); - double rx2 = rx1 + getWidth(); - double ry2 = ry1 + getHeight(); - - Point2D p1 = getStartPoint(); - Point2D p2 = getEndPoint(); - - double bx1 = containsAngle(180.0) ? rx1 : Math.min(p1.getX(), p2.getX()); - double by1 = containsAngle(90.0) ? ry1 : Math.min(p1.getY(), p2.getY()); - double bx2 = containsAngle(0.0) ? rx2 : Math.max(p1.getX(), p2.getX()); - double by2 = containsAngle(270.0) ? ry2 : Math.max(p1.getY(), p2.getY()); - - if (type == PIE) { - double cx = getCenterX(); - double cy = getCenterY(); - bx1 = Math.min(bx1, cx); - by1 = Math.min(by1, cy); - bx2 = Math.max(bx2, cx); - by2 = Math.max(by2, cy); - } - return makeBounds(bx1, by1, bx2 - bx1, by2 - by1); - } - - @Override - public void setFrame(double x, double y, double width, double height) { - setArc(x, y, width, height, getAngleStart(), getAngleExtent(), type); - } - - /** - * Sets the data that defines the arc. - * - * @param point - * the upper left corner of the bounding rectangle. - * @param size - * the size of the bounding rectangle. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the angle width of the arc in degrees. - * @param type - * the closure type, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public void setArc(Point2D point, Dimension2D size, double start, double extent, int type) { - setArc(point.getX(), point.getY(), size.getWidth(), size.getHeight(), start, extent, type); - } - - /** - * Sets the data that defines the arc. - * - * @param rect - * the arc's bounding rectangle. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the angle width of the arc in degrees. - * @param type - * the closure type, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public void setArc(Rectangle2D rect, double start, double extent, int type) { - setArc(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), start, extent, type); - } - - /** - * Sets the data that defines the arc by copying it from another Arc2D. - * - * @param arc - * the arc whose data is copied into this arc. - */ - public void setArc(Arc2D arc) { - setArc(arc.getX(), arc.getY(), arc.getWidth(), arc.getHeight(), arc.getAngleStart(), arc - .getAngleExtent(), arc.getArcType()); - } - - /** - * Sets the data for a circular arc by giving its center and radius. - * - * @param x - * the x coordinate of the center of the circle. - * @param y - * the y coordinate of the center of the circle. - * @param radius - * the radius of the circle. - * @param start - * the start angle of the arc in degrees. - * @param extent - * the angle width of the arc in degrees. - * @param type - * the closure type, either {@link Arc2D#OPEN}, - * {@link Arc2D#CHORD}, or {@link Arc2D#PIE}. - */ - public void setArcByCenter(double x, double y, double radius, double start, double extent, - int type) { - setArc(x - radius, y - radius, radius * 2.0, radius * 2.0, start, extent, type); - } - - /** - * Sets the arc data for a circular arc based on two tangent lines and the - * radius. The two tangent lines are the lines from p1 to p2 and from p2 to - * p3, which determine a unique circle with the given radius. The start and - * end points of the arc are the points where the circle touches the two - * lines, and the arc itself is the shorter of the two circle segments - * determined by the two points (in other words, it is the piece of the - * circle that is closer to the lines' intersection point p2 and forms a - * concave shape with the segments from p1 to p2 and from p2 to p3). - * - * @param p1 - * a point which determines one of the two tangent lines (with - * p2). - * @param p2 - * the point of intersection of the two tangent lines. - * @param p3 - * a point which determines one of the two tangent lines (with - * p2). - * @param radius - * the radius of the circular arc. - */ - public void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double radius) { - // Used simple geometric calculations of arc center, radius and angles - // by tangents - double a1 = -Math.atan2(p1.getY() - p2.getY(), p1.getX() - p2.getX()); - double a2 = -Math.atan2(p3.getY() - p2.getY(), p3.getX() - p2.getX()); - double am = (a1 + a2) / 2.0; - double ah = a1 - am; - double d = radius / Math.abs(Math.sin(ah)); - double x = p2.getX() + d * Math.cos(am); - double y = p2.getY() - d * Math.sin(am); - ah = ah >= 0.0 ? Math.PI * 1.5 - ah : Math.PI * 0.5 - ah; - a1 = getNormAngle(Math.toDegrees(am - ah)); - a2 = getNormAngle(Math.toDegrees(am + ah)); - double delta = a2 - a1; - if (delta <= 0.0) { - delta += 360.0; - } - setArcByCenter(x, y, radius, a1, delta, type); - } - - /** - * Sets a new start angle to be the angle given by the the vector from the - * current center point to the specified point. - * - * @param point - * the point that determines the new start angle. - */ - public void setAngleStart(Point2D point) { - double angle = Math.atan2(point.getY() - getCenterY(), point.getX() - getCenterX()); - setAngleStart(getNormAngle(-Math.toDegrees(angle))); - } - - /** - * Sets the angles in terms of vectors from the current arc center to the - * points (x1, y1) and (x2, y2). The start angle is given by the vector from - * the current center to the point (x1, y1) and the end angle is given by - * the vector from the center to the point (x2, y2). - * - * @param x1 - * the x coordinate of the point whose vector from the center - * point determines the new start angle of the arc. - * @param y1 - * the y coordinate of the point whose vector from the center - * point determines the new start angle of the arc. - * @param x2 - * the x coordinate of the point whose vector from the center - * point determines the new end angle of the arc. - * @param y2 - * the y coordinate of the point whose vector from the center - * point determines the new end angle of the arc. - */ - public void setAngles(double x1, double y1, double x2, double y2) { - double cx = getCenterX(); - double cy = getCenterY(); - double a1 = getNormAngle(-Math.toDegrees(Math.atan2(y1 - cy, x1 - cx))); - double a2 = getNormAngle(-Math.toDegrees(Math.atan2(y2 - cy, x2 - cx))); - a2 -= a1; - if (a2 <= 0.0) { - a2 += 360.0; - } - setAngleStart(a1); - setAngleExtent(a2); - } - - /** - * Sets the angles in terms of vectors from the current arc center to the - * points p1 and p2. The start angle is given by the vector from the current - * center to the point p1 and the end angle is given by the vector from the - * center to the point p2. - * - * @param p1 - * the point whose vector from the center point determines the - * new start angle of the arc. - * @param p2 - * the point whose vector from the center point determines the - * new end angle of the arc. - */ - public void setAngles(Point2D p1, Point2D p2) { - setAngles(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Normalizes the angle by removing extra winding (past 360 degrees) and - * placing it in the positive degree range. - * - * @param angle - * the source angle in degrees. - * @return an angle between 0 and 360 degrees which corresponds to the same - * direction vector as the source angle. - */ - double getNormAngle(double angle) { - double n = Math.floor(angle / 360.0); - return angle - n * 360.0; - } - - /** - * Determines whether the given angle is contained in the span of the arc. - * - * @param angle - * the angle to test in degrees. - * @return true, if the given angle is between the start angle and the end - * angle of the arc. - */ - public boolean containsAngle(double angle) { - double extent = getAngleExtent(); - if (extent >= 360.0) { - return true; - } - angle = getNormAngle(angle); - double a1 = getNormAngle(getAngleStart()); - double a2 = a1 + extent; - if (a2 > 360.0) { - return angle >= a1 || angle <= a2 - 360.0; - } - if (a2 < 0.0) { - return angle >= a2 + 360.0 || angle <= a1; - } - return extent > 0.0 ? a1 <= angle && angle <= a2 : a2 <= angle && angle <= a1; - } - - public boolean contains(double px, double py) { - // Normalize point - double nx = (px - getX()) / getWidth() - 0.5; - double ny = (py - getY()) / getHeight() - 0.5; - - if ((nx * nx + ny * ny) > 0.25) { - return false; - } - - double extent = getAngleExtent(); - double absExtent = Math.abs(extent); - if (absExtent >= 360.0) { - return true; - } - - boolean containsAngle = containsAngle(Math.toDegrees(-Math.atan2(ny, nx))); - if (type == PIE) { - return containsAngle; - } - if (absExtent <= 180.0 && !containsAngle) { - return false; - } - - Line2D l = new Line2D.Double(getStartPoint(), getEndPoint()); - int ccw1 = l.relativeCCW(px, py); - int ccw2 = l.relativeCCW(getCenterX(), getCenterY()); - return ccw1 == 0 || ccw2 == 0 || ((ccw1 + ccw2) == 0 ^ absExtent > 180.0); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - - if (!(contains(rx, ry) && contains(rx + rw, ry) && contains(rx + rw, ry + rh) && contains( - rx, ry + rh))) { - return false; - } - - double absExtent = Math.abs(getAngleExtent()); - if (type != PIE || absExtent <= 180.0 || absExtent >= 360.0) { - return true; - } - - Rectangle2D r = new Rectangle2D.Double(rx, ry, rw, rh); - - double cx = getCenterX(); - double cy = getCenterY(); - if (r.contains(cx, cy)) { - return false; - } - - Point2D p1 = getStartPoint(); - Point2D p2 = getEndPoint(); - - return !r.intersectsLine(cx, cy, p1.getX(), p1.getY()) - && !r.intersectsLine(cx, cy, p2.getX(), p2.getY()); - } - - @Override - public boolean contains(Rectangle2D rect) { - return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - - if (isEmpty() || rw <= 0.0 || rh <= 0.0) { - return false; - } - - // Check: Does arc contain rectangle's points - if (contains(rx, ry) || contains(rx + rw, ry) || contains(rx, ry + rh) - || contains(rx + rw, ry + rh)) { - return true; - } - - double cx = getCenterX(); - double cy = getCenterY(); - Point2D p1 = getStartPoint(); - Point2D p2 = getEndPoint(); - Rectangle2D r = new Rectangle2D.Double(rx, ry, rw, rh); - - // Check: Does rectangle contain arc's points - if (r.contains(p1) || r.contains(p2) || (type == PIE && r.contains(cx, cy))) { - return true; - } - - if (type == PIE) { - if (r.intersectsLine(p1.getX(), p1.getY(), cx, cy) - || r.intersectsLine(p2.getX(), p2.getY(), cx, cy)) { - return true; - } - } else { - if (r.intersectsLine(p1.getX(), p1.getY(), p2.getX(), p2.getY())) { - return true; - } - } - - // Nearest rectangle point - double nx = cx < rx ? rx : (cx > rx + rw ? rx + rw : cx); - double ny = cy < ry ? ry : (cy > ry + rh ? ry + rh : cy); - return contains(nx, ny); - } - - public PathIterator getPathIterator(AffineTransform at) { - return new Iterator(this, at); - } - -} diff --git a/awt/java/awt/geom/Area.java b/awt/java/awt/geom/Area.java deleted file mode 100644 index e6619e3..0000000 --- a/awt/java/awt/geom/Area.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.geom.PathIterator; -import java.awt.geom.Rectangle2D; -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; -import org.apache.harmony.luni.util.NotImplementedException; - -/** - * The Class Area provides a minimal implementation for a generic shape. - * - * @since Android 1.0 - */ -public class Area implements Shape, Cloneable { - - /** - * The source Shape object. - */ - Shape s; - - /** - * The Class NullIterator. - */ - private static class NullIterator implements PathIterator { - - /** - * Instantiates a new null iterator. - */ - NullIterator() { - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return true; - } - - public void next() { - // nothing - } - - public int currentSegment(double[] coords) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - - public int currentSegment(float[] coords) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - - } - - /** - * Instantiates a new area with no data. - */ - public Area() { - } - - /** - * Instantiates a new area with data given by the specified shape. - * - * @param s - * the shape that gives the data for this Area. - */ - public Area(Shape s) { - if (s == null) { - throw new NullPointerException(); - } - this.s = s; - } - - public boolean contains(double x, double y) { - return s == null ? false : s.contains(x, y); - } - - public boolean contains(double x, double y, double width, double height) { - return s == null ? false : s.contains(x, y, width, height); - } - - public boolean contains(Point2D p) { - if (p == null) { - throw new NullPointerException(); - } - return s == null ? false : s.contains(p); - } - - public boolean contains(Rectangle2D r) { - if (r == null) { - throw new NullPointerException(); - } - return s == null ? false : s.contains(r); - } - - /** - * Tests whether the object is equal to this Area. - * - * @param obj - * the object to compare. - * @return true, if successful. - * @throws NotImplementedException - * if this method is not implemented. - */ - public boolean equals(Area obj) throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - public boolean intersects(double x, double y, double width, double height) { - return s == null ? false : s.intersects(x, y, width, height); - } - - public boolean intersects(Rectangle2D r) { - if (r == null) { - throw new NullPointerException(); - } - return s == null ? false : s.intersects(r); - } - - public Rectangle getBounds() { - return s == null ? new Rectangle() : s.getBounds(); - } - - public Rectangle2D getBounds2D() { - return s == null ? new Rectangle2D.Double() : s.getBounds2D(); - } - - public PathIterator getPathIterator(AffineTransform t) { - return s == null ? new NullIterator() : s.getPathIterator(t); - } - - public PathIterator getPathIterator(AffineTransform t, double flatness) { - return s == null ? new NullIterator() : s.getPathIterator(t, flatness); - } - - /** - * Adds the specified area to this area. - * - * @param area - * the area to add to this area. - * @throws NotImplementedException - * if this method is not implemented. - */ - public void add(Area area) throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Performs an exclusive or operation between this shape and the specified - * shape. - * - * @param area - * the area to XOR against this area. - * @throws NotImplementedException - * if this method is not implemented. - */ - public void exclusiveOr(Area area) throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Extracts a Rectangle2D from the source shape if the underlying shape data - * describes a rectangle. - * - * @return a Rectangle2D object if the source shape is rectangle, or null if - * shape is empty or not rectangle. - */ - Rectangle2D extractRectangle() { - if (s == null) { - return null; - } - float[] points = new float[12]; - int count = 0; - PathIterator p = s.getPathIterator(null); - float[] coords = new float[6]; - while (!p.isDone()) { - int type = p.currentSegment(coords); - if (count > 12 || type == PathIterator.SEG_QUADTO || type == PathIterator.SEG_CUBICTO) { - return null; - } - points[count++] = coords[0]; - points[count++] = coords[1]; - p.next(); - } - if (points[0] == points[6] && points[6] == points[8] && points[2] == points[4] - && points[1] == points[3] && points[3] == points[9] && points[5] == points[7]) { - return new Rectangle2D.Float(points[0], points[1], points[2] - points[0], points[7] - - points[1]); - } - return null; - } - - /** - * Reduces the size of this Area by intersecting it with the specified Area - * if they are both rectangles. - * - * @see java.awt.geom.Rectangle2D#intersect(Rectangle2D, Rectangle2D, - * Rectangle2D) - * @param area - * the area. - */ - public void intersect(Area area) { - Rectangle2D src1 = extractRectangle(); - Rectangle2D src2 = area.extractRectangle(); - if (src1 != null && src2 != null) { - Rectangle2D.intersect(src1, src2, (Rectangle2D)s); - } - } - - /** - * Subtract the specified area from this area. - * - * @param area - * the area to subtract. - * @throws NotImplementedException - * if this method is not implemented. - */ - public void subtract(Area area) throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Checks if this Area is empty. - * - * @return true, if this Area is empty. - * @throws NotImplementedException - * if this method is not implemented. - */ - public boolean isEmpty() throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Checks if this Area is polygonal. - * - * @return true, if this Area is polygonal. - * @throws NotImplementedException - * if this method is not implemented. - */ - public boolean isPolygonal() throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Checks if this Area is rectangular. - * - * @return true, if this Area is rectangular. - * @throws NotImplementedException - * if this method is not implemented. - */ - public boolean isRectangular() throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Checks if this Area is singular. - * - * @return true, if this Area is singular. - * @throws NotImplementedException - * if this method is not implemented. - */ - public boolean isSingular() throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Resets the data of this Area. - * - * @throws NotImplementedException - * if this method is not implemented. - */ - public void reset() throws org.apache.harmony.luni.util.NotImplementedException { - throw new RuntimeException("Not implemented"); //$NON-NLS-1$ - } - - /** - * Transforms the data of this Area according to the specified - * AffineTransform. - * - * @param t - * the transform to use to transform the data. - */ - public void transform(AffineTransform t) { - s = t.createTransformedShape(s); - } - - /** - * Creates a new Area that is the result of transforming the data of this - * Area according to the specified AffineTransform. - * - * @param t - * the transform to use to transform the data. - * @return the new Area that is the result of transforming the data of this - * Area according to the specified AffineTransform. - */ - public Area createTransformedArea(AffineTransform t) { - return s == null ? new Area() : new Area(t.createTransformedShape(s)); - } - - @Override - public Object clone() { - return new Area(this); - } - -} diff --git a/awt/java/awt/geom/CubicCurve2D.java b/awt/java/awt/geom/CubicCurve2D.java deleted file mode 100644 index 1ddedf3..0000000 --- a/awt/java/awt/geom/CubicCurve2D.java +++ /dev/null @@ -1,1047 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.gl.Crossing; -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class CubicCurve2D is a Shape that represents a segment of a quadratic - * (Bezier) curve. The curved segment is determined by four points: a start - * point, an end point, and two control points. The control points give - * information about the tangent and next derivative at the endpoints according - * to the standard theory of Bezier curves. For more information on Bezier - * curves, see <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">this - * article</a>. - * - * @since Android 1.0 - */ -public abstract class CubicCurve2D implements Shape, Cloneable { - - /** - * The Class Float is the subclass of CubicCurve2D that has all of its data - * values stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends CubicCurve2D { - - /** - * The x coordinate of the starting point. - */ - public float x1; - - /** - * The y coordinate of the starting point. - */ - public float y1; - - /** - * The x coordinate of the first control point. - */ - public float ctrlx1; - - /** - * The y coordinate of the first control point. - */ - public float ctrly1; - - /** - * The x coordinate of the second control point. - */ - public float ctrlx2; - - /** - * The y coordinate of the second control point. - */ - public float ctrly2; - - /** - * The x coordinate of the end point. - */ - public float x2; - - /** - * The y coordinate of the end point. - */ - public float y2; - - /** - * Instantiates a new float-valued CubicCurve2D with all coordinate - * values set to zero. - */ - public Float() { - } - - /** - * Instantiates a new float-valued CubicCurve2D with the specified - * coordinate values. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public Float(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, - float x2, float y2) { - setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getCtrlX1() { - return ctrlx1; - } - - @Override - public double getCtrlY1() { - return ctrly1; - } - - @Override - public double getCtrlX2() { - return ctrlx2; - } - - @Override - public double getCtrlY2() { - return ctrly2; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Float(x1, y1); - } - - @Override - public Point2D getCtrlP1() { - return new Point2D.Float(ctrlx1, ctrly1); - } - - @Override - public Point2D getCtrlP2() { - return new Point2D.Float(ctrlx2, ctrly2); - } - - @Override - public Point2D getP2() { - return new Point2D.Float(x2, y2); - } - - @Override - public void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, - double ctrly2, double x2, double y2) { - this.x1 = (float)x1; - this.y1 = (float)y1; - this.ctrlx1 = (float)ctrlx1; - this.ctrly1 = (float)ctrly1; - this.ctrlx2 = (float)ctrlx2; - this.ctrly2 = (float)ctrly2; - this.x2 = (float)x2; - this.y2 = (float)y2; - } - - /** - * Sets the data values of the curve. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public void setCurve(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, - float ctrly2, float x2, float y2) { - this.x1 = x1; - this.y1 = y1; - this.ctrlx1 = ctrlx1; - this.ctrly1 = ctrly1; - this.ctrlx2 = ctrlx2; - this.ctrly2 = ctrly2; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - float rx1 = Math.min(Math.min(x1, x2), Math.min(ctrlx1, ctrlx2)); - float ry1 = Math.min(Math.min(y1, y2), Math.min(ctrly1, ctrly2)); - float rx2 = Math.max(Math.max(x1, x2), Math.max(ctrlx1, ctrlx2)); - float ry2 = Math.max(Math.max(y1, y2), Math.max(ctrly1, ctrly2)); - return new Rectangle2D.Float(rx1, ry1, rx2 - rx1, ry2 - ry1); - } - } - - /** - * The Class Double is the subclass of CubicCurve2D that has all of its data - * values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends CubicCurve2D { - - /** - * The x coordinate of the starting point. - */ - public double x1; - - /** - * The y coordinate of the starting point. - */ - public double y1; - - /** - * The x coordinate of the first control point. - */ - public double ctrlx1; - - /** - * The y coordinate of the first control point. - */ - public double ctrly1; - - /** - * The x coordinate of the second control point. - */ - public double ctrlx2; - - /** - * The y coordinate of the second control point. - */ - public double ctrly2; - - /** - * The x coordinate of the end point. - */ - public double x2; - - /** - * The y coordinate of the end point. - */ - public double y2; - - /** - * Instantiates a new double-valued CubicCurve2D with all coordinate - * values set to zero. - */ - public Double() { - } - - /** - * Instantiates a new double-valued CubicCurve2D with the specified - * coordinate values. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public Double(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, - double ctrly2, double x2, double y2) { - setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getCtrlX1() { - return ctrlx1; - } - - @Override - public double getCtrlY1() { - return ctrly1; - } - - @Override - public double getCtrlX2() { - return ctrlx2; - } - - @Override - public double getCtrlY2() { - return ctrly2; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Double(x1, y1); - } - - @Override - public Point2D getCtrlP1() { - return new Point2D.Double(ctrlx1, ctrly1); - } - - @Override - public Point2D getCtrlP2() { - return new Point2D.Double(ctrlx2, ctrly2); - } - - @Override - public Point2D getP2() { - return new Point2D.Double(x2, y2); - } - - @Override - public void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, - double ctrly2, double x2, double y2) { - this.x1 = x1; - this.y1 = y1; - this.ctrlx1 = ctrlx1; - this.ctrly1 = ctrly1; - this.ctrlx2 = ctrlx2; - this.ctrly2 = ctrly2; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - double rx1 = Math.min(Math.min(x1, x2), Math.min(ctrlx1, ctrlx2)); - double ry1 = Math.min(Math.min(y1, y2), Math.min(ctrly1, ctrly2)); - double rx2 = Math.max(Math.max(x1, x2), Math.max(ctrlx1, ctrlx2)); - double ry2 = Math.max(Math.max(y1, y2), Math.max(ctrly1, ctrly2)); - return new Rectangle2D.Double(rx1, ry1, rx2 - rx1, ry2 - ry1); - } - } - - /* - * CubicCurve2D path iterator - */ - /** - * The Iterator class for the Shape CubicCurve2D. - */ - class Iterator implements PathIterator { - - /** - * The source CubicCurve2D object. - */ - CubicCurve2D c; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new CubicCurve2D.Iterator for given line and - * transformation - * - * @param c - * the source CubicCurve2D object. - * @param t - * the affine transformation object. - */ - Iterator(CubicCurve2D c, AffineTransform t) { - this.c = c; - this.t = t; - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > 1; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = c.getX1(); - coords[1] = c.getY1(); - count = 1; - } else { - type = SEG_CUBICTO; - coords[0] = c.getCtrlX1(); - coords[1] = c.getCtrlY1(); - coords[2] = c.getCtrlX2(); - coords[3] = c.getCtrlY2(); - coords[4] = c.getX2(); - coords[5] = c.getY2(); - count = 3; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = (float)c.getX1(); - coords[1] = (float)c.getY1(); - count = 1; - } else { - type = SEG_CUBICTO; - coords[0] = (float)c.getCtrlX1(); - coords[1] = (float)c.getCtrlY1(); - coords[2] = (float)c.getCtrlX2(); - coords[3] = (float)c.getCtrlY2(); - coords[4] = (float)c.getX2(); - coords[5] = (float)c.getY2(); - count = 3; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - } - - /** - * Instantiates a new 2-D cubic curve. - */ - protected CubicCurve2D() { - } - - /** - * Gets the x coordinate of the starting point. - * - * @return the x coordinate of the starting point. - */ - public abstract double getX1(); - - /** - * Gets the y coordinate of the starting point. - * - * @return the y coordinate of the starting point. - */ - public abstract double getY1(); - - /** - * Gets the starting point. - * - * @return the starting point. - */ - public abstract Point2D getP1(); - - /** - * Gets the x coordinate of the first control point. - * - * @return the x coordinate of the first control point. - */ - public abstract double getCtrlX1(); - - /** - * Gets the y coordinate of the first control point. - * - * @return the y coordinate of the first control point. - */ - public abstract double getCtrlY1(); - - /** - * Gets the second control point. - * - * @return the second control point. - */ - public abstract Point2D getCtrlP1(); - - /** - * Gets the x coordinate of the second control point. - * - * @return the x coordinate of the second control point - */ - public abstract double getCtrlX2(); - - /** - * Gets the y coordinate of the second control point. - * - * @return the y coordinate of the second control point - */ - public abstract double getCtrlY2(); - - /** - * Gets the second control point. - * - * @return the second control point. - */ - public abstract Point2D getCtrlP2(); - - /** - * Gets the x coordinate of the end point. - * - * @return the x coordinate of the end point. - */ - public abstract double getX2(); - - /** - * Gets the y coordinate of the end point. - * - * @return the y coordinate of the end point. - */ - public abstract double getY2(); - - /** - * Gets the end point. - * - * @return the end point. - */ - public abstract Point2D getP2(); - - /** - * Sets the data of the curve. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public abstract void setCurve(double x1, double y1, double ctrlx1, double ctrly1, - double ctrlx2, double ctrly2, double x2, double y2); - - /** - * Sets the data of the curve as point objects. - * - * @param p1 - * the starting point. - * @param cp1 - * the first control point. - * @param cp2 - * the second control point. - * @param p2 - * the end point. - * @throws NullPointerException - * if any of the points is null. - */ - public void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2) { - setCurve(p1.getX(), p1.getY(), cp1.getX(), cp1.getY(), cp2.getX(), cp2.getY(), p2.getX(), - p2.getY()); - } - - /** - * Sets the data of the curve by reading the data from an array of values. - * The values are read in the same order as the arguments of the method - * {@link CubicCurve2D#setCurve(double, double, double, double, double, double, double, double)} - * . - * - * @param coords - * the array of values containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @throws ArrayIndexOutOfBoundsException - * if {@code coords.length} < offset + 8. - * @throws NullPointerException - * if the coordinate array is null. - */ - public void setCurve(double[] coords, int offset) { - setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], - coords[offset + 4], coords[offset + 5], coords[offset + 6], coords[offset + 7]); - } - - /** - * Sets the data of the curve by reading the data from an array of points. - * The values are read in the same order as the arguments of the method - * {@link CubicCurve2D#setCurve(Point2D, Point2D, Point2D, Point2D)} - * - * @param points - * the array of points containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @throws ArrayIndexOutOfBoundsException - * if {@code points.length} < offset + . - * @throws NullPointerException - * if the point array is null. - */ - public void setCurve(Point2D[] points, int offset) { - setCurve(points[offset + 0].getX(), points[offset + 0].getY(), points[offset + 1].getX(), - points[offset + 1].getY(), points[offset + 2].getX(), points[offset + 2].getY(), - points[offset + 3].getX(), points[offset + 3].getY()); - } - - /** - * Sets the data of the curve by copying it from another CubicCurve2D. - * - * @param curve - * the curve to copy the data points from. - * @throws NullPointerException - * if the curve is null. - */ - public void setCurve(CubicCurve2D curve) { - setCurve(curve.getX1(), curve.getY1(), curve.getCtrlX1(), curve.getCtrlY1(), curve - .getCtrlX2(), curve.getCtrlY2(), curve.getX2(), curve.getY2()); - } - - /** - * Gets the square of the flatness of this curve, where the flatness is the - * maximum distance from the curves control points to the line segment - * connecting the two points. - * - * @return the square of the flatness. - */ - public double getFlatnessSq() { - return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(), getCtrlY2(), - getX2(), getY2()); - } - - /** - * Gets the square of the flatness of the cubic curve segment defined by the - * specified values. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - * @return the square of the flatness. - */ - public static double getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, - double ctrlx2, double ctrly2, double x2, double y2) { - return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx1, ctrly1), Line2D.ptSegDistSq(x1, - y1, x2, y2, ctrlx2, ctrly2)); - } - - /** - * Gets the square of the flatness of the cubic curve segment defined by the - * specified values. The values are read in the same order as the arguments - * of the method - * {@link CubicCurve2D#getFlatnessSq(double, double, double, double, double, double, double, double)} - * . - * - * @param coords - * the array of points containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @return the square of the flatness. - * @throws ArrayIndexOutOfBoundsException - * if points.length < offset + . - * @throws NullPointerException - * if the point array is null. - */ - public static double getFlatnessSq(double coords[], int offset) { - return getFlatnessSq(coords[offset + 0], coords[offset + 1], coords[offset + 2], - coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6], - coords[offset + 7]); - } - - /** - * Gets the flatness of this curve, where the flatness is the maximum - * distance from the curves control points to the line segment connecting - * the two points. - * - * @return the flatness of this curve. - */ - public double getFlatness() { - return getFlatness(getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(), getCtrlY2(), - getX2(), getY2()); - } - - /** - * Gets the flatness of the cubic curve segment defined by the specified - * values. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param ctrlx1 - * the x coordinate of the first control point. - * @param ctrly1 - * the y coordinate of the first control point. - * @param ctrlx2 - * the x coordinate of the second control point. - * @param ctrly2 - * the y coordinate of the second control point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - * @return the flatness. - */ - public static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, - double ctrlx2, double ctrly2, double x2, double y2) { - return Math.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2)); - } - - /** - * Gets the flatness of the cubic curve segment defined by the specified - * values. The values are read in the same order as the arguments of the - * method - * {@link CubicCurve2D#getFlatness(double, double, double, double, double, double, double, double)} - * . - * - * @param coords - * the array of points containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @return the flatness. - * @throws ArrayIndexOutOfBoundsException - * if points.length < offset + . - * @throws NullPointerException - * if the point array is null. - */ - public static double getFlatness(double coords[], int offset) { - return getFlatness(coords[offset + 0], coords[offset + 1], coords[offset + 2], - coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6], - coords[offset + 7]); - } - - /** - * Creates the data for two cubic curves by dividing this curve in two. The - * division point is the point on the curve that is closest to the average - * of curve's two control points. The two new control points (nearest the - * new endpoint) are computed by averaging the original control points with - * the new endpoint. The data of this curve is left unchanged. - * - * @param left - * the CubicCurve2D where the left (start) segment's data is - * written. - * @param right - * the CubicCurve2D where the right (end) segment's data is - * written. - * @throws NullPointerException - * if either curve is null. - */ - public void subdivide(CubicCurve2D left, CubicCurve2D right) { - subdivide(this, left, right); - } - - /** - * Creates the data for two cubic curves by dividing the specified curve in - * two. The division point is the point on the curve that is closest to the - * average of curve's two control points. The two new control points - * (nearest the new endpoint) are computed by averaging the original control - * points with the new endpoint. The data of the source curve is left - * unchanged. - * - * @param src - * the original curve to be divided in two. - * @param left - * the CubicCurve2D where the left (start) segment's data is - * written. - * @param right - * the CubicCurve2D where the right (end) segment's data is - * written. - * @throws NullPointerException - * if either curve is null. - */ - public static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right) { - double x1 = src.getX1(); - double y1 = src.getY1(); - double cx1 = src.getCtrlX1(); - double cy1 = src.getCtrlY1(); - double cx2 = src.getCtrlX2(); - double cy2 = src.getCtrlY2(); - double x2 = src.getX2(); - double y2 = src.getY2(); - double cx = (cx1 + cx2) / 2.0; - double cy = (cy1 + cy2) / 2.0; - cx1 = (x1 + cx1) / 2.0; - cy1 = (y1 + cy1) / 2.0; - cx2 = (x2 + cx2) / 2.0; - cy2 = (y2 + cy2) / 2.0; - double ax = (cx1 + cx) / 2.0; - double ay = (cy1 + cy) / 2.0; - double bx = (cx2 + cx) / 2.0; - double by = (cy2 + cy) / 2.0; - cx = (ax + bx) / 2.0; - cy = (ay + by) / 2.0; - if (left != null) { - left.setCurve(x1, y1, cx1, cy1, ax, ay, cx, cy); - } - if (right != null) { - right.setCurve(cx, cy, bx, by, cx2, cy2, x2, y2); - } - } - - /** - * Creates the data for two cubic curves by dividing the specified curve in - * two. The division point is the point on the curve that is closest to the - * average of curve's two control points. The two new control points - * (nearest the new endpoint) are computed by averaging the original control - * points with the new endpoint. The data of the source curve is left - * unchanged. The data for the three curves is read/written in the usual - * order: { x1, y1, ctrlx1, ctrly1, ctrlx2, crtry2, x2, y3 } - * - * @param src - * the array that gives the data values for the source curve. - * @param srcOff - * the offset in the src array to read the values from. - * @param left - * the array where the coordinates of the start curve should be - * written. - * @param leftOff - * the offset in the left array to start writing the values. - * @param right - * the array where the coordinates of the end curve should be - * written. - * @param rightOff - * the offset in the right array to start writing the values. - * @throws ArrayIndexOutOfBoundsException - * if src.length < srcoff + 8 or if left.length < leftOff + 8 or - * if right.length < rightOff + 8. - * @throws NullPointerException - * if one of the arrays is null. - */ - public static void subdivide(double src[], int srcOff, double left[], int leftOff, - double right[], int rightOff) { - double x1 = src[srcOff + 0]; - double y1 = src[srcOff + 1]; - double cx1 = src[srcOff + 2]; - double cy1 = src[srcOff + 3]; - double cx2 = src[srcOff + 4]; - double cy2 = src[srcOff + 5]; - double x2 = src[srcOff + 6]; - double y2 = src[srcOff + 7]; - double cx = (cx1 + cx2) / 2.0; - double cy = (cy1 + cy2) / 2.0; - cx1 = (x1 + cx1) / 2.0; - cy1 = (y1 + cy1) / 2.0; - cx2 = (x2 + cx2) / 2.0; - cy2 = (y2 + cy2) / 2.0; - double ax = (cx1 + cx) / 2.0; - double ay = (cy1 + cy) / 2.0; - double bx = (cx2 + cx) / 2.0; - double by = (cy2 + cy) / 2.0; - cx = (ax + bx) / 2.0; - cy = (ay + by) / 2.0; - if (left != null) { - left[leftOff + 0] = x1; - left[leftOff + 1] = y1; - left[leftOff + 2] = cx1; - left[leftOff + 3] = cy1; - left[leftOff + 4] = ax; - left[leftOff + 5] = ay; - left[leftOff + 6] = cx; - left[leftOff + 7] = cy; - } - if (right != null) { - right[rightOff + 0] = cx; - right[rightOff + 1] = cy; - right[rightOff + 2] = bx; - right[rightOff + 3] = by; - right[rightOff + 4] = cx2; - right[rightOff + 5] = cy2; - right[rightOff + 6] = x2; - right[rightOff + 7] = y2; - } - } - - /** - * Finds the roots of the cubic polynomial. This is accomplished by finding - * the (real) values of x that solve the following equation: eqn[3]*x*x*x + - * eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written back into - * the array eqn starting from the index 0 in the array. The return value - * tells how many array elements have been changed by this method call. - * - * @param eqn - * an array containing the coefficients of the cubic polynomial - * to solve. - * @return the number of roots of the cubic polynomial. - * @throws ArrayIndexOutOfBoundsException - * if eqn.length < 4. - * @throws NullPointerException - * if the array is null. - */ - public static int solveCubic(double eqn[]) { - return solveCubic(eqn, eqn); - } - - /** - * Finds the roots of the cubic polynomial. This is accomplished by finding - * the (real) values of x that solve the following equation: eqn[3]*x*x*x + - * eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written into the - * array res starting from the index 0 in the array. The return value tells - * how many array elements have been changed by this method call. - * - * @param eqn - * an array containing the coefficients of the cubic polynomial - * to solve. - * @param res - * the array that this method writes the results into. - * @return the number of roots of the cubic polynomial. - * @throws ArrayIndexOutOfBoundsException - * if eqn.length < 4 or if res.length is less than the number of - * roots. - * @throws NullPointerException - * if either array is null. - */ - public static int solveCubic(double eqn[], double res[]) { - return Crossing.solveCubic(eqn, res); - } - - public boolean contains(double px, double py) { - return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py)); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross != Crossing.CROSSING && Crossing.isInsideEvenOdd(cross); - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross == Crossing.CROSSING || Crossing.isInsideEvenOdd(cross); - } - - public boolean contains(Point2D p) { - return contains(p.getX(), p.getY()); - } - - public boolean intersects(Rectangle2D r) { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public boolean contains(Rectangle2D r) { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public Rectangle getBounds() { - return getBounds2D().getBounds(); - } - - public PathIterator getPathIterator(AffineTransform t) { - return new Iterator(this, t); - } - - public PathIterator getPathIterator(AffineTransform at, double flatness) { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } -}
\ No newline at end of file diff --git a/awt/java/awt/geom/Dimension2D.java b/awt/java/awt/geom/Dimension2D.java deleted file mode 100644 index ea081c5..0000000 --- a/awt/java/awt/geom/Dimension2D.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -/** - * The Class Dimension2D represents a size (width and height) of a geometric - * object. It stores double-valued data in order to be compatible with - * high-precision geometric operations. - * - * @since Android 1.0 - */ -public abstract class Dimension2D implements Cloneable { - - /** - * Instantiates a new dimension 2d with no data. - */ - protected Dimension2D() { - } - - /** - * Gets the width. - * - * @return the width. - */ - public abstract double getWidth(); - - /** - * Gets the height. - * - * @return the height. - */ - public abstract double getHeight(); - - /** - * Sets the width and height. - * - * @param width - * the width. - * @param height - * the height. - */ - public abstract void setSize(double width, double height); - - /** - * Sets the width and height based on the data of another Dimension2D - * object. - * - * @param d - * the Dimension2D object providing the data to copy into this - * Dimension2D object. - */ - public void setSize(Dimension2D d) { - setSize(d.getWidth(), d.getHeight()); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } -} diff --git a/awt/java/awt/geom/Ellipse2D.java b/awt/java/awt/geom/Ellipse2D.java deleted file mode 100644 index 89fd0d0..0000000 --- a/awt/java/awt/geom/Ellipse2D.java +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class Ellipse2D describes an ellipse defined by a rectangular area in - * which it is inscribed. - * - * @since Android 1.0 - */ -public abstract class Ellipse2D extends RectangularShape { - - /** - * The Class Float is the subclass of Ellipse2D that has all of its data - * values stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends Ellipse2D { - - /** - * The x coordinate of the upper left corner of the ellipse's bounding - * rectangle. - */ - public float x; - - /** - * The y coordinate of the upper left corner of the ellipse's bounding - * rectangle. - */ - public float y; - - /** - * The width of the ellipse's bounding rectangle. - */ - public float width; - - /** - * The height of the ellipse's bounding rectangle. - */ - public float height; - - /** - * Instantiates a new float-valued Ellipse2D. - */ - public Float() { - } - - /** - * Instantiates a new float-valued Ellipse2D with the specified data. - * - * @param x - * the x coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param y - * the y coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param width - * the width of the ellipse's bounding rectangle. - * @param height - * the height of the ellipse's bounding rectangle. - */ - public Float(float x, float y, float width, float height) { - setFrame(x, y, width, height); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public boolean isEmpty() { - return width <= 0.0 || height <= 0.0; - } - - /** - * Sets the data of the ellipse's bounding rectangle. - * - * @param x - * the x coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param y - * the y coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param width - * the width of the ellipse's bounding rectangle. - * @param height - * the height of the ellipse's bounding rectangle. - */ - public void setFrame(float x, float y, float width, float height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - @Override - public void setFrame(double x, double y, double width, double height) { - this.x = (float)x; - this.y = (float)y; - this.width = (float)width; - this.height = (float)height; - } - - public Rectangle2D getBounds2D() { - return new Rectangle2D.Float(x, y, width, height); - } - } - - /** - * The Class Double is the subclass of Ellipse2D that has all of its data - * values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends Ellipse2D { - - /** - * The x coordinate of the upper left corner of the ellipse's bounding - * rectangle. - */ - public double x; - - /** - * The y coordinate of the upper left corner of the ellipse's bounding - * rectangle. - */ - public double y; - - /** - * The width of the ellipse's bounding rectangle. - */ - public double width; - - /** - * The height of the ellipse's bounding rectangle. - */ - public double height; - - /** - * Instantiates a new double-valued Ellipse2D. - */ - public Double() { - } - - /** - * Instantiates a new double-valued Ellipse2D with the specified data. - * - * @param x - * the x coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param y - * the y coordinate of the upper left corner of the ellipse's - * bounding rectangle. - * @param width - * the width of the ellipse's bounding rectangle. - * @param height - * the height of the ellipse's bounding rectangle. - */ - public Double(double x, double y, double width, double height) { - setFrame(x, y, width, height); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public boolean isEmpty() { - return width <= 0.0 || height <= 0.0; - } - - @Override - public void setFrame(double x, double y, double width, double height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - public Rectangle2D getBounds2D() { - return new Rectangle2D.Double(x, y, width, height); - } - } - - /* - * Ellipse2D path iterator - */ - /** - * The subclass of PathIterator to traverse an Ellipse2D. - */ - class Iterator implements PathIterator { - - /* - * Ellipse is subdivided into four quarters by x and y axis. Each part - * approximated by cubic Bezier curve. Arc in first quarter is started - * in (a, 0) and finished in (0, b) points. Control points for cubic - * curve wiil be (a, 0), (a, m), (n, b) and (0, b) where n and m are - * calculated based on requirement Bezier curve in point 0.5 should lay - * on the arc. - */ - - /** - * The coefficient to calculate control points of Bezier curves. - */ - final double u = 2.0 / 3.0 * (Math.sqrt(2.0) - 1.0); - - /** - * The points coordinates calculation table. - */ - final double points[][] = { - { - 1.0, 0.5 + u, 0.5 + u, 1.0, 0.5, 1.0 - }, { - 0.5 - u, 1.0, 0.0, 0.5 + u, 0.0, 0.5 - }, { - 0.0, 0.5 - u, 0.5 - u, 0.0, 0.5, 0.0 - }, { - 0.5 + u, 0.0, 1.0, 0.5 - u, 1.0, 0.5 - } - }; - - /** - * The x coordinate of left-upper corner of the ellipse bounds. - */ - double x; - - /** - * The y coordinate of left-upper corner of the ellipse bounds. - */ - double y; - - /** - * The width of the ellipse bounds. - */ - double width; - - /** - * The height of the ellipse bounds. - */ - double height; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new Ellipse2D.Iterator for given ellipse and - * transformation - * - * @param e - * the source Ellipse2D object. - * @param t - * the affine transformation object. - */ - Iterator(Ellipse2D e, AffineTransform t) { - this.x = e.getX(); - this.y = e.getY(); - this.width = e.getWidth(); - this.height = e.getHeight(); - this.t = t; - if (width < 0.0 || height < 0.0) { - index = 6; - } - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > 5; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == 5) { - return SEG_CLOSE; - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - count = 1; - double p[] = points[3]; - coords[0] = x + p[4] * width; - coords[1] = y + p[5] * height; - } else { - type = SEG_CUBICTO; - count = 3; - double p[] = points[index - 1]; - int j = 0; - for (int i = 0; i < 3; i++) { - coords[j] = x + p[j++] * width; - coords[j] = y + p[j++] * height; - } - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == 5) { - return SEG_CLOSE; - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - count = 1; - double p[] = points[3]; - coords[0] = (float)(x + p[4] * width); - coords[1] = (float)(y + p[5] * height); - } else { - type = SEG_CUBICTO; - count = 3; - int j = 0; - double p[] = points[index - 1]; - for (int i = 0; i < 3; i++) { - coords[j] = (float)(x + p[j++] * width); - coords[j] = (float)(y + p[j++] * height); - } - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - } - - /** - * Instantiates a new Ellipse2D. - */ - protected Ellipse2D() { - } - - public boolean contains(double px, double py) { - if (isEmpty()) { - return false; - } - - double a = (px - getX()) / getWidth() - 0.5; - double b = (py - getY()) / getHeight() - 0.5; - - return a * a + b * b < 0.25; - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - if (isEmpty() || rw <= 0.0 || rh <= 0.0) { - return false; - } - - double cx = getX() + getWidth() / 2.0; - double cy = getY() + getHeight() / 2.0; - - double rx1 = rx; - double ry1 = ry; - double rx2 = rx + rw; - double ry2 = ry + rh; - - double nx = cx < rx1 ? rx1 : (cx > rx2 ? rx2 : cx); - double ny = cy < ry1 ? ry1 : (cy > ry2 ? ry2 : cy); - - return contains(nx, ny); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - if (isEmpty() || rw <= 0.0 || rh <= 0.0) { - return false; - } - - double rx1 = rx; - double ry1 = ry; - double rx2 = rx + rw; - double ry2 = ry + rh; - - return contains(rx1, ry1) && contains(rx2, ry1) && contains(rx2, ry2) && contains(rx1, ry2); - } - - public PathIterator getPathIterator(AffineTransform at) { - return new Iterator(this, at); - } -} diff --git a/awt/java/awt/geom/FlatteningPathIterator.java b/awt/java/awt/geom/FlatteningPathIterator.java deleted file mode 100644 index 8208f39..0000000 --- a/awt/java/awt/geom/FlatteningPathIterator.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class FlatteningPathIterator takes a PathIterator for traversing a curved - * shape and flattens it by estimating the curve as a series of line segments. - * The flattening factor indicates how far the estimating line segments are - * allowed to be from the actual curve: the FlatteningPathIterator will keep - * dividing each curved segment into smaller and smaller flat segments until - * either the segments are within the flattening factor of the curve or until - * the buffer limit is reached. - * - * @since Android 1.0 - */ -public class FlatteningPathIterator implements PathIterator { - - /** - * The default points buffer size. - */ - private static final int BUFFER_SIZE = 16; - - /** - * The default curve subdivision limit. - */ - private static final int BUFFER_LIMIT = 16; - - /** - * The points buffer capacity. - */ - private static final int BUFFER_CAPACITY = 16; - - /** - * The type of current segment to be flat. - */ - int bufType; - - /** - * The curve subdivision limit. - */ - int bufLimit; - - /** - * The current points buffer size. - */ - int bufSize; - - /** - * The inner cursor position in points buffer. - */ - int bufIndex; - - /** - * The current subdivision count. - */ - int bufSubdiv; - - /** - * The points buffer. - */ - double buf[]; - - /** - * The indicator of empty points buffer. - */ - boolean bufEmpty = true; - - /** - * The source PathIterator. - */ - PathIterator p; - - /** - * The flatness of new path. - */ - double flatness; - - /** - * The square of flatness. - */ - double flatness2; - - /** - * The x coordinate of previous path segment. - */ - double px; - - /** - * The y coordinate of previous path segment. - */ - double py; - - /** - * The temporary buffer for getting points from PathIterator. - */ - double coords[] = new double[6]; - - /** - * Instantiates a new flattening path iterator given the path iterator for a - * (possibly) curved path and a flattening factor which indicates how close - * together the points on the curve should be chosen. The buffer limit - * defaults to 16 which means that each curve will be divided into no more - * than 16 segments regardless of the flattening factor. - * - * @param path - * the path iterator of the original curve. - * @param flatness - * the flattening factor that indicates how far the flat path is - * allowed to be from the actual curve in order to decide when to - * stop dividing the path into smaller and smaller segments. - * @throws IllegalArgumentException - * if the flatness is less than zero. - * @throws NullPointerException - * if the path is null. - */ - public FlatteningPathIterator(PathIterator path, double flatness) { - this(path, flatness, BUFFER_LIMIT); - } - - /** - * Instantiates a new flattening path iterator given the path iterator for a - * (possibly) curved path and a flattening factor and a buffer limit. The - * FlatteningPathIterator will keep dividing each curved segment into - * smaller and smaller flat segments until either the segments are within - * the flattening factor of the curve or until the buffer limit is reached. - * - * @param path - * the path iterator of the original curve. - * @param flatness - * the flattening factor that indicates how far the flat path is - * allowed to be from the actual curve in order to decide when to - * stop dividing the path into smaller and smaller segments. - * @param limit - * the maximum number of flat segments to divide each curve into. - * @throws IllegalArgumentException - * if the flatness or limit is less than zero. - * @throws NullPointerException - * if the path is null. - */ - public FlatteningPathIterator(PathIterator path, double flatness, int limit) { - if (flatness < 0.0) { - // awt.206=Flatness is less then zero - throw new IllegalArgumentException(Messages.getString("awt.206")); //$NON-NLS-1$ - } - if (limit < 0) { - // awt.207=Limit is less then zero - throw new IllegalArgumentException(Messages.getString("awt.207")); //$NON-NLS-1$ - } - if (path == null) { - // awt.208=Path is null - throw new NullPointerException(Messages.getString("awt.208")); //$NON-NLS-1$ - } - this.p = path; - this.flatness = flatness; - this.flatness2 = flatness * flatness; - this.bufLimit = limit; - this.bufSize = Math.min(bufLimit, BUFFER_SIZE); - this.buf = new double[bufSize]; - this.bufIndex = bufSize; - } - - /** - * Gets the flattening factor. - * - * @return the flattening factor. - */ - public double getFlatness() { - return flatness; - } - - /** - * Gets the maximum number of subdivisions per curved segment. - * - * @return the maximum number of subdivisions per curved segment. - */ - public int getRecursionLimit() { - return bufLimit; - } - - public int getWindingRule() { - return p.getWindingRule(); - } - - public boolean isDone() { - return bufEmpty && p.isDone(); - } - - /** - * Calculates flat path points for current segment of the source shape. Line - * segment is flat by itself. Flatness of quad and cubic curves evaluated by - * getFlatnessSq() method. Curves subdivided until current flatness is - * bigger than user defined and subdivision limit isn't exhausted. Single - * source segment translated to series of buffer points. The less flatness - * the bigger series. Every currentSegment() call extract one point from the - * buffer. When series completed evaluate() takes next source shape segment. - */ - void evaluate() { - if (bufEmpty) { - bufType = p.currentSegment(coords); - } - - switch (bufType) { - case SEG_MOVETO: - case SEG_LINETO: - px = coords[0]; - py = coords[1]; - break; - case SEG_QUADTO: - if (bufEmpty) { - bufIndex -= 6; - buf[bufIndex + 0] = px; - buf[bufIndex + 1] = py; - System.arraycopy(coords, 0, buf, bufIndex + 2, 4); - bufSubdiv = 0; - } - - while (bufSubdiv < bufLimit) { - if (QuadCurve2D.getFlatnessSq(buf, bufIndex) < flatness2) { - break; - } - - // Realloc buffer - if (bufIndex <= 4) { - double tmp[] = new double[bufSize + BUFFER_CAPACITY]; - System.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize - - bufIndex); - buf = tmp; - bufSize += BUFFER_CAPACITY; - bufIndex += BUFFER_CAPACITY; - } - - QuadCurve2D.subdivide(buf, bufIndex, buf, bufIndex - 4, buf, bufIndex); - - bufIndex -= 4; - bufSubdiv++; - } - - bufIndex += 4; - px = buf[bufIndex]; - py = buf[bufIndex + 1]; - - bufEmpty = (bufIndex == bufSize - 2); - if (bufEmpty) { - bufIndex = bufSize; - bufType = SEG_LINETO; - } else { - bufSubdiv--; - } - break; - case SEG_CUBICTO: - if (bufEmpty) { - bufIndex -= 8; - buf[bufIndex + 0] = px; - buf[bufIndex + 1] = py; - System.arraycopy(coords, 0, buf, bufIndex + 2, 6); - bufSubdiv = 0; - } - - while (bufSubdiv < bufLimit) { - if (CubicCurve2D.getFlatnessSq(buf, bufIndex) < flatness2) { - break; - } - - // Realloc buffer - if (bufIndex <= 6) { - double tmp[] = new double[bufSize + BUFFER_CAPACITY]; - System.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize - - bufIndex); - buf = tmp; - bufSize += BUFFER_CAPACITY; - bufIndex += BUFFER_CAPACITY; - } - - CubicCurve2D.subdivide(buf, bufIndex, buf, bufIndex - 6, buf, bufIndex); - - bufIndex -= 6; - bufSubdiv++; - } - - bufIndex += 6; - px = buf[bufIndex]; - py = buf[bufIndex + 1]; - - bufEmpty = (bufIndex == bufSize - 2); - if (bufEmpty) { - bufIndex = bufSize; - bufType = SEG_LINETO; - } else { - bufSubdiv--; - } - break; - } - - } - - public void next() { - if (bufEmpty) { - p.next(); - } - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4Bx")); //$NON-NLS-1$ - } - evaluate(); - int type = bufType; - if (type != SEG_CLOSE) { - coords[0] = (float)px; - coords[1] = (float)py; - if (type != SEG_MOVETO) { - type = SEG_LINETO; - } - } - return type; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - evaluate(); - int type = bufType; - if (type != SEG_CLOSE) { - coords[0] = px; - coords[1] = py; - if (type != SEG_MOVETO) { - type = SEG_LINETO; - } - } - return type; - } -} diff --git a/awt/java/awt/geom/GeneralPath.java b/awt/java/awt/geom/GeneralPath.java deleted file mode 100644 index 0669bc7..0000000 --- a/awt/java/awt/geom/GeneralPath.java +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.gl.Crossing; -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The class GeneralPath represents a shape whose outline is given by different - * types of curved and straight segments. - * - * @since Android 1.0 - */ -public final class GeneralPath implements Shape, Cloneable { - - /** - * The Constant WIND_EVEN_ODD see {@link PathIterator#WIND_EVEN_ODD}. - */ - public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD; - - /** - * The Constant WIND_NON_ZERO see {@link PathIterator#WIND_NON_ZERO}. - */ - public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO; - - /** - * The buffers size. - */ - private static final int BUFFER_SIZE = 10; - - /** - * The buffers capacity. - */ - private static final int BUFFER_CAPACITY = 10; - - /** - * The point's types buffer. - */ - byte[] types; - - /** - * The points buffer. - */ - float[] points; - - /** - * The point's type buffer size. - */ - int typeSize; - - /** - * The points buffer size. - */ - int pointSize; - - /** - * The path rule. - */ - int rule; - - /** - * The space amount in points buffer for different segmenet's types. - */ - static int pointShift[] = { - 2, // MOVETO - 2, // LINETO - 4, // QUADTO - 6, // CUBICTO - 0 - }; // CLOSE - - /* - * GeneralPath path iterator - */ - /** - * The Class Iterator is the subclass of Iterator for traversing the outline - * of a GeneralPath. - */ - class Iterator implements PathIterator { - - /** - * The current cursor position in types buffer. - */ - int typeIndex; - - /** - * The current cursor position in points buffer. - */ - int pointIndex; - - /** - * The source GeneralPath object. - */ - GeneralPath p; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * Constructs a new GeneralPath.Iterator for given general path. - * - * @param path - * the source GeneralPath object. - */ - Iterator(GeneralPath path) { - this(path, null); - } - - /** - * Constructs a new GeneralPath.Iterator for given general path and - * transformation. - * - * @param path - * the source GeneralPath object. - * @param at - * the AffineTransform object to apply rectangle path. - */ - Iterator(GeneralPath path, AffineTransform at) { - this.p = path; - this.t = at; - } - - public int getWindingRule() { - return p.getWindingRule(); - } - - public boolean isDone() { - return typeIndex >= p.typeSize; - } - - public void next() { - typeIndex++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type = p.types[typeIndex]; - int count = GeneralPath.pointShift[type]; - for (int i = 0; i < count; i++) { - coords[i] = p.points[pointIndex + i]; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count / 2); - } - pointIndex += count; - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type = p.types[typeIndex]; - int count = GeneralPath.pointShift[type]; - System.arraycopy(p.points, pointIndex, coords, 0, count); - if (t != null) { - t.transform(coords, 0, coords, 0, count / 2); - } - pointIndex += count; - return type; - } - - } - - /** - * Instantiates a new general path with the winding rule set to - * {@link PathIterator#WIND_NON_ZERO} and the initial capacity (number of - * segments) set to the default value 10. - */ - public GeneralPath() { - this(WIND_NON_ZERO, BUFFER_SIZE); - } - - /** - * Instantiates a new general path with the given winding rule and the - * initial capacity (number of segments) set to the default value 10. - * - * @param rule - * the winding rule, either {@link PathIterator#WIND_EVEN_ODD} or - * {@link PathIterator#WIND_NON_ZERO}. - */ - public GeneralPath(int rule) { - this(rule, BUFFER_SIZE); - } - - /** - * Instantiates a new general path with the given winding rule and initial - * capacity (number of segments). - * - * @param rule - * the winding rule, either {@link PathIterator#WIND_EVEN_ODD} or - * {@link PathIterator#WIND_NON_ZERO}. - * @param initialCapacity - * the number of segments the path is set to hold. - */ - public GeneralPath(int rule, int initialCapacity) { - setWindingRule(rule); - types = new byte[initialCapacity]; - points = new float[initialCapacity * 2]; - } - - /** - * Creates a new GeneralPath from the outline of the given shape. - * - * @param shape - * the shape. - */ - public GeneralPath(Shape shape) { - this(WIND_NON_ZERO, BUFFER_SIZE); - PathIterator p = shape.getPathIterator(null); - setWindingRule(p.getWindingRule()); - append(p, false); - } - - /** - * Sets the winding rule, which determines how to decide whether a point - * that isn't on the path itself is inside or outside of the shape. - * - * @param rule - * the new winding rule. - * @throws IllegalArgumentException - * if the winding rule is neither - * {@link PathIterator#WIND_EVEN_ODD} nor - * {@link PathIterator#WIND_NON_ZERO}. - */ - public void setWindingRule(int rule) { - if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) { - // awt.209=Invalid winding rule value - throw new java.lang.IllegalArgumentException(Messages.getString("awt.209")); //$NON-NLS-1$ - } - this.rule = rule; - } - - /** - * Gets the winding rule. - * - * @return the winding rule, either {@link PathIterator#WIND_EVEN_ODD} or - * {@link PathIterator#WIND_NON_ZERO}. - */ - public int getWindingRule() { - return rule; - } - - /** - * Checks the point data buffer sizes to see whether pointCount additional - * point-data elements can fit. (Note that the number of point data elements - * to add is more than one per point -- it depends on the type of point - * being added.) Reallocates the buffers to enlarge the size if necessary. - * - * @param pointCount - * the number of point data elements to be added. - * @param checkMove - * whether to check for existing points. - * @throws IllegalPathStateException - * checkMove is true and the path is currently empty. - */ - void checkBuf(int pointCount, boolean checkMove) { - if (checkMove && typeSize == 0) { - // awt.20A=First segment should be SEG_MOVETO type - throw new IllegalPathStateException(Messages.getString("awt.20A")); //$NON-NLS-1$ - } - if (typeSize == types.length) { - byte tmp[] = new byte[typeSize + BUFFER_CAPACITY]; - System.arraycopy(types, 0, tmp, 0, typeSize); - types = tmp; - } - if (pointSize + pointCount > points.length) { - float tmp[] = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)]; - System.arraycopy(points, 0, tmp, 0, pointSize); - points = tmp; - } - } - - /** - * Appends a new point to the end of this general path, disconnected from - * the existing path. - * - * @param x - * the x coordinate of the next point to append. - * @param y - * the y coordinate of the next point to append. - */ - public void moveTo(float x, float y) { - if (typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_MOVETO) { - points[pointSize - 2] = x; - points[pointSize - 1] = y; - } else { - checkBuf(2, false); - types[typeSize++] = PathIterator.SEG_MOVETO; - points[pointSize++] = x; - points[pointSize++] = y; - } - } - - /** - * Appends a new segment to the end of this general path by making a - * straight line segment from the current endpoint to the given new point. - * - * @param x - * the x coordinate of the next point to append. - * @param y - * the y coordinate of the next point to append. - */ - public void lineTo(float x, float y) { - checkBuf(2, true); - types[typeSize++] = PathIterator.SEG_LINETO; - points[pointSize++] = x; - points[pointSize++] = y; - } - - /** - * Appends a new segment to the end of this general path by making a - * quadratic curve from the current endpoint to the point (x2, y2) using the - * point (x1, y1) as the quadratic curve's control point. - * - * @param x1 - * the x coordinate of the quadratic curve's control point. - * @param y1 - * the y coordinate of the quadratic curve's control point. - * @param x2 - * the x coordinate of the quadratic curve's end point. - * @param y2 - * the y coordinate of the quadratic curve's end point. - */ - public void quadTo(float x1, float y1, float x2, float y2) { - checkBuf(4, true); - types[typeSize++] = PathIterator.SEG_QUADTO; - points[pointSize++] = x1; - points[pointSize++] = y1; - points[pointSize++] = x2; - points[pointSize++] = y2; - } - - /** - * Appends a new segment to the end of this general path by making a cubic - * curve from the current endpoint to the point (x3, y3) using (x1, y1) and - * (x2, y2) as control points. - * - * @see java.awt.geom.CubicCurve2D - * @param x1 - * the x coordinate of the new cubic segment's first control - * point. - * @param y1 - * the y coordinate of the new cubic segment's first control - * point. - * @param x2 - * the x coordinate of the new cubic segment's second control - * point. - * @param y2 - * the y coordinate of the new cubic segment's second control - * point. - * @param x3 - * the x coordinate of the new cubic segment's end point. - * @param y3 - * the y coordinate of the new cubic segment's end point. - */ - public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) { - checkBuf(6, true); - types[typeSize++] = PathIterator.SEG_CUBICTO; - points[pointSize++] = x1; - points[pointSize++] = y1; - points[pointSize++] = x2; - points[pointSize++] = y2; - points[pointSize++] = x3; - points[pointSize++] = y3; - } - - /** - * Appends the type information to declare that the current endpoint closes - * the curve. - */ - public void closePath() { - if (typeSize == 0 || types[typeSize - 1] != PathIterator.SEG_CLOSE) { - checkBuf(0, true); - types[typeSize++] = PathIterator.SEG_CLOSE; - } - } - - /** - * Appends the outline of the specified shape onto the end of this - * GeneralPath. - * - * @param shape - * the shape whose outline is to be appended. - * @param connect - * true to connect this path's current endpoint to the first - * point of the shape's outline or false to append the shape's - * outline without connecting it. - * @throws NullPointerException - * if the shape parameter is null. - */ - public void append(Shape shape, boolean connect) { - PathIterator p = shape.getPathIterator(null); - append(p, connect); - } - - /** - * Appends the path defined by the specified PathIterator onto the end of - * this GeneralPath. - * - * @param path - * the PathIterator that defines the new path to append. - * @param connect - * true to connect this path's current endpoint to the first - * point of the shape's outline or false to append the shape's - * outline without connecting it. - */ - public void append(PathIterator path, boolean connect) { - while (!path.isDone()) { - float coords[] = new float[6]; - switch (path.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - if (!connect || typeSize == 0) { - moveTo(coords[0], coords[1]); - break; - } - if (types[typeSize - 1] != PathIterator.SEG_CLOSE - && points[pointSize - 2] == coords[0] - && points[pointSize - 1] == coords[1]) { - break; - } - // NO BREAK; - case PathIterator.SEG_LINETO: - lineTo(coords[0], coords[1]); - break; - case PathIterator.SEG_QUADTO: - quadTo(coords[0], coords[1], coords[2], coords[3]); - break; - case PathIterator.SEG_CUBICTO: - curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); - break; - case PathIterator.SEG_CLOSE: - closePath(); - break; - } - path.next(); - connect = false; - } - } - - /** - * Gets the current end point of the path. - * - * @return the current end point of the path. - */ - public Point2D getCurrentPoint() { - if (typeSize == 0) { - return null; - } - int j = pointSize - 2; - if (types[typeSize - 1] == PathIterator.SEG_CLOSE) { - - for (int i = typeSize - 2; i > 0; i--) { - int type = types[i]; - if (type == PathIterator.SEG_MOVETO) { - break; - } - j -= pointShift[type]; - } - } - return new Point2D.Float(points[j], points[j + 1]); - } - - /** - * Resets the GeneralPath to being an empty path. The underlying point and - * segment data is not deleted but rather the end indices of the data arrays - * are set to zero. - */ - public void reset() { - typeSize = 0; - pointSize = 0; - } - - /** - * Transform all of the coordinates of this path according to the specified - * AffineTransform. - * - * @param t - * the AffineTransform. - */ - public void transform(AffineTransform t) { - t.transform(points, 0, points, 0, pointSize / 2); - } - - /** - * Creates a new GeneralPath whose data is given by this path's data - * transformed according to the specified AffineTransform. - * - * @param t - * the AffineTransform. - * @return the new GeneralPath whose data is given by this path's data - * transformed according to the specified AffineTransform. - */ - public Shape createTransformedShape(AffineTransform t) { - GeneralPath p = (GeneralPath)clone(); - if (t != null) { - p.transform(t); - } - return p; - } - - public Rectangle2D getBounds2D() { - float rx1, ry1, rx2, ry2; - if (pointSize == 0) { - rx1 = ry1 = rx2 = ry2 = 0.0f; - } else { - int i = pointSize - 1; - ry1 = ry2 = points[i--]; - rx1 = rx2 = points[i--]; - while (i > 0) { - float y = points[i--]; - float x = points[i--]; - if (x < rx1) { - rx1 = x; - } else if (x > rx2) { - rx2 = x; - } - if (y < ry1) { - ry1 = y; - } else if (y > ry2) { - ry2 = y; - } - } - } - return new Rectangle2D.Float(rx1, ry1, rx2 - rx1, ry2 - ry1); - } - - public Rectangle getBounds() { - return getBounds2D().getBounds(); - } - - /** - * Checks the cross count (number of times a ray from the point crosses the - * shape's boundary) to determine whether the number of crossings - * corresponds to a point inside the shape or not (according to the shape's - * path rule). - * - * @param cross - * the point's cross count. - * @return true if the point is inside the path, or false otherwise. - */ - boolean isInside(int cross) { - if (rule == WIND_NON_ZERO) { - return Crossing.isInsideNonZero(cross); - } - return Crossing.isInsideEvenOdd(cross); - } - - public boolean contains(double px, double py) { - return isInside(Crossing.crossShape(this, px, py)); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross != Crossing.CROSSING && isInside(cross); - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross == Crossing.CROSSING || isInside(cross); - } - - public boolean contains(Point2D p) { - return contains(p.getX(), p.getY()); - } - - public boolean contains(Rectangle2D r) { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public boolean intersects(Rectangle2D r) { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public PathIterator getPathIterator(AffineTransform t) { - return new Iterator(this, t); - } - - public PathIterator getPathIterator(AffineTransform t, double flatness) { - return new FlatteningPathIterator(getPathIterator(t), flatness); - } - - @Override - public Object clone() { - try { - GeneralPath p = (GeneralPath)super.clone(); - p.types = types.clone(); - p.points = points.clone(); - return p; - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - -} diff --git a/awt/java/awt/geom/IllegalPathStateException.java b/awt/java/awt/geom/IllegalPathStateException.java deleted file mode 100644 index 750ba29..0000000 --- a/awt/java/awt/geom/IllegalPathStateException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -/** - * The Class IllegalPathStateException indicates errors where the current state - * of a path object is incompatible with the desired action, such as performing - * non-trivial actions on an empty path. - * - * @since Android 1.0 - */ -public class IllegalPathStateException extends RuntimeException { - - /** - * The Constant serialVersionUID. - */ - private static final long serialVersionUID = -5158084205220481094L; - - /** - * Instantiates a new illegal path state exception. - */ - public IllegalPathStateException() { - } - - /** - * Instantiates a new illegal path state exception with the specified detail - * message. - * - * @param s - * the details of the error. - */ - public IllegalPathStateException(String s) { - super(s); - } - -} diff --git a/awt/java/awt/geom/Line2D.java b/awt/java/awt/geom/Line2D.java deleted file mode 100644 index fcd51b6..0000000 --- a/awt/java/awt/geom/Line2D.java +++ /dev/null @@ -1,948 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class Line2D represents a line whose data is given in high-precision - * values appropriate for graphical operations. - * - * @since Android 1.0 - */ -public abstract class Line2D implements Shape, Cloneable { - - /** - * The Class Float is the subclass of Line2D that has all of its data values - * stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends Line2D { - - /** - * The x coordinate of the starting point. - */ - public float x1; - - /** - * The y coordinate of the starting point. - */ - public float y1; - - /** - * The x coordinate of the end point. - */ - public float x2; - - /** - * The y coordinate of the end point. - */ - public float y2; - - /** - * Instantiates a new float-valued Line2D with its data values set to - * zero. - */ - public Float() { - } - - /** - * Instantiates a new float-valued Line2D with the specified endpoints. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public Float(float x1, float y1, float x2, float y2) { - setLine(x1, y1, x2, y2); - } - - /** - * Instantiates a new float-valued Line2D with the specified endpoints. - * - * @param p1 - * the starting point. - * @param p2 - * the end point. - */ - public Float(Point2D p1, Point2D p2) { - setLine(p1, p2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Float(x1, y1); - } - - @Override - public Point2D getP2() { - return new Point2D.Float(x2, y2); - } - - @Override - public void setLine(double x1, double y1, double x2, double y2) { - this.x1 = (float)x1; - this.y1 = (float)y1; - this.x2 = (float)x2; - this.y2 = (float)y2; - } - - /** - * Sets the data values that define the line. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public void setLine(float x1, float y1, float x2, float y2) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - float rx, ry, rw, rh; - if (x1 < x2) { - rx = x1; - rw = x2 - x1; - } else { - rx = x2; - rw = x1 - x2; - } - if (y1 < y2) { - ry = y1; - rh = y2 - y1; - } else { - ry = y2; - rh = y1 - y2; - } - return new Rectangle2D.Float(rx, ry, rw, rh); - } - } - - /** - * The Class Double is the subclass of Line2D that has all of its data - * values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends Line2D { - - /** - * The x coordinate of the starting point. - */ - public double x1; - - /** - * The y coordinate of the starting point. - */ - public double y1; - - /** - * The x coordinate of the end point. - */ - public double x2; - - /** - * The y coordinate of the end point. - */ - public double y2; - - /** - * Instantiates a new double-valued Line2D with its data values set to - * zero. - */ - public Double() { - } - - /** - * Instantiates a new double-valued Line2D with the specified endpoints. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public Double(double x1, double y1, double x2, double y2) { - setLine(x1, y1, x2, y2); - } - - /** - * Instantiates a new double-valued Line2D with the specified endpoints. - * - * @param p1 - * the starting point. - * @param p2 - * the end point. - */ - public Double(Point2D p1, Point2D p2) { - setLine(p1, p2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Double(x1, y1); - } - - @Override - public Point2D getP2() { - return new Point2D.Double(x2, y2); - } - - @Override - public void setLine(double x1, double y1, double x2, double y2) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - double rx, ry, rw, rh; - if (x1 < x2) { - rx = x1; - rw = x2 - x1; - } else { - rx = x2; - rw = x1 - x2; - } - if (y1 < y2) { - ry = y1; - rh = y2 - y1; - } else { - ry = y2; - rh = y1 - y2; - } - return new Rectangle2D.Double(rx, ry, rw, rh); - } - } - - /* - * Line2D path iterator - */ - /** - * The subclass of PathIterator to traverse a Line2D. - */ - class Iterator implements PathIterator { - - /** - * The x coordinate of the start line point. - */ - double x1; - - /** - * The y coordinate of the start line point. - */ - double y1; - - /** - * The x coordinate of the end line point. - */ - double x2; - - /** - * The y coordinate of the end line point. - */ - double y2; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new Line2D.Iterator for given line and transformation. - * - * @param l - * the source Line2D object. - * @param at - * the AffineTransform object to apply rectangle path. - */ - Iterator(Line2D l, AffineTransform at) { - this.x1 = l.getX1(); - this.y1 = l.getY1(); - this.x2 = l.getX2(); - this.y2 = l.getY2(); - this.t = at; - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > 1; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = x1; - coords[1] = y1; - } else { - type = SEG_LINETO; - coords[0] = x2; - coords[1] = y2; - } - if (t != null) { - t.transform(coords, 0, coords, 0, 1); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = (float)x1; - coords[1] = (float)y1; - } else { - type = SEG_LINETO; - coords[0] = (float)x2; - coords[1] = (float)y2; - } - if (t != null) { - t.transform(coords, 0, coords, 0, 1); - } - return type; - } - - } - - /** - * Instantiates a new Line2D. - */ - protected Line2D() { - } - - /** - * Gets the x coordinate of the starting point. - * - * @return the x coordinate of the starting point. - */ - public abstract double getX1(); - - /** - * Gets the y coordinate of the starting point. - * - * @return the y coordinate of the starting point. - */ - public abstract double getY1(); - - /** - * Gets the x coordinate of the end point. - * - * @return the x2. - */ - public abstract double getX2(); - - /** - * Gets the y coordinate of the end point. - * - * @return the y coordinate of the end point. - */ - public abstract double getY2(); - - /** - * Gets the p the starting point. - * - * @return the p the starting point. - */ - public abstract Point2D getP1(); - - /** - * Gets the p end point. - * - * @return the p end point. - */ - public abstract Point2D getP2(); - - /** - * Sets the line's endpoints. - * - * @param x1 - * the x coordinate of the starting point. - * @param y1 - * the y coordinate of the starting point. - * @param x2 - * the x coordinate of the end point. - * @param y2 - * the y coordinate of the end point. - */ - public abstract void setLine(double x1, double y1, double x2, double y2); - - /** - * Sets the line's endpoints. - * - * @param p1 - * the starting point. - * @param p2 - * the end point. - */ - public void setLine(Point2D p1, Point2D p2) { - setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Sets the line's endpoints by copying the data from another Line2D. - * - * @param line - * the Line2D to copy the endpoint data from. - */ - public void setLine(Line2D line) { - setLine(line.getX1(), line.getY1(), line.getX2(), line.getY2()); - } - - public Rectangle getBounds() { - return getBounds2D().getBounds(); - } - - /** - * Tells where the point is with respect to the line segment, given the - * orientation of the line segment. If the ray found by extending the line - * segment from its starting point is rotated, this method tells whether the - * ray should rotate in a clockwise direction or a counter-clockwise - * direction to hit the point first. The return value is 0 if the point is - * on the line segment, it's 1 if the point is on the ray or if the ray - * should rotate in a counter-clockwise direction to get to the point, and - * it's -1 if the ray should rotate in a clockwise direction to get to the - * point or if the point is on the line determined by the line segment but - * not on the ray from the segment's starting point and through its end - * point. - * - * @param x1 - * the x coordinate of the starting point of the line segment. - * @param y1 - * the y coordinate of the starting point of the line segment. - * @param x2 - * the x coordinate of the end point of the line segment. - * @param y2 - * the y coordinate of the end point of the line segment. - * @param px - * the x coordinate of the test point. - * @param py - * the p coordinate of the test point. - * @return the value that describes where the point is with respect to the - * line segment, given the orientation of the line segment. - */ - public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py) { - /* - * A = (x2-x1, y2-y1) P = (px-x1, py-y1) - */ - x2 -= x1; - y2 -= y1; - px -= x1; - py -= y1; - double t = px * y2 - py * x2; // PxA - if (t == 0.0) { - t = px * x2 + py * y2; // P*A - if (t > 0.0) { - px -= x2; // B-A - py -= y2; - t = px * x2 + py * y2; // (P-A)*A - if (t < 0.0) { - t = 0.0; - } - } - } - - return t < 0.0 ? -1 : (t > 0.0 ? 1 : 0); - } - - /** - * Tells where the point is with respect to this line segment, given the - * orientation of this line segment. If the ray found by extending the line - * segment from its starting point is rotated, this method tells whether the - * ray should rotate in a clockwise direction or a counter-clockwise - * direction to hit the point first. The return value is 0 if the point is - * on the line segment, it's 1 if the point is on the ray or if the ray - * should rotate in a counter-clockwise direction to get to the point, and - * it's -1 if the ray should rotate in a clockwise direction to get to the - * point or if the point is on the line determined by the line segment but - * not on the ray from the segment's starting point and through its end - * point. - * - * @param px - * the x coordinate of the test point. - * @param py - * the p coordinate of the test point. - * @return the value that describes where the point is with respect to this - * line segment, given the orientation of this line segment. - */ - public int relativeCCW(double px, double py) { - return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Tells where the point is with respect to this line segment, given the - * orientation of this line segment. If the ray found by extending the line - * segment from its starting point is rotated, this method tells whether the - * ray should rotate in a clockwise direction or a counter-clockwise - * direction to hit the point first. The return value is 0 if the point is - * on the line segment, it's 1 if the point is on the ray or if the ray - * should rotate in a counter-clockwise direction to get to the point, and - * it's -1 if the ray should rotate in a clockwise direction to get to the - * point or if the point is on the line determined by the line segment but - * not on the ray from the segment's starting point and through its end - * point. - * - * @param p - * the test point. - * @return the value that describes where the point is with respect to this - * line segment, given the orientation of this line segment. - */ - public int relativeCCW(Point2D p) { - return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Tells whether the two line segments cross. - * - * @param x1 - * the x coordinate of the starting point of the first segment. - * @param y1 - * the y coordinate of the starting point of the first segment. - * @param x2 - * the x coordinate of the end point of the first segment. - * @param y2 - * the y coordinate of the end point of the first segment. - * @param x3 - * the x coordinate of the starting point of the second segment. - * @param y3 - * the y coordinate of the starting point of the second segment. - * @param x4 - * the x coordinate of the end point of the second segment. - * @param y4 - * the y coordinate of the end point of the second segment. - * @return true, if the two line segments cross. - */ - public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, - double y3, double x4, double y4) { - /* - * A = (x2-x1, y2-y1) B = (x3-x1, y3-y1) C = (x4-x1, y4-y1) D = (x4-x3, - * y4-y3) = C-B E = (x1-x3, y1-y3) = -B F = (x2-x3, y2-y3) = A-B Result - * is ((AxB) (AxC) <=0) and ((DxE) (DxF) <= 0) DxE = (C-B)x(-B) = - * BxB-CxB = BxC DxF = (C-B)x(A-B) = CxA-CxB-BxA+BxB = AxB+BxC-AxC - */ - - x2 -= x1; // A - y2 -= y1; - x3 -= x1; // B - y3 -= y1; - x4 -= x1; // C - y4 -= y1; - - double AvB = x2 * y3 - x3 * y2; - double AvC = x2 * y4 - x4 * y2; - - // Online - if (AvB == 0.0 && AvC == 0.0) { - if (x2 != 0.0) { - return (x4 * x3 <= 0.0) - || ((x3 * x2 >= 0.0) && (x2 > 0.0 ? x3 <= x2 || x4 <= x2 : x3 >= x2 - || x4 >= x2)); - } - if (y2 != 0.0) { - return (y4 * y3 <= 0.0) - || ((y3 * y2 >= 0.0) && (y2 > 0.0 ? y3 <= y2 || y4 <= y2 : y3 >= y2 - || y4 >= y2)); - } - return false; - } - - double BvC = x3 * y4 - x4 * y3; - - return (AvB * AvC <= 0.0) && (BvC * (AvB + BvC - AvC) <= 0.0); - } - - /** - * Tells whether the specified line segments crosses this line segment. - * - * @param x1 - * the x coordinate of the starting point of the test segment. - * @param y1 - * the y coordinate of the starting point of the test segment. - * @param x2 - * the x coordinate of the end point of the test segment. - * @param y2 - * the y coordinate of the end point of the test segment. - * @return true, if the specified line segments crosses this line segment. - */ - public boolean intersectsLine(double x1, double y1, double x2, double y2) { - return linesIntersect(x1, y1, x2, y2, getX1(), getY1(), getX2(), getY2()); - } - - /** - * Tells whether the specified line segments crosses this line segment. - * - * @param l - * the test segment. - * @return true, if the specified line segments crosses this line segment. - * @throws NullPointerException - * if l is null. - */ - public boolean intersectsLine(Line2D l) { - return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(), getX1(), getY1(), - getX2(), getY2()); - } - - /** - * Gives the square of the distance between the point and the line segment. - * - * @param x1 - * the x coordinate of the starting point of the line segment. - * @param y1 - * the y coordinate of the starting point of the line segment. - * @param x2 - * the x coordinate of the end point of the line segment. - * @param y2 - * the y coordinate of the end point of the line segment. - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the the square of the distance between the point and the line - * segment. - */ - public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, - double py) { - /* - * A = (x2 - x1, y2 - y1) P = (px - x1, py - y1) - */ - x2 -= x1; // A = (x2, y2) - y2 -= y1; - px -= x1; // P = (px, py) - py -= y1; - double dist; - if (px * x2 + py * y2 <= 0.0) { // P*A - dist = px * px + py * py; - } else { - px = x2 - px; // P = A - P = (x2 - px, y2 - py) - py = y2 - py; - if (px * x2 + py * y2 <= 0.0) { // P*A - dist = px * px + py * py; - } else { - dist = px * y2 - py * x2; - dist = dist * dist / (x2 * x2 + y2 * y2); // pxA/|A| - } - } - if (dist < 0) { - dist = 0; - } - return dist; - } - - /** - * Gives the distance between the point and the line segment. - * - * @param x1 - * the x coordinate of the starting point of the line segment. - * @param y1 - * the y coordinate of the starting point of the line segment. - * @param x2 - * the x coordinate of the end point of the line segment. - * @param y2 - * the y coordinate of the end point of the line segment. - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the the distance between the point and the line segment. - */ - public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py) { - return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py)); - } - - /** - * Gives the square of the distance between the point and this line segment. - * - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the the square of the distance between the point and this line - * segment. - */ - public double ptSegDistSq(double px, double py) { - return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Gives the square of the distance between the point and this line segment. - * - * @param p - * the test point. - * @return the square of the distance between the point and this line - * segment. - */ - public double ptSegDistSq(Point2D p) { - return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Gives the distance between the point and this line segment. - * - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the distance between the point and this line segment. - */ - public double ptSegDist(double px, double py) { - return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Gives the distance between the point and this line segment. - * - * @param p - * the test point. - * @return the distance between the point and this line segment. - */ - public double ptSegDist(Point2D p) { - return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Gives the square of the distance between the point and the line. - * - * @param x1 - * the x coordinate of the starting point of the line segment. - * @param y1 - * the y coordinate of the starting point of the line segment. - * @param x2 - * the x coordinate of the end point of the line segment. - * @param y2 - * the y coordinate of the end point of the line segment. - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the square of the distance between the point and the line. - */ - public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, - double py) { - x2 -= x1; - y2 -= y1; - px -= x1; - py -= y1; - double s = px * y2 - py * x2; - return s * s / (x2 * x2 + y2 * y2); - } - - /** - * Gives the square of the distance between the point and the line. - * - * @param x1 - * the x coordinate of the starting point of the line segment. - * @param y1 - * the y coordinate of the starting point of the line segment. - * @param x2 - * the x coordinate of the end point of the line segment. - * @param y2 - * the y coordinate of the end point of the line segment. - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the square of the distance between the point and the line. - */ - public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py) { - return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py)); - } - - /** - * Gives the square of the distance between the point and the line - * determined by this Line2D. - * - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the square of the distance between the point and the line - * determined by this Line2D. - */ - public double ptLineDistSq(double px, double py) { - return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Gives the square of the distance between the point and the line - * determined by this Line2D. - * - * @param p - * the test point. - * @return the square of the distance between the point and the line - * determined by this Line2D. - */ - public double ptLineDistSq(Point2D p) { - return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Gives the distance between the point and the line determined by this - * Line2D. - * - * @param px - * the x coordinate of the test point. - * @param py - * the y coordinate of the test point. - * @return the distance between the point and the line determined by this - * Line2D. - */ - public double ptLineDist(double px, double py) { - return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Gives the distance between the point and the line determined by this - * Line2D. - * - * @param p - * the test point. - * @return the distance between the point and the line determined by this - * Line2D. - */ - public double ptLineDist(Point2D p) { - return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - public boolean contains(double px, double py) { - return false; - } - - public boolean contains(Point2D p) { - return false; - } - - public boolean contains(Rectangle2D r) { - return false; - } - - public boolean contains(double rx, double ry, double rw, double rh) { - return false; - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - return intersects(new Rectangle2D.Double(rx, ry, rw, rh)); - } - - public boolean intersects(Rectangle2D r) { - return r.intersectsLine(getX1(), getY1(), getX2(), getY2()); - } - - public PathIterator getPathIterator(AffineTransform at) { - return new Iterator(this, at); - } - - public PathIterator getPathIterator(AffineTransform at, double flatness) { - return new Iterator(this, at); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - -} diff --git a/awt/java/awt/geom/NoninvertibleTransformException.java b/awt/java/awt/geom/NoninvertibleTransformException.java deleted file mode 100644 index a4e6f0f..0000000 --- a/awt/java/awt/geom/NoninvertibleTransformException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -/** - * The Class NoninvertibleTransformException is the exception that is thrown - * when an action requires inverting an {@link AffineTransform} that is not - * invertible (has determinant 0). - * - * @since Android 1.0 - */ -public class NoninvertibleTransformException extends java.lang.Exception { - - /** - * The Constant serialVersionUID. - */ - private static final long serialVersionUID = 6137225240503990466L; - - /** - * Instantiates a new non-invertible transform exception. - * - * @param s - * the error message. - */ - public NoninvertibleTransformException(String s) { - super(s); - } - -} diff --git a/awt/java/awt/geom/PathIterator.java b/awt/java/awt/geom/PathIterator.java deleted file mode 100644 index 2d1c0ff..0000000 --- a/awt/java/awt/geom/PathIterator.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -/** - * The Interface PathIterator represents an iterator object that can be used to - * traverse the outline of a {@link java.awt.Shape}. It returns points along the - * boundary of the Shape which may be actual vertices (in the case of a shape - * made of line segments) or may be points on a curved segment with the distance - * between the points determined by a chosen flattening factor. - * <p> - * If the shape is closed, the outline is traversed in the counter-clockwise - * direction. That means that moving forward along the boundary is to travel in - * such a way that the interior of the shape is to the left of the outline path - * and the exterior of the shape is to the right of the outline path. The - * interior and exterior of the shape are determined by a winding rule. - * </p> - * - * @since Android 1.0 - */ -public interface PathIterator { - - /** - * The Constant WIND_EVEN_ODD indicates the winding rule that says that a - * point is outside the shape if any infinite ray from the point crosses the - * outline of the shape an even number of times, otherwise it is inside. - */ - public static final int WIND_EVEN_ODD = 0; - - /** - * The Constant WIND_NON_ZERO indicates the winding rule that says that a - * point is inside the shape if every infinite ray starting from that point - * crosses the outline of the shape a non-zero number of times. - */ - public static final int WIND_NON_ZERO = 1; - - /** - * The Constant SEG_MOVETO indicates that to follow the shape's outline from - * the previous point to the current point, the cursor (traversal point) - * should be placed directly on the current point. - */ - public static final int SEG_MOVETO = 0; - - /** - * The Constant SEG_LINETO indicates that to follow the shape's outline from - * the previous point to the current point, the cursor (traversal point) - * should follow a straight line. - */ - public static final int SEG_LINETO = 1; - - /** - * The Constant SEG_QUADTO indicates that to follow the shape's outline from - * the previous point to the current point, the cursor (traversal point) - * should follow a quadratic curve. - */ - public static final int SEG_QUADTO = 2; - - /** - * The Constant SEG_CUBICTO indicates that to follow the shape's outline - * from the previous point to the current point, the cursor (traversal - * point) should follow a cubic curve. - */ - public static final int SEG_CUBICTO = 3; - - /** - * The Constant SEG_CLOSE indicates that the previous point was the end of - * the shape's outline. - */ - public static final int SEG_CLOSE = 4; - - /** - * Gets the winding rule, either {@link PathIterator#WIND_EVEN_ODD} or - * {@link PathIterator#WIND_NON_ZERO}. - * - * @return the winding rule. - */ - public int getWindingRule(); - - /** - * Checks if this PathIterator has been completely traversed. - * - * @return true, if this PathIterator has been completely traversed. - */ - public boolean isDone(); - - /** - * Tells this PathIterator to skip to the next segment. - */ - public void next(); - - /** - * Gets the coordinates of the next vertex point along the shape's outline - * and a flag that indicates what kind of segment to use in order to connect - * the previous vertex point to the current vertex point to form the current - * segment. - * - * @param coords - * the array that the coordinates of the end point of the current - * segment are written into. - * @return the flag that indicates how to follow the shape's outline from - * the previous point to the current one, chosen from the following - * constants: {@link PathIterator#SEG_MOVETO}, - * {@link PathIterator#SEG_LINETO}, {@link PathIterator#SEG_QUADTO}, - * {@link PathIterator#SEG_CUBICTO}, or - * {@link PathIterator#SEG_CLOSE}. - */ - public int currentSegment(float[] coords); - - /** - * Gets the coordinates of the next vertex point along the shape's outline - * and a flag that indicates what kind of segment to use in order to connect - * the previous vertex point to the current vertex point to form the current - * segment. - * - * @param coords - * the array that the coordinates of the end point of the current - * segment are written into. - * @return the flag that indicates how to follow the shape's outline from - * the previous point to the current one, chosen from the following - * constants: {@link PathIterator#SEG_MOVETO}, - * {@link PathIterator#SEG_LINETO}, {@link PathIterator#SEG_QUADTO}, - * {@link PathIterator#SEG_CUBICTO}, or - * {@link PathIterator#SEG_CLOSE}. - */ - public int currentSegment(double[] coords); - -} diff --git a/awt/java/awt/geom/Point2D.java b/awt/java/awt/geom/Point2D.java deleted file mode 100644 index f7026c8..0000000 --- a/awt/java/awt/geom/Point2D.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import org.apache.harmony.misc.HashCode; - -/** - * The Class Point2D represents a point whose data is given in high-precision - * values appropriate for graphical operations. - * - * @since Android 1.0 - */ -public abstract class Point2D implements Cloneable { - - /** - * The Class Float is the subclass of Point2D that has all of its data - * values stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends Point2D { - - /** - * The x coordinate. - */ - public float x; - - /** - * The y coordinate. - */ - public float y; - - /** - * Instantiates a new float-valued Point2D with its data set to zero. - */ - public Float() { - } - - /** - * Instantiates a new float-valued Point2D with the specified - * coordinates. - * - * @param x - * the x coordinate. - * @param y - * the y coordinate. - */ - public Float(float x, float y) { - this.x = x; - this.y = y; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - /** - * Sets the point's coordinates. - * - * @param x - * the x coordinate. - * @param y - * the y coordinate. - */ - public void setLocation(float x, float y) { - this.x = x; - this.y = y; - } - - @Override - public void setLocation(double x, double y) { - this.x = (float)x; - this.y = (float)y; - } - - @Override - public String toString() { - return getClass().getName() + "[x=" + x + ",y=" + y + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - } - - /** - * The Class Double is the subclass of Point2D that has all of its data - * values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends Point2D { - - /** - * The x coordinate. - */ - public double x; - - /** - * The y coordinate. - */ - public double y; - - /** - * Instantiates a new double-valued Point2D with its data set to zero. - */ - public Double() { - } - - /** - * Instantiates a new double-valued Point2D with the specified - * coordinates. - * - * @param x - * the x coordinate. - * @param y - * the y coordinate. - */ - public Double(double x, double y) { - this.x = x; - this.y = y; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public void setLocation(double x, double y) { - this.x = x; - this.y = y; - } - - @Override - public String toString() { - return getClass().getName() + "[x=" + x + ",y=" + y + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - } - - /** - * Instantiates a new Point2D. - */ - protected Point2D() { - } - - /** - * Gets the x coordinate. - * - * @return the x coordinate. - */ - public abstract double getX(); - - /** - * Gets the y coordinate. - * - * @return the y coordinate. - */ - public abstract double getY(); - - /** - * Sets the point's coordinates. - * - * @param x - * the x coordinate. - * @param y - * the y coordinate. - */ - public abstract void setLocation(double x, double y); - - /** - * Sets the point's coordinates by copying them from another point. - * - * @param p - * the point to copy the data from. - */ - public void setLocation(Point2D p) { - setLocation(p.getX(), p.getY()); - } - - /** - * Finds the square of the distance between the two specified points. - * - * @param x1 - * the x coordinate of the first point. - * @param y1 - * the y coordinate of the first point. - * @param x2 - * the x coordinate of the second point. - * @param y2 - * the y coordinate of the second point. - * @return the square of the distance between the two specified points. - */ - public static double distanceSq(double x1, double y1, double x2, double y2) { - x2 -= x1; - y2 -= y1; - return x2 * x2 + y2 * y2; - } - - /** - * Finds the square of the distance between this point and the specified - * point. - * - * @param px - * the x coordinate of the point. - * @param py - * the y coordinate of the point. - * @return the square of the distance between this point and the specified - * point. - */ - public double distanceSq(double px, double py) { - return Point2D.distanceSq(getX(), getY(), px, py); - } - - /** - * Finds the square of the distance between this point and the specified - * point. - * - * @param p - * the other point. - * @return the square of the distance between this point and the specified - * point. - */ - public double distanceSq(Point2D p) { - return Point2D.distanceSq(getX(), getY(), p.getX(), p.getY()); - } - - /** - * Finds the distance between the two specified points. - * - * @param x1 - * the x coordinate of the first point. - * @param y1 - * the y coordinate of the first point. - * @param x2 - * the x coordinate of the second point. - * @param y2 - * the y coordinate of the second point. - * @return the distance between the two specified points. - */ - public static double distance(double x1, double y1, double x2, double y2) { - return Math.sqrt(distanceSq(x1, y1, x2, y2)); - } - - /** - * Finds the distance between this point and the specified point. - * - * @param px - * the x coordinate of the point. - * @param py - * the y coordinate of the point. - * @return the distance between this point and the specified point. - */ - public double distance(double px, double py) { - return Math.sqrt(distanceSq(px, py)); - } - - /** - * Finds the distance between this point and the specified point. - * - * @param p - * the other point. - * @return the distance between this point and the specified point. - */ - public double distance(Point2D p) { - return Math.sqrt(distanceSq(p)); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - - @Override - public int hashCode() { - HashCode hash = new HashCode(); - hash.append(getX()); - hash.append(getY()); - return hash.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Point2D) { - Point2D p = (Point2D)obj; - return getX() == p.getX() && getY() == p.getY(); - } - return false; - } -} diff --git a/awt/java/awt/geom/QuadCurve2D.java b/awt/java/awt/geom/QuadCurve2D.java deleted file mode 100644 index 7a86a48..0000000 --- a/awt/java/awt/geom/QuadCurve2D.java +++ /dev/null @@ -1,918 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.gl.Crossing; -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class QuadCurve2D is a Shape that represents a segment of a quadratic - * (Bezier) curve. The curved segment is determined by three points: a start - * point, an end point, and a control point. The line from the control point to - * the starting point gives the tangent to the curve at the starting point, and - * the line from the control point to the end point gives the tangent to the - * curve at the end point. - * - * @since Android 1.0 - */ -public abstract class QuadCurve2D implements Shape, Cloneable { - - /** - * The Class Float is the subclass of QuadCurve2D that has all of its data - * values stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends QuadCurve2D { - - /** - * The x coordinate of the starting point of the curved segment. - */ - public float x1; - - /** - * The y coordinate of the starting point of the curved segment. - */ - public float y1; - - /** - * The x coordinate of the control point. - */ - public float ctrlx; - - /** - * The y coordinate of the control point. - */ - public float ctrly; - - /** - * The x coordinate of the end point of the curved segment. - */ - public float x2; - - /** - * The y coordinate of the end point of the curved segment. - */ - public float y2; - - /** - * Instantiates a new float-valued QuadCurve2D with all coordinate - * values set to zero. - */ - public Float() { - } - - /** - * Instantiates a new float-valued QuadCurve2D with the specified - * coordinate values. - * - * @param x1 - * the x coordinate of the starting point of the curved - * segment. - * @param y1 - * the y coordinate of the starting point of the curved - * segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - */ - public Float(float x1, float y1, float ctrlx, float ctrly, float x2, float y2) { - setCurve(x1, y1, ctrlx, ctrly, x2, y2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getCtrlX() { - return ctrlx; - } - - @Override - public double getCtrlY() { - return ctrly; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Float(x1, y1); - } - - @Override - public Point2D getCtrlPt() { - return new Point2D.Float(ctrlx, ctrly); - } - - @Override - public Point2D getP2() { - return new Point2D.Float(x2, y2); - } - - @Override - public void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) { - this.x1 = (float)x1; - this.y1 = (float)y1; - this.ctrlx = (float)ctrlx; - this.ctrly = (float)ctrly; - this.x2 = (float)x2; - this.y2 = (float)y2; - } - - /** - * Sets the data values of the curve. - * - * @param x1 - * the x coordinate of the starting point of the curved - * segment. - * @param y1 - * the y coordinate of the starting point of the curved - * segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - */ - public void setCurve(float x1, float y1, float ctrlx, float ctrly, float x2, float y2) { - this.x1 = x1; - this.y1 = y1; - this.ctrlx = ctrlx; - this.ctrly = ctrly; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - float rx0 = Math.min(Math.min(x1, x2), ctrlx); - float ry0 = Math.min(Math.min(y1, y2), ctrly); - float rx1 = Math.max(Math.max(x1, x2), ctrlx); - float ry1 = Math.max(Math.max(y1, y2), ctrly); - return new Rectangle2D.Float(rx0, ry0, rx1 - rx0, ry1 - ry0); - } - } - - /** - * The Class Double is the subclass of QuadCurve2D that has all of its data - * values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends QuadCurve2D { - - /** - * The x coordinate of the starting point of the curved segment. - */ - public double x1; - - /** - * The y coordinate of the starting point of the curved segment. - */ - public double y1; - - /** - * The x coordinate of the control point. - */ - public double ctrlx; - - /** - * The y coordinate of the control point. - */ - public double ctrly; - - /** - * The x coordinate of the end point of the curved segment. - */ - public double x2; - - /** - * The y coordinate of the end point of the curved segment. - */ - public double y2; - - /** - * Instantiates a new double-valued QuadCurve2D with all coordinate - * values set to zero. - */ - public Double() { - } - - /** - * Instantiates a new double-valued QuadCurve2D with the specified - * coordinate values. - * - * @param x1 - * the x coordinate of the starting point of the curved - * segment. - * @param y1 - * the y coordinate of the starting point of the curved - * segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - */ - public Double(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) { - setCurve(x1, y1, ctrlx, ctrly, x2, y2); - } - - @Override - public double getX1() { - return x1; - } - - @Override - public double getY1() { - return y1; - } - - @Override - public double getCtrlX() { - return ctrlx; - } - - @Override - public double getCtrlY() { - return ctrly; - } - - @Override - public double getX2() { - return x2; - } - - @Override - public double getY2() { - return y2; - } - - @Override - public Point2D getP1() { - return new Point2D.Double(x1, y1); - } - - @Override - public Point2D getCtrlPt() { - return new Point2D.Double(ctrlx, ctrly); - } - - @Override - public Point2D getP2() { - return new Point2D.Double(x2, y2); - } - - @Override - public void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) { - this.x1 = x1; - this.y1 = y1; - this.ctrlx = ctrlx; - this.ctrly = ctrly; - this.x2 = x2; - this.y2 = y2; - } - - public Rectangle2D getBounds2D() { - double rx0 = Math.min(Math.min(x1, x2), ctrlx); - double ry0 = Math.min(Math.min(y1, y2), ctrly); - double rx1 = Math.max(Math.max(x1, x2), ctrlx); - double ry1 = Math.max(Math.max(y1, y2), ctrly); - return new Rectangle2D.Double(rx0, ry0, rx1 - rx0, ry1 - ry0); - } - } - - /* - * QuadCurve2D path iterator - */ - /** - * The PathIterator for a Quad2D curve. - */ - class Iterator implements PathIterator { - - /** - * The source QuadCurve2D object. - */ - QuadCurve2D c; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new QuadCurve2D.Iterator for given curve and - * transformation - * - * @param q - * the source QuadCurve2D object. - * @param t - * the AffineTransform that acts on the coordinates before - * returning them (or null). - */ - Iterator(QuadCurve2D q, AffineTransform t) { - this.c = q; - this.t = t; - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return (index > 1); - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = c.getX1(); - coords[1] = c.getY1(); - count = 1; - } else { - type = SEG_QUADTO; - coords[0] = c.getCtrlX(); - coords[1] = c.getCtrlY(); - coords[2] = c.getX2(); - coords[3] = c.getY2(); - count = 2; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type; - int count; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = (float)c.getX1(); - coords[1] = (float)c.getY1(); - count = 1; - } else { - type = SEG_QUADTO; - coords[0] = (float)c.getCtrlX(); - coords[1] = (float)c.getCtrlY(); - coords[2] = (float)c.getX2(); - coords[3] = (float)c.getY2(); - count = 2; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count); - } - return type; - } - - } - - /** - * Instantiates a new quadratic curve. - */ - protected QuadCurve2D() { - } - - /** - * Gets the x coordinate of the starting point. - * - * @return the x coordinate of the starting point. - */ - public abstract double getX1(); - - /** - * Gets the y coordinate of the starting point. - * - * @return the y coordinate of the starting point. - */ - public abstract double getY1(); - - /** - * Gets the starting point. - * - * @return the starting point. - */ - public abstract Point2D getP1(); - - /** - * Gets the x coordinate of the control point. - * - * @return the x coordinate of the control point. - */ - public abstract double getCtrlX(); - - /** - * Gets the y coordinate of the control point. - * - * @return y coordinate of the control point. - */ - public abstract double getCtrlY(); - - /** - * Gets the control point. - * - * @return the control point. - */ - public abstract Point2D getCtrlPt(); - - /** - * Gets the x coordinate of the end point. - * - * @return the x coordinate of the end point. - */ - public abstract double getX2(); - - /** - * Gets the y coordinate of the end point. - * - * @return the y coordinate of the end point. - */ - public abstract double getY2(); - - /** - * Gets the end point. - * - * @return the end point. - */ - public abstract Point2D getP2(); - - /** - * Sets the data of the curve. - * - * @param x1 - * the x coordinate of the starting point of the curved segment. - * @param y1 - * the y coordinate of the starting point of the curved segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - */ - public abstract void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, - double y2); - - /** - * Sets the data of the curve. - * - * @param p1 - * the starting point of the curved segment. - * @param cp - * the control point. - * @param p2 - * the end point of the curved segment. - * @throws NullPointerException - * if any of the three points is null. - */ - public void setCurve(Point2D p1, Point2D cp, Point2D p2) { - setCurve(p1.getX(), p1.getY(), cp.getX(), cp.getY(), p2.getX(), p2.getY()); - } - - /** - * Sets the data of the curve by reading the data from an array of values. - * The values are read in the same order as the arguments of the method - * {@link QuadCurve2D#setCurve(double, double, double, double, double, double)} - * . - * - * @param coords - * the array of values containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @throws ArrayIndexOutOfBoundsException - * if {@code coords.length} < offset + 6. - * @throws NullPointerException - * if the coordinate array is null. - */ - public void setCurve(double[] coords, int offset) { - setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], - coords[offset + 4], coords[offset + 5]); - } - - /** - * Sets the data of the curve by reading the data from an array of points. - * The values are read in the same order as the arguments of the method - * {@link QuadCurve2D#setCurve(Point2D, Point2D, Point2D)}. - * - * @param points - * the array of points containing the new coordinates. - * @param offset - * the offset of the data to read within the array. - * @throws ArrayIndexOutOfBoundsException - * if points.length < offset + 3. - * @throws NullPointerException - * if the point array is null. - */ - public void setCurve(Point2D[] points, int offset) { - setCurve(points[offset + 0].getX(), points[offset + 0].getY(), points[offset + 1].getX(), - points[offset + 1].getY(), points[offset + 2].getX(), points[offset + 2].getY()); - } - - /** - * Sets the data of the curve by copying it from another QuadCurve2D. - * - * @param curve - * the curve to copy the data points from. - * @throws NullPointerException - * if the curve is null. - */ - public void setCurve(QuadCurve2D curve) { - setCurve(curve.getX1(), curve.getY1(), curve.getCtrlX(), curve.getCtrlY(), curve.getX2(), - curve.getY2()); - } - - /** - * Gets the square of the distance from the control point to the straight - * line segment connecting the start point and the end point for this curve. - * - * @return the square of the distance from the control point to the straight - * line segment connecting the start point and the end point. - */ - public double getFlatnessSq() { - return Line2D.ptSegDistSq(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY()); - } - - /** - * Gets the square of the distance from the control point to the straight - * line segment connecting the start point and the end point. - * - * @param x1 - * the x coordinate of the starting point of the curved segment. - * @param y1 - * the y coordinate of the starting point of the curved segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - * @return the square of the distance from the control point to the straight - * line segment connecting the start point and the end point. - */ - public static double getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, - double y2) { - return Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx, ctrly); - } - - /** - * Gets the square of the distance from the control point to the straight - * line segment connecting the start point and the end point by reading the - * coordinates of the points from an array of values. The values are read in - * the same order as the arguments of the method - * {@link QuadCurve2D#getFlatnessSq(double, double, double, double, double, double)} - * . - * - * @param coords - * the array of points containing the coordinates to use for the - * calculation - * @param offset - * the offset of the data to read within the array - * @return the square of the distance from the control point to the straight - * line segment connecting the start point and the end point. - * @throws ArrayIndexOutOfBoundsException - * if {@code coords.length} < offset + 6. - * @throws NullPointerException - * if the coordinate array is null. - */ - public static double getFlatnessSq(double coords[], int offset) { - return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], coords[offset + 4], - coords[offset + 5], coords[offset + 2], coords[offset + 3]); - } - - /** - * Gets the distance from the control point to the straight line segment - * connecting the start point and the end point of this QuadCurve2D. - * - * @return the the distance from the control point to the straight line - * segment connecting the start point and the end point of this - * QuadCurve2D. - */ - public double getFlatness() { - return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY()); - } - - /** - * Gets the distance from the control point to the straight line segment - * connecting the start point and the end point. - * - * @param x1 - * the x coordinate of the starting point of the curved segment. - * @param y1 - * the y coordinate of the starting point of the curved segment. - * @param ctrlx - * the x coordinate of the control point. - * @param ctrly - * the y coordinate of the control point. - * @param x2 - * the x coordinate of the end point of the curved segment. - * @param y2 - * the y coordinate of the end point of the curved segment. - * @return the the distance from the control point to the straight line - * segment connecting the start point and the end point. - */ - public static double getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, - double y2) { - return Line2D.ptSegDist(x1, y1, x2, y2, ctrlx, ctrly); - } - - /** - * Gets the the distance from the control point to the straight line segment - * connecting the start point and the end point. The values are read in the - * same order as the arguments of the method - * {@link QuadCurve2D#getFlatness(double, double, double, double, double, double)} - * . - * - * @param coords - * the array of points containing the coordinates to use for the - * calculation. - * @param offset - * the offset of the data to read within the array. - * @return the the distance from the control point to the straight line - * segment connecting the start point and the end point. - * @throws ArrayIndexOutOfBoundsException - * if {code coords.length} < offset + 6. - * @throws NullPointerException - * if the coordinate array is null. - */ - public static double getFlatness(double coords[], int offset) { - return Line2D.ptSegDist(coords[offset + 0], coords[offset + 1], coords[offset + 4], - coords[offset + 5], coords[offset + 2], coords[offset + 3]); - } - - /** - * Creates the data for two quadratic curves by dividing this curve in two. - * The division point is the point on the curve that is closest to this - * curve's control point. The data of this curve is left unchanged. - * - * @param left - * the QuadCurve2D where the left (start) segment's data is - * written. - * @param right - * the QuadCurve2D where the right (end) segment's data is - * written. - * @throws NullPointerException - * if either curve is null. - */ - public void subdivide(QuadCurve2D left, QuadCurve2D right) { - subdivide(this, left, right); - } - - /** - * Creates the data for two quadratic curves by dividing a source curve in - * two. The division point is the point on the curve that is closest to the - * source curve's control point. The data of the source curve is left - * unchanged. - * - * @param src - * the curve that provides the initial data. - * @param left - * the QuadCurve2D where the left (start) segment's data is - * written. - * @param right - * the QuadCurve2D where the right (end) segment's data is - * written. - * @throws NullPointerException - * if one of the curves is null. - */ - public static void subdivide(QuadCurve2D src, QuadCurve2D left, QuadCurve2D right) { - double x1 = src.getX1(); - double y1 = src.getY1(); - double cx = src.getCtrlX(); - double cy = src.getCtrlY(); - double x2 = src.getX2(); - double y2 = src.getY2(); - double cx1 = (x1 + cx) / 2.0; - double cy1 = (y1 + cy) / 2.0; - double cx2 = (x2 + cx) / 2.0; - double cy2 = (y2 + cy) / 2.0; - cx = (cx1 + cx2) / 2.0; - cy = (cy1 + cy2) / 2.0; - if (left != null) { - left.setCurve(x1, y1, cx1, cy1, cx, cy); - } - if (right != null) { - right.setCurve(cx, cy, cx2, cy2, x2, y2); - } - } - - /** - * Creates the data for two quadratic curves by dividing a source curve in - * two. The division point is the point on the curve that is closest to the - * source curve's control point. The data for the three curves is read and - * written from arrays of values in the usual order: x1, y1, cx, cy, x2, y2. - * - * @param src - * the array that gives the data values for the source curve. - * @param srcoff - * the offset in the src array to read the values from. - * @param left - * the array where the coordinates of the start curve should be - * written. - * @param leftOff - * the offset in the left array to start writing the values. - * @param right - * the array where the coordinates of the end curve should be - * written. - * @param rightOff - * the offset in the right array to start writing the values. - * @throws ArrayIndexOutOfBoundsException - * if {@code src.length} < srcoff + 6 or if {@code left.length} - * < leftOff + 6 or if {@code right.length} < rightOff + 6. - * @throws NullPointerException - * if one of the arrays is null. - */ - public static void subdivide(double src[], int srcoff, double left[], int leftOff, - double right[], int rightOff) { - double x1 = src[srcoff + 0]; - double y1 = src[srcoff + 1]; - double cx = src[srcoff + 2]; - double cy = src[srcoff + 3]; - double x2 = src[srcoff + 4]; - double y2 = src[srcoff + 5]; - double cx1 = (x1 + cx) / 2.0; - double cy1 = (y1 + cy) / 2.0; - double cx2 = (x2 + cx) / 2.0; - double cy2 = (y2 + cy) / 2.0; - cx = (cx1 + cx2) / 2.0; - cy = (cy1 + cy2) / 2.0; - if (left != null) { - left[leftOff + 0] = x1; - left[leftOff + 1] = y1; - left[leftOff + 2] = cx1; - left[leftOff + 3] = cy1; - left[leftOff + 4] = cx; - left[leftOff + 5] = cy; - } - if (right != null) { - right[rightOff + 0] = cx; - right[rightOff + 1] = cy; - right[rightOff + 2] = cx2; - right[rightOff + 3] = cy2; - right[rightOff + 4] = x2; - right[rightOff + 5] = y2; - } - } - - /** - * Finds the roots of the quadratic polynomial. This is accomplished by - * finding the (real) values of x that solve the following equation: - * eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written back into - * the array eqn starting from the index 0 in the array. The return value - * tells how many array elements have been changed by this method call. - * - * @param eqn - * an array containing the coefficients of the quadratic - * polynomial to solve. - * @return the number of roots of the quadratic polynomial. - * @throws ArrayIndexOutOfBoundsException - * if {@code eqn.length} < 3. - * @throws NullPointerException - * if the array is null. - */ - public static int solveQuadratic(double eqn[]) { - return solveQuadratic(eqn, eqn); - } - - /** - * Finds the roots of the quadratic polynomial. This is accomplished by - * finding the (real) values of x that solve the following equation: - * eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written into the - * array res starting from the index 0 in the array. The return value tells - * how many array elements have been written by this method call. - * - * @param eqn - * an array containing the coefficients of the quadratic - * polynomial to solve. - * @param res - * the array that this method writes the results into. - * @return the number of roots of the quadratic polynomial. - * @throws ArrayIndexOutOfBoundsException - * if {@code eqn.length} < 3 or if {@code res.length} is less - * than the number of roots. - * @throws NullPointerException - * if either array is null. - */ - public static int solveQuadratic(double eqn[], double res[]) { - return Crossing.solveQuad(eqn, res); - } - - public boolean contains(double px, double py) { - return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py)); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross != Crossing.CROSSING && Crossing.isInsideEvenOdd(cross); - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross == Crossing.CROSSING || Crossing.isInsideEvenOdd(cross); - } - - public boolean contains(Point2D p) { - return contains(p.getX(), p.getY()); - } - - public boolean intersects(Rectangle2D r) { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public boolean contains(Rectangle2D r) { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - public Rectangle getBounds() { - return getBounds2D().getBounds(); - } - - public PathIterator getPathIterator(AffineTransform t) { - return new Iterator(this, t); - } - - public PathIterator getPathIterator(AffineTransform t, double flatness) { - return new FlatteningPathIterator(getPathIterator(t), flatness); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - -} diff --git a/awt/java/awt/geom/Rectangle2D.java b/awt/java/awt/geom/Rectangle2D.java deleted file mode 100644 index 8166134..0000000 --- a/awt/java/awt/geom/Rectangle2D.java +++ /dev/null @@ -1,824 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; -import org.apache.harmony.misc.HashCode; - -/** - * The Class Rectangle2D represents a rectangle whose coordinates are given with - * the correct precision to be used with the Graphics2D classes. - * - * @since Android 1.0 - */ -public abstract class Rectangle2D extends RectangularShape { - - /** - * The Constant OUT_LEFT is a mask that is used to indicate that a given - * point is outside the rectangle and to its left. - */ - public static final int OUT_LEFT = 1; - - /** - * The Constant OUT_TOP is a mask that is used to indicate that a given - * point is outside the rectangle and above it. - */ - public static final int OUT_TOP = 2; - - /** - * The Constant OUT_RIGHT is a mask that is used to indicate that a given - * point is outside the rectangle and to its right. - */ - public static final int OUT_RIGHT = 4; - - /** - * The Constant OUT_BOTTOM is a mask that is used to indicate that a given - * point is outside the rectangle and above it. - */ - public static final int OUT_BOTTOM = 8; - - /** - * The Class Float is the subclass of Rectangle2D that represents a - * rectangle whose data values are given as floats (with float-level - * precision). - * - * @since Android 1.0 - */ - public static class Float extends Rectangle2D { - - /** - * The x coordinate of the rectangle's upper left corner. - */ - public float x; - - /** - * The y coordinate of the rectangle's upper left corner. - */ - public float y; - - /** - * The width of the rectangle. - */ - public float width; - - /** - * The height of the rectangle. - */ - public float height; - - /** - * Instantiates a new empty rectangle with float-precision data fields. - */ - public Float() { - } - - /** - * Instantiates a new rectangle with the specified float-precision data. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - */ - public Float(float x, float y, float width, float height) { - setRect(x, y, width, height); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public boolean isEmpty() { - return width <= 0.0f || height <= 0.0f; - } - - /** - * Sets the rectangle's data to the given values. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - */ - public void setRect(float x, float y, float width, float height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - @Override - public void setRect(double x, double y, double width, double height) { - this.x = (float)x; - this.y = (float)y; - this.width = (float)width; - this.height = (float)height; - } - - @Override - public void setRect(Rectangle2D r) { - this.x = (float)r.getX(); - this.y = (float)r.getY(); - this.width = (float)r.getWidth(); - this.height = (float)r.getHeight(); - } - - @Override - public int outcode(double px, double py) { - int code = 0; - - if (width <= 0.0f) { - code |= OUT_LEFT | OUT_RIGHT; - } else if (px < x) { - code |= OUT_LEFT; - } else if (px > x + width) { - code |= OUT_RIGHT; - } - - if (height <= 0.0f) { - code |= OUT_TOP | OUT_BOTTOM; - } else if (py < y) { - code |= OUT_TOP; - } else if (py > y + height) { - code |= OUT_BOTTOM; - } - - return code; - } - - @Override - public Rectangle2D getBounds2D() { - return new Float(x, y, width, height); - } - - @Override - public Rectangle2D createIntersection(Rectangle2D r) { - Rectangle2D dst; - if (r instanceof Double) { - dst = new Rectangle2D.Double(); - } else { - dst = new Rectangle2D.Float(); - } - Rectangle2D.intersect(this, r, dst); - return dst; - } - - @Override - public Rectangle2D createUnion(Rectangle2D r) { - Rectangle2D dst; - if (r instanceof Double) { - dst = new Rectangle2D.Double(); - } else { - dst = new Rectangle2D.Float(); - } - Rectangle2D.union(this, r, dst); - return dst; - } - - @Override - public String toString() { - // The output format based on 1.5 release behaviour. It could be - // obtained in the following way - // System.out.println(new Rectangle2D.Float().toString()) - return getClass().getName() - + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - } - } - - /** - * The Class Double is the subclass of Rectangle2D that represents a - * rectangle whose data values are given as doubles (with - * double-precision-level precision). - * - * @since Android 1.0 - */ - public static class Double extends Rectangle2D { - - /** - * The x coordinate of the rectangle's upper left corner. - */ - public double x; - - /** - * The y coordinate of the rectangle's upper left corner. - */ - public double y; - - /** - * The width of the rectangle. - */ - public double width; - - /** - * The height of the rectangle. - */ - public double height; - - /** - * Instantiates a new empty rectangle with double-precision data fields. - */ - public Double() { - } - - /** - * Instantiates a new rectangle with the given double values. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - */ - public Double(double x, double y, double width, double height) { - setRect(x, y, width, height); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public boolean isEmpty() { - return width <= 0.0 || height <= 0.0; - } - - @Override - public void setRect(double x, double y, double width, double height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - @Override - public void setRect(Rectangle2D r) { - this.x = r.getX(); - this.y = r.getY(); - this.width = r.getWidth(); - this.height = r.getHeight(); - } - - @Override - public int outcode(double px, double py) { - int code = 0; - - if (width <= 0.0) { - code |= OUT_LEFT | OUT_RIGHT; - } else if (px < x) { - code |= OUT_LEFT; - } else if (px > x + width) { - code |= OUT_RIGHT; - } - - if (height <= 0.0) { - code |= OUT_TOP | OUT_BOTTOM; - } else if (py < y) { - code |= OUT_TOP; - } else if (py > y + height) { - code |= OUT_BOTTOM; - } - - return code; - } - - @Override - public Rectangle2D getBounds2D() { - return new Double(x, y, width, height); - } - - @Override - public Rectangle2D createIntersection(Rectangle2D r) { - Rectangle2D dst = new Rectangle2D.Double(); - Rectangle2D.intersect(this, r, dst); - return dst; - } - - @Override - public Rectangle2D createUnion(Rectangle2D r) { - Rectangle2D dest = new Rectangle2D.Double(); - Rectangle2D.union(this, r, dest); - return dest; - } - - @Override - public String toString() { - // The output format based on 1.5 release behaviour. It could be - // obtained in the following way - // System.out.println(new Rectangle2D.Double().toString()) - return getClass().getName() - + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - } - } - - /** - * The Class Iterator provides access to the coordinates of the - * Rectangle2D's boundary modified by an AffineTransform. - */ - class Iterator implements PathIterator { - - /** - * The x coordinate of the rectangle's upper left corner. - */ - double x; - - /** - * The y coordinate of the rectangle's upper left corner. - */ - double y; - - /** - * The width of the rectangle. - */ - double width; - - /** - * The height of the rectangle. - */ - double height; - - /** - * The AffineTransform that is used to modify the coordinates that are - * returned by the path iterator. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new Rectangle2D.Iterator for given rectangle and - * transformation. - * - * @param r - * the source Rectangle2D object. - * @param at - * the AffineTransform object to apply to the coordinates - * before returning them. - */ - Iterator(Rectangle2D r, AffineTransform at) { - this.x = r.getX(); - this.y = r.getY(); - this.width = r.getWidth(); - this.height = r.getHeight(); - this.t = at; - if (width < 0.0 || height < 0.0) { - index = 6; - } - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > 5; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == 5) { - return SEG_CLOSE; - } - int type; - if (index == 0) { - type = SEG_MOVETO; - coords[0] = x; - coords[1] = y; - } else { - type = SEG_LINETO; - switch (index) { - case 1: - coords[0] = x + width; - coords[1] = y; - break; - case 2: - coords[0] = x + width; - coords[1] = y + height; - break; - case 3: - coords[0] = x; - coords[1] = y + height; - break; - case 4: - coords[0] = x; - coords[1] = y; - break; - } - } - if (t != null) { - t.transform(coords, 0, coords, 0, 1); - } - return type; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == 5) { - return SEG_CLOSE; - } - int type; - if (index == 0) { - coords[0] = (float)x; - coords[1] = (float)y; - type = SEG_MOVETO; - } else { - type = SEG_LINETO; - switch (index) { - case 1: - coords[0] = (float)(x + width); - coords[1] = (float)y; - break; - case 2: - coords[0] = (float)(x + width); - coords[1] = (float)(y + height); - break; - case 3: - coords[0] = (float)x; - coords[1] = (float)(y + height); - break; - case 4: - coords[0] = (float)x; - coords[1] = (float)y; - break; - } - } - if (t != null) { - t.transform(coords, 0, coords, 0, 1); - } - return type; - } - - } - - /** - * Instantiates a new Rectangle2D. - */ - protected Rectangle2D() { - } - - /** - * Sets the rectangle's location and dimension. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - */ - public abstract void setRect(double x, double y, double width, double height); - - /** - * Gets the location of the point with respect to the rectangle and packs - * the information into a single integer using the bitmasks - * {@link Rectangle2D#OUT_LEFT}, {@link Rectangle2D#OUT_RIGHT}, - * {@link Rectangle2D#OUT_TOP}, and {@link Rectangle2D#OUT_BOTTOM}. If the - * rectangle has zero or negative width, then every point is regarded as - * being both to the left and to the right of the rectangle. Similarly, if - * the height is zero or negative then all points are considered to be both - * both above and below it. - * - * @param x - * the x coordinate of the point to check. - * @param y - * the y coordinate of the point to check. - * @return the point's location with respect to the rectangle. - */ - public abstract int outcode(double x, double y); - - /** - * Creates an new rectangle that is the intersection of this rectangle with - * the given rectangle. The resulting rectangle may be empty. The data of - * this rectangle is left unchanged. - * - * @param r - * the rectangle to intersect with this rectangle. - * @return the new rectangle given by intersection. - */ - public abstract Rectangle2D createIntersection(Rectangle2D r); - - /** - * Creates an new rectangle that is the union of this rectangle with the - * given rectangle. The new rectangle is the smallest rectangle which - * contains both this rectangle and the rectangle specified as a parameter. - * The data of this rectangle is left unchanged. - * - * @param r - * the rectangle to combine with this rectangle. - * @return the new rectangle given by union. - */ - public abstract Rectangle2D createUnion(Rectangle2D r); - - /** - * Sets the data of this rectangle to match the data of the given rectangle. - * - * @param r - * the rectangle whose data is to be copied into this rectangle's - * fields. - */ - public void setRect(Rectangle2D r) { - setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - @Override - public void setFrame(double x, double y, double width, double height) { - setRect(x, y, width, height); - } - - public Rectangle2D getBounds2D() { - return (Rectangle2D)clone(); - } - - /** - * Determines whether any part of the line segment between (and including) - * the two given points touches any part of the rectangle, including its - * boundary. - * - * @param x1 - * the x coordinate of one of the points that determines the line - * segment to test. - * @param y1 - * the y coordinate of one of the points that determines the line - * segment to test. - * @param x2 - * the x coordinate of one of the points that determines the line - * segment to test. - * @param y2 - * the y coordinate of one of the points that determines the line - * segment to test. - * @return true, if at least one point of the line segment between the two - * points matches any point of the interior of the rectangle or the - * rectangle's boundary. - */ - public boolean intersectsLine(double x1, double y1, double x2, double y2) { - double rx1 = getX(); - double ry1 = getY(); - double rx2 = rx1 + getWidth(); - double ry2 = ry1 + getHeight(); - return (rx1 <= x1 && x1 <= rx2 && ry1 <= y1 && y1 <= ry2) - || (rx1 <= x2 && x2 <= rx2 && ry1 <= y2 && y2 <= ry2) - || Line2D.linesIntersect(rx1, ry1, rx2, ry2, x1, y1, x2, y2) - || Line2D.linesIntersect(rx2, ry1, rx1, ry2, x1, y1, x2, y2); - } - - /** - * Determines whether any part of the specified line segment touches any - * part of the rectangle, including its boundary. - * - * @param l - * the line segment to test. - * @return true, if at least one point of the given line segment matches any - * point of the interior of the rectangle or the rectangle's - * boundary. - */ - public boolean intersectsLine(Line2D l) { - return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2()); - } - - /** - * Gets the location of the point with respect to the rectangle and packs - * the information into a single integer using the bitmasks - * {@link Rectangle2D#OUT_LEFT}, {@link Rectangle2D#OUT_RIGHT}, - * {@link Rectangle2D#OUT_TOP}, and {@link Rectangle2D#OUT_BOTTOM}. If the - * rectangle has zero or negative width, then every point is regarded as - * being both to the left and to the right of the rectangle. Similarly, if - * the height is zero or negative then all points are considered to be both - * both above and below it. - * - * @param p - * the point to check. - * @return the point's location with respect to the rectangle. - */ - public int outcode(Point2D p) { - return outcode(p.getX(), p.getY()); - } - - public boolean contains(double x, double y) { - if (isEmpty()) { - return false; - } - - double x1 = getX(); - double y1 = getY(); - double x2 = x1 + getWidth(); - double y2 = y1 + getHeight(); - - return x1 <= x && x < x2 && y1 <= y && y < y2; - } - - public boolean intersects(double x, double y, double width, double height) { - if (isEmpty() || width <= 0.0 || height <= 0.0) { - return false; - } - - double x1 = getX(); - double y1 = getY(); - double x2 = x1 + getWidth(); - double y2 = y1 + getHeight(); - - return x + width > x1 && x < x2 && y + height > y1 && y < y2; - } - - public boolean contains(double x, double y, double width, double height) { - if (isEmpty() || width <= 0.0 || height <= 0.0) { - return false; - } - - double x1 = getX(); - double y1 = getY(); - double x2 = x1 + getWidth(); - double y2 = y1 + getHeight(); - - return x1 <= x && x + width <= x2 && y1 <= y && y + height <= y2; - } - - /** - * Changes the data values of the destination rectangle to match the - * intersection of the two source rectangles, leaving the two source - * rectangles unchanged. The resulting rectangle may be empty. - * - * @param src1 - * one of the two source rectangles giving the data to intersect. - * @param src2 - * one of the two source rectangles giving the data to intersect. - * @param dst - * the destination object where the data of the intersection is - * written. - */ - public static void intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst) { - double x1 = Math.max(src1.getMinX(), src2.getMinX()); - double y1 = Math.max(src1.getMinY(), src2.getMinY()); - double x2 = Math.min(src1.getMaxX(), src2.getMaxX()); - double y2 = Math.min(src1.getMaxY(), src2.getMaxY()); - dst.setFrame(x1, y1, x2 - x1, y2 - y1); - } - - /** - * Changes the data values of the destination rectangle to match the union - * of the two source rectangles, leaving the two source rectangles - * unchanged. The union is the smallest rectangle that completely covers the - * two source rectangles. - * - * @param src1 - * one of the two source rectangles giving the data. - * @param src2 - * one of the two source rectangles giving the data. - * @param dst - * the destination object where the data of the union is written. - */ - public static void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst) { - double x1 = Math.min(src1.getMinX(), src2.getMinX()); - double y1 = Math.min(src1.getMinY(), src2.getMinY()); - double x2 = Math.max(src1.getMaxX(), src2.getMaxX()); - double y2 = Math.max(src1.getMaxY(), src2.getMaxY()); - dst.setFrame(x1, y1, x2 - x1, y2 - y1); - } - - /** - * Enlarges the rectangle so that it includes the given point. - * - * @param x - * the x coordinate of the new point to be covered by the - * rectangle. - * @param y - * the y coordinate of the new point to be covered by the - * rectangle. - */ - public void add(double x, double y) { - double x1 = Math.min(getMinX(), x); - double y1 = Math.min(getMinY(), y); - double x2 = Math.max(getMaxX(), x); - double y2 = Math.max(getMaxY(), y); - setRect(x1, y1, x2 - x1, y2 - y1); - } - - /** - * Enlarges the rectangle so that it includes the given point. - * - * @param p - * the new point to be covered by the rectangle. - */ - public void add(Point2D p) { - add(p.getX(), p.getY()); - } - - /** - * Enlarges the rectangle so that it covers the given rectangle. - * - * @param r - * the new rectangle to be covered by this rectangle. - */ - public void add(Rectangle2D r) { - union(this, r, this); - } - - public PathIterator getPathIterator(AffineTransform t) { - return new Iterator(this, t); - } - - @Override - public PathIterator getPathIterator(AffineTransform t, double flatness) { - return new Iterator(this, t); - } - - @Override - public int hashCode() { - HashCode hash = new HashCode(); - hash.append(getX()); - hash.append(getY()); - hash.append(getWidth()); - hash.append(getHeight()); - return hash.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Rectangle2D) { - Rectangle2D r = (Rectangle2D)obj; - return getX() == r.getX() && getY() == r.getY() && getWidth() == r.getWidth() - && getHeight() == r.getHeight(); - } - return false; - } - -} diff --git a/awt/java/awt/geom/RectangularShape.java b/awt/java/awt/geom/RectangularShape.java deleted file mode 100644 index 0b0d05c..0000000 --- a/awt/java/awt/geom/RectangularShape.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; - -/** - * The Class RectangularShape represents a Shape whose data is (at least - * partially) described by a rectangular frame. This includes shapes which are - * obviously rectangular (such as Rectangle2D) as well as shapes like Arc2D - * which are largely determined by the rectangle they fit inside. - * - * @since Android 1.0 - */ -public abstract class RectangularShape implements Shape, Cloneable { - - /** - * Instantiates a new rectangular shape. - */ - protected RectangularShape() { - } - - /** - * Gets the x coordinate of the upper left corner of the rectangle. - * - * @return the x coordinate of the upper left corner of the rectangle. - */ - public abstract double getX(); - - /** - * Gets the y coordinate of the upper left corner of the rectangle. - * - * @return the y coordinate of the upper left corner of the rectangle. - */ - public abstract double getY(); - - /** - * Gets the width of the rectangle. - * - * @return the width of the rectangle. - */ - public abstract double getWidth(); - - /** - * Gets the height of the rectangle. - * - * @return the height of the rectangle. - */ - public abstract double getHeight(); - - /** - * Checks if this is an empty rectangle: one with zero as its width or - * height. - * - * @return true, if the width or height is empty. - */ - public abstract boolean isEmpty(); - - /** - * Sets the data for the bounding rectangle in terms of double values. - * - * @param x - * the x coordinate of the upper left corner of the rectangle. - * @param y - * the y coordinate of the upper left corner of the rectangle. - * @param w - * the width of the rectangle. - * @param h - * the height of the rectangle. - */ - public abstract void setFrame(double x, double y, double w, double h); - - /** - * Gets the minimum x value of the bounding rectangle (the x coordinate of - * the upper left corner of the rectangle). - * - * @return the minimum x value of the bounding rectangle. - */ - public double getMinX() { - return getX(); - } - - /** - * Gets the minimum y value of the bounding rectangle (the y coordinate of - * the upper left corner of the rectangle). - * - * @return the minimum y value of the bounding rectangle. - */ - public double getMinY() { - return getY(); - } - - /** - * Gets the maximum x value of the bounding rectangle (the x coordinate of - * the upper left corner of the rectangle plus the rectangle's width). - * - * @return the maximum x value of the bounding rectangle. - */ - public double getMaxX() { - return getX() + getWidth(); - } - - /** - * Gets the maximum y value of the bounding rectangle (the y coordinate of - * the upper left corner of the rectangle plus the rectangle's height). - * - * @return the maximum y value of the bounding rectangle. - */ - public double getMaxY() { - return getY() + getHeight(); - } - - /** - * Gets the x coordinate of the center of the rectangle. - * - * @return the x coordinate of the center of the rectangle. - */ - public double getCenterX() { - return getX() + getWidth() / 2.0; - } - - /** - * Gets the y coordinate of the center of the rectangle. - * - * @return the y coordinate of the center of the rectangle. - */ - public double getCenterY() { - return getY() + getHeight() / 2.0; - } - - /** - * Places the rectangle's size and location data in a new Rectangle2D object - * and returns it. - * - * @return the bounding rectangle as a new Rectangle2D object. - */ - public Rectangle2D getFrame() { - return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight()); - } - - /** - * Sets the bounding rectangle in terms of a Point2D which gives its upper - * left corner and a Dimension2D object giving its width and height. - * - * @param loc - * the new upper left corner coordinate. - * @param size - * the new size dimensions. - */ - public void setFrame(Point2D loc, Dimension2D size) { - setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight()); - } - - /** - * Sets the bounding rectangle to match the data contained in the specified - * Rectangle2D. - * - * @param r - * the rectangle that gives the new frame data. - */ - public void setFrame(Rectangle2D r) { - setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Sets the framing rectangle given two opposite corners. Any two corners - * may be used in any order as long as they are diagonally opposite one - * another. - * - * @param x1 - * the x coordinate of one of the corner points. - * @param y1 - * the y coordinate of one of the corner points. - * @param x2 - * the x coordinate of the other corner point. - * @param y2 - * the y coordinate of the other corner point. - */ - public void setFrameFromDiagonal(double x1, double y1, double x2, double y2) { - double rx, ry, rw, rh; - if (x1 < x2) { - rx = x1; - rw = x2 - x1; - } else { - rx = x2; - rw = x1 - x2; - } - if (y1 < y2) { - ry = y1; - rh = y2 - y1; - } else { - ry = y2; - rh = y1 - y2; - } - setFrame(rx, ry, rw, rh); - } - - /** - * Sets the framing rectangle given two opposite corners. Any two corners - * may be used in any order as long as they are diagonally opposite one - * another. - * - * @param p1 - * one of the corner points. - * @param p2 - * the other corner point. - */ - public void setFrameFromDiagonal(Point2D p1, Point2D p2) { - setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Sets the framing rectangle given the center point and one corner. Any - * corner may be used. - * - * @param centerX - * the x coordinate of the center point. - * @param centerY - * the y coordinate of the center point. - * @param cornerX - * the x coordinate of one of the corner points. - * @param cornerY - * the y coordinate of one of the corner points. - */ - public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) { - double width = Math.abs(cornerX - centerX); - double height = Math.abs(cornerY - centerY); - setFrame(centerX - width, centerY - height, width * 2.0, height * 2.0); - } - - /** - * Sets the framing rectangle given the center point and one corner. Any - * corner may be used. - * - * @param center - * the center point. - * @param corner - * a corner point. - */ - public void setFrameFromCenter(Point2D center, Point2D corner) { - setFrameFromCenter(center.getX(), center.getY(), corner.getX(), corner.getY()); - } - - public boolean contains(Point2D point) { - return contains(point.getX(), point.getY()); - } - - public boolean intersects(Rectangle2D rect) { - return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); - } - - public boolean contains(Rectangle2D rect) { - return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); - } - - public Rectangle getBounds() { - int x1 = (int)Math.floor(getMinX()); - int y1 = (int)Math.floor(getMinY()); - int x2 = (int)Math.ceil(getMaxX()); - int y2 = (int)Math.ceil(getMaxY()); - return new Rectangle(x1, y1, x2 - x1, y2 - y1); - } - - public PathIterator getPathIterator(AffineTransform t, double flatness) { - return new FlatteningPathIterator(getPathIterator(t), flatness); - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - -} diff --git a/awt/java/awt/geom/RoundRectangle2D.java b/awt/java/awt/geom/RoundRectangle2D.java deleted file mode 100644 index 8fbddd6..0000000 --- a/awt/java/awt/geom/RoundRectangle2D.java +++ /dev/null @@ -1,635 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - -import org.apache.harmony.awt.internal.nls.Messages; - -/** - * The Class RoundRectangle2D describes a rectangle with rounded corners with - * high-precision data that is appropriate for geometric operations. - * - * @since Android 1.0 - */ -public abstract class RoundRectangle2D extends RectangularShape { - - /** - * The Class Float is the subclass of RoundRectangle2D that has all of its - * data values stored with float-level precision. - * - * @since Android 1.0 - */ - public static class Float extends RoundRectangle2D { - - /** - * The x coordinate of the rectangle's upper left corner. - */ - public float x; - - /** - * The y coordinate of the rectangle's upper left corner. - */ - public float y; - - /** - * The width of the rectangle. - */ - public float width; - - /** - * The height of the rectangle. - */ - public float height; - - /** - * The arc width of the rounded corners. - */ - public float arcwidth; - - /** - * The arc height of the rounded corners. - */ - public float archeight; - - /** - * Instantiates a new float-valued RoundRectangle2D with its data-values - * set to zero. - */ - public Float() { - } - - /** - * Instantiates a new float-valued RoundRectangle2D with the specified - * data values. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - * @param arcwidth - * the arc width of the rounded corners. - * @param archeight - * the arc height of the rounded corners. - */ - public Float(float x, float y, float width, float height, float arcwidth, float archeight) { - setRoundRect(x, y, width, height, arcwidth, archeight); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public double getArcWidth() { - return arcwidth; - } - - @Override - public double getArcHeight() { - return archeight; - } - - @Override - public boolean isEmpty() { - return width <= 0.0f || height <= 0.0f; - } - - /** - * Sets the data of the round rectangle. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - * @param arcwidth - * the arc width of the rounded corners. - * @param archeight - * the arc height of the rounded corners. - */ - public void setRoundRect(float x, float y, float width, float height, float arcwidth, - float archeight) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.arcwidth = arcwidth; - this.archeight = archeight; - } - - @Override - public void setRoundRect(double x, double y, double width, double height, double arcwidth, - double archeight) { - this.x = (float)x; - this.y = (float)y; - this.width = (float)width; - this.height = (float)height; - this.arcwidth = (float)arcwidth; - this.archeight = (float)archeight; - } - - @Override - public void setRoundRect(RoundRectangle2D rr) { - this.x = (float)rr.getX(); - this.y = (float)rr.getY(); - this.width = (float)rr.getWidth(); - this.height = (float)rr.getHeight(); - this.arcwidth = (float)rr.getArcWidth(); - this.archeight = (float)rr.getArcHeight(); - } - - public Rectangle2D getBounds2D() { - return new Rectangle2D.Float(x, y, width, height); - } - } - - /** - * The Class Double is the subclass of RoundRectangle2D that has all of its - * data values stored with double-level precision. - * - * @since Android 1.0 - */ - public static class Double extends RoundRectangle2D { - - /** - * The x coordinate of the rectangle's upper left corner. - */ - public double x; - - /** - * The y coordinate of the rectangle's upper left corner. - */ - public double y; - - /** - * The width of the rectangle. - */ - public double width; - - /** - * The height of the rectangle. - */ - public double height; - - /** - * The arc width of the rounded corners. - */ - public double arcwidth; - - /** - * The arc height of the rounded corners. - */ - public double archeight; - - /** - * Instantiates a new double-valued RoundRectangle2D with its - * data-values set to zero. - */ - public Double() { - } - - /** - * Instantiates a new double-valued RoundRectangle2D with the specified - * data values. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - * @param arcwidth - * the arc width of the rounded corners. - * @param archeight - * the arc height of the rounded corners. - */ - public Double(double x, double y, double width, double height, double arcwidth, - double archeight) { - setRoundRect(x, y, width, height, arcwidth, archeight); - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getWidth() { - return width; - } - - @Override - public double getHeight() { - return height; - } - - @Override - public double getArcWidth() { - return arcwidth; - } - - @Override - public double getArcHeight() { - return archeight; - } - - @Override - public boolean isEmpty() { - return width <= 0.0 || height <= 0.0; - } - - @Override - public void setRoundRect(double x, double y, double width, double height, double arcwidth, - double archeight) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.arcwidth = arcwidth; - this.archeight = archeight; - } - - @Override - public void setRoundRect(RoundRectangle2D rr) { - this.x = rr.getX(); - this.y = rr.getY(); - this.width = rr.getWidth(); - this.height = rr.getHeight(); - this.arcwidth = rr.getArcWidth(); - this.archeight = rr.getArcHeight(); - } - - public Rectangle2D getBounds2D() { - return new Rectangle2D.Double(x, y, width, height); - } - } - - /* - * RoundRectangle2D path iterator - */ - /** - * The subclass of PathIterator to traverse a RoundRectangle2D. - */ - class Iterator implements PathIterator { - - /* - * Path for round corners generated the same way as Ellipse2D - */ - - /** - * The coefficient to calculate control points of Bezier curves. - */ - double u = 0.5 - 2.0 / 3.0 * (Math.sqrt(2.0) - 1.0); - - /** - * The points coordinates calculation table. - */ - double points[][] = { - { - 0.0, 0.5, 0.0, 0.0 - }, // MOVETO - { - 1.0, -0.5, 0.0, 0.0 - }, // LINETO - { - 1.0, -u, 0.0, 0.0, // CUBICTO - 1.0, 0.0, 0.0, u, 1.0, 0.0, 0.0, 0.5 - }, { - 1.0, 0.0, 1.0, -0.5 - }, // LINETO - { - 1.0, 0.0, 1.0, -u, // CUBICTO - 1.0, -u, 1.0, 0.0, 1.0, -0.5, 1.0, 0.0 - }, { - 0.0, 0.5, 1.0, 0.0 - }, // LINETO - { - 0.0, u, 1.0, 0.0, // CUBICTO - 0.0, 0.0, 1.0, -u, 0.0, 0.0, 1.0, -0.5 - }, { - 0.0, 0.0, 0.0, 0.5 - }, // LINETO - { - 0.0, 0.0, 0.0, u, // CUBICTO - 0.0, u, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0 - } - }; - - /** - * The segment types correspond to points array. - */ - int types[] = { - SEG_MOVETO, SEG_LINETO, SEG_CUBICTO, SEG_LINETO, SEG_CUBICTO, SEG_LINETO, - SEG_CUBICTO, SEG_LINETO, SEG_CUBICTO - }; - - /** - * The x coordinate of left-upper corner of the round rectangle bounds. - */ - double x; - - /** - * The y coordinate of left-upper corner of the round rectangle bounds. - */ - double y; - - /** - * The width of the round rectangle bounds. - */ - double width; - - /** - * The height of the round rectangle bounds. - */ - double height; - - /** - * The width of arc corners of the round rectangle. - */ - double aw; - - /** - * The height of arc corners of the round rectangle. - */ - double ah; - - /** - * The path iterator transformation. - */ - AffineTransform t; - - /** - * The current segment index. - */ - int index; - - /** - * Constructs a new RoundRectangle2D.Iterator for given round rectangle - * and transformation. - * - * @param rr - * - the source RoundRectangle2D object - * @param at - * - the AffineTransform object to apply rectangle path - */ - Iterator(RoundRectangle2D rr, AffineTransform at) { - this.x = rr.getX(); - this.y = rr.getY(); - this.width = rr.getWidth(); - this.height = rr.getHeight(); - this.aw = Math.min(width, rr.getArcWidth()); - this.ah = Math.min(height, rr.getArcHeight()); - this.t = at; - if (width < 0.0 || height < 0.0 || aw < 0.0 || ah < 0.0) { - index = points.length; - } - } - - public int getWindingRule() { - return WIND_NON_ZERO; - } - - public boolean isDone() { - return index > points.length; - } - - public void next() { - index++; - } - - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == points.length) { - return SEG_CLOSE; - } - int j = 0; - double p[] = points[index]; - for (int i = 0; i < p.length; i += 4) { - coords[j++] = x + p[i + 0] * width + p[i + 1] * aw; - coords[j++] = y + p[i + 2] * height + p[i + 3] * ah; - } - if (t != null) { - t.transform(coords, 0, coords, 0, j / 2); - } - return types[index]; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - if (index == points.length) { - return SEG_CLOSE; - } - int j = 0; - double p[] = points[index]; - for (int i = 0; i < p.length; i += 4) { - coords[j++] = (float)(x + p[i + 0] * width + p[i + 1] * aw); - coords[j++] = (float)(y + p[i + 2] * height + p[i + 3] * ah); - } - if (t != null) { - t.transform(coords, 0, coords, 0, j / 2); - } - return types[index]; - } - - } - - /** - * Instantiates a new RoundRectangle2D. - */ - protected RoundRectangle2D() { - } - - /** - * Gets the arc width. - * - * @return the arc width. - */ - public abstract double getArcWidth(); - - /** - * Gets the arc height. - * - * @return the arc height. - */ - public abstract double getArcHeight(); - - /** - * Sets the data of the RoundRectangle2D. - * - * @param x - * the x coordinate of the rectangle's upper left corner. - * @param y - * the y coordinate of the rectangle's upper left corner. - * @param width - * the width of the rectangle. - * @param height - * the height of the rectangle. - * @param arcWidth - * the arc width of the rounded corners. - * @param arcHeight - * the arc height of the rounded corners. - */ - public abstract void setRoundRect(double x, double y, double width, double height, - double arcWidth, double arcHeight); - - /** - * Sets the data of the RoundRectangle2D by copying the values from an - * existing RoundRectangle2D. - * - * @param rr - * the round rectangle to copy the data from. - * @throws NullPointerException - * if rr is null. - */ - public void setRoundRect(RoundRectangle2D rr) { - setRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(), rr.getArcWidth(), rr - .getArcHeight()); - } - - @Override - public void setFrame(double x, double y, double width, double height) { - setRoundRect(x, y, width, height, getArcWidth(), getArcHeight()); - } - - public boolean contains(double px, double py) { - if (isEmpty()) { - return false; - } - - double rx1 = getX(); - double ry1 = getY(); - double rx2 = rx1 + getWidth(); - double ry2 = ry1 + getHeight(); - - if (px < rx1 || px >= rx2 || py < ry1 || py >= ry2) { - return false; - } - - double aw = getArcWidth() / 2.0; - double ah = getArcHeight() / 2.0; - - double cx, cy; - - if (px < rx1 + aw) { - cx = rx1 + aw; - } else if (px > rx2 - aw) { - cx = rx2 - aw; - } else { - return true; - } - - if (py < ry1 + ah) { - cy = ry1 + ah; - } else if (py > ry2 - ah) { - cy = ry2 - ah; - } else { - return true; - } - - px = (px - cx) / aw; - py = (py - cy) / ah; - return px * px + py * py <= 1.0; - } - - public boolean intersects(double rx, double ry, double rw, double rh) { - if (isEmpty() || rw <= 0.0 || rh <= 0.0) { - return false; - } - - double x1 = getX(); - double y1 = getY(); - double x2 = x1 + getWidth(); - double y2 = y1 + getHeight(); - - double rx1 = rx; - double ry1 = ry; - double rx2 = rx + rw; - double ry2 = ry + rh; - - if (rx2 < x1 || x2 < rx1 || ry2 < y1 || y2 < ry1) { - return false; - } - - double cx = (x1 + x2) / 2.0; - double cy = (y1 + y2) / 2.0; - - double nx = cx < rx1 ? rx1 : (cx > rx2 ? rx2 : cx); - double ny = cy < ry1 ? ry1 : (cy > ry2 ? ry2 : cy); - - return contains(nx, ny); - } - - public boolean contains(double rx, double ry, double rw, double rh) { - if (isEmpty() || rw <= 0.0 || rh <= 0.0) { - return false; - } - - double rx1 = rx; - double ry1 = ry; - double rx2 = rx + rw; - double ry2 = ry + rh; - - return contains(rx1, ry1) && contains(rx2, ry1) && contains(rx2, ry2) && contains(rx1, ry2); - } - - public PathIterator getPathIterator(AffineTransform at) { - return new Iterator(this, at); - } - -} diff --git a/awt/java/awt/geom/package.html b/awt/java/awt/geom/package.html deleted file mode 100644 index e3a236e..0000000 --- a/awt/java/awt/geom/package.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> - <body> - <p> - This package contains classes and interfaces related to Java2D shapes and geometry. - </p> - @since Android 1.0 - </body> -</html> |