List of usage examples for java.awt.geom Line2D.Float getP2
public abstract Point2D getP2();
From source file:tufts.vue.Actions.java
private static void projectNodes(final Iterable<LWComponent> toPush, final Collection toExclude, final LWComponent pushing, // we want to remove this argument and only rely on pushShape, but we need alot more refactoring for that final RectangularShape pushShape, final int distance) { if (DEBUG.Enabled) Log.debug("projectNodes: " + "\n\t pushing: " + pushing + "\n\tpushShape: " + pushShape + "\n\t toPush: " + Util.tags(toPush) + "\n\t distance: " + distance);//,new Throwable("HERE")); final Point2D.Float groundZero = new Point2D.Float((float) pushShape.getCenterX(), (float) pushShape.getCenterY()); final java.util.List<LWComponent> links = new java.util.ArrayList(); final java.util.List<LWComponent> nodes = new java.util.ArrayList(); for (LWComponent node : toPush) { if (toExclude.contains(node)) continue; if (node.isManagedLocation()) continue; if (node instanceof LWLink) { LWLink link = (LWLink) node; if (link.isConnected() || link.isCurved()) // both cases are buggy right now continue; }/*from w ww .ja v a2s.c o m*/ final Line2D.Float connector = new Line2D.Float(); final boolean overlap = VueUtil.computeConnectorAndCenterHit(pushing, node, connector); //VueUtil.computeConnector(pushing, node, connector); Point2D newCenter = null; float adjust = distance; //final boolean intersects = node.intersects(pushingRect); // problems w/slide icons final boolean intersects = pushShape.intersects(node.getMapBounds()); final boolean moveToEdge = overlap || intersects; if (false && DEBUG_PUSH) { // create a detached link from center of pushing to edge of each pushed to show vectors LWLink link = new LWLink(); link.setHeadPoint(connector.getP1()); link.setTailPoint(connector.getP2()); link.setArrowState(LWLink.ARROW_TAIL); link.setNotes("head: " + pushing + "\ntail: " + node); links.add(link); } if (moveToEdge) { if (distance < 0) // do nothing further if pulling on continue; // If overlapping, we want to move the node along a line away from the center // of the pushing node until it no longer overlaps. As part of this process, // we compute the point at the edge of the pushing node that the overlapping // node would be at if all we were going to do was move it to the edge. This // isn't strictly needed to produce the end result (we could start iterating // immediately, we don't need to start at the intersect), but it's useful for // debugging, and it may be a useful location to know for future tweaks to this // code. // first, find a point along the line from center of pushing to the center of node // that we know is outside of the pushing node final Point2D farOut = VueUtil.projectPoint(groundZero, connector, Short.MAX_VALUE); // now produce a ray that shoots from that point back to the center of the pushing node final Line2D.Float testRay = new Line2D.Float(farOut, groundZero); // now find the point at the edge of the pushing node that the ray intersects it final Point2D.Float intersect = VueUtil.computeIntersection(testRay, pushing); // now project the node along the connector line from the intersect // by small increments until the node no longer overlaps the // pushing node if (Util.isBadPoint(farOut) || Util.isBadPoint(intersect)) { Log.warn("bad projection points:" + "\n\tgroundZero: " + Util.fmt(groundZero) + "\n\t connector: " + Util.fmt(connector) + "\n\t farOut: " + Util.fmt(farOut) + "\n\t testRay: " + Util.fmt(testRay) + "\n\t intersect: " + Util.fmt(intersect) + "\n\t pusher: " + pushing + "\n\t pushee: " + node); } else { for (int i = 0; i < 1000; i++) { node.setCenterAt(VueUtil.projectPoint(intersect, connector, i * 2f)); // if (!node.intersects(pushingRect)) // problems w/slide icons // break; if (!pushShape.intersects(node.getMapBounds())) break; if (DEBUG_PUSH) Log.debug("PUSH ITER " + i + " on " + node); } } adjust /= 2; // we'll only push half the standard amount from here } newCenter = VueUtil.projectPoint(node.getMapCenterX(), node.getMapCenterY(), connector, adjust); if (Util.isBadPoint(newCenter)) { Log.error("bad newCenter: " + newCenter); newCenter = null; } if (DEBUG_PUSH) { float dist = (float) connector.getP1().distance(connector.getP2()); String notes = String.format("distance: %.1f\nadjust: %.1f\n-center: %s\n+center: %s\nconnect: %s", dist, adjust, Util.fmt(node.getMapCenter()), Util.fmt(newCenter), Util.fmt(connector)); if (intersects) notes += "\nINTERSECTS"; if (overlap) notes += "\nOVERLAP"; final LWComponent n; if (false) { n = node.duplicate(); node.setNotes(notes); nodes.add(n); n.setStrokeWidth(1); } else n = node; if (moveToEdge) { n.setTextColor(java.awt.Color.red); n.mFontStyle.set(java.awt.Font.BOLD); } n.setNotes(notes); if (newCenter != null) n.setCenterAt(newCenter); } else { if (newCenter != null) node.setCenterAt(newCenter); } } if (DEBUG_PUSH) { pushing.getMap().sendToBack(pushing); pushing.getMap().addChildren(nodes); pushing.getMap().addChildren(links); } }