Ejemplo n.º 1
0
        public bool Intersects(Vector2 p0, Vector2 p1, out Vector2 intersection)
        {
            intersection = Vector2.zero;

//			p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0);
//			p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1);
            p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0);
            p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1);             // Double, for whatever reason

            float cc = connector.GetCompCount();

            if (cc == 16 || cc == 0)              // Matrices
            {
                cc = 1;
            }

            if (cc == 1)
            {
                if (SF_Tools.LineIntersection(p0, p1, this[0, 0], out intersection))
                {
                    return(true);
                }
            }
            else if (cc == 2)
            {
                Vector2 intA = Vector2.zero;
                Vector2 intB = Vector2.zero;

                bool hitA = SF_Tools.LineIntersection(p0, p1, this[0, 0], out intA);
                bool hitB = SF_Tools.LineIntersection(p0, p1, this[0, 1], out intB);

                if (hitA && hitB)
                {
                    intersection = (intA + intB) / 2;
                    return(true);
                }
            }
            else if (cc == 3)
            {
                if (SF_Tools.LineIntersection(p0, p1, this[0, 1], out intersection))
                {
                    return(true);
                }
            }
            else if (cc == 4)
            {
                Vector2 intA = Vector2.zero;
                Vector2 intB = Vector2.zero;

                bool hitA = SF_Tools.LineIntersection(p0, p1, this[0, 1], out intA);
                bool hitB = SF_Tools.LineIntersection(p0, p1, this[0, 2], out intB);

                if (hitA && hitB)
                {
                    intersection = (intA + intB) / 2;
                    return(true);
                }
            }

            return(false);
        }