spacecoords.java
来自「Java mulitplayer strategy game. Adaptati」· Java 代码 · 共 134 行
JAVA
134 行
package net.sf.jawp.api.domain;
import java.io.Serializable;
/**
* Immutable SpaceCoords object.
*
*
* @author jarek
* @version $Revision: 1.8 $
*
*/
public final class SpaceCoords implements Serializable, Cloneable
{
/**
*
*/
private static final long serialVersionUID = 1L;
private final float x;
private final float y;
private final float z;
public SpaceCoords(final int x, final int y, final int z)
{
super();
this.x = x;
this.y = y;
this.z = z;
}
public SpaceCoords(final float x, final float y, final float z)
{
super();
this.x = x;
this.y = y;
this.z = z;
}
public SpaceCoords( final SpaceCoords other)
{
this(other.x, other.y, other.z);
}
public float getX()
{
return this.x;
}
/*public void setX(final int x)
{
this.x = x;
}*/
public float getY()
{
return this.y;
}
/*public void setY(final int y)
{
this.y = y;
}*/
public float getZ()
{
return this.z;
}
/*
public void setZ(final int z)
{
this.z = z;
}*/
public SpaceCoords add(final SpaceCoords arg)
{
return new SpaceCoords( this.x + arg.x, this.y + arg.y, this.z + arg.z);
/*this.x += arg.x;
this.y += arg.y;
this.z += arg.z;*/
}
public String toString()
{
return "(" + getX() + "," + getY() + "," + getZ() + ")";
}
@Override
public Object clone()
{
return new SpaceCoords(this);
}
@Override
public boolean equals( final Object o)
{
if ( o == this)
{
return true;
}
return this.equals( (SpaceCoords)o);
}
public boolean equals( final SpaceCoords o)
{
return this.x == o.x && this.y == o.y && this.z == o.z;
}
@Override
public int hashCode()
{
return 37 + Float.floatToRawIntBits(this.x)
^ Float.floatToRawIntBits(this.y) ^ Float.floatToRawIntBits(this.z);
}
public double getDistance( final SpaceCoords trg)
{
final float difx = getX() - trg.getX();
final float dify = getY() - trg.getY();
final float difz = getZ() - trg.getZ();
final double dist2 = (difx * difx) + (dify * dify) + (difz * difz);
//assert LOG.debug("dist2 is:" + dist2);
return Math.sqrt( dist2);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?