Author: Kore Nordmann
Date: 2007-01-25 16:44:09 +0100 (Thu, 25 Jan 2007)
New Revision: 4578

Log:
- Always return $this, to enable "fluent interfaces"

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-01-25 15:32:47 UTC (rev 4577)
+++ trunk/Graph/src/math/vector.php     2007-01-25 15:44:09 UTC (rev 4578)
@@ -26,6 +26,8 @@
         $tmp = $this->x;
         $this->x = -$this->y;
         $this->y = $tmp;
+
+        return $this;
     }
 
     /**
@@ -38,6 +40,8 @@
         $tmp = $this->x;
         $this->x = $this->y;
         $this->y = -$tmp;
+
+        return $this;
     }
     
     /**
@@ -55,6 +59,8 @@
 
         $this->x /= $length;
         $this->y /= $length;
+
+        return $this;
     }
 
     /**
@@ -80,6 +86,8 @@
     {
         $this->x *= $value;
         $this->y *= $value;
+
+        return $this;
     }
 
     /**
@@ -103,6 +111,8 @@
     {
         $this->x += $vector->x;
         $this->y += $vector->y;
+
+        return $this;
     }
 
     /**
@@ -115,6 +125,8 @@
     {
         $this->x -= $vector->x;
         $this->y -= $vector->y;
+
+        return $this;
     }
 
     /**

Modified: trunk/Graph/tests/vector_test.php
===================================================================
--- trunk/Graph/tests/vector_test.php   2007-01-25 15:32:47 UTC (rev 4577)
+++ trunk/Graph/tests/vector_test.php   2007-01-25 15:44:09 UTC (rev 4578)
@@ -65,7 +65,7 @@
     public function testUnifyVector()
     {
         $vector = new ezcGraphVector( 2, 0 );
-        $vector->unify();
+        $result = $vector->unify();
 
         $this->assertEquals(
             1,
@@ -76,12 +76,18 @@
             0,
             $vector->y
         );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
     }
 
     public function testVectorMultiplyScalar()
     {
         $vector = new ezcGraphVector( 1, 2 );
-        $vector->scalar( 2 );
+        $result = $vector->scalar( 2 );
 
         $this->assertEquals(
             2,
@@ -92,6 +98,12 @@
             4,
             $vector->y
         );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
     }
 
     public function testVectorMultiplyCoordinate()
@@ -119,7 +131,7 @@
     public function testVectorAddCoordinate()
     {
         $vector = new ezcGraphVector( 1, 2 );
-        $vector->add( new ezcGraphCoordinate( 3, 2 ) );
+        $result = $vector->add( new ezcGraphCoordinate( 3, 2 ) );
 
         $this->assertEquals(
             $vector,
@@ -130,34 +142,52 @@
     public function testVectorAddVector()
     {
         $vector = new ezcGraphVector( 1, 2 );
-        $vector->add( new ezcGraphVector( 3, 2 ) );
+        $result = $vector->add( new ezcGraphVector( 3, 2 ) );
 
         $this->assertEquals(
             $vector,
             new ezcGraphVector( 4, 4 )
         );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
     }
 
     public function testVectorSubCoordinate()
     {
         $vector = new ezcGraphVector( 1, 2 );
-        $vector->sub( new ezcGraphCoordinate( 3, 2 ) );
+        $result = $vector->sub( new ezcGraphCoordinate( 3, 2 ) );
 
         $this->assertEquals(
             $vector,
             new ezcGraphVector( -2, 0 )
         );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
     }
 
     public function testVectorSubVector()
     {
         $vector = new ezcGraphVector( 1, 2 );
-        $vector->sub( new ezcGraphVector( 3, 2 ) );
+        $result = $vector->sub( new ezcGraphVector( 3, 2 ) );
 
         $this->assertEquals(
             $vector,
             new ezcGraphVector( -2, 0 )
         );
+
+        $this->assertEquals(
+            $result,
+            $vector,
+            'Result should be the vector itself'
+        );
     }
 }
 

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

Reply via email to