FileDocCategorySizeDatePackage
HeightCoordinatesImpl.javaAPI DocAzureus 3.0.3.43391Mon Apr 24 13:20:30 BST 2006com.aelitis.azureus.core.dht.netcoords.vivaldi.ver1.impl

HeightCoordinatesImpl

public class HeightCoordinatesImpl extends Object implements Coordinates

Fields Summary
protected float
x
protected float
y
protected float
h
Constructors Summary
public HeightCoordinatesImpl(float x, float y, float h)

    this.x = x;
    this.y = y;
    this.h = h;
  
public HeightCoordinatesImpl(HeightCoordinatesImpl copy)

    this.x = copy.x;
    this.y = copy.y;
    this.h = copy.h;
  
Methods Summary
public Coordinatesadd(Coordinates other)

    HeightCoordinatesImpl o = (HeightCoordinatesImpl) other;
    return new HeightCoordinatesImpl(x+o.x,y+o.y,Math.abs(h+o.h));
  
public booleanatOrigin()

	  return( x==0&&y==0);
  
public floatdistance(Coordinates other)

    return this.sub(other).measure();
  
public booleanequals(java.lang.Object arg0)

   if(arg0 instanceof HeightCoordinatesImpl) {
     HeightCoordinatesImpl other = (HeightCoordinatesImpl) arg0;
     if(other.x != x || other.y != y || other.h != h) return false;
     return true;
   }
   return false;
  
public floatgetH()

return
Returns the h.

    return h;
  
public floatgetX()

return
Returns the x.

    return x;
  
public floatgetY()

return
Returns the y.

    return y;
  
public booleanisValid()

	 return( valid(x) && valid(y) && valid(h) && Math.abs(x) <= MAX_X && Math.abs(y) <= MAX_Y && Math.abs(h) <= MAX_H);
  
public floatmeasure()

    return (float) (Math.sqrt(x * x + y * y) + h);
  
public Coordinatesscale(float scale)

    return new HeightCoordinatesImpl(scale * x,scale * y ,scale * h);
  
public Coordinatessub(Coordinates other)

    HeightCoordinatesImpl o = (HeightCoordinatesImpl) other;
    return new HeightCoordinatesImpl(x-o.x,y-o.y,Math.abs(h+o.h));
  
public java.lang.StringtoString()

    return (int)x + "," + (int)y + "," + (int)h;
  
public Coordinatesunity()

    float measure = this.measure();
    if(measure == 0) {
      //Special Vivaldi Case, when u(0) = random unity vector
      float x = (float)Math.random();
      float y = (float)Math.random();
      float h = (float)Math.random();
      return new HeightCoordinatesImpl(x,y,h).unity();      
    }
    return this.scale(1/measure);
  
private booleanvalid(float f)

	  return( !(Float.isInfinite( f ) || Float.isNaN( f )));