21 package org.matsim.api.core.v01;
23 import java.io.Serializable;
35 public final class Coord implements Serializable {
41 private double z = Double.NEGATIVE_INFINITY;
55 public Coord(
final double x,
final double y) {
58 this.z = Double.NEGATIVE_INFINITY;
61 public Coord(
double[] coord ) {
63 switch ( coord.length ) {
67 x = coord[0] ; y = coord[1] ;
70 throw new RuntimeException(
"double[] of wrong length; cannot be interpreted as coordinate ") ;
75 public Coord(
final double x,
final double y,
final double z){
76 if(z == Double.NEGATIVE_INFINITY){
77 throw new IllegalArgumentException(
"Double.NEGATIVE_INFINITY is an invalid elevation. " +
78 "If you want to ignore elevation, use Coord(x, y) constructor instead.");
94 public double getZ() throws IllegalStateException {
96 throw new IllegalStateException(
"Requesting elevation (z) without having first set it.");
102 return this.z != Double.NEGATIVE_INFINITY;
107 public boolean equals(
final Object other) {
108 if (!(other instanceof
Coord)) {
111 Coord o = (
Coord)other;
116 if ( o.
hasZ() )
return false;
119 return (this.x == o.
getX()) && (this.y == o.
getY());
124 if ( !o.
hasZ() )
return false;
128 (this.x == o.
getX()) &&
129 (this.y == o.
getY()) &&
130 (this.z == o.
getZ());
138 long xbits = Double.doubleToLongBits(this.x);
139 long ybits = Double.doubleToLongBits(this.y);
140 long zbits = Double.doubleToLongBits(this.z);
141 int result = (int) (xbits ^ (xbits >>> 32));
142 result = 31 * result + (int) (ybits ^ (ybits >>> 32));
143 result = 31 * result + (int) (zbits ^ (zbits >>> 32));
151 return "[x=" + this.x +
" | y=" + this.y +
"]";
153 return "[x=" + this.x +
" | y=" + this.y +
" | z=" + this.z +
"]";
Coord(final double x, final double y)
Coord(final double x, final double y, final double z)
boolean equals(final Object other)
static final long serialVersionUID