+//printf(" --> R x S = 0! (q - p) x r = %lf\n", qpxr);
+//printf(" -->(q - p) . r = %lf, r . r = %lf\n", v1.Dot(r), r.Dot(r));
+//printf(" -->(p - q) . s = %lf, s . s = %lf\n", v2.Dot(s), s.Dot(s));
+//printf(" -->(q - p) . s = %lf, (p - q) . r = %lf\n", v1.Dot(s), v2.Dot(r));
+
+ // Lines are parallel, so no intersection...
+ if (qpxr != 0)
+ return 0;
+
+#if 0
+//this works IFF the vectors are pointing in the same direction. everything else
+//is fucked!
+ // If (q - p) . r == r . r, t = 1, u = 0
+ if (v1.Dot(r) == r.Dot(r))
+ t = 1.0, u = 0;
+ // If (p - q) . s == s . s, t = 0, u = 1
+ else if (v2.Dot(s) == s.Dot(s))
+ t = 0, u = 1.0;
+ else
+ return 0;
+#else
+ // Check to see which endpoints are connected... Four possibilities:
+ if (l1->position == l2->position)
+ t = 0, u = 0;
+ else if (l1->position == l2->endpoint)
+ t = 0, u = 1.0;
+ else if (l1->endpoint == l2->position)
+ t = 1.0, u = 0;
+ else if (l1->endpoint == l2->endpoint)
+ t = 1.0, u = 1.0;
+ else
+ return 0;
+#endif
+ }
+ else
+ {
+ t = ((v1.x * s.y) - (s.x * v1.y)) / rxs;
+ u = ((v1.x * r.y) - (r.x * v1.y)) / rxs;
+ }