org.graphstream.ui.graphicGraph
Class GraphPosLengthUtils

java.lang.Object
  extended by org.graphstream.ui.graphicGraph.GraphPosLengthUtils

public class GraphPosLengthUtils
extends Object

Lots of small often used measuring algorithms on graphs.

Use this class with a static import.


Constructor Summary
GraphPosLengthUtils()
           
 
Method Summary
static double edgeLength(Edge edge)
          Like edgeLength(Graph,String) but use an existing edge as argument.
static double edgeLength(Graph graph, String id)
          Compute the edge length of the given edge according to its two nodes positions.
static Point3 nodePointPosition(Graph graph, String id)
          Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz").
static Point3 nodePointPosition(Node node)
          Like nodePointPosition(Graph,String) but use an existing node as argument.
static double[] nodePosition(Graph graph, String id)
          Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz").
static void nodePosition(Graph graph, String id, double[] xyz)
          Like nodePosition(Graph,String), but instead of returning a newly allocated array, fill up the array given as parameter.
static void nodePosition(Graph graph, String id, Point3 pos)
          Like nodePointPosition(Graph,String), but instead of returning a newly allocated array, fill up the array given as parameter.
static double[] nodePosition(Node node)
          Like nodePosition(Graph,String) but use an existing node as argument.
static void nodePosition(Node node, double[] xyz)
          Like nodePosition(Graph,String,double[]) but use an existing node as argument.
static void nodePosition(Node node, Point3 pos)
          Like nodePosition(Graph,String,Point3) but use an existing node as argument.
static Node randomNode(Graph graph)
          Choose a node at random.
static Node randomNode(Graph graph, Random random)
          Choose a node at random.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphPosLengthUtils

public GraphPosLengthUtils()
Method Detail

randomNode

public static Node randomNode(Graph graph)
Choose a node at random.

Returns:
A node chosen at random.
Computational Complexity :
at worse O(n) where n is the number of nodes.

randomNode

public static Node randomNode(Graph graph,
                              Random random)
Choose a node at random.

Parameters:
random - The random number generator to use.
Returns:
A node chosen at random.
Computational Complexity :
at worse O(n) where n is the number of nodes.

nodePosition

public static double[] nodePosition(Graph graph,
                                    String id)
Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz").

Parameters:
id - The node identifier.
Returns:
A newly allocated array of three floats containing the (x,y,z) position of the node, or null if the node is not part of the graph.

nodePointPosition

public static Point3 nodePointPosition(Graph graph,
                                       String id)
Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz").

Parameters:
id - The node identifier.
Returns:
A newly allocated point containing the (x,y,z) position of the node, or null if the node is not part of the graph.

nodePosition

public static double[] nodePosition(Node node)
Like nodePosition(Graph,String) but use an existing node as argument.

Parameters:
node - The node to consider.
Returns:
A newly allocated array of three floats containing the (x,y,z) position of the node.

nodePointPosition

public static Point3 nodePointPosition(Node node)
Like nodePointPosition(Graph,String) but use an existing node as argument.

Parameters:
node - The node to consider.
Returns:
A newly allocated point containing the (x,y,z) position of the node.

nodePosition

public static void nodePosition(Graph graph,
                                String id,
                                double[] xyz)
Like nodePosition(Graph,String), but instead of returning a newly allocated array, fill up the array given as parameter. This array must have at least three cells.

Parameters:
id - The node identifier.
xyz - An array of at least three cells.
Throws:
RuntimeException - If the node with the given identifier does not exist.

nodePosition

public static void nodePosition(Graph graph,
                                String id,
                                Point3 pos)
Like nodePointPosition(Graph,String), but instead of returning a newly allocated array, fill up the array given as parameter. This array must have at least three cells.

Parameters:
id - The node identifier.
pos - A point that will receive the node position.
Throws:
RuntimeException - If the node with the given identifier does not exist.

nodePosition

public static void nodePosition(Node node,
                                double[] xyz)
Like nodePosition(Graph,String,double[]) but use an existing node as argument.

Parameters:
node - The node to consider.
xyz - An array of at least three cells.

nodePosition

public static void nodePosition(Node node,
                                Point3 pos)
Like nodePosition(Graph,String,Point3) but use an existing node as argument.

Parameters:
node - The node to consider.
pos - A point that will receive the node position.

edgeLength

public static double edgeLength(Graph graph,
                                String id)
Compute the edge length of the given edge according to its two nodes positions.

Parameters:
id - The identifier of the edge.
Returns:
The edge length or -1 if the nodes of the edge have no positions.
Throws:
RuntimeException - If the edge cannot be found.

edgeLength

public static double edgeLength(Edge edge)
Like edgeLength(Graph,String) but use an existing edge as argument.

Parameters:
edge -
Returns:
The edge length or -1 if the nodes of the edge have no positions.


Copyright © 2011. All Rights Reserved.