コード例 #1
0
ファイル: Polygon.php プロジェクト: babkinandreyhm/polygon
 function add(Vertex $nv)
 {
     if ($this->cnt == 0) {
         $this->first =& $nv;
         // Save a reference to it in the polygon
         $this->first->setNext($nv);
         // Set its pointer to point to itself
         $this->first->setPrev($nv);
         // because it is the only vertex in the list
         $ps =& $this->first->Nseg();
         // Get ref to the Next segment object
         $this->first->setPseg($ps);
         // and save it as Prev segment as well
     } else {
         // $p <-> $nv <-> $n
         //    $ps     $ns
         $n =& $this->first;
         // Get a ref to the first vertex in the list
         $p =& $n->Prev();
         // Get ref to previous vertex
         $n->setPrev($nv);
         // Add at end of list (just before first)
         $nv->setNext($n);
         // link the new vertex to it
         $nv->setPrev($p);
         // link to the pervious EOL vertex
         $p->setNext($nv);
         // And finally link the previous EOL vertex
         // Segments
         $ns =& $nv->Nseg();
         // Get ref to the new next segment
         $ps =& $p->Nseg();
         // Get ref to the previous segment
         $n->setPseg($ns);
         // Set new previous seg for $this->first
         $nv->setPseg($ps);
         // Set previous seg of the new vertex
     }
     $this->cnt++;
     // Increment the count of vertices
 }
コード例 #2
0
ファイル: Polygon.php プロジェクト: edewaele/yapafo
 function &del(Vertex &$v)
 {
     // $p <-> $v <-> $n				   Will delete $v and $ns
     //    $ps    $ns
     $p = $v->Prev();
     // Get ref to previous vertex
     $n = $v->Next();
     // Get ref to next vertex
     $p->setNext($n);
     // Link previous forward to next
     $n->setPrev($p);
     // Link next back to previous
     // Segments
     $ps = $p->Nseg();
     // Get ref to previous segment
     $ns = $v->Nseg();
     // Get ref to next segment
     $n->setPseg($ps);
     // Link next back to previous segment
     $ns = NULL;
     $v = NULL;
     // Free the memory
     $this->cnt--;
     // One less vertex
     return $n;
     // Return a ref to the next valid vertex
 }