| 139 | } |
| 140 | |
| 141 | function drawArrow(edge: SimEdge, camera: Camera) { |
| 142 | const { sourceNode: a, targetNode: b } = edge; |
| 143 | const dx = b.x - a.x; |
| 144 | const dy = b.y - a.y; |
| 145 | const dist = Math.sqrt(dx * dx + dy * dy) || 1; |
| 146 | const ux = dx / dist; |
| 147 | const uy = dy / dist; |
| 148 | const tipX = b.x - ux * (b.radius + 3); |
| 149 | const tipY = b.y - uy * (b.radius + 3); |
| 150 | const size = Math.min(7, 5.5 / Math.sqrt(camera.k) + 2); |
| 151 | ctx.beginPath(); |
| 152 | ctx.moveTo(tipX, tipY); |
| 153 | ctx.lineTo(tipX - ux * size - uy * size * 0.55, tipY - uy * size + ux * size * 0.55); |
| 154 | ctx.lineTo(tipX - ux * size + uy * size * 0.55, tipY - uy * size - ux * size * 0.55); |
| 155 | ctx.closePath(); |
| 156 | ctx.fill(); |
| 157 | } |
| 158 | |
| 159 | function render() { |
| 160 | const sim = simRef.current; |