using System; using System.Collections; namespace ytLive.Helpers; /// /// The arithmetic behind dragging a row in the layer list, kept out of the window's code-behind so it /// can be tested without a mouse. It used to live inline in the preview-mouse handlers, and the only /// test that covered it injected REAL cursor movement (SetCursorPos + mouse_event) — which /// took over whatever machine ran the tests and failed whenever the desktop was busy. 2026-11-05: the /// arithmetic moved here (pure, tested), the injected-input test was deleted. /// public static class DragReorderMath { /// True once the pointer has travelled far enough to mean "drag", not "click". WPF's /// own thresholds are the caller's (SystemParameters.MinimumHorizontal/VerticalDragDistance). public static bool ExceededThreshold(double dx, double dy, double horizontal, double vertical) => Math.Abs(dx) >= horizontal || Math.Abs(dy) >= vertical; /// Moves one item to the position currently occupied by another. Returns the index the /// item actually landed on (the caller keeps dragging from there), or -1 when the move is a no-op /// or the indices are out of range. /// Order matters: the item is removed first, so a downward move inserts at the target's old /// index and lands exactly under the pointer — this is the behaviour the mouse test used to pin. /// public static int TryMove(IList items, int from, int to) { if (items == null || from < 0 || to < 0 || from >= items.Count || to >= items.Count) return -1; if (from == to) return -1; var moved = items[from]!; items.RemoveAt(from); items.Insert(to, moved); return to; } }