/// This is used for node coordinates and other things, primarily to avoid floating point calculations in the core pathfinding routines (as they can be slow and non-deterministic if you are not careful).
///
/// You can cast back and forth between Vector3s and Int3s like:
/// <code>
/// Int3 intPoint = (Int3)transform.position;
/// transform.position = (Vector3)intPoint;
/// </code>
///
/// During the cast, the coordinates will be rounded to the nearest millimeter.
/// </summary>
publicstructInt3:System.IEquatable<Int3>{
publicintx;
publicinty;
publicintz;
//These should be set to the same value (only PrecisionFactor should be 1 divided by Precision)
/// <summary>
/// Precision for the integer coordinates.
/// One world unit is divided into [value] pieces. A value of 1000 would mean millimeter precision, a value of 1 would mean meter precision (assuming 1 world unit = 1 meter).
/// This value affects the maximum coordinates for nodes as well as how large the cost values are for moving between two nodes.
/// A higher value means that you also have to set all penalty values to a higher value to compensate since the normal cost of moving will be higher.
/// </summary>
publicconstintPrecision=1000;
/// <summary><see cref="Precision"/> as a float</summary>
publicconstfloatFloatPrecision=1000F;
/// <summary>1 divided by <see cref="Precision"/></summary>
/// except that the Y coordinate is left unchanged with this operation.
/// </summary>
publicInt3Normal2D(){
returnnewInt3(z,y,-x);
}
/// <summary>
/// Returns the magnitude of the vector. The magnitude is the 'length' of the vector from 0,0,0 to this point. Can be used for distance calculations:
/// <code> Debug.Log ("Distance between 3,4,5 and 6,7,8 is: "+(new Int3(3,4,5) - new Int3(6,7,8)).magnitude); </code>
/// </summary>
publicfloatmagnitude{
get{
//It turns out that using doubles is just as fast as using ints with Mathf.Sqrt. And this can also handle larger numbers (possibly with small errors when using huge numbers)!
double_x=x;
double_y=y;
double_z=z;
return(float)System.Math.Sqrt(_x*_x+_y*_y+_z*_z);
}
}
/// <summary>
/// Magnitude used for the cost between two nodes. The default cost between two nodes can be calculated like this:
/// <code> int cost = (node1.position-node2.position).costMagnitude; </code>
///
/// This is simply the magnitude, rounded to the nearest integer
/// </summary>
publicintcostMagnitude{
get{
return(int)System.Math.Round(magnitude);
}
}
/// <summary>The squared magnitude of the vector</summary>
publicfloatsqrMagnitude{
get{
double_x=x;
double_y=y;
double_z=z;
return(float)(_x*_x+_y*_y+_z*_z);
}
}
/// <summary>The squared magnitude of the vector</summary>
publiclongsqrMagnitudeLong{
get{
long_x=x;
long_y=y;
long_z=z;
return(_x*_x+_y*_y+_z*_z);
}
}
publicstaticimplicitoperatorstring(Int3obj){
returnobj.ToString();
}
/// <summary>Returns a nicely formatted string representing the vector</summary>