org.hermit.geometry
Class Edge

java.lang.Object
  extended by org.hermit.geometry.Edge
All Implemented Interfaces:
java.lang.Comparable<Edge>

public class Edge
extends java.lang.Object
implements java.lang.Comparable<Edge>

An immutable edge in a geometric graph.

This immutable class embodies an edge in a graph where the vertices are assumed to be points in the plane. Either or both of the vertices may be at infinity, in which case this class can provide the position and direction of the line representing the edge.


Constructor Summary
Edge(Point a, Point b)
          Create an Edge from individual vertices.
Edge(Point a, Point b, Point ld, Point rd)
          Create an Edge from two data points and individual vertices.
 
Method Summary
 int compareTo(Edge ev)
          Compare an edge against another edge.
 Vector directionVector()
          Get the direction vector for this edge.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 Point getDatumA()
          Get one datum point of this edge (denoted "A").
 Point getDatumB()
          Get one datum point of this edge (denoted "B").
 Point getVertexA()
          Get one vertex of this edge (denoted "A").
 Point getVertexB()
          Get one vertex of this edge (denoted "B").
 int hashCode()
          Returns a hash code value for the object.
 boolean isInfinite()
          Determine whether this edge is infinite.
 boolean isPartlyInfinite()
          Determine whether this edge is partly infinite.
 double length()
          Get the length of this edge.
 Point referencePoint()
          Get a reference point which fixes the position of this edge.
 java.lang.String toString()
          Convert this instance to a String suitable for display.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Edge

public Edge(Point a,
            Point b)
Create an Edge from individual vertices.

Parameters:
a - One vertex, in no particular order. Must be a real Point.
b - The other vertex. Must be a real Point.

Edge

public Edge(Point a,
            Point b,
            Point ld,
            Point rd)
Create an Edge from two data points and individual vertices.

Parameters:
ld - One data point for the edge. This is a point which the edge passes through, and defines the position and direction of an infinite edge.
rd - Other data point for the edge.
a - One vertex, in no particular order. Must be Point.INFINITE or a real Point.
b - The other vertex. May be Point.INFINITE or a real Point.
Method Detail

getVertexA

public Point getVertexA()
Get one vertex of this edge (denoted "A").

Returns:
The "A" vertex of this edge. May be Point.INFINITE or a real Point.

getVertexB

public Point getVertexB()
Get one vertex of this edge (denoted "B").

Returns:
The "B" vertex of this edge. May be Point.INFINITE or a real Point.

getDatumA

public Point getDatumA()
Get one datum point of this edge (denoted "A").

Returns:
The "A" datum of this edge. Will be null if there is no datum, as may be the case for non-infinite edges.

getDatumB

public Point getDatumB()
Get one datum point of this edge (denoted "B").

Returns:
The "B" datum of this edge. Will be null if there is no datum, as may be the case for non-infinite edges.

isInfinite

public boolean isInfinite()
Determine whether this edge is infinite.

Returns:
True if both vertices are infinite; false else.

isPartlyInfinite

public boolean isPartlyInfinite()
Determine whether this edge is partly infinite.

Returns:
True if either vertex is infinite; false else.

referencePoint

public Point referencePoint()
Get a reference point which fixes the position of this edge.

Returns:
A reference point which can be used to fix the position of this edge. If the edge is fully infinite, this will be some point which the edge passes through; if the edge is partly infinite, it will be the non-infinite vertex; otherwise it will be one of the vertices.

directionVector

public Vector directionVector()
Get the direction vector for this edge. If the edge is partly or fully infinite, this can be used to draw the edge in conjunction with referencePoint().

Returns:
The direction vector for this edge.

length

public double length()
Get the length of this edge.

Returns:
The length of this edge; this will be Double.POSITIVE_INFINITY if the edge is infinite or partly infinite.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. This method implements an equivalence relation on non-null object references.

This method simply compares the co-ordinates of the two points, with a limited precision.

This comparison has little objective value; it is used to enforce a natural ordering on edges, so that arrays of edges can be compared easily for equality. This is in turn used for testing. Because compareTo() only compares vertices, so does this method.

Note that the precision of the test is limited by the precision set in MathTools.setPrecision(double). That is, only as many fractional digits are compared as configured there; hence, two very close points will be considered equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The reference object with which to compare.
Returns:
true if this object is the same as the obj argument, to within the given precision; false otherwise.

compareTo

public int compareTo(Edge ev)
Compare an edge against another edge. The comparison is based on comparing the two vertices, as per Point.compareTo(Point).

Note that the precision of the test is limited by the precision set in MathTools.setPrecision(double). That is, only as many fractional digits are compared as configured there; hence, two very close points will be considered equal.

This comparison has little objective value; it is used to enforce a natural ordering on edges, so that arrays of edges can be compared easily for equality. This is in turn used for testing.

Specified by:
compareTo in interface java.lang.Comparable<Edge>
Parameters:
ev - The other edge to compare to.
Returns:
A negative, zero or positive integer, as this edge is less than, equal to, or greater than ev.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables.

The hash code returned here is based on the hash codes of the vertices. See Point.hashCode(). This means that the least significant bits of the co-ordinates are not compared, in line with the precision set in MathTools.setPrecision(double). Hence, this method should be consistent with equals() and compareTo().

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for this object.

toString

public java.lang.String toString()
Convert this instance to a String suitable for display.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this instance.