Author: Kore Nordmann
Date: 2007-02-01 13:19:17 +0100 (Thu, 01 Feb 2007)
New Revision: 4608

Log:
. Test unify for vector with zero length

Modified:
   trunk/Graph/src/math/vector.php
   trunk/Graph/tests/vector_test.php

Modified: trunk/Graph/src/math/vector.php
===================================================================
--- trunk/Graph/src/math/vector.php     2007-02-01 10:02:58 UTC (rev 4607)
+++ trunk/Graph/src/math/vector.php     2007-02-01 12:19:17 UTC (rev 4608)
@@ -54,7 +54,7 @@
         $length = $this->length();
         if ( $length == 0 )
         {
-            return false;
+            return $this;
         }
 
         $this->x /= $length;
@@ -115,10 +115,16 @@
             $vector = ezcGraphVector::fromCoordinate( $vector );
         }
         
-        return acos(
-            $this->mul( $vector ) /
-            ( $this->length() * $vector->length() )
-        );
+        $factor = $this->length() * $vector->length();
+
+        if ( $factor == 0 )
+        {
+            return false;
+        }
+        else
+        {
+            return acos( $this->mul( $vector ) / $factor );
+        }
     }
 
     /**

Modified: trunk/Graph/tests/vector_test.php
===================================================================
--- trunk/Graph/tests/vector_test.php   2007-02-01 10:02:58 UTC (rev 4607)
+++ trunk/Graph/tests/vector_test.php   2007-02-01 12:19:17 UTC (rev 4608)
@@ -84,6 +84,28 @@
         );
     }
 
+    public function testUnifyNullVector()
+    {
+        $vector = new ezcGraphVector( 0, 0 );
+        $result = $vector->unify();
+
+        $this->assertEquals(
+            0,
+            $vector->x
+        );
+
+        $this->assertEquals(
+            0,
+            $vector->y
+        );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
+    }
+
     public function testVectorMultiplyScalar()
     {
         $vector = new ezcGraphVector( 1, 2 );

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to