|
4 | 4 |
|
5 | 5 | use Fhaculty\Graph\Algorithm\BaseGraph;
|
6 | 6 | use Fhaculty\Graph\Edge\Base as Edge;
|
| 7 | +use Fhaculty\Graph\Edge\Directed as DirectedEdge; |
7 | 8 | use Fhaculty\Graph\Graph;
|
8 | 9 | use LogicException;
|
9 | 10 |
|
@@ -55,19 +56,18 @@ public function hasEdgeParallelEdge(Edge $edge)
|
55 | 56 | */
|
56 | 57 | public function getEdgesParallelEdge(Edge $edge)
|
57 | 58 | {
|
58 |
| - $ends = $edge->getVertices(); |
59 |
| - |
60 |
| - // get all edges between this edge's endpoints |
61 |
| - $edges = $ends[0]->getEdgesTo($ends[1]); |
62 |
| - // edge points into both directions (undirected/bidirectional edge) |
63 |
| - if ($edge->isConnection($ends[1], $ends[0])) { |
| 59 | + if ($edge instanceof DirectedEdge) { |
| 60 | + // get all edges between this edge's endpoints |
| 61 | + $edges = $edge->getVertexStart()->getEdgesTo($edge->getVertexEnd()); |
| 62 | + } else { |
| 63 | + // edge points into both directions (undirected/bidirectional edge) |
64 | 64 | // also get all edges in other direction
|
65 |
| - $back = $ends[1]->getEdgesTo($ends[0]); |
66 |
| - foreach ($back as $edgee) { |
67 |
| - if (!in_array($edgee, $edges)) { |
68 |
| - $edges[] = $edgee; |
69 |
| - } |
70 |
| - } // alternative implementation for array_unique(), because it requires casting edges to string |
| 65 | + $ends = $edge->getVertices(); |
| 66 | + $edgesOther = $ends[1]->getEdges(); |
| 67 | + |
| 68 | + $edges = array_filter($ends[0]->getEdges(), function(Edge $edge) use ($edgesOther) { |
| 69 | + return in_array($edge, $edgesOther, true); |
| 70 | + }); |
71 | 71 | }
|
72 | 72 |
|
73 | 73 | $pos = array_search($edge, $edges, true);
|
|
0 commit comments