Example #1
0
        public bool Overlaps(clsSketch aSketch, double aTol)
        {
            int      i;
            int      j;
            int      k;
            clsLine  l1;
            clsLine  l2;
            clsPoint p1;
            bool     isInside;

            //Disregard the case of when one sketch is contained in the other.
            isInside = true;
            for (i = 0; i <= NumPoints; i++)
            {
                if (aSketch.IsPointInside2(Point(i)) == false)
                {
                    isInside = false;
                }
            }
            if (isInside)
            {
                return(false);
            }
            isInside = true;
            for (i = 0; i <= aSketch.NumPoints; i++)
            {
                if (IsPointInside2(aSketch.Point(i)) == false)
                {
                    isInside = false;
                }
            }
            if (isInside)
            {
                return(false);
            }

            //Firstly see if a point of one sketch lies inside the other
            for (i = 0; i <= NumPoints; i++)
            {
                if (aSketch.IsPointInside2(Point(i)))
                {
                    return(true);
                }
            }
            for (i = 0; i <= aSketch.NumPoints; i++)
            {
                if (IsPointInside2(aSketch.Point(i)))
                {
                    return(true);
                }
            }

            //Next, do more than 3 points coincide?
            if (NumCommonPoints(aSketch, aTol) > 1)
            {
                return(true);
            }

            //Is there a non-trivial intersection?
            for (i = 0; i <= NumPoints; i++)
            {
                if (i < NumPoints)
                {
                    k = i + 1;
                }
                else
                {
                    k = 0;
                }
                l1 = new clsLine(Point(i), Point(k));

                //Is there a non-trivial intersection?
                for (j = 0; j <= aSketch.NumPoints; j++)
                {
                    if (j < aSketch.NumPoints)
                    {
                        k = j + 1;
                    }
                    else
                    {
                        k = 0;
                    }
                    l2 = new clsLine(aSketch.Point(j), aSketch.Point(k));
                    p1 = l1.Intersect(l2);
                    if (p1 != null)
                    {
                        if (l1.IsOnShortLine(p1, 0, true) & l2.IsOnShortLine(p1, 0, true))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }