Synergy Home Page

au.edu.swin.synergy.math
Class BScalar

java.lang.Object
  |
  +--au.edu.swin.synergy.math.BScalar

public class BScalar
extends Object
implements Serializable

Class for a generic scalar type.. Haven't decided if it should be floating point or fixed point int's yet, so by making it a class i should be able to change it later without having to change everything that uses it. Currently uses a 16:16 fixed point format. so scalar values should never exceed -32768..32767 This class doesn't have any debug/log messages printed because it needs to be fast. It's just provides wrapper methods that mean I don't have to put in shifts and mults in the actual program code.

Author:
Imron Alston
See Also:
Serialized Form

Field Summary
static float kFloatToFixed
          value to convert from float to fixed
static int kShiftAmount
          shift amount for the fixed point format
 
Constructor Summary
protected BScalar()
           
  BScalar(BScalar value)
           
  BScalar(float value)
           
  BScalar(int value)
           
 
Method Summary
 void add(BScalar amount)
          adds another BScalar to this BScalar
static int add(BScalar op1, BScalar op2)
           
 void add(int amount)
          adds an int to this BScalar
 void addH(BScalarRect rect)
           
 void addMult(BScalar op1, int op2)
          multiplies a BScalar by an int and adds the result to value
 void addW(BScalarRect rect)
           
 void addX(BScalarRect rect)
           
 void addY(BScalarRect rect)
           
 void div(BScalar amount)
          divides two BScalar types
 void div(int amount)
          divides a BScalar by an int
 void divByH(BScalarRect rect)
           
 void divByW(BScalarRect rect)
           
 int getActualValue()
          gets the actual value of the scalar
 float getFloatValue()
          gets the floating point value of this scalar type
 int getIntValue()
          gets the integer (truncated) value of this scalar type
 int getValue()
          just get the value of the scalar (this is truncated if an int)
 boolean greaterThan(BScalar op1)
           
 boolean greaterThanOrEqualTo(BScalar op1)
           
 void half()
           
 boolean lessThan(BScalar op1)
           
 boolean lessThanOrEqualTo(BScalar op1)
           
 void mod(int amount)
          the modulus of the scalar type
 void mult(BScalar amount)
          multiplies two BScalar types
 void mult(BScalar op1, BScalar op2)
           
 void mult(float amount)
          multiplies the BScalar by a float
 void mult(int amount)
          multiplies the BScalar by an int
 void neg()
          reverses the sign of the scalar
 void reciprocal(BScalar op1)
          sets the value of this scalar to the reciprocal of the param
 void setActualValue(int newValue)
          sets the actual value of the Scalar, without shifting etc
 void setValue(BScalar newValue)
          sets the value of the Scalar from a Scalar
 void setValue(float newValue)
          sets the value of the Scalar from a float
 void setValue(int newValue)
          sets the value of the Scalar from an int
 void setValueH(BScalarRect rect)
          sets the value to the y value of the rect
 void setValueW(BScalarRect rect)
          sets the value to the x value of the rect
 void setValueX(BScalarRect rect)
          sets the value to the x value of the rect
 void setValueY(BScalarRect rect)
          sets the value to the y value of the rect
 void sub(BScalar amount)
          subs a BScalar from this BScalar
 void sub(int amount)
          subs an int from this BScalar
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

kFloatToFixed

public static final float kFloatToFixed
value to convert from float to fixed

kShiftAmount

public static final int kShiftAmount
shift amount for the fixed point format
Constructor Detail

BScalar

public BScalar(BScalar value)

BScalar

public BScalar(int value)

BScalar

public BScalar(float value)

BScalar

protected BScalar()
Method Detail

setValue

public final void setValue(float newValue)
sets the value of the Scalar from a float

setValue

public final void setValue(int newValue)
sets the value of the Scalar from an int

setValue

public final void setValue(BScalar newValue)
sets the value of the Scalar from a Scalar

setValueX

public final void setValueX(BScalarRect rect)
sets the value to the x value of the rect

setValueY

public final void setValueY(BScalarRect rect)
sets the value to the y value of the rect

setValueW

public final void setValueW(BScalarRect rect)
sets the value to the x value of the rect

setValueH

public final void setValueH(BScalarRect rect)
sets the value to the y value of the rect

setActualValue

public final void setActualValue(int newValue)
sets the actual value of the Scalar, without shifting etc

getIntValue

public final int getIntValue()
gets the integer (truncated) value of this scalar type

getFloatValue

public final float getFloatValue()
gets the floating point value of this scalar type

getValue

public final int getValue()
just get the value of the scalar (this is truncated if an int)

getActualValue

public final int getActualValue()
gets the actual value of the scalar

add

public final void add(BScalar amount)
adds another BScalar to this BScalar

add

public final void add(int amount)
adds an int to this BScalar

add

public static final int add(BScalar op1,
                            BScalar op2)

addX

public final void addX(BScalarRect rect)

addY

public final void addY(BScalarRect rect)

addW

public final void addW(BScalarRect rect)

addH

public final void addH(BScalarRect rect)

sub

public final void sub(BScalar amount)
subs a BScalar from this BScalar

sub

public final void sub(int amount)
subs an int from this BScalar

mult

public final void mult(int amount)
multiplies the BScalar by an int

addMult

public final void addMult(BScalar op1,
                          int op2)
multiplies a BScalar by an int and adds the result to value

mult

public final void mult(float amount)
multiplies the BScalar by a float

mult

public final void mult(BScalar amount)
multiplies two BScalar types

mult

public final void mult(BScalar op1,
                       BScalar op2)

div

public final void div(int amount)
divides a BScalar by an int

divByW

public final void divByW(BScalarRect rect)

divByH

public final void divByH(BScalarRect rect)

div

public final void div(BScalar amount)
divides two BScalar types

mod

public final void mod(int amount)
the modulus of the scalar type

neg

public final void neg()
reverses the sign of the scalar

reciprocal

public final void reciprocal(BScalar op1)
sets the value of this scalar to the reciprocal of the param

half

public final void half()

lessThan

public final boolean lessThan(BScalar op1)

lessThanOrEqualTo

public final boolean lessThanOrEqualTo(BScalar op1)

greaterThan

public final boolean greaterThan(BScalar op1)

greaterThanOrEqualTo

public final boolean greaterThanOrEqualTo(BScalar op1)

toString

public final String toString()
Overrides:
toString in class Object

Synergy Home Page