001// License: GPL. For details, see Readme.txt file. 002package org.openstreetmap.gui.jmapviewer; 003 004import java.awt.geom.Point2D; 005import java.io.IOException; 006import java.io.ObjectInputStream; 007import java.io.ObjectOutputStream; 008import java.util.Objects; 009 010import org.openstreetmap.gui.jmapviewer.interfaces.IProjected; 011 012/** 013 * Projected coordinates represented by an encapsulates a Point2D.Double value. 014 */ 015public class Projected implements IProjected { 016 private transient Point2D.Double data; 017 018 /** 019 * Constructs a new {@code Projected}. 020 * @param east easting 021 * @param north northing 022 */ 023 public Projected(double east, double north) { 024 data = new Point2D.Double(east, north); 025 } 026 027 @Override 028 public double getEast() { 029 return data.x; 030 } 031 032 @Override 033 public double getNorth() { 034 return data.y; 035 } 036 037 private void writeObject(ObjectOutputStream out) throws IOException { 038 out.writeObject(data.x); 039 out.writeObject(data.y); 040 } 041 042 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 043 data = new Point2D.Double(); 044 data.x = (Double) in.readObject(); 045 data.y = (Double) in.readObject(); 046 } 047 048 @Override 049 public String toString() { 050 return "Projected[" + data.y + ", " + data.x + ']'; 051 } 052 053 @Override 054 public int hashCode() { 055 int hash = 3; 056 hash = 61 * hash + Objects.hashCode(this.data); 057 return hash; 058 } 059 060 @Override 061 public boolean equals(Object obj) { 062 if (obj == null) { 063 return false; 064 } 065 if (getClass() != obj.getClass()) { 066 return false; 067 } 068 final Projected other = (Projected) obj; 069 return Objects.equals(this.data, other.data); 070 } 071} 072