Merge latest changes from branch miscellaneous-fixes. patched
authorachurch
Fri, 07 Jan 2011 02:36:54 +0900
branchpatched
changeset 640 57445129408f
parent 637 628f25c13eca (current diff)
parent 639 3e9ea3275214 (diff)
child 641 b9c86e22b347
child 645 532436711b0e
Merge latest changes from branch miscellaneous-fixes.
BBGE/Base.cpp
--- a/BBGE/Base.cpp	Thu Jan 06 01:43:28 2011 +0900
+++ b/BBGE/Base.cpp	Fri Jan 07 02:36:54 2011 +0900
@@ -781,12 +781,17 @@
 {
     Vector dir = lineEnd - lineStart;
     Vector diff = point - lineStart;
-    float t = diff.dot2D(dir) / dir.dot2D(dir);
-    if (t < 0.0f)
-        t = 0.0f;
-    if (t > 1.0f)
-        t = 1.0f;
-    Vector closest = lineStart + t * dir;
+    Vector closest;
+    if (!dir.isZero()) {
+	float t = diff.dot2D(dir) / dir.dot2D(dir);
+	if (t < 0.0f)
+	    t = 0.0f;
+	if (t > 1.0f)
+	    t = 1.0f;
+	closest = lineStart + t * dir;
+    } else {
+	closest = lineStart;
+    }
     Vector d = point - closest;
     float distsqr = d.dot2D(d);
 	if (closestP)