List of usage examples for java.awt.geom AffineTransform inverseTransform
public void inverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws NoninvertibleTransformException
From source file:tufts.vue.LWComponent.java
/** * @param mapRect -- incoming rectangle to transform to be relative to 0,0 of this component * @param zeroRect -- result is placed here -- will be created if is null * @return zeroRect/* w ww. j ava 2 s . com*/ * * E.g., if the incoming mapRect was from map coords 100,100->120,120, and this component was at 100,100, * the resulting zeroRect in this case would be 0,0->20,20 (assuming no scale or rotation). * */ //protected Rectangle2D transformMapToZeroRect(Rectangle2D mapRect, Rectangle2D zeroRect) protected Rectangle2D transformMapToZeroRect(Rectangle2D mapRect) { // if (zeroRect == null) // zeroRect = (Rectangle2D) mapRect.clone(); // simpler than newInstace, tho we won't need the data-copy in the end Rectangle2D zeroRect = new Rectangle2D.Float(); // If want to handle rotation, we'll need to transform each corner of the // rectangle separately, generating Polygon2D (which sun never implemented!) or // a GeneralPath, in either case changing this method to return a Shape. Better // would be to keep a cached rotated map Shape in each object, tho that means // solving the general problem of making sure we're updated any time our // ultimate map location/size/scale/rotation, etc, changes, which of course // changes if any of those values change on any ancestor. If we did that, we'd // also be able to fully cache the _zeroTransform w/out having to recompute it // for each call just in case. (Which would mean getting rid of this method // entirely and using the map shape in intersects, etc) Of course, crap, we // couldn't do all this for links, could we? Tho maybe via special handing in an // override... tho that would only work for the transform, not the shape, as the // parent shape is useless to the link. FYI, currently, we only use this // for doing intersections of links and non-rectangular nodes // final double[] points = new double[8]; // final double width = zeroRect.getWidth(); // final double height = zeroRect.getHeight(); // // UL // points[0] = zeroRect.getX(); // points[1] = zeroRect.getY(); // // UR // points[2] = points[0] + width; // points[3] = points[1]; // // LL // points[4] = points[0]; // points[5] = points[1] + height; // // LR // points[6] = points[0] + width; // points[7] = points[1] + height; // Now that we know the below code can never handle rotation, we also might as // well toss out using the transform entirely and just use getMapScale / // getMapX/Y to mod a Rectangle2D.Float directly... Tho then our zoomed rollover // mod, which is in the transformDown code would stop working for rectangle // picking & clipping, tho we shouldn't need rect picking for zoomed rollovers, // (only point picking) and the zoomed rollover always draws no matter what (in // the MapViewer), so that may be moot, tho would need to fully test to be sure. // All of the this also applies to transformZeroToMapRect below. final AffineTransform tx = getZeroTransform(); final double[] points = new double[4]; points[0] = mapRect.getX(); points[1] = mapRect.getY(); points[2] = points[0] + mapRect.getWidth(); points[3] = points[1] + mapRect.getHeight(); try { tx.inverseTransform(points, 0, points, 0, 2); } catch (java.awt.geom.NoninvertibleTransformException e) { Util.printStackTrace(e); } zeroRect.setRect(points[0], points[1], points[2] - points[0], points[3] - points[1]); return zeroRect; }