|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hermit.geometry.Vector
public class Vector
An immutable vector in the plane. This immutable class represents a vector as an X and Y offset.
Constructor Summary | |
---|---|
Vector(double x,
double y)
Create a Vector from individual offsets. |
Method Summary | |
---|---|
static Vector |
add(Vector a,
Vector b)
Calculate the vector sum of two vectors. |
int |
compareTo(Vector o)
Compares this object with the specified object for order. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. |
double |
getX()
Get the X component of this vector. |
double |
getY()
Get the Y component of this vector. |
int |
hashCode()
Returns a hash code value for the object. |
double |
length()
Get the length of this vector. |
static Vector |
scale(Vector vec,
double scale)
Scale a vector by a given value. |
static Vector |
sub(Vector a,
Vector b)
Calculate the vector difference of two vectors. |
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 |
---|
public Vector(double x, double y)
x
- The X offset.y
- The Y offset.Method Detail |
---|
public double getX()
public double getY()
public double length()
public static Vector add(Vector a, Vector b)
a
- The first vector to add.b
- The second vector.
public static Vector sub(Vector a, Vector b)
a
- The first vector to add.b
- The second vector.
public static Vector scale(Vector vec, double scale)
vec
- The vector to scale.scale
- The value to scale by.
public boolean equals(java.lang.Object obj)
This method simply compares the components of the two vectors, with a limited precision.
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 vectors will be considered equal.
equals
in class java.lang.Object
obj
- The reference object with which to compare.
public int compareTo(Vector o)
This method compares the components of the two vectors, with a limited precision. The Y component is given precedence; that is, the smaller Y will be considered less than the larger Y. If the Y values are equal to within the configured precision, then the X values are compared.
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 vectors will be considered equal.
compareTo
in interface java.lang.Comparable<Vector>
o
- The object to be compared to this one.
java.lang.ClassCastException
- The specified object's type prevents it
from being compared to this object.public int hashCode()
The hash code returned here is based on the components of this
Vector, and is designed to be different for different vectors.
The least significant bits of the components are not compared,
in line with the precision set in
MathTools.setPrecision(double)
. Hence, this method should
be consistent with equals() and compareTo().
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |