0

I've been trying to google connectors for shapes on Canvas but I wasn't able to find a solution which works for me. I don't know if its because of Avalonia could be so much different or just I am not able to apply it.

What I am trying to achieve is to connect shapes I generated onto Canvas with an arrow. The easy solution would normally be just drawing a line and applying some style. But I'm going to generate many nodes (I'm visualizing some graphs) and with connector I wouldn't need to always care if the line crosses another node, or dealing with it by some curvatures and stuff. (btw I'm writing it in c# only, not using XAML for this particular window) So I don't know how many nodes and how many edges I will generate when I run the program, it depends on the file I load. So my question would be: Is there any possible way how to connect those shapes|objects|Ellipses dynamically with connector which changes its shape in order not to cross through any node ? Or if you think that Canvas is not the right option for me I would be glad if you told me.

Thanks in advance!

Richard
  • 17
  • 1
  • 6
  • The answer is yes. Working out whether a line crosses a non rectangular shape is tricky stuff though. To work out all the 1 px sized cells a shape covers i render offscreen as a picture in our app. Hit testing is very expensive. You could maybe render offscreen a base shape and then apply an x and y offset. There's also a thing called a hull algorithm might be useful. And there's a bresenham line algorithm gives you all the cells a line passes through. I use cell because i'm taking 2d array and integer x,y whilst a point is double,double. – Andy Jul 17 '20 at 12:12
  • There's also a bresenham circle algorithm if you only have rectangles and circles – Andy Jul 17 '20 at 12:12

0 Answers0