Я работаю над приложением WPF, где мне нужно реализовать функциональность, чтобы перетаскивать элементы пути на холст. После того, как элемент сброшен, он должен пробиться до ближайшего пути Нурбса (или любых других предположительных путей в системе). Тем не менее, я сталкиваюсь с проблемами с точным перехватом перетасного пути к ближайшему пути в коллекции. Я могу перетаскивать элементы пути на холст. Путь Nurbs или любой путь, когда он достаточно близко. Если перетащенный путь находится на определенном расстоянии от любого пути от списка путей, он должен прийти к нему. Вот код, который я использую для функциональности схватки: < /p>
Код: Выделить всё
private void SnapToClosestNURBSSpline(Path movingPath, List
wellPaths, double threshold)
{
foreach (PathGeometry wellPath in wellPaths)
{
if (IsNearPath(movingPath: movingPath.Data, wellPath: wellPath, threshold: threshold))
{
// Snapping logic to match the position of the moving path to the closest well path
movingPath.Data = wellPath.Clone();
return;
}
}
}
private bool IsNearPath(Geometry movingPath, Geometry wellPath, double threshold)
{
// Using bounds to compare proximity (this might be an issue for complex NURBS paths)
Rect movingBounds = movingPath.Bounds;
Rect wellBounds = wellPath.Bounds;
return (Math.Abs(movingBounds.Left - wellBounds.Left)
Подробнее здесь: [url]https://stackoverflow.com/questions/79404944/how-to-snap-a-path-element-to-the-nearest-nurbs-path-in-a-wpf-canvas[/url]