Thanks, Slavcho
double DistToRect(Point point, Rect rect)
{
var v = new[]
{
new Point(rect.Left, rect.Top),
new Point(rect.Right, rect.Top),
new Point(rect.Right, rect.Bottom),
new Point(rect.Left, rect.Bottom),
};
double minDist = double.MaxValue;
for (var i = 0; i < 4; i++)
{
var v1 = v[i];
var v2 = v[(i + 1) % 4];
var dist = Utilities.DistToLineSegment(point, v1, v2);
if (dist < minDist)
minDist = dist;
}
return minDist;
}
DiagramNode NearestRect(Point point)
{
DiagramNode nearest = null;
double minDist = double.MaxValue;
foreach (var node in diagram.Nodes)
{
var dist = DistToRect(point, node.Bounds);
if (dist < minDist)
{
minDist = dist;
nearest = node;
}
}
return nearest;
}
Currently I need to implement this function: the left mouse button can only click on the edge of the ShapeNode to select it. How to modify?
When multiple ShapeNodes intersect or overlap, the center handle of the selected ShapeNode will not be affected by another ShapeNode close to it and cannot be dragged. How can I solve it?
Best regards.