/** * Gets the point on a rectangle that corresponds to the given angle. */ public static Point angleToPoint(Rectangle r, double angle) { double si = sin(angle); double co = cos(angle); double e = 0.0001; int x = 0, y = 0; if (abs(si) > e) { x = (int) ((1.0 + co / abs(si)) / 2.0 * r.width); x = range(0, r.width, x); } else if (co >= 0.0) { x = r.width; } if (abs(co) > e) { y = (int) ((1.0 + si / abs(co)) / 2.0 * r.height); y = range(0, r.height, y); } else if (si >= 0.0) { y = r.height; } return new Point(r.x + x, r.y + y); }
/** * Gets the point on a rectangle that corresponds to the given angle. */ public static Point2D.Double angleToPoint(Rectangle2D.Double r, double angle) { double si = sin(angle); double co = cos(angle); double e = 0.0001; double x = 0, y = 0; if (abs(si) > e) { x = (1.0 + co / abs(si)) / 2.0 * r.width; x = range(0, r.width, x); } else if (co >= 0.0) { x = r.width; } if (abs(co) > e) { y = (1.0 + si / abs(co)) / 2.0 * r.height; y = range(0, r.height, y); } else if (si >= 0.0) { y = r.height; } return new Point2D.Double(r.x + x, r.y + y); }
@Override public void trackStep(Point anchor, Point lead, int modifiersEx) { int dx = lead.x - anchor.x; int dy = lead.y - anchor.y; RoundRectangleFigure owner = (RoundRectangleFigure) getOwner(); Rectangle r = view.drawingToView(owner.getBounds()); Point viewArc = new Point( Geom.range(0, r.width, 2 * (originalArc.x / 2 + dx)), Geom.range(0, r.height, 2 * (originalArc.y / 2 + dy))); Point2D.Double arc = view.viewToDrawing(viewArc); owner.willChange(); owner.setArc(arc.x, arc.y); owner.changed(); }
@Override public void trackEnd(Point anchor, Point lead, int modifiersEx) { int dx = lead.x - anchor.x; int dy = lead.y - anchor.y; RoundRectangleFigure owner = (RoundRectangleFigure) getOwner(); Rectangle r = view.drawingToView(owner.getBounds()); Point viewArc = new Point( Geom.range(0, r.width, 2 * (originalArc.x / 2 + dx)), Geom.range(0, r.height, 2 * (originalArc.y / 2 + dy))); Point2D.Double oldArc = view.viewToDrawing(originalArc); Point2D.Double newArc = view.viewToDrawing(viewArc); ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); CompositeFigureEdit edit = new CompositeFigureEdit(owner, labels.getString("attribute.roundRectRadius")); fireUndoableEditHappened(edit); fireUndoableEditHappened(new PropertyChangeEdit(owner, RoundRectangleFigure.ARC_WIDTH_PROPERTY, oldArc.x, newArc.x)); fireUndoableEditHappened(new PropertyChangeEdit(owner, RoundRectangleFigure.ARC_HEIGHT_PROPERTY, oldArc.y, newArc.y)); fireUndoableEditHappened(edit); }