org.jbox2d.common
Class Vec2

java.lang.Object
  extended by org.jbox2d.common.Vec2

public class Vec2
extends java.lang.Object

A 2-dimensional vector class. Used heavily in JBox2d.


Field Summary
static int creationCount
          Running count of Vec2 creations.
static boolean watchCreations
          Should we count Vec2 creations?
 float x
           
 float y
           
 
Constructor Summary
Vec2()
           
Vec2(float x, float y)
           
 
Method Summary
 Vec2 abs()
          Return a new vector that has positive components.
static Vec2 abs(Vec2 a)
           
 Vec2 add(Vec2 v)
          Return the sum of this vector and another; does not alter either one.
 Vec2 addLocal(Vec2 v)
          Add another vector to this one and return result - alters this vector.
 Vec2 clone()
           
static Vec2 cross(float s, Vec2 a)
           
static Vec2 cross(Vec2 a, float s)
           
static float cross(Vec2 a, Vec2 b)
           
static float dot(Vec2 a, Vec2 b)
           
 boolean isValid()
          True if the vector represents a pair of valid, non-infinite floating point numbers.
 float length()
          Return the length of this vector.
 float lengthSquared()
          Return the squared length of this vector.
static Vec2 max(Vec2 a, Vec2 b)
           
static Vec2 min(Vec2 a, Vec2 b)
           
 Vec2 mul(float a)
          Return this vector multiplied by a scalar; does not alter this vector.
 Vec2 mulLocal(float a)
          Multiply this vector by a number and return result - alters this vector.
 Vec2 negate()
          Return the negation of this vector; does not alter this vector.
 Vec2 negateLocal()
          Flip the vector and return it - alters this vector.
 float normalize()
          Normalize this vector and return the length before normalization.
 void set(float x, float y)
          Set the vector component-wise.
 void set(Vec2 v)
          Set this vector to another vector.
 void setZero()
          Zero out this vector.
 Vec2 sub(Vec2 v)
          Return the difference of this vector and another; does not alter either one.
 Vec2 subLocal(Vec2 v)
          Subtract another vector from this one and return result - alters this vector.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

watchCreations

public static final boolean watchCreations
Should we count Vec2 creations?

See Also:
Constant Field Values

creationCount

public static int creationCount
Running count of Vec2 creations. Must be zeroed out manually (perhaps at start of time step). Incremented in Vec2 constructor if watchCreations flag is true.

Mainly used for optimization purposes, since temporary Vec2 creation is often a bottleneck.


x

public float x

y

public float y
Constructor Detail

Vec2

public Vec2()

Vec2

public Vec2(float x,
            float y)
Method Detail

setZero

public void setZero()
Zero out this vector.


set

public void set(float x,
                float y)
Set the vector component-wise.


set

public void set(Vec2 v)
Set this vector to another vector.


add

public Vec2 add(Vec2 v)
Return the sum of this vector and another; does not alter either one.


sub

public Vec2 sub(Vec2 v)
Return the difference of this vector and another; does not alter either one.


mul

public Vec2 mul(float a)
Return this vector multiplied by a scalar; does not alter this vector.


negate

public Vec2 negate()
Return the negation of this vector; does not alter this vector.


negateLocal

public Vec2 negateLocal()
Flip the vector and return it - alters this vector.


addLocal

public Vec2 addLocal(Vec2 v)
Add another vector to this one and return result - alters this vector.


subLocal

public Vec2 subLocal(Vec2 v)
Subtract another vector from this one and return result - alters this vector.


mulLocal

public Vec2 mulLocal(float a)
Multiply this vector by a number and return result - alters this vector.


length

public float length()
Return the length of this vector.


lengthSquared

public float lengthSquared()
Return the squared length of this vector.


normalize

public float normalize()
Normalize this vector and return the length before normalization. Alters this vector.


isValid

public boolean isValid()
True if the vector represents a pair of valid, non-infinite floating point numbers.


abs

public Vec2 abs()
Return a new vector that has positive components.


clone

public Vec2 clone()
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

abs

public static Vec2 abs(Vec2 a)

dot

public static float dot(Vec2 a,
                        Vec2 b)

cross

public static float cross(Vec2 a,
                          Vec2 b)

cross

public static Vec2 cross(Vec2 a,
                         float s)

cross

public static Vec2 cross(float s,
                         Vec2 a)

min

public static Vec2 min(Vec2 a,
                       Vec2 b)

max

public static Vec2 max(Vec2 a,
                       Vec2 b)