예제 #1
0
        private int FindClosestEdge(MagnetEdge refEdge)
        {
            if (refEdge == null)
            {
                return(int.MinValue);
            }

            // get all forms edges list
            var edges = Forms
                        .Where(frm => (frm != m_OriginalForm) && frm.Visible)
                        .SelectMany(MagnetUtils.FormToEdges)
                        .Where(t => !m_MoveLocks.Any(q => (q.Item1 == t.Window) && (q.Item2 == MagnetUtils.OppsiteEdge(t.EdgeDir))))
                        .ToList();
            var corners = Forms
                          .Where(frm => (frm != m_OriginalForm) && frm.Visible)
                          .SelectMany(MagnetUtils.FormToCorners)
                          .Where(t => !m_ResizeLocks.Any(q => (q.Item1 == t.Window) && (q.Item2 == t.AttractsEdge)))
                          .ToList();

            var bestDist = int.MaxValue;

            foreach (var edge in edges)
            {
                var dist = edge.MeasureAttraction(refEdge);
                if (dist != int.MinValue)
                {
                    if (Math.Abs(dist) < bestDist)
                    {
                        bestDist = dist;
                    }
                }
            }

            foreach (var corner in corners)
            {
                var dist = corner.MeasureAttraction(refEdge);
                if (dist != int.MinValue)
                {
                    if (Math.Abs(dist) < bestDist)
                    {
                        bestDist = dist;
                    }
                }
            }

            return(bestDist);
        }
예제 #2
0
 public MagnetEdge GetOppsiteEdge()
 {
     return(new MagnetEdge {
         EdgeDir = MagnetUtils.OppsiteEdge(EdgeDir), End = End, Start = Start, Window = null
     });
 }