diff options
Diffstat (limited to 'libjava/classpath/java/awt/geom')
-rw-r--r-- | libjava/classpath/java/awt/geom/AffineTransform.java | 16 | ||||
-rw-r--r-- | libjava/classpath/java/awt/geom/Arc2D.java | 44 | ||||
-rw-r--r-- | libjava/classpath/java/awt/geom/GeneralPath.java | 39 | ||||
-rw-r--r-- | libjava/classpath/java/awt/geom/RectangularShape.java | 5 | ||||
-rw-r--r-- | libjava/classpath/java/awt/geom/RoundRectangle2D.java | 415 |
5 files changed, 305 insertions, 214 deletions
diff --git a/libjava/classpath/java/awt/geom/AffineTransform.java b/libjava/classpath/java/awt/geom/AffineTransform.java index 55b6883..5bc51dd 100644 --- a/libjava/classpath/java/awt/geom/AffineTransform.java +++ b/libjava/classpath/java/awt/geom/AffineTransform.java @@ -1401,10 +1401,10 @@ public class AffineTransform implements Cloneable, Serializable * documented, but appears to be the same as: * <pre> * long l = Double.doubleToLongBits(getScaleX()); - * l = l * 31 + Double.doubleToLongBits(getShearY()); * l = l * 31 + Double.doubleToLongBits(getShearX()); - * l = l * 31 + Double.doubleToLongBits(getScaleY()); * l = l * 31 + Double.doubleToLongBits(getTranslateX()); + * l = l * 31 + Double.doubleToLongBits(getShearY()); + * l = l * 31 + Double.doubleToLongBits(getScaleY()); * l = l * 31 + Double.doubleToLongBits(getTranslateY()); * return (int) ((l >> 32) ^ l); * </pre> @@ -1413,12 +1413,12 @@ public class AffineTransform implements Cloneable, Serializable */ public int hashCode() { - long l = Double.doubleToLongBits(m00); - l = l * 31 + Double.doubleToLongBits(m10); - l = l * 31 + Double.doubleToLongBits(m01); - l = l * 31 + Double.doubleToLongBits(m11); - l = l * 31 + Double.doubleToLongBits(m02); - l = l * 31 + Double.doubleToLongBits(m12); + long l = Double.doubleToLongBits(m00); + l = l * 31 + Double.doubleToLongBits(m01); + l = l * 31 + Double.doubleToLongBits(m02); + l = l * 31 + Double.doubleToLongBits(m10); + l = l * 31 + Double.doubleToLongBits(m11); + l = l * 31 + Double.doubleToLongBits(m12); return (int) ((l >> 32) ^ l); } diff --git a/libjava/classpath/java/awt/geom/Arc2D.java b/libjava/classpath/java/awt/geom/Arc2D.java index eff34a0..8d5b01c 100644 --- a/libjava/classpath/java/awt/geom/Arc2D.java +++ b/libjava/classpath/java/awt/geom/Arc2D.java @@ -774,14 +774,9 @@ public abstract class Arc2D extends RectangularShape y = a.getY(); w = a.getWidth(); h = a.getHeight(); - double start = a.getAngleStart() * (Math.PI / 180); - double extent = a.getAngleExtent() * (Math.PI / 180); + double start = Math.toRadians(a.getAngleStart()); + double extent = Math.toRadians(a.getAngleExtent()); - if (extent < 0) - { - extent = -extent; - start = 2 * Math.PI - extent + start; - } this.start = start; this.extent = extent; @@ -790,11 +785,11 @@ public abstract class Arc2D extends RectangularShape limit = -1; else if (extent == 0) limit = type; - else if (extent <= Math.PI / 2.0) + else if (Math.abs(extent) <= Math.PI / 2.0) limit = type + 1; - else if (extent <= Math.PI) + else if (Math.abs(extent) <= Math.PI) limit = type + 2; - else if (extent <= 3.0 * (Math.PI / 2.0)) + else if (Math.abs(extent) <= 3.0 * (Math.PI / 2.0)) limit = type + 3; else limit = type + 4; @@ -909,9 +904,20 @@ public abstract class Arc2D extends RectangularShape double kappa = (Math.sqrt(2.0) - 1.0) * (4.0 / 3.0); double quad = (Math.PI / 2.0); - double curr_begin = start + (current - 1) * quad; - double curr_extent = Math.min((start + extent) - curr_begin, quad); - double portion_of_a_quadrant = curr_extent / quad; + double curr_begin; + double curr_extent; + if (extent > 0) + { + curr_begin = start + (current - 1) * quad; + curr_extent = Math.min((start + extent) - curr_begin, quad); + } + else + { + curr_begin = start - (current - 1) * quad; + curr_extent = Math.max((start + extent) - curr_begin, -quad); + } + + double portion_of_a_quadrant = Math.abs(curr_extent / quad); double x0 = xmid + rx * Math.cos(curr_begin); double y0 = ymid - ry * Math.sin(curr_begin); @@ -932,7 +938,11 @@ public abstract class Arc2D extends RectangularShape // will *subtract* the y value of this control vector from our first // point. cvec[0] = 0; - cvec[1] = len; + if (extent > 0) + cvec[1] = len; + else + cvec[1] = -len; + trans.scale(rx, ry); trans.rotate(angle); trans.transform(cvec, 0, cvec, 0, 1); @@ -942,7 +952,11 @@ public abstract class Arc2D extends RectangularShape // control vector #2 would, ideally, be sticking out and to the // right, in a first quadrant arc segment. again, subtraction of y. cvec[0] = 0; - cvec[1] = -len; + if (extent > 0) + cvec[1] = -len; + else + cvec[1] = len; + trans.rotate(curr_extent); trans.transform(cvec, 0, cvec, 0, 1); coords[2] = x1 + cvec[0]; diff --git a/libjava/classpath/java/awt/geom/GeneralPath.java b/libjava/classpath/java/awt/geom/GeneralPath.java index e0ca8e1..1e9ede5 100644 --- a/libjava/classpath/java/awt/geom/GeneralPath.java +++ b/libjava/classpath/java/awt/geom/GeneralPath.java @@ -86,7 +86,7 @@ public final class GeneralPath implements Shape, Cloneable public static final int WIND_EVEN_ODD = java.awt.geom.PathIterator.WIND_EVEN_ODD; - /** Same constant as {@link PathIterator.WIND_NON_ZERO}. */ + /** Same constant as {@link PathIterator#WIND_NON_ZERO}. */ public static final int WIND_NON_ZERO = java.awt.geom.PathIterator.WIND_NON_ZERO; @@ -140,7 +140,11 @@ public final class GeneralPath implements Shape, Cloneable /** * Constructs a GeneralPath with a specific winding rule * and the default initial capacity (20). - * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD) + * @param rule the winding rule ({@link #WIND_NON_ZERO} or + * {@link #WIND_EVEN_ODD}) + * + * @throws IllegalArgumentException if <code>rule</code> is not one of the + * listed values. */ public GeneralPath(int rule) { @@ -151,8 +155,12 @@ public final class GeneralPath implements Shape, Cloneable * Constructs a GeneralPath with a specific winding rule * and the initial capacity. The initial capacity should be * the approximate number of path segments to be used. - * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD) + * @param rule the winding rule ({@link #WIND_NON_ZERO} or + * {@link #WIND_EVEN_ODD}) * @param capacity the inital capacity, in path segments + * + * @throws IllegalArgumentException if <code>rule</code> is not one of the + * listed values. */ public GeneralPath(int rule, int capacity) { @@ -169,7 +177,10 @@ public final class GeneralPath implements Shape, Cloneable /** * Constructs a GeneralPath from an arbitrary shape object. * The Shapes PathIterator path and winding rule will be used. - * @param s the shape + * + * @param s the shape (<code>null</code> not permitted). + * + * @throws NullPointerException if <code>shape</code> is <code>null</code>. */ public GeneralPath(Shape s) { @@ -183,6 +194,9 @@ public final class GeneralPath implements Shape, Cloneable /** * Adds a new point to a path. + * + * @param x the x-coordinate. + * @param y the y-coordinate. */ public void moveTo(float x, float y) { @@ -263,6 +277,11 @@ public final class GeneralPath implements Shape, Cloneable * Appends the segments of a Shape to the path. If <code>connect</code> is * true, the new path segments are connected to the existing one with a line. * The winding rule of the Shape is ignored. + * + * @param s the shape (<code>null</code> not permitted). + * @param connect whether to connect the new shape to the existing path. + * + * @throws NullPointerException if <code>s</code> is <code>null</code>. */ public void append(Shape s, boolean connect) { @@ -276,7 +295,7 @@ public final class GeneralPath implements Shape, Cloneable * PathIterator#SEG_LINETO} segment. * * @param iter the PathIterator specifying which segments shall be - * appended. + * appended (<code>null</code> not permitted). * * @param connect <code>true</code> for substituting the initial * {@link PathIterator#SEG_MOVETO} segment by a {@link @@ -327,6 +346,8 @@ public final class GeneralPath implements Shape, Cloneable /** * Returns the path’s current winding rule. + * + * @return {@link #WIND_EVEN_ODD} or {@link #WIND_NON_ZERO}. */ public int getWindingRule() { @@ -338,6 +359,8 @@ public final class GeneralPath implements Shape, Cloneable * considered ’inside’ or ’outside’ the path * on drawing. Valid rules are WIND_EVEN_ODD for an even-odd winding rule, * or WIND_NON_ZERO for a non-zero winding rule. + * + * @param rule the rule ({@link #WIND_EVEN_ODD} or {@link #WIND_NON_ZERO}). */ public void setWindingRule(int rule) { @@ -348,6 +371,8 @@ public final class GeneralPath implements Shape, Cloneable /** * Returns the current appending point of the path. + * + * @return The point. */ public Point2D getCurrentPoint() { @@ -367,6 +392,8 @@ public final class GeneralPath implements Shape, Cloneable /** * Applies a transform to the path. + * + * @param xform the transform (<code>null</code> not permitted). */ public void transform(AffineTransform xform) { @@ -706,6 +733,8 @@ public final class GeneralPath implements Shape, Cloneable /** * Helper method - ensure the size of the data arrays, * otherwise, reallocate new ones twice the size + * + * @param size the minimum array size. */ private void ensureSize(int size) { diff --git a/libjava/classpath/java/awt/geom/RectangularShape.java b/libjava/classpath/java/awt/geom/RectangularShape.java index 8f66dab..3ee1615 100644 --- a/libjava/classpath/java/awt/geom/RectangularShape.java +++ b/libjava/classpath/java/awt/geom/RectangularShape.java @@ -326,15 +326,12 @@ public abstract class RectangularShape implements Shape, Cloneable /** * Returns a bounding box for this shape, in integer format. Notice that you - * may get a tighter bound with getBounds2D. If the frame is empty, the - * box is the default empty box at the origin. + * may get a tighter bound with getBounds2D. * * @return a bounding box */ public Rectangle getBounds() { - if (isEmpty()) - return new Rectangle(); double x = getX(); double y = getY(); double maxx = Math.ceil(x + getWidth()); diff --git a/libjava/classpath/java/awt/geom/RoundRectangle2D.java b/libjava/classpath/java/awt/geom/RoundRectangle2D.java index ac0e6f8..ac4d89f 100644 --- a/libjava/classpath/java/awt/geom/RoundRectangle2D.java +++ b/libjava/classpath/java/awt/geom/RoundRectangle2D.java @@ -1,5 +1,5 @@ /* RoundRectangle2D.java -- represents a rectangle with rounded corners - Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation + Copyright (C) 2000, 2002, 2003, 2004, 2006, Free Software Foundation This file is part of GNU Classpath. @@ -37,7 +37,6 @@ exception statement from your version. */ package java.awt.geom; -import java.util.NoSuchElementException; /** This class implements a rectangle with rounded corners. @@ -46,13 +45,29 @@ import java.util.NoSuchElementException; */ public abstract class RoundRectangle2D extends RectangularShape { - /** Return the arc height of this round rectangle. */ + /** + * Return the arc height of this round rectangle. The arc height and width + * control the roundness of the corners of the rectangle. + * + * @return The arc height. + * + * @see #getArcWidth() + */ public abstract double getArcHeight(); - /** Return the arc width of this round rectangle. */ + /** + * Return the arc width of this round rectangle. The arc width and height + * control the roundness of the corners of the rectangle. + * + * @return The arc width. + * + * @see #getArcHeight() + */ public abstract double getArcWidth(); - /** Set the values of this round rectangle + /** + * Set the values of this round rectangle. + * * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -63,14 +78,16 @@ public abstract class RoundRectangle2D extends RectangularShape public abstract void setRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight); - /** Create a RoundRectangle2D. This is protected because this class + /** + * Create a RoundRectangle2D. This is protected because this class * is abstract and cannot be instantiated. */ protected RoundRectangle2D() { } - /** Return true if this object contains the specified point. + /** + * Return true if this object contains the specified point. * @param x The x coordinate * @param y The y coordinate */ @@ -106,7 +123,8 @@ public abstract class RoundRectangle2D extends RectangularShape return dx * dx + dy * dy <= 1.0; } - /** Return true if this object contains the specified rectangle + /** + * Return true if this object contains the specified rectangle * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -120,176 +138,185 @@ public abstract class RoundRectangle2D extends RectangularShape && contains(x + w, y)); } - /** Return a new path iterator which iterates over this rectangle. + /** + * Return a new path iterator which iterates over this rectangle. + * * @param at An affine transform to apply to the object */ - public PathIterator getPathIterator(final AffineTransform at) + public PathIterator getPathIterator(final AffineTransform at) { - final double minx = getX(); - final double miny = getY(); - final double maxx = minx + getWidth(); - final double maxy = miny + getHeight(); - final double arcwidth = getArcWidth(); - final double archeight = getArcHeight(); - return new PathIterator() + double arcW = Math.min(getArcWidth(), getWidth()); + double arcH = Math.min(getArcHeight(), getHeight()); + + // check for special cases... + if (arcW <= 0 || arcH <= 0) + { + Rectangle2D r = new Rectangle2D.Double(getX(), getY(), getWidth(), + getHeight()); + return r.getPathIterator(at); + } + else if (arcW >= getWidth() && arcH >= getHeight()) + { + Ellipse2D e = new Ellipse2D.Double(getX(), getY(), getWidth(), + getHeight()); + return e.getPathIterator(at); + } + + // otherwise return the standard case... + return new PathIterator() + { + double x = getX(); + double y = getY(); + double w = getWidth(); + double h = getHeight(); + double arcW = Math.min(getArcWidth(), w); + double arcH = Math.min(getArcHeight(), h); + Arc2D.Double arc = new Arc2D.Double(); + PathIterator corner; + int step = -1; + + public int currentSegment(double[] coords) + { + if (corner != null) // steps 1, 3, 5 and 7 + { + int r = corner.currentSegment(coords); + if (r == SEG_MOVETO) + r = SEG_LINETO; + return r; + } + if (step == -1) + { + // move to the start position + coords[0] = x + w - arcW / 2; + coords[1] = y; + } + else if (step == 0) + { + // top line + coords[0] = x + arcW / 2; + coords[1] = y; + } + else if (step == 2) + { + // left line + coords[0] = x; + coords[1] = y + h - arcH / 2; + } + else if (step == 4) + { + // bottom line + coords[0] = x + w - arcW / 2; + coords[1] = y + h; + } + else if (step == 6) + { + // right line + coords[0] = x + w; + coords[1] = y + arcH / 2; + } + if (at != null) + at.transform(coords, 0, coords, 0, 1); + return step == -1 ? SEG_MOVETO : SEG_LINETO; + } + + public int currentSegment(float[] coords) { + if (corner != null) // steps 1, 3, 5 and 7 + { + int r = corner.currentSegment(coords); + if (r == SEG_MOVETO) + r = SEG_LINETO; + return r; + } + if (step == -1) + { + // move to the start position + coords[0] = (float) (x + w - arcW / 2); + coords[1] = (float) y; + } + else if (step == 0) + { + // top line + coords[0] = (float) (x + arcW / 2); + coords[1] = (float) y; + } + else if (step == 2) + { + // left line + coords[0] = (float) x; + coords[1] = (float) (y + h - arcH / 2); + } + else if (step == 4) + { + // bottom line + coords[0] = (float) (x + w - arcW / 2); + coords[1] = (float) (y + h); + } + else if (step == 6) + { + // right line + coords[0] = (float) (x + w); + coords[1] = (float) (y + arcH / 2); + } + if (at != null) + at.transform(coords, 0, coords, 0, 1); + return step == -1 ? SEG_MOVETO : SEG_LINETO; + } + + public int getWindingRule() { + return WIND_NON_ZERO; + } + + public boolean isDone() { + return step >= 8; + } + + public void next() { - /** We iterate counterclockwise around the rectangle, starting in the - * upper right. This variable tracks our current point, which - * can be on either side of a given corner. */ - private int current = 0; - - /** Child path iterator, used for corners. */ - private PathIterator corner; - - /** This is used when rendering the corners. We re-use the arc - * for each corner. */ - private Arc2D arc = new Arc2D.Double(); - - /** Temporary array used by getPoint. */ - private double[] temp = new double[2]; - - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current > 9; - } - - private void getPoint(int val) - { - switch (val) - { - case 0: - case 8: - temp[0] = maxx; - temp[1] = miny + archeight; - break; - case 7: - temp[0] = maxx; - temp[1] = maxy - archeight; - break; - case 6: - temp[0] = maxx - arcwidth; - temp[1] = maxy; - break; - case 5: - temp[0] = minx + arcwidth; - temp[1] = maxy; - break; - case 4: - temp[0] = minx; - temp[1] = maxy - archeight; - break; - case 3: - temp[0] = minx; - temp[1] = miny + archeight; - break; - case 2: - temp[0] = minx + arcwidth; - temp[1] = miny; - break; - case 1: - temp[0] = maxx - arcwidth; - temp[1] = miny; - break; - } - } - - public void next() - { - if (current >= 8) - ++current; - else if (corner != null) - { - // We're iterating through the corner. Work on the child - // iterator; if it finishes, reset and move to the next - // point along the rectangle. - corner.next(); - if (corner.isDone()) - { - corner = null; - ++current; - } - } - else - { - // Make an arc between this point on the rectangle and - // the next one, and then iterate over this arc. - getPoint(current); - double x1 = temp[0]; - double y1 = temp[1]; - getPoint(current + 1); - Rectangle2D.Double r = new Rectangle2D.Double(Math.min(x1, - temp[0]), - Math.min(y1, - temp[1]), - Math.abs(x1 - - temp[0]), - Math.abs(y1 - - temp[1])); - arc.setArc(r, (current >> 1) * 90.0, 90.0, Arc2D.OPEN); - corner = arc.getPathIterator(at); - } - } - - public int currentSegment(float[] coords) - { - if (corner != null) - { - int r = corner.currentSegment(coords); - if (r == SEG_MOVETO) - r = SEG_LINETO; - return r; - } - - if (current < 9) - { - getPoint(current); - coords[0] = (float) temp[0]; - coords[1] = (float) temp[1]; - } - else if (current == 9) - return SEG_CLOSE; - else - throw new NoSuchElementException("rect iterator out of bounds"); - - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - - public int currentSegment(double[] coords) - { - if (corner != null) - { - int r = corner.currentSegment(coords); - if (r == SEG_MOVETO) - r = SEG_LINETO; - return r; - } - - if (current < 9) - { - getPoint(current); - coords[0] = temp[0]; - coords[1] = temp[1]; - } - else if (current == 9) - return SEG_CLOSE; - else - throw new NoSuchElementException("rect iterator out of bounds"); - - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - }; + if (corner != null) + { + corner.next(); + if (corner.isDone()) + { + corner = null; + step++; + } + } + else + { + step++; + if (step == 1) + { + // create top left corner + arc.setArc(x, y, arcW, arcH, 90, 90, Arc2D.OPEN); + corner = arc.getPathIterator(at); + } + else if (step == 3) + { + // create bottom left corner + arc.setArc(x, y + h - arcH, arcW, arcH, 180, 90, + Arc2D.OPEN); + corner = arc.getPathIterator(at); + } + else if (step == 5) + { + // create bottom right corner + arc.setArc(x + w - arcW, y + h - arcH, arcW, arcH, 270, 90, + Arc2D.OPEN); + corner = arc.getPathIterator(at); + } + else if (step == 7) + { + // create top right corner + arc.setArc(x + w - arcW, y, arcW, arcH, 0, 90, Arc2D.OPEN); + corner = arc.getPathIterator(at); + } + } + } + }; } - /** Return true if the given rectangle intersects this shape. + /** + * Return true if the given rectangle intersects this shape. * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -302,7 +329,8 @@ public abstract class RoundRectangle2D extends RectangularShape || contains(x + w, y)); } - /** Set the boundary of this round rectangle. + /** + * Set the boundary of this round rectangle. * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -314,7 +342,8 @@ public abstract class RoundRectangle2D extends RectangularShape setRoundRect(x, y, w, h, getArcWidth(), getArcHeight()); } - /** Set the values of this round rectangle to be the same as those + /** + * Set the values of this round rectangle to be the same as those * of the argument. * @param rr The round rectangle to copy */ @@ -324,8 +353,10 @@ public abstract class RoundRectangle2D extends RectangularShape rr.getArcWidth(), rr.getArcHeight()); } - /** A subclass of RoundRectangle which keeps its parameters as - * doubles. */ + /** + * A subclass of RoundRectangle which keeps its parameters as + * doubles. + */ public static class Double extends RoundRectangle2D { /** The height of the corner arc. */ @@ -346,12 +377,15 @@ public abstract class RoundRectangle2D extends RectangularShape /** The height of this object. */ public double height; - /** Construct a new instance, with all parameters set to 0. */ + /** + * Construct a new instance, with all parameters set to 0. + */ public Double() { } - /** Construct a new instance with the given arguments. + /** + * Construct a new instance with the given arguments. * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -422,8 +456,10 @@ public abstract class RoundRectangle2D extends RectangularShape } } // class Double - /** A subclass of RoundRectangle which keeps its parameters as - * floats. */ + /** + * A subclass of RoundRectangle which keeps its parameters as + * floats. + */ public static class Float extends RoundRectangle2D { /** The height of the corner arc. */ @@ -444,12 +480,15 @@ public abstract class RoundRectangle2D extends RectangularShape /** The height of this object. */ public float height; - /** Construct a new instance, with all parameters set to 0. */ + /** + * Construct a new instance, with all parameters set to 0. + */ public Float() { } - /** Construct a new instance with the given arguments. + /** + * Construct a new instance with the given arguments. * @param x The x coordinate * @param y The y coordinate * @param w The width @@ -508,6 +547,18 @@ public abstract class RoundRectangle2D extends RectangularShape return width <= 0 || height <= 0; } + /** + * Sets the dimensions for this rounded rectangle. + * + * @param x the x-coordinate of the top left corner. + * @param y the y-coordinate of the top left corner. + * @param w the width of the rectangle. + * @param h the height of the rectangle. + * @param arcWidth the arc width. + * @param arcHeight the arc height. + * + * @see #setRoundRect(double, double, double, double, double, double) + */ public void setRoundRect(float x, float y, float w, float h, float arcWidth, float arcHeight) { |