New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rounded polygon shapes (e.g. round-triangle
)
#2496
Conversation
I'd prefer that if this sort of shape is added that the code be made a bit more general to support N-sided rounded polygons. That way, those shapes could be added in future. We might want to keep the rectangle case separate, because it may be a bit simpler and cheaper that way. |
Understood, thanks! |
0d6e79d
to
a782c43
Compare
I generalized the code to draw a rounded polygon, but I'm reusing the line intersection and point inside tests ( I think we can use these for now, while they are not 100% accurate with the rounded shape, they are really close and i don't think they would degrade the experience of the user. WDYT? |
I agree in principle, but I'll try it out to confirm. |
I think it should be more accurate, mostly because of the visual result on the corners: Here are approaches for the hit test and the intersection: For the hit test, we check whether the given point is inside the cut-off polygon shape (just the points, without the round corners). We already have those points, and we already have a hit test function for polygons. So the only part that remains for hit tests, if the polygon check fails, is to check whether the point is inside any of the corner circles. That's just a distance squared comparison with the centre point of each circle -- if the square distance is less than the square radius, then the point is inside. For the intersection, we use a similar approach. First we consider the cut-off polygon. We don't need to consider the corner sides, so we use the existing finite line intersection function for each main side. We also get the intersections with each corner circle. There should be an existing function for intersecting with ellipses. You just take all the intersection points and choose the one with the smallest distance from the given point. Again use square distance comparisons to avoid having to do expensive square root calculations. |
Thanks for the detailed explanation, I'll work on this. |
I'm starting to check this, but i have some questions:
I see that there is also a padding, I'm assuming (from what i understood from the other code) that the padding is added to each side of each axis.
From what I can see this is already handled here:
Is that correct? |
Yes, but I think that's just historical. Offhand, I'm not sure why the padding was a separate parameter. Currently, the padding value is just passed as 0 to all those functions. The width and height include the padding instead. If you like or if it makes things simpler, you could remove the padding completely from those functions. |
Thanks, I was asking because i don't see Line 1061 in a782c43
|
Ok, I'll remove the padding. |
The structure for that function seems to be tailored to nodes. So you consider a finite line from a point outside the node to the centre point of the node. That usually results in only one or zero intersections. If you have a weird polygon (like a concave shape where the centre point is hollow), I suppose there could be conflicts. In order to resolve that issue and to make that function easier for you to reuse, it probably makes sense to put all the intersections in the |
Or you could keep track of the min square distance as you iterate. |
- Missing a specific function for line intersection and checkPoint Currently using the polygon functions which are not 100% exact (the round corners)
- round-diamond - round-pentagon - round-hexagon - round-heptagon - round-octagon - round-tag
a782c43
to
f1a1a6b
Compare
@maxkfranz I finished the intersection and hit test for the rounded polygon. I had to update the points to pre-compute some points to make the rendering and checks easier at the expense of more points (I add one point for every initial point) I also added some more round shapes, I hope that it's OK. Here are some GIF's of the demo. |
round-triangle
)
Merged in for 3.11.0. Thanks! |
Link to the relevant demo: http://js.cytoscape.org/demos/node-types/ |
Feature request: Add the following rounded node shapes: round-triangle, round-diamond, round-pentagon, round-hexagon, round-heptagon, round-octagon, round-tag
OP follows:
--
I would like to add a new shape, would something like this be accepted into the code base (once finished)?