diff --git a/core/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java b/core/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java index 9b2702d..d239585 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java +++ b/core/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java @@ -44,33 +44,43 @@ * @author Jesse Grosjean */ public class PActivity { - + /** + * Parameter for terminate that signifies that activity should bail out + * immediately without flagging activity as finished. + */ public static final int TERMINATE_WITHOUT_FINISHING = 0; - public static final int TERMINATE_AND_FINISH = 1; - public static final int TERMINATE_AND_FINISH_IF_STEPPING = 2; - - private PActivityScheduler scheduler; - - private long startTime; - private long duration; - private long stepRate; - private PActivityDelegate delegate; - - private boolean stepping; - private long nextStepTime; /** - * PActivityDelegate is used by classes to learn about and act on the - * different states that a PActivity goes through, such as when the activity - * starts and stops stepping. + * Parameter for terminate that signifies that activity should bail out + * immediately, but flag activity as finished. */ - public interface PActivityDelegate { - public void activityStarted(PActivity activity); + public static final int TERMINATE_AND_FINISH = 1; - public void activityStepped(PActivity activity); + /** + * Parameter for terminate that signifies that activity should bail out + * immediately, if currently active. + */ + public static final int TERMINATE_AND_FINISH_IF_STEPPING = 2; - public void activityFinished(PActivity activity); - } + /** Activity scheduler that this activity is bound to. */ + private PActivityScheduler scheduler; + + /** Time at which this activity should start in PRoot global time. */ + private long startTime; + + /** Duration in milliseconds that this activity should last. */ + private long duration; + + /** How many milliseconds should pass between steps. */ + private long stepRate; + + private PActivityDelegate delegate; + + /** Whether this activity is currently active. */ + private boolean stepping; + + /** Next time at which step should occur. */ + private long nextStepTime; /** * Constructs a new PActivity. @@ -120,6 +130,8 @@ * Return the time that this activity should start running in PRoot global * time. When this time is reached (or soon after) this activity will have * its startStepping() method called. + * + * @return time at which this activity should start in PRoot global time. */ public long getStartTime() { return startTime; @@ -129,6 +141,9 @@ * Set the time that this activity should start running in PRoot global * time. When this time is reached (or soon after) this activity will have * its startStepping() method called. + * + * @param aTriggerTime time at which you want this activity to begin in + * PRoot global time */ public void setStartTime(final long aTriggerTime) { startTime = aTriggerTime; @@ -136,6 +151,8 @@ /** * Return the amount of time that this activity should delay between steps. + * + * @return the desired milliseconds between steps */ public long getStepRate() { return stepRate; @@ -143,11 +160,19 @@ /** * Set the amount of time that this activity should delay between steps. + * + * @param aStepRate desired step rate in milliseconds between steps */ public void setStepRate(final long aStepRate) { stepRate = aStepRate; } + /** + * Gets the next step time desired for this activity. Exists since some + * steps might eat into the step rate otherwise. + * + * @return next calculated step time + */ public long getNextStepTime() { return nextStepTime; } @@ -155,6 +180,8 @@ /** * Return the amount of time that this activity should take to complete, * after the startStepping method is called. + * + * @return time that this activity should take to complete */ public long getDuration() { return duration; @@ -163,15 +190,29 @@ /** * Set the amount of time that this activity should take to complete, after * the startStepping method is called. + * + * @param aDuration desired duration this activity should take (-1 for + * infinite) once it begins stepping */ public void setDuration(final long aDuration) { duration = aDuration; } + /** + * Returns the activity scheduler associated with this activity. + * + * @return associated scheduler + */ public PActivityScheduler getActivityScheduler() { return scheduler; } + /** + * Informs the activity of the scheduler that will be responsible for + * scheduling it. + * + * @param aScheduler scheduler to associate with this activity + */ public void setActivityScheduler(final PActivityScheduler aScheduler) { scheduler = aScheduler; } @@ -182,6 +223,8 @@ /** * Return true if this activity is stepping. + * + * @return whether this activity is stepping */ public boolean isStepping() { return stepping; @@ -191,6 +234,9 @@ * Return true if this activity is performing an animation. This is used by * the PCanvas to determine if it should set the render quality to * PCanvas.animatingRenderQuality or not for each frame it renders. + * + * @return whether this activity is an animation, subclasses can override + * this. */ protected boolean isAnimation() { return false; @@ -233,6 +279,8 @@ /** * Get the delegate for this activity. The delegate is notified when the * activity starts and stops stepping. + * + * @return delegate of this activity, may be null */ public PActivityDelegate getDelegate() { return delegate; @@ -241,6 +289,8 @@ /** * Set the delegate for this activity. The delegate is notified when the * activity starts and stops stepping. + * + * @param delegate delegate that should be informed of activity events */ public void setDelegate(final PActivityDelegate delegate) { this.delegate = delegate; @@ -255,6 +305,8 @@ * Note that no link is created between these activities, if the startTime * or duration of the first activity is later changed this activities start * time will not be updated to reflect that change. + * + * @param first activity after which this activity should be scheduled */ public void startAfter(final PActivity first) { setStartTime(first.getStartTime() + first.getDuration()); @@ -283,6 +335,9 @@ * the activity has not yet started the method activityStarted will also be * called. TERMINATE_AND_FINISH_IF_STEPPING - The method activityFinished * will only be called if the activity has previously started. + * + * @param terminationBehavior behavior to use regarding delegate + * notification and event firing */ public void terminate(final int terminationBehavior) { if (scheduler != null) { @@ -312,12 +367,18 @@ activityFinished(); } break; + default: + throw new RuntimeException("Invalid termination behaviour provided to PActivity.terminate"); } } /** * The activity scheduler calls this method and it is here that the activity * decides if it should do a step or not for the given time. + * + * @param currentTime in global root time + * @return number of milliseconds in global root time before processStep + * should be called again, -1 if never */ public long processStep(final long currentTime) { // if before start time @@ -357,6 +418,8 @@ /** * Return the time when this activity should finish running. At this time * (or soon after) the stoppedStepping method will be called + * + * @return time at which this activity should be stopped */ public long getStopTime() { if (duration == -1) { @@ -367,8 +430,39 @@ /** * @deprecated see http://code.google.com/p/piccolo2d/issues/detail?id=99 + * + * @return string representation of this activity */ protected String paramString() { return ""; } + + /** + * PActivityDelegate is used by classes to learn about and act on the + * different states that a PActivity goes through, such as when the activity + * starts and stops stepping. + */ + public interface PActivityDelegate { + /** + * Gets called when the activity starts. + * + * @param activity activity that started + */ + void activityStarted(PActivity activity); + + /** + * Gets called for each step of the activity. + * + * @param activity activity that is stepping + */ + void activityStepped(PActivity activity); + + /** + * Gets called when the activity finishes. + * + * @param activity activity that finished + */ + void activityFinished(PActivity activity); + } + } diff --git a/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java b/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java index e17a56d..abf7c10 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java +++ b/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java @@ -82,6 +82,12 @@ * be set correctly to Paint objects in any property change event. */ public static final String PROPERTY_STROKE_PAINT = "strokePaint"; + + /** + * The property code that identifies a change of this node's stroke paint + * (see {@link #getStrokePaint getStrokePaint}). Both old and new value will + * be set correctly to Paint objects in any property change event. + */ public static final int PROPERTY_CODE_STROKE_PAINT = 1 << 16; /** @@ -90,6 +96,12 @@ * correctly to Stroke objects in any property change event. */ public static final String PROPERTY_STROKE = "stroke"; + + /** + * The property code that identifies a change of this node's stroke (see + * {@link #getStroke getStroke}). Both old and new value will be set + * correctly to Stroke objects in any property change event. + */ public static final int PROPERTY_CODE_STROKE = 1 << 17; /** @@ -99,6 +111,13 @@ * always be null. */ public static final String PROPERTY_PATH = "path"; + + /** + * The property code that identifies a change of this node's path (see + * {@link #getPathReference getPathReference}). In any property change event + * the new value will be a reference to this node's path, but old value will + * always be null. + */ public static final int PROPERTY_CODE_PATH = 1 << 18; private static final Rectangle2D.Float TEMP_RECTANGLE = new Rectangle2D.Float(); @@ -114,6 +133,16 @@ private transient boolean updatingBoundsFromPath; private Paint strokePaint; + /** + * Creates a PPath object in the shape of a rectangle. + * + * @param x left of the rectangle + * @param y top of the rectangle + * @param width width of the rectangle + * @param height height of the rectangle + * + * @return created rectangle + */ public static PPath createRectangle(final float x, final float y, final float width, final float height) { TEMP_RECTANGLE.setFrame(x, y, width, height); final PPath result = new PPath(TEMP_RECTANGLE); @@ -121,6 +150,18 @@ return result; } + /** + * Creates a PPath object in the shape of a rounded rectangle. + * + * @param x left of the rectangle + * @param y top of the rectangle + * @param width width of the rectangle + * @param height height of the rectangle + * @param arcWidth the arc width at the corners of the rectangle + * @param arcHeight the arc height at the corners of the rectangle + * + * @return created rounded rectangle + */ public static PPath createRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight); @@ -129,6 +170,16 @@ return result; } + /** + * Creates a PPath object in the shape of an ellipse. + * + * @param x left of the ellipse + * @param y top of the ellipse + * @param width width of the ellipse + * @param height height of the ellipse + * + * @return created ellipse + */ public static PPath createEllipse(final float x, final float y, final float width, final float height) { TEMP_ELLIPSE.setFrame(x, y, width, height); final PPath result = new PPath(TEMP_ELLIPSE); @@ -136,6 +187,16 @@ return result; } + /** + * Creates a PPath in the shape of a line. + * + * @param x1 x component of the first point + * @param y1 y component of the first point + * @param x2 x component of the second point + * @param y2 y component of the second point + * + * @return created line + */ public static PPath createLine(final float x1, final float y1, final float x2, final float y2) { final PPath result = new PPath(); result.moveTo(x1, y1); @@ -144,6 +205,13 @@ return result; } + /** + * Creates a PPath for the poly-line for the given points. + * + * @param points array of points for the point lines + * + * @return created poly-line for the given points + */ public static PPath createPolyline(final Point2D[] points) { final PPath result = new PPath(); result.setPathToPolyline(points); @@ -151,6 +219,14 @@ return result; } + /** + * Creates a PPath for the poly-line for the given points. + * + * @param xp array of x components of the points of the poly-lines + * @param yp array of y components of the points of the poly-lines + * + * @return created poly-line for the given points + */ public static PPath createPolyline(final float[] xp, final float[] yp) { final PPath result = new PPath(); result.setPathToPolyline(xp, yp); @@ -158,12 +234,20 @@ return result; } + /** + * Creates an empty PPath with the default paint and stroke. + */ public PPath() { strokePaint = DEFAULT_STROKE_PAINT; stroke = DEFAULT_STROKE; path = new GeneralPath(); } + /** + * Creates an PPath in the given shape with the default paint and stroke. + * + * @param aShape the desired shape + */ public PPath(final Shape aShape) { this(aShape, DEFAULT_STROKE); } @@ -176,6 +260,9 @@ * allows you to override that default stroke before the bounds are ever * calculated, so if you pass in a null stroke here you won't ever have to * pay that bounds calculation price if you don't need to. + * + * @param aShape desired shape or null if you desire an empty path + * @param aStroke desired stroke */ public PPath(final Shape aShape, final Stroke aStroke) { this(); @@ -189,6 +276,11 @@ // Stroke // **************************************************************** + /** + * Returns the stroke paint of the PPath. + * + * @return stroke paint of the PPath + */ public Paint getStrokePaint() { return strokePaint; } diff --git a/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java b/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java index e61291b..115a75d 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java +++ b/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java @@ -49,50 +49,131 @@ */ private static final long serialVersionUID = 1L; - private static double[] PTS1 = new double[8]; - private static double[] PTS2 = new double[8]; + /** Used internally to speed up computation. */ + private static final double[] PTS1 = new double[8]; + /** Used internally to speed up computation. */ + private static final double[] PTS2 = new double[8]; + + /** + * Constructs a new AffineTransform representing the Identity + * transformation. + */ public PAffineTransform() { super(); } + /** + * Constructs a new AffineTransform from an array of double precision values + * representing either the 4 non-translation entries or the 6 specifiable + * entries of the 3x3 transformation matrix. The values are retrieved from + * the array as { m00 m10 m01 m11 [m02 m12]}. + * + * @param flatmatrix the double array containing the values to be set in the + * new AffineTransform object. The length of the array is assumed + * to be at least 4. If the length of the array is less than 6, + * only the first 4 values are taken. If the length of the array + * is greater than 6, the first 6 values are taken. + */ public PAffineTransform(final double[] flatmatrix) { super(flatmatrix); } + /** + * Constructs a new AffineTransform from an array of floating point values + * representing either the 4 non-translation entries or the 6 specifiable + * entries of the 3x3 transformation matrix. The values are retrieved from + * the array as { m00 m10 m01 m11 [m02 m12]}. + * + * @param flatmatrix the float array containing the values to be set in the + * new AffineTransform object. The length of the array is assumed + * to be at least 4. If the length of the array is less than 6, + * only the first 4 values are taken. If the length of the array + * is greater than 6, the first 6 values are taken. + */ public PAffineTransform(final float[] flatmatrix) { super(flatmatrix); } + /** + * Constructs a new AffineTransform from 6 double precision values + * representing the 6 specifiable entries of the 3x3 transformation matrix. + * + * @param m00 the X coordinate scaling element of the 3x3 matrix + * @param m10 the Y coordinate shearing element of the 3x3 matrix + * @param m01 the X coordinate shearing element of the 3x3 matrix + * @param m11 the Y coordinate scaling element of the 3x3 matrix + * @param m02 the X coordinate translation element of the 3x3 matrix + * @param m12 the Y coordinate translation element of the 3x3 matrix + */ public PAffineTransform(final double m00, final double m10, final double m01, final double m11, final double m02, final double m12) { super(m00, m10, m01, m11, m02, m12); } + /** + * Constructs a new AffineTransform from 6 floating point values + * representing the 6 specifiable entries of the 3x3 transformation matrix. + * + * @param m00 the X coordinate scaling element of the 3x3 matrix + * @param m10 the Y coordinate shearing element of the 3x3 matrix + * @param m01 the X coordinate shearing element of the 3x3 matrix + * @param m11 the Y coordinate scaling element of the 3x3 matrix + * @param m02 the X coordinate translation element of the 3x3 matrix + * @param m12 the Y coordinate translation element of the 3x3 matrix + */ public PAffineTransform(final float m00, final float m10, final float m01, final float m11, final float m02, final float m12) { super(m00, m10, m01, m11, m02, m12); } + /** + * Constructs a new AffineTransform that is a copy of the specified + * AffineTransform object. + * + * @param tx transform to copy + */ public PAffineTransform(final AffineTransform tx) { super(tx); } + /** + * Scales the transform about the given point by the given scale. + * + * @param scale to transform the transform by + * @param x x coordinate around which the scale should take place + * @param y y coordinate around which the scale should take place + */ public void scaleAboutPoint(final double scale, final double x, final double y) { translate(x, y); scale(scale, scale); translate(-x, -y); } + /** + * Returns the scale applied to this transform. Note that it does so by + * computing the change in length of a unit segment after being passed + * through the transform. This means that a transform that a transform that + * doesn't scale the in the x but doubles the y will be reported as 2. + * + * @return the different in length of a unit segment after being + * transformed. + */ public double getScale() { - PTS1[0] = 0;// x1 - PTS1[1] = 0;// y1 - PTS1[2] = 1;// x2 - PTS1[3] = 0;// y2 + PTS1[0] = 0; // x1 + PTS1[1] = 0; // y1 + PTS1[2] = 1; // x2 + PTS1[3] = 0; // y2 transform(PTS1, 0, PTS2, 0, 2); return Point2D.distance(PTS2[0], PTS2[1], PTS2[2], PTS2[3]); } + /** + * Sets the scale about to the origin of this transform to the scale + * provided. + * + * @param scale The desired resulting scale + */ public void setScale(final double scale) { if (scale == 0) { throw new PAffineTransformException("Can't set scale to 0", this); @@ -101,6 +182,12 @@ scaleAboutPoint(scale / getScale(), 0, 0); } + /** + * Applies modifies the transform so that it translates by the given offset. + * + * @param tx x translation of resulting transform + * @param ty y translation of resulting transform + */ public void setOffset(final double tx, final double ty) { setTransform(getScaleX(), getShearY(), getShearX(), getScaleY(), tx, ty); } @@ -112,10 +199,10 @@ * @return rotation in radians */ public double getRotation() { - PTS1[0] = 0;// x1 - PTS1[1] = 0;// y1 - PTS1[2] = 1;// x2 - PTS1[3] = 0;// y2 + PTS1[0] = 0; // x1 + PTS1[1] = 0; // y1 + PTS1[2] = 1; // x2 + PTS1[3] = 0; // y2 transform(PTS1, 0, PTS2, 0, 2); @@ -129,37 +216,57 @@ rotation = Math.PI - rotation; } } + else if (PTS2[2] - PTS2[0] > 0) { + rotation = 2 * Math.PI - rotation; + } else { - if (PTS2[2] - PTS2[0] > 0) { - rotation = 2 * Math.PI - rotation; - } - else { - rotation = rotation + Math.PI; - } + rotation = rotation + Math.PI; } return rotation; } /** - * Set rotation in radians. + * Set rotation in radians. This is not cumulative. + * + * @param theta desired rotation in radians. */ public void setRotation(final double theta) { rotate(theta - getRotation()); } - public Dimension2D transform(final Dimension2D dimSrc, Dimension2D dimDst) { + /** + * Applies the transform to the provided dimension. + * + * @param dimSrc source dimension + * @param dimDst will be changed to be the transformed dimension, may be + * null + * @return the transformed dimension + */ + public Dimension2D transform(final Dimension2D dimSrc, final Dimension2D dimDst) { + final Dimension2D result; if (dimDst == null) { - dimDst = (Dimension2D) dimSrc.clone(); + result = (Dimension2D) dimSrc.clone(); + } + else { + result = dimDst; } PTS1[0] = dimSrc.getWidth(); PTS1[1] = dimSrc.getHeight(); deltaTransform(PTS1, 0, PTS2, 0, 1); - dimDst.setSize(PTS2[0], PTS2[1]); - return dimDst; + result.setSize(PTS2[0], PTS2[1]); + return result; } + /** + * Applies the inverse of this transform to the source point if possible. + * + * @param ptSrc point to be transformed + * @param ptDst result of transform will be placed in this point + * + * @return the transformed point + */ public Point2D inverseTransform(final Point2D ptSrc, final Point2D ptDst) { try { return super.inverseTransform(ptSrc, ptDst); @@ -169,9 +276,22 @@ } } - public Dimension2D inverseTransform(final Dimension2D dimSrc, Dimension2D dimDst) { + /** + * Applies the inverse of this transform to the source dimension if + * possible. + * + * @param dimSrc dimension to be transformed + * @param dimDst result of transform will be placed in this dimension + * + * @return the transformed dimension + */ + public Dimension2D inverseTransform(final Dimension2D dimSrc, final Dimension2D dimDst) { + final Dimension2D result; if (dimDst == null) { - dimDst = (Dimension2D) dimSrc.clone(); + result = (Dimension2D) dimSrc.clone(); + } + else { + result = dimDst; } final double width = dimSrc.getWidth(); @@ -183,89 +303,115 @@ final double det = m00 * m11 - m01 * m10; if (Math.abs(det) > Double.MIN_VALUE) { - dimDst.setSize((width * m11 - height * m01) / det, (height * m00 - width * m10) / det); + result.setSize((width * m11 - height * m01) / det, (height * m00 - width * m10) / det); } else { throw new PAffineTransformException("Could not invert transform", this); } - return dimDst; + return result; } - public Rectangle2D transform(final Rectangle2D rectSrc, Rectangle2D rectDst) { + /** + * Applies this transform to the source rectangle and stores the result in + * rectDst. + * + * @param rectSrc rectangle to be transformed + * @param rectDst result of transform will be placed in this rectangle + * + * @return the transformed rectangle + */ + public Rectangle2D transform(final Rectangle2D rectSrc, final Rectangle2D rectDst) { + final Rectangle2D result; if (rectDst == null) { - rectDst = (Rectangle2D) rectSrc.clone(); + result = (Rectangle2D) rectSrc.clone(); + } + else { + result = rectDst; } if (rectSrc.isEmpty()) { - rectDst.setRect(rectSrc); - if (rectDst instanceof PBounds) { - ((PBounds) rectDst).reset(); + result.setRect(rectSrc); + if (result instanceof PBounds) { + ((PBounds) result).reset(); } - return rectDst; + return result; } double scale; switch (getType()) { case AffineTransform.TYPE_IDENTITY: - if (rectSrc != rectDst) { - rectDst.setRect(rectSrc); + if (rectSrc != result) { + result.setRect(rectSrc); } break; case AffineTransform.TYPE_TRANSLATION: - rectDst.setRect(rectSrc.getX() + getTranslateX(), rectSrc.getY() + getTranslateY(), rectSrc.getWidth(), + result.setRect(rectSrc.getX() + getTranslateX(), rectSrc.getY() + getTranslateY(), rectSrc.getWidth(), rectSrc.getHeight()); break; case AffineTransform.TYPE_UNIFORM_SCALE: scale = getScaleX(); - rectDst.setRect(rectSrc.getX() * scale, rectSrc.getY() * scale, rectSrc.getWidth() * scale, rectSrc + result.setRect(rectSrc.getX() * scale, rectSrc.getY() * scale, rectSrc.getWidth() * scale, rectSrc .getHeight() * scale); break; case AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_UNIFORM_SCALE: scale = getScaleX(); - rectDst.setRect(rectSrc.getX() * scale + getTranslateX(), rectSrc.getY() * scale + getTranslateY(), + result.setRect(rectSrc.getX() * scale + getTranslateX(), rectSrc.getY() * scale + getTranslateY(), rectSrc.getWidth() * scale, rectSrc.getHeight() * scale); break; default: final double[] pts = rectToArray(rectSrc); transform(pts, 0, pts, 0, 4); - rectFromArray(rectDst, pts); + rectFromArray(result, pts); break; } - return rectDst; + return result; } - public Rectangle2D inverseTransform(final Rectangle2D rectSrc, Rectangle2D rectDst) { + /** + * Applies the inverse of this transform to the source rectangle and stores + * the result in rectDst. + * + * @param rectSrc rectangle to be transformed + * @param rectDst result of transform will be placed in this rectangle + * + * @return the transformed rectangle + */ + public Rectangle2D inverseTransform(final Rectangle2D rectSrc, final Rectangle2D rectDst) { + final Rectangle2D result; if (rectDst == null) { - rectDst = (Rectangle2D) rectSrc.clone(); + result = (Rectangle2D) rectSrc.clone(); + } + else { + result = rectDst; } if (rectSrc.isEmpty()) { - rectDst.setRect(rectSrc); - if (rectDst instanceof PBounds) { - ((PBounds) rectDst).reset(); + result.setRect(rectSrc); + if (result instanceof PBounds) { + ((PBounds) result).reset(); } - return rectDst; + return result; } double scale; switch (getType()) { case AffineTransform.TYPE_IDENTITY: - if (rectSrc != rectDst) { - rectDst.setRect(rectSrc); + if (rectSrc != result) { + result.setRect(rectSrc); } break; case AffineTransform.TYPE_TRANSLATION: - rectDst.setRect(rectSrc.getX() - getTranslateX(), rectSrc.getY() - getTranslateY(), rectSrc.getWidth(), + result.setRect(rectSrc.getX() - getTranslateX(), rectSrc.getY() - getTranslateY(), rectSrc.getWidth(), rectSrc.getHeight()); break; @@ -275,7 +421,7 @@ throw new PAffineTransformException("Could not invertTransform rectangle", this); } - rectDst.setRect(rectSrc.getX() / scale, rectSrc.getY() / scale, rectSrc.getWidth() / scale, rectSrc + result.setRect(rectSrc.getX() / scale, rectSrc.getY() / scale, rectSrc.getWidth() / scale, rectSrc .getHeight() / scale); break; @@ -285,7 +431,7 @@ if (scale == 0) { throw new PAffineTransformException("Could not invertTransform rectangle", this); } - rectDst.setRect((rectSrc.getX() - getTranslateX()) / scale, (rectSrc.getY() - getTranslateY()) / scale, + result.setRect((rectSrc.getX() - getTranslateX()) / scale, (rectSrc.getY() - getTranslateY()) / scale, rectSrc.getWidth() / scale, rectSrc.getHeight() / scale); break; @@ -297,13 +443,21 @@ catch (final NoninvertibleTransformException e) { throw new PAffineTransformException("Could not invert transform", e, this); } - rectFromArray(rectDst, pts); + rectFromArray(result, pts); break; } - return rectDst; + return result; } + /** + * Builds an array of coordinates from an source rectangle. + * + * @param aRectangle rectangle from which points coordinates will be + * extracted + * + * @return coordinate array + */ private static double[] rectToArray(final Rectangle2D aRectangle) { PTS1[0] = aRectangle.getX(); PTS1[1] = aRectangle.getY(); @@ -316,6 +470,12 @@ return PTS1; } + /** + * Creates a rectangle from an array of coordinates. + * + * @param aRectangle rectangle into which coordinates will be stored + * @param pts coordinate source + */ private static void rectFromArray(final Rectangle2D aRectangle, final double[] pts) { double minX = pts[0]; double minY = pts[1];