public QuadCurve2D evaluate(QuadCurve2D v0, QuadCurve2D v1, float fraction) { double x1 = v0.getX1() + ((v1.getX1() - v0.getX1()) * fraction); double y1 = v0.getY1() + ((v1.getY1() - v0.getY1()) * fraction); double x2 = v0.getX2() + ((v1.getX2() - v0.getX2()) * fraction); double y2 = v0.getY2() + ((v1.getY2() - v0.getY2()) * fraction); double ctrlx = v0.getCtrlX() + ((v1.getCtrlX() - v0.getCtrlX()) * fraction); double ctrly = v0.getCtrlY() + ((v1.getCtrlY() - v0.getCtrlY()) * fraction); QuadCurve2D value = (QuadCurve2D) v0.clone(); value.setCurve(x1, y1, ctrlx, ctrly, x2, y2); return value; }
/** Initializes object to draw given edge. */ private void updateCurve(VisualEdge e) { Vec2 fromPos = e.getFrom().getVisibleAncestor().getPos(); Vec2 toPos = e.getTo().getVisibleAncestor().getPos(); Vec2 curveCenter = e.getPos(); // second control point double px = 2 * (curveCenter.x - 0.25 * fromPos.x - 0.25 * toPos.x); double py = 2 * (curveCenter.y - 0.25 * fromPos.y - 0.25 * toPos.y); if (curve == null) curve = new QuadCurve2D.Double(); curve.setCurve(fromPos.x, fromPos.y, px, py, toPos.x, toPos.y); }
/** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */ @Override protected Shape getRawShape(VisualItem item) { EdgeItem e = (EdgeItem) item; VisualItem source = e.getSourceItem(); VisualItem target = e.getTargetItem(); int type = m_edgeType; int edgeIndex = -1; getAlignedPoint(m_tmpPoints[0], source.getBounds(), m_xAlign1, m_yAlign1); getAlignedPoint(m_tmpPoints[1], target.getBounds(), m_xAlign2, m_yAlign2); m_curWidth = (float) (m_width * getLineWidth(item)); boolean curveCtrlPtsReady = false; Polygon arrowHead; // create the arrow head, if needed if (isDirected(e) && m_edgeArrow != Constants.EDGE_ARROW_NONE && (arrowHead = getArrowHead(e)) != null) { // get starting and ending edge endpoints boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD); Point2D start = null, end = null; start = m_tmpPoints[forward ? 0 : 1]; end = m_tmpPoints[forward ? 1 : 0]; // compute the intersection with the source/target bounding box VisualItem src = getSourceItem(e, forward); VisualItem dest = getTargetItem(e, forward); if (edgeBounded && !e.isAggregating()) { adjustEndingPoint(start, end, src, dest); } else if (GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints) > 0) { end.setLocation(m_isctPoints[0]); } // create the arrow head shape AffineTransform arrowTrans; if (multipleEdge) { edgeIndex = adjustEndingPointByMultipleEdge(e, start, end); if (lineForSingleEdge && edgeIndex < 0) { type = Constants.EDGE_TYPE_LINE; arrowTrans = getArrowTrans(start, end, m_curWidth); } else { getCurveControlPoints( edgeIndex, m_ctrlPoints, start.getX(), start.getY(), end.getX(), end.getY()); curveCtrlPtsReady = true; arrowTrans = getArrowTrans(m_ctrlPoints[0], end, m_curWidth); } } else { arrowTrans = getArrowTrans(start, end, m_curWidth); } m_curArrow = m_tmpArrow.set(arrowHead, arrowTrans); // update the endpoints for the edge shape // need to bias this by arrow head size adjustLineEndByArrowHead(e, end); arrowTrans.transform(end, end); } else { m_curArrow = null; if (edgeBounded && !e.isAggregating()) { adjustEndingPoint(m_tmpPoints[0], m_tmpPoints[1], source, target); } if (multipleEdge) { edgeIndex = adjustEndingPointByMultipleEdge(e, m_tmpPoints[0], m_tmpPoints[1]); if (lineForSingleEdge && edgeIndex < 0) { type = Constants.EDGE_TYPE_LINE; } else { getCurveControlPoints( edgeIndex, m_ctrlPoints, m_tmpPoints[0].getX(), m_tmpPoints[0].getY(), m_tmpPoints[1].getX(), m_tmpPoints[1].getY()); curveCtrlPtsReady = true; } } } // create the edge shape Shape shape = null; double sx = m_tmpPoints[0].getX(); double sy = m_tmpPoints[0].getY(); double ex = m_tmpPoints[1].getX(); double ey = m_tmpPoints[1].getY(); switch (type) { case Constants.EDGE_TYPE_LINE: m_line.setLine(sx, sy, ex, ey); shape = m_line; break; case Constants.EDGE_TYPE_CURVE: if (!curveCtrlPtsReady) { getCurveControlPoints(e, m_ctrlPoints, sx, sy, ex, ey); } m_quad.setCurve(sx, sy, m_ctrlPoints[0].getX(), m_ctrlPoints[0].getY(), ex, ey); shape = m_quad; break; default: throw new IllegalStateException("Unknown edge type"); } // return the edge shape return shape; }