int GetConnectionConflicts(IList <LabelState> lbls)
        {
            int ncon = 0;

            int len = lbls.Count;

            for (int i = 0; i < len; i++)
            {
                if (lbls[i].IsVisible)
                {
                    for (int j = 0; j < len; j++)
                    {
                        if (i != j && lbls[j].IsVisible)
                        {
                            if (!LabelHelper.Intersect(lbls[i].Point, lbls[i].GetConnectingPoint(), lbls[j].Point, lbls[j].GetConnectingPoint()).IsEmpty())
                            {
                                lbls[i].Energy += wRectConflict;
                                lbls[j].Energy += wRectConflict;
                                ncon++;
                            }
                        }
                    }
                }
            }

            return(ncon * wRectConflict);
        }
Exemplo n.º 2
0
        // verify whether the current label position is good relatively to the other labels
        static bool IsGoodPosition(LabelState lbl, Rect border, LabelState[] labels, IList <Rect> rects, int index)
        {
            // check border
            if (!Contains(lbl, border))
            {
                return(false);
            }

            if (rects != null)
            {
                int cnt = rects.Count;
                for (int i = 0; i < cnt; i++)
                {
                    if (Intersect(lbl, rects[i]))
                    {
                        return(false);
                    }
                }
            }

            // check other anchor points
            int len = labels.Length;

            for (int i = 0; i < len; i++)
            {
                if (i != index)
                {
                    if (IntersectPoint(lbl, labels[i].Point))
                    {
                        return(false);
                    }
                }
            }

            for (int i = 0; i < index; i++)
            {
                // check already placed labels
                if (labels[i].IsVisible)
                {
                    // label rectangle
                    if (Intersect(lbl, labels[i]))
                    {
                        return(false);
                    }

                    // connecting lines
                    if (!LabelHelper.Intersect(lbl.Point, lbl.GetConnectingPoint(), labels[i].Point, labels[i].GetConnectingPoint()).IsEmpty())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }