private static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right, final double coef) { final double coef1 = coef; final double coef2 = 1 - coef; final double centerxA = src.getCtrlX1() * coef1 + src.getCtrlX2() * coef2; final double centeryA = src.getCtrlY1() * coef1 + src.getCtrlY2() * coef2; final double x1 = src.getX1(); final double y1 = src.getY1(); final double x2 = src.getX2(); final double y2 = src.getY2(); final double ctrlx1 = x1 * coef1 + src.getCtrlX1() * coef1; final double ctrly1 = y1 * coef1 + src.getCtrlY1() * coef1; final double ctrlx2 = x2 * coef1 + src.getCtrlX2() * coef1; final double ctrly2 = y2 * coef1 + src.getCtrlY2() * coef1; final double ctrlx12 = ctrlx1 * coef1 + centerxA * coef1; final double ctrly12 = ctrly1 * coef1 + centeryA * coef1; final double ctrlx21 = ctrlx2 * coef1 + centerxA * coef1; final double ctrly21 = ctrly2 * coef1 + centeryA * coef1; final double centerxB = ctrlx12 * coef1 + ctrlx21 * coef1; final double centeryB = ctrly12 * coef1 + ctrly21 * coef1; left.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx12, ctrly12, centerxB, centeryB); right.setCurve(centerxB, centeryB, ctrlx21, ctrly21, ctrlx2, ctrly2, x2, y2); }
public void curveTo(CubicCurve2D curve) { final double flatness = curve.getFlatness(); final double dist = curve.getP1().distance(curve.getP2()); if (flatness > 0.1 && dist > 20) { final CubicCurve2D left = new CubicCurve2D.Double(); final CubicCurve2D right = new CubicCurve2D.Double(); curve.subdivide(left, right); curveTo(left); curveTo(right); return; } lineTo(curve.getP2()); }
private CubicCurve2D createCubicCurve2D(Point startPoint, Point startPoint2, Point endPoint2, Point endPoint) { final CubicCurve2D arrowLinkCurve = new CubicCurve2D.Double(); if (startPoint != null && endPoint != null) { arrowLinkCurve.setCurve(startPoint, startPoint2, endPoint2, endPoint); } else if (startPoint != null) { arrowLinkCurve.setCurve(startPoint, startPoint2, startPoint, startPoint2); } else if (endPoint != null) { arrowLinkCurve.setCurve(endPoint, endPoint2, endPoint, endPoint2); } return arrowLinkCurve; }
PathIterator pi = cc.getPathIterator(null, 2); Point2D tmp[] = new Point2D[200]; int i = 0;
private void addSecEdges(TreeLayoutData treeLayout, LayoutOptions options) { for (Edge e: graph.getEdges()) { if (!GRAPH_TOOLS.hasEdgeSubtype(e, GRAPH_TOOLS.getSecEdgeSubType())) { continue; } Rectangle2D sourceRect = treeLayout.getRect(e.getSource()); Rectangle2D targetRect = treeLayout.getRect(e.getDestination()); CubicCurve2D curveData = secedgeCurve(treeLayout.getOrientation(), sourceRect, targetRect); T secedgeElem = backend.cubicCurve(curveData, styler.getStroke(e, input), styler.getEdgeColor(e, input)); secedgeElem.setZValue(-2); T arrowElem = backend.arrow(curveData.getP1(), curveData.getCtrlP1(), new Rectangle2D.Double(0, 0, 8, 8), styler.getEdgeColor(e, input)); arrowElem.setZValue(-1); arrowElem.setParentItem(secedgeElem); Point2D labelPos = evaluate(curveData, 0.8); T label = backend.makeLabel( labeler.getLabel(e, input), labelPos, styler.getFont(e), styler.getTextBrush(e), Alignment.CENTERED, styler.getShape(e, input)); label.setParentItem(secedgeElem); secedgeElem.setParentItem(treeLayout.getParentItem()); } }
@Override public boolean check (SlurInter slur) { if ((slur.getHead(LEFT) == null) && (slur.getExtension(LEFT) == null)) { // Check we are in first measure Point2D end = slur.getCurve().getP1(); SystemInfo system = slur.getSig().getSystem(); MeasureStack stack = system.getStackAt(end); if (stack == system.getFirstStack()) { // Check slur ends in first measure half (excluding header area) Staff staff = system.getClosestStaff(end); Measure measure = stack.getMeasureAt(staff); int middle = (staff.getHeaderStop() + measure.getAbscissa(LEFT, staff) + measure.getWidth()) / 2; if (end.getX() < middle) { return true; } } } return false; } };
@Override public boolean check (SlurInter slur) { if ((slur.getHead(RIGHT) == null) && (slur.getExtension(RIGHT) == null)) { // Check we are in last measure Point2D end = slur.getCurve().getP2(); SystemInfo system = slur.getSig().getSystem(); MeasureStack stack = system.getStackAt(end); if (stack == system.getLastStack()) { // Check slur ends in last measure half Staff staff = system.getClosestStaff(end); Measure measure = stack.getMeasureAt(staff); int middle = measure.getAbscissa(LEFT, staff) + (measure.getWidth() / 2); if (end.getX() > middle) { return true; } } } return false; } };
public CubicCurve2D getRepresentedCubic() { CubicCurve2D toRet=new CubicCurve2D.Double(); toRet.setCurve(this.p0, this.c0, this.c1, this.p1); return toRet; }
@Override public Point2D getEndVector (boolean reverse) { // We use the control points to retrieve tangent vector Point2D vector = reverse ? PointUtil.subtraction(curve.getP1(), curve.getCtrlP1()) : PointUtil.subtraction(curve.getP2(), curve.getCtrlP2()); // Normalize vector = PointUtil.times(vector, 1.0 / PointUtil.length(vector)); return vector; }
public void curveTo(CubicCurve2D curve) { final double flatness = curve.getFlatness(); final double dist = curve.getP1().distance(curve.getP2()); if (flatness > 0.1 && dist > 20) { final CubicCurve2D left = new CubicCurve2D.Double(); final CubicCurve2D right = new CubicCurve2D.Double(); curve.subdivide(left, right); curveTo(left); curveTo(right); return; } lineTo(curve.getP2()); }
PathIterator pi = cc.getPathIterator(null, 2); Point2D tmp[] = new Point2D[200]; int i = 0;
/** * Get the shape for this edge, returning either the shared instance or, in the case of * self-loop edges, the Loop shared instance. */ public Shape apply(Context<Network<N, E>, E> context) { Network graph = context.graph; E e = context.element; if (isLoop(graph, e)) { return loop.apply(context); } int index = getIndex(context, edgeIndexFunction); float controlY = control_offset_increment + control_offset_increment * index; CUBIC_CURVE.setCurve(0.0f, 0.0f, 0.33f, 2 * controlY, .66f, -controlY, 1.0f, 0.0f); return CUBIC_CURVE; } }