/
OsmNode.java
62 lines (49 loc) · 1.5 KB
/
OsmNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jcan2;
import org.openstreetmap.gui.jmapviewer.Coordinate;
/**
*
* @author Micha
*/
public class OsmNode {
private long id;
private double lat;
private double lon;
private boolean init = false;
private static final double PRECISION = 0.00000001; //precision for double comparison
public OsmNode(){
init = false;
}
public OsmNode(long id, double lat, double lon){
this.id = id;
this.lat = lat;
this.lon = lon;
init = true;
}
public boolean isInit(){return init;}
public double getLon(){return lon;}
public double getLat(){return lat;}
public Coordinate getCoord(){
Coordinate c = new Coordinate(lat,lon);
return c;
}
/**
* Intern function to compare two double values with a certain precision
* stored as a local variable
* @param a double 1 to compare
* @param b double 2 to compare
* @return true when equal
*/
private static boolean equals(double a, double b){
return a == b ? true : Math.abs(a - b) < PRECISION;
}
public static boolean equals(OsmNode n1, OsmNode n2){
if(equals(n1.getLat(),n2.getLat())&&equals(n1.getLon(),n2.getLon()))
return true;
else return false;
}
}