(graph: Graph, scale: number)
| 96 | |
| 97 | // Adjust edge to avoid |
| 98 | export default function adjustEdge(graph: Graph, scale: number) { |
| 99 | const tmp0: number[] = []; |
| 100 | const quadraticSubdivide = curveTool.quadraticSubdivide; |
| 101 | const pts: number[][] = [[], [], []]; |
| 102 | const pts2: number[][] = [[], []]; |
| 103 | const v: number[] = []; |
| 104 | scale /= 2; |
| 105 | |
| 106 | graph.eachEdge(function (edge, idx) { |
| 107 | const linePoints = edge.getLayout(); |
| 108 | const fromSymbol = edge.getVisual('fromSymbol'); |
| 109 | const toSymbol = edge.getVisual('toSymbol'); |
| 110 | |
| 111 | if (!linePoints.__original) { |
| 112 | linePoints.__original = [ |
| 113 | vec2.clone(linePoints[0]), |
| 114 | vec2.clone(linePoints[1]) |
| 115 | ]; |
| 116 | if (linePoints[2]) { |
| 117 | linePoints.__original.push(vec2.clone(linePoints[2])); |
| 118 | } |
| 119 | } |
| 120 | const originalPoints = linePoints.__original; |
| 121 | // Quadratic curve |
| 122 | if (linePoints[2] != null) { |
| 123 | vec2.copy(pts[0], originalPoints[0]); |
| 124 | vec2.copy(pts[1], originalPoints[2]); |
| 125 | vec2.copy(pts[2], originalPoints[1]); |
| 126 | if (fromSymbol && fromSymbol !== 'none') { |
| 127 | const symbolSize = getSymbolSize(edge.node1); |
| 128 | |
| 129 | const t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale); |
| 130 | // Subdivide and get the second |
| 131 | quadraticSubdivide(pts[0][0], pts[1][0], pts[2][0], t, tmp0); |
| 132 | pts[0][0] = tmp0[3]; |
| 133 | pts[1][0] = tmp0[4]; |
| 134 | quadraticSubdivide(pts[0][1], pts[1][1], pts[2][1], t, tmp0); |
| 135 | pts[0][1] = tmp0[3]; |
| 136 | pts[1][1] = tmp0[4]; |
| 137 | } |
| 138 | if (toSymbol && toSymbol !== 'none') { |
| 139 | const symbolSize = getSymbolSize(edge.node2); |
| 140 | |
| 141 | const t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale); |
| 142 | // Subdivide and get the first |
| 143 | quadraticSubdivide(pts[0][0], pts[1][0], pts[2][0], t, tmp0); |
| 144 | pts[1][0] = tmp0[1]; |
| 145 | pts[2][0] = tmp0[2]; |
| 146 | quadraticSubdivide(pts[0][1], pts[1][1], pts[2][1], t, tmp0); |
| 147 | pts[1][1] = tmp0[1]; |
| 148 | pts[2][1] = tmp0[2]; |
| 149 | } |
| 150 | // Copy back to layout |
| 151 | vec2.copy(linePoints[0], pts[0]); |
| 152 | vec2.copy(linePoints[1], pts[2]); |
| 153 | vec2.copy(linePoints[2], pts[1]); |
| 154 | } |
| 155 | // Line |
no test coverage detected
searching dependent graphs…