Exemplo n.º 1
0
 public function renderSegment(Vertex $origin, Vertex $end)
 {
     $ox = round($origin->get_x());
     $oy = round($origin->get_y());
     $ex = round($end->get_x());
     $ey = round($end->get_y());
     $size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
     $dx = round($ox - $ex >= 0 ? $ox - $ex : $ex - $ox);
     $dy = round($oy - $ey >= 0 ? $oy - $ey : $ey - $oy);
     $sx = round($ox < $ex ? 1 : -1);
     $sy = round($oy < $ey ? 1 : -1);
     $errx = round($dx > $dy ? $dx : -$dy) / 2;
     while ($ox != $ex || $oy != $ey) {
         $current_size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
         $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $origin->get_color()->sub($end->get_color())->mult(1 - $current_size / $size)]));
         $erry = $errx;
         if ($erry > -$dx) {
             $errx -= $dy;
             $ox += $sx;
         }
         if ($erry < $dy) {
             $errx += $dx;
             $oy += $sy;
         }
     }
     $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $end->get_color()]));
     return;
 }
Exemplo n.º 2
0
 function __construct($kwargs)
 {
     if (array_key_exists('dest', $kwargs)) {
         $dest = $kwargs['dest'];
         $this->_x = $dest->getX();
         $this->_y = $dest->getY();
         $this->_z = $dest->getZ();
         $this->_w = $dest->getW();
     } else {
         echo "Vector: missing dest key in constructor\n";
         exit(-1);
     }
     if (array_key_exists('orig', $kwargs)) {
         $orig = $kwargs['orig'];
         $this->_x -= $orig->getX();
         $this->_y -= $orig->getY();
         $this->_z -= $orig->getZ();
         $this->_w -= $orig->getW();
     } else {
         $orig = new Vertex(array('x' => 0, 'y' => 0, 'z' => 0, 'w' => 1));
         $this->_w -= $orig->getW();
     }
     if (self::$verbose === TRUE) {
         printf("Vector( x:%.02f, y:%.02f, z:%.02f, w:%.02f ) constructed\n", $this->_x, $this->_y, $this->_z, $this->_w);
     }
 }
Exemplo n.º 3
0
 /**
  * Adds vertex to a graph. If vertex with the same id already exists,
  * throws and exception
  * @param Vertex $vertex
  * @throws \Exception
  */
 public function addVertex(Vertex $vertex)
 {
     $id = $vertex->getId();
     if (array_key_exists($id, $this->vertices)) {
         throw new \Exception('Vertex with ID="' . $id . '" already exists');
     }
     $this->vertices[$id] = $vertex;
 }
 protected function buildBaseWhoAlsoQuery($type, $objRequest)
 {
     $vertex = new Vertex();
     $query = $vertex->findBy($objRequest->product->label, $objRequest->product->properties);
     $queryCategory = ').';
     if (isset($objRequest->category) && strlen($objRequest->category)) {
         $queryCategory = "filter(out('belong').has('id',ID_CATEGORY)).";
         $this->connection->message->bindValue('ID_CATEGORY', "{$objRequest->category}");
     }
     $limit = isset($objRequest->limit) ? (int) $objRequest->limit : self::DEFAULT_LIMIT;
     $query .= ".as('p').in('view').\n            out('view').where(neq('p')).\n            {$queryCategory}\n            groupCount().by('id').order(local).by(valueDecr).limit(local,{$limit});";
     return $query;
 }
Exemplo n.º 5
0
 function isPolySelfIntersect()
 {
     $intersect = FALSE;
     $s = $this->getFirst();
     // Get the first vertex in this polygon
     $c = $s->Next();
     // Get the next vertex
     do {
         do {
             if ($this->ints($s, $s->Next(), $c, $c->Next(), $n, $x, $y, $aS, $aC)) {
                 // If the segments intersect
                 for ($i = 0; $i <= $n; $i++) {
                     // then for each intersection point
                     if (isset($aS[$i]) && $aS[$i] != 0 || isset($aC[$i]) && $aC[$i] != 0) {
                         // check that it NOT at the end of the segment
                         $intersect = TRUE;
                     }
                 }
             }
             // Because sequential segments always intersect at their ends
             $c = $c->Next();
         } while ($c->id() != $this->first->id());
         $s = $s->Next();
     } while ($s->id() != $this->first->id());
     return $intersect;
 }
 public function findOrCreate($edge, $vIn, $vOut)
 {
     if (!$edge || !$vIn || !$vOut) {
         throw new \Exception('Invalid arguments');
     }
     $vertex = new Vertex();
     // findOrCreate origin vertex
     $vertex->setSufix('in');
     $query = $vertex->findOrCreate($vIn->label, $vIn->properties, false);
     $vertex->prepareQuery($vIn->label, $vIn->properties);
     // findOrCreate target vertex
     $vertex->setSufix('out');
     $query .= $vertex->findOrCreate($vOut->label, $vOut->properties, false);
     $vertex->prepareQuery($vOut->label, $vOut->properties);
     //create edge betweeen vertices
     $edgeProperties = ParserProperties::parsePropertiesToInsert(false, $edge->properties);
     $query .= "vin.addEdge('{$edge->label}', vout";
     if (strlen($edgeProperties)) {
         $query .= ",{$edgeProperties});";
         $this->prepareQuery(false, $edge->properties);
     } else {
         $query .= ');';
     }
     //die($query);
     return $this->executeQuery($query);
 }
Exemplo n.º 7
0
 public function transformVertex(Vertex $vtx)
 {
     $tmp_array = array();
     $tmp_array[0][0] = $vtx->getX();
     $tmp_array[1][0] = $vtx->getY();
     $tmp_array[2][0] = $vtx->getZ();
     $tmp_array[3][0] = $vtx->getW();
     return new Vertex(array('x' => $this->_mult_line_row($tmp_array, 0, 0), 'y' => $this->_mult_line_row($tmp_array, 1, 0), 'z' => $this->_mult_line_row($tmp_array, 2, 0), 'color' => $vtx->getColor()));
 }
 /**
  * Tests if the updateVertex method accepts an instance of Graph as first argument and extracts the graph name out of it.
  */
 public function testUpdateVertexWithGraphInstance()
 {
     $this->createGraph();
     $new = Vertex::createFromArray(array('_key' => 'vertex1', 'someKey' => 'foobar'));
     $this->assertTrue($this->graphHandler->updateVertex($this->graph, 'vertex1', $new));
 }
Exemplo n.º 9
0
 /**
  * Create an array of Vertex from the input array
  *
  * @param array $data - array of incoming "vertex" arrays
  *
  * @return void
  */
 private function addVerticesFromArray(array $data)
 {
     $this->_result[] = Vertex::createFromArray($data, $this->_options);
 }
Exemplo n.º 10
0
 /**
  * Inserts the given vertex into this graph.
  *
  * @param object Vertex $v The vertex to insert.
  */
 protected function insertVertex(Vertex $v)
 {
     if ($this->numberOfVertices == $this->vertex->getLength()) {
         throw new ContainerFullException();
     }
     if ($v->getNumber() != $this->numberOfVertices) {
         throw new ArgumentError();
     }
     $this->vertex[$this->numberOfVertices] = $v;
     ++$this->numberOfVertices;
 }
Exemplo n.º 11
0
 private function _setVectorFromVertex(Vertex $orig, Vertex $dest)
 {
     $this->_x = $dest->getX() / $dest->getW() - $orig->getX() / $orig->getW();
     $this->_y = $dest->getY() / $dest->getW() - $orig->getY() / $orig->getW();
     $this->_z = $dest->getZ() / $dest->getW() - $orig->getZ() / $orig->getW();
 }
 /**
  * Intermediate function to call the createFromArray function from the right context
  *
  * @param $data
  * @param $options
  *
  * @return Document
  */
 public function createFromArrayWithContext($data, $options)
 {
     return Vertex::createFromArray($data, $options);
 }
Exemplo n.º 13
0
require_once 'Color.class.php';
require_once 'Vertex.class.php';
Color::$verbose = False;
print Vertex::doc();
Vertex::$verbose = True;
$vtxO = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 0.0));
print $vtxO . PHP_EOL;
$red = new Color(array('red' => 255, 'green' => 0, 'blue' => 0));
$green = new Color(array('red' => 0, 'green' => 255, 'blue' => 0));
$blue = new Color(array('red' => 0, 'green' => 0, 'blue' => 255));
$unitX = new Vertex(array('x' => 1.0, 'y' => 0.0, 'z' => 0.0, 'color' => $green));
$unitY = new Vertex(array('x' => 0.0, 'y' => 1.0, 'z' => 0.0, 'color' => $red));
$unitZ = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 1.0, 'color' => $blue));
print $unitX . PHP_EOL;
print $unitY . PHP_EOL;
print $unitZ . PHP_EOL;
Vertex::$verbose = False;
$sqrA = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 0.0));
$sqrB = new Vertex(array('x' => 4.2, 'y' => 0.0, 'z' => 0.0));
$sqrC = new Vertex(array('x' => 4.2, 'y' => 4.2, 'z' => 0.0));
$sqrD = new Vertex(array('x' => 0.0, 'y' => 4.2, 'z' => 0.0));
print $sqrA . PHP_EOL;
print $sqrB . PHP_EOL;
print $sqrC . PHP_EOL;
print $sqrD . PHP_EOL;
$A = new Vertex(array('x' => 3.0, 'y' => 3.0, 'z' => 3.0));
print $A . PHP_EOL;
$equA = new Vertex(array('x' => 9.0, 'y' => 9.0, 'z' => 9.0, 'w' => 3.0));
print $equA . PHP_EOL;
Vertex::$verbose = True;
 $graph->set('_key', 'Graph');
 $graph->setVerticesCollection('VertexCollection');
 $graph->setEdgesCollection('EdgeCollection');
 try {
     $graphHandler->dropGraph($graph);
 } catch (\Exception $e) {
     // graph may not yet exist. ignore this error for now
 }
 $graphHandler->createGraph($graph);
 // Define some arrays to build the content of the vertices and edges
 $vertex1Array = array('_key' => 'vertex1', 'someKey1' => 'someValue1');
 $vertex2Array = array('_key' => 'vertex2', 'someKey2' => 'someValue2');
 $edge1Array = array('_key' => 'edge1', 'someEdgeKey1' => 'someEdgeValue1');
 // Create documents for 2 vertices and a connecting edge
 $vertex1 = Vertex::createFromArray($vertex1Array);
 $vertex2 = Vertex::createFromArray($vertex2Array);
 $edge1 = Edge::createFromArray($edge1Array);
 // Save the vertices
 $saveResult1 = $graphHandler->saveVertex('Graph', $vertex1);
 $saveResult2 = $graphHandler->saveVertex('Graph', $vertex2);
 // Get the vertices
 $getResult1 = $graphHandler->getVertex('Graph', 'vertex1');
 $getResult2 = $graphHandler->getVertex('Graph', 'vertex2');
 // check if vertex exists
 var_dump($graphHandler->hasVertex('Graph', 'vertex1'));
 // Save the connecting edge
 $saveEdgeResult1 = $graphHandler->saveEdge('Graph', $vertex1->getHandle(), $vertex2->getHandle(), 'somelabelValue', $edge1);
 // check if edge exists
 var_dump($graphHandler->hasEdge('Graph', 'edge1'));
 // Get the connecting edge
 $getEdgeResult1 = $graphHandler->getEdge('Graph', 'edge1');
Exemplo n.º 15
0
 /**
  * Add a new edge.
  *
  * @param Vertex $vertex   The 'from' vertex
  * @param Vertex $toVertex The 'to' vertex
  *
  * @return Edge
  */
 public function addEdge($vertex, $toVertex)
 {
     $edge = $vertex->createEdgeTo($toVertex);
     $edge->setLayoutAttribute('shape', 'none');
     $edge->setLayoutAttribute('fontname', 'Arial');
     $edge->setLayoutAttribute('fontsize', '12');
     return $edge;
 }
Exemplo n.º 16
0
 public function transformVertex(Vertex $v)
 {
     $x = $this->_matrix['x']['x'] * $v->get_x() + $this->_matrix['x']['y'] * $v->get_y();
     $x += $this->_matrix['x']['z'] * $v->get_z() + $this->_matrix['x']['w'] * $v->get_w();
     $y = $this->_matrix['y']['x'] * $v->get_x() + $this->_matrix['y']['y'] * $v->get_y();
     $y += $this->_matrix['y']['z'] * $v->get_z() + $this->_matrix['y']['w'] * $v->get_w();
     $z = $this->_matrix['z']['x'] * $v->get_x() + $this->_matrix['z']['y'] * $v->get_y();
     $z += $this->_matrix['z']['z'] * $v->get_z() + $this->_matrix['z']['w'] * $v->get_w();
     $w = $this->_matrix['w']['x'] * $v->get_x() + $this->_matrix['w']['y'] * $v->get_y();
     $w += $this->_matrix['w']['z'] * $v->get_z() + $this->_matrix['w']['w'] * $v->get_w();
     $res = new Vertex(array('x' => $x, 'y' => $y, 'z' => $z, 'w' => $w));
     return $res;
 }
 /**
  */
 public function testsaveGetUpdateReplaceRemoveVertex()
 {
     $vertex1 = Vertex::createFromArray($this->vertex1Array);
     $ex = null;
     try {
         $this->graphHandler->saveVertex($this->graphName, $vertex1);
     } catch (Exception $e) {
         $ex = $e->getMessage();
     }
     $this->assertTrue($ex == 'A collection must be provided.');
     $this->createGraph();
     $ex = null;
     try {
         $this->graphHandler->getVertex($this->graphName, $this->vertex1Array["_key"]);
     } catch (Exception $e) {
         $ex = $e->getMessage();
     }
     $this->assertTrue($ex == 'A collection must be provided.');
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->vertex1Array["_key"], array(), $this->v1);
     $v2 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $this->assertTrue($v1->getInternalKey() == $v2->getInternalKey());
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $v = Vertex::createFromArray($this->vertex7Array);
     $v->setRevision($v1->getRevision());
     $ex = null;
     try {
         $this->graphHandler->replaceVertex($this->graphName, $this->vertex1Array["_key"], $v, array());
     } catch (Exception $e) {
         $ex = $e->getMessage();
     }
     $this->assertTrue($ex == 'A collection must be provided.');
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $v = Vertex::createFromArray($this->vertex7Array);
     $v->setRevision($v1->getRevision());
     $this->assertTrue($this->graphHandler->replaceVertex($this->graphName, $this->vertex1Array["_key"], $v, array('revision' => $v1->getRevision()), $this->v1));
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $v = Vertex::createFromArray($this->vertex7Array);
     $v->setRevision($v1->getRevision());
     $this->assertTrue($this->graphHandler->replaceVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v, array('revision' => true)));
     $ex = null;
     try {
         $this->graphHandler->updateVertex($this->graphName, $this->vertex1Array["_key"], $v, array());
     } catch (Exception $e) {
         $ex = $e->getMessage();
     }
     $this->assertTrue($ex == 'A collection must be provided.');
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $v = Vertex::createFromArray($this->vertex7Array);
     $v->setRevision($v1->getRevision());
     $this->assertTrue($this->graphHandler->updateVertex($this->graphName, $this->vertex1Array["_key"], $v, array('revision' => true), $this->v1));
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $v = Vertex::createFromArray($this->vertex7Array);
     $v->setRevision($v1->getRevision());
     $this->assertTrue($this->graphHandler->updateVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v, array('revision' => $v1->getRevision())));
     //removeVertex($graph, $vertexId, $revision = null, $options = array(), $collection = null)
     $ex = null;
     try {
         $this->graphHandler->removeVertex($this->graphName, $this->vertex1Array["_key"], null, array());
     } catch (Exception $e) {
         $ex = $e->getMessage();
     }
     $this->assertTrue($ex == 'A collection must be provided.');
     $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array());
     $this->assertTrue($this->graphHandler->removeVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v1->getRevision(), array()));
 }
 public function createGraph()
 {
     $vertex1 = Vertex::createFromArray($this->vertex1Array);
     $vertex2 = Vertex::createFromArray($this->vertex2Array);
     $vertex3 = Vertex::createFromArray($this->vertex3Array);
     $vertex4 = Vertex::createFromArray($this->vertex4Array);
     $vertex5 = Vertex::createFromArray($this->vertex5Array);
     $edge1 = Edge::createFromArray($this->edge1Array);
     $edge2 = Edge::createFromArray($this->edge2Array);
     $edge3 = Edge::createFromArray($this->edge3Array);
     $edge4 = Edge::createFromArray($this->edge4Array);
     $edge5 = Edge::createFromArray($this->edge5Array);
     $this->graphHandler->saveVertex($this->graphName, $vertex1);
     $this->graphHandler->saveVertex($this->graphName, $vertex2);
     $this->graphHandler->saveVertex($this->graphName, $vertex3);
     $this->graphHandler->saveVertex($this->graphName, $vertex4);
     $this->graphHandler->saveVertex($this->graphName, $vertex5);
     $this->graphHandler->getVertex($this->graphName, $this->vertex1Name);
     $this->graphHandler->getVertex($this->graphName, $this->vertex2Name);
     $this->graphHandler->getVertex($this->graphName, $this->vertex3Name);
     $this->graphHandler->getVertex($this->graphName, $this->vertex4Name);
     $this->graphHandler->getVertex($this->graphName, $this->vertex5Name);
     $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex1Name, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->edgeLabel1, $edge1);
     $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->vertexCollectionName . "/" . $this->vertex3Name, $this->edgeLabel2, $edge2);
     $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->vertexCollectionName . "/" . $this->vertex4Name, $this->edgeLabel3, $edge3);
     $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex5Name, $this->vertexCollectionName . "/" . $this->vertex1Name, $this->edgeLabel4, $edge4);
     $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex5Name, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->edgeLabel5, $edge5);
 }
Exemplo n.º 19
0
 public function transformVertex(Vertex $vtx)
 {
     $newX = $vtx->getX() * $this->_matrix[0][0] + $vtx->getY() * $this->_matrix[0][1] + $vtx->getZ() * $this->_matrix[0][2] + $this->_matrix[0][3];
     $newY = $vtx->getX() * $this->_matrix[1][0] + $vtx->getY() * $this->_matrix[1][1] + $vtx->getZ() * $this->_matrix[1][2] + $this->_matrix[1][3];
     $newZ = $vtx->getX() * $this->_matrix[2][0] + $vtx->getY() * $this->_matrix[2][1] + $vtx->getZ() * $this->_matrix[2][2] + $this->_matrix[2][3];
     $newW = $vtx->getX() * $this->_matrix[3][0] + $vtx->getY() * $this->_matrix[3][1] + $vtx->getZ() * $this->_matrix[3][2] + $this->_matrix[3][3];
     return new Vertex(array('x' => $newX / $newW, 'y' => $newY / $newW, 'z' => $newZ / $newW));
 }
Exemplo n.º 20
0
print Vector::doc();
Vector::$verbose = True;
$vtxO = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 0.0));
$vtxX = new Vertex(array('x' => 1.0, 'y' => 0.0, 'z' => 0.0));
$vtxY = new Vertex(array('x' => 0.0, 'y' => 1.0, 'z' => 0.0));
$vtxZ = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 1.0));
$vtcXunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxX));
$vtcYunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxY));
$vtcZunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxZ));
print $vtcXunit . PHP_EOL;
print $vtcYunit . PHP_EOL;
print $vtcZunit . PHP_EOL;
$dest1 = new Vertex(array('x' => -12.34, 'y' => 23.45, 'z' => -34.56));
Vertex::$verbose = True;
$vtc1 = new Vector(array('dest' => $dest1));
Vertex::$verbose = False;
$orig2 = new Vertex(array('x' => 23.87, 'y' => -37.95, 'z' => 78.34));
$dest2 = new Vertex(array('x' => -12.34, 'y' => 23.45, 'z' => -34.56));
$vtc2 = new Vector(array('orig' => $orig2, 'dest' => $dest2));
print 'Magnitude is ' . $vtc2->magnitude() . PHP_EOL;
$nVtc2 = $vtc2->normalize();
print 'Normalized $vtc2 is ' . $nVtc2 . PHP_EOL;
print 'Normalized $vtc2 magnitude is ' . $nVtc2->magnitude() . PHP_EOL;
print '$vtc1 + $vtc2 is ' . $vtc1->add($vtc2) . PHP_EOL;
print '$vtc1 - $vtc2 is ' . $vtc1->sub($vtc2) . PHP_EOL;
print 'opposite of $vtc1 is ' . $vtc1->opposite() . PHP_EOL;
print 'scalar product of $vtc1 and 42 is ' . $vtc1->scalarProduct(42) . PHP_EOL;
print 'dot product of $vtc1 and $vtc2 is ' . $vtc1->dotProduct($vtc2) . PHP_EOL;
print 'cross product of $vtc1 and $vtc2 is ' . $vtc1->crossProduct($vtc2) . PHP_EOL;
print 'cross product of $vtcXunit and $vtcYunit is ' . $vtcXunit->crossProduct($vtcYunit) . 'aka $vtcZunit' . PHP_EOL;
print 'cosinus of angle between $vtc1 and $vtc2 is ' . $vtc1->cos($vtc2) . PHP_EOL;
Exemplo n.º 21
0
 public function getEdgesToVertex(Vertex $v)
 {
     return $v->getInwardEdges();
 }
Exemplo n.º 22
0
 /**
  * Get a single vertex from a graph
  *
  * This will throw if the vertex cannot be fetched from the server<br><br>
  *
  * @throws Exception
  *
  * @param mixed $graph - graph name as a string or instance of Graph
  * @param mixed $vertexId - the vertex identifier
  * @param array $options  optional, an array of options:
  * <p>
  * <li><b>_includeInternals</b> - true to include the internal attributes. Defaults to false</li>
  * <li><b>includeInternals</b> - Deprecated, please use '_includeInternals'.</li>
  * <li><b>_ignoreHiddenAttributes</b> - true to show hidden attributes. Defaults to false</li>
  * <li><b>ignoreHiddenAttributes</b> - Deprecated, please use '_ignoreHiddenAttributes'.</li>
  * </p>
  * @param string $collection - if one uses a graph with more than one vertex collection one must provide the collection
  *  to load the vertex.                        
  *
  * @return Document
  * @since 1.2
  */
 public function getVertex($graph, $vertexId, array $options = array(), $collection = null)
 {
     if ($graph instanceof Graph) {
         $graph = $graph->getKey();
     }
     $parts = explode("/", $vertexId);
     if (count($parts) === 2) {
         $vertexId = $parts[1];
         $collection = $parts[0];
     }
     if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
         throw new ClientException('A collection must be provided.');
     } else {
         if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
             $collection = $this->getVertexCollections($graph);
             $collection = $collection[0];
         }
     }
     $url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_VERTEX, $collection, $vertexId));
     $response = $this->getConnection()->get($url);
     $jsonArray = $response->getJson();
     $vertex = $jsonArray['vertex'];
     $options['_isNew'] = false;
     return Vertex::createFromArray($vertex, $options);
 }
Exemplo n.º 23
0
    public function getPredecessors()
    {
        return new Vertex_IteratorAggregate($this, $this->getIncidentEdges());
    }
    /**
     * Returns the vertices in this graph
     * which are successors of this vertex.
     *
     * @return object IteratorAggregate
     * The vertices in this graph which are successors of this vertex.
     */
    public function getSuccessors()
    {
        return new Vertex_IteratorAggregate($this, $this->getEmanatingEdges());
    }
    /**
     * Main program.
     *
     * @param array $args Command-line arguments.
     * @return integer Zero on success; non-zero on failure.
     */
    public static function main($args)
    {
        printf("Vertex main program.\n");
        $status = 0;
        return $status;
    }
}
if (realpath($argv[0]) == realpath(__FILE__)) {
    exit(Vertex::main(array_slice($argv, 1)));
}