|
|
//double distance(Coordinate& p); | //double distance(Coordinate& p); |
static Coordinate nullCoord; | static Coordinate nullCoord; |
| |
void Coordinate::setNull() { |
void setNull() { |
x=DoubleNotANumber; | x=DoubleNotANumber; |
y=DoubleNotANumber; | y=DoubleNotANumber; |
z=DoubleNotANumber; | z=DoubleNotANumber; |
} | } |
| |
static Coordinate& Coordinate::getNull() { |
static Coordinate& getNull() { |
return nullCoord; | return nullCoord; |
} | } |
| |
Coordinate::Coordinate() { |
Coordinate() { |
x=0.0; | x=0.0; |
y=0.0; | y=0.0; |
z=DoubleNotANumber; | z=DoubleNotANumber; |
} | } |
| |
Coordinate::Coordinate(double xNew, double yNew, double zNew) { |
Coordinate(double xNew, double yNew, double zNew) { |
x=xNew; | x=xNew; |
y=yNew; | y=yNew; |
z=zNew; | z=zNew; |
} | } |
| |
#ifndef PROFILE_COORDINATE_COPIES | #ifndef PROFILE_COORDINATE_COPIES |
Coordinate::Coordinate(const Coordinate& c){ |
Coordinate(const Coordinate& c){ |
x=c.x; | x=c.x; |
y=c.y; | y=c.y; |
z=c.z; | z=c.z; |
} | } |
#else | #else |
Coordinate::Coordinate(const Coordinate& c); |
Coordinate(const Coordinate& c); |
Coordinate &operator=(const Coordinate &c); | Coordinate &operator=(const Coordinate &c); |
#endif | #endif |
| |
Coordinate::Coordinate(double xNew, double yNew){ |
Coordinate(double xNew, double yNew){ |
x=xNew; | x=xNew; |
y=yNew; | y=yNew; |
z=DoubleNotANumber; | z=DoubleNotANumber; |
} | } |
| |
void Coordinate::setCoordinate(const Coordinate& other) { |
void setCoordinate(const Coordinate& other) { |
x = other.x; | x = other.x; |
y = other.y; | y = other.y; |
z = other.z; | z = other.z; |
} | } |
| |
bool Coordinate::equals2D(const Coordinate& other) const { |
bool equals2D(const Coordinate& other) const { |
if (x != other.x) { | if (x != other.x) { |
return false; | return false; |
} | } |
|
|
return true; | return true; |
} | } |
| |
int Coordinate::compareTo(const Coordinate& other) const { |
int compareTo(const Coordinate& other) const { |
if (x < other.x) { | if (x < other.x) { |
return -1; | return -1; |
} | } |
|
|
return 0; | return 0; |
} | } |
| |
bool Coordinate::equals3D(const Coordinate& other) const { |
bool equals3D(const Coordinate& other) const { |
return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z))); | return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z))); |
} | } |
| |
void Coordinate::makePrecise(const PrecisionModel *precisionModel) { |
void makePrecise(const PrecisionModel *precisionModel) { |
x = precisionModel->makePrecise(x); | x = precisionModel->makePrecise(x); |
y = precisionModel->makePrecise(y); | y = precisionModel->makePrecise(y); |
} | } |
| |
double Coordinate::distance(const Coordinate& p) const { |
double distance(const Coordinate& p) const { |
double dx = x - p.x; | double dx = x - p.x; |
double dy = y - p.y; | double dy = y - p.y; |
return sqrt(dx * dx + dy * dy); | return sqrt(dx * dx + dy * dy); |
} | } |
| |
int Coordinate::hashCode() { |
int hashCode() { |
//Algorithm from Effective Java by Joshua Bloch [Jon Aquino] | //Algorithm from Effective Java by Joshua Bloch [Jon Aquino] |
int result = 17; | int result = 17; |
result = 37 * result + hashCode(x); | result = 37 * result + hashCode(x); |
|
|
* Returns a hash code for a double value, using the algorithm from | * Returns a hash code for a double value, using the algorithm from |
* Joshua Bloch's book <i>Effective Java</i> | * Joshua Bloch's book <i>Effective Java</i> |
*/ | */ |
static int Coordinate::hashCode(double x) { |
static int hashCode(double x) { |
int64 f = (int64)(x); | int64 f = (int64)(x); |
return (int)(f^(f>>32)); | return (int)(f^(f>>32)); |
} | } |