View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.storyworld.perception;
2   
3   import javax.vecmath.Point3d;
4   
5   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
6   
7   
8   public class SPLocation {
9   	
10  	private double x;
11  	
12  	private double y;
13  	
14  	private double z;
15  	
16  	private Object point3DMutex = new Object();
17  	
18  	private Point3d point3D = null;
19  
20  	private Object locationMutex = new Object();
21  
22  	private Location location = null;
23  	
24  	public SPLocation() {
25  		this(0,0,0);
26  	}
27  
28  	public SPLocation(double x, double y, double z) {
29  		this.x = x;
30  		this.y = y;
31  		this.z = z;
32  	}
33  	
34  	public SPLocation(Location location) {
35  		this(location.x, location.y, location.z);
36  	}
37  	
38  	/**
39  	 * Used by XStream after deserialization.
40  	 * @return
41  	 */
42  	private SPLocation readResolve() {
43  		point3DMutex = new Object();
44  		return this;
45  	}
46  	
47  	public boolean equals(Object obj) {
48  		if (obj == null) return false;
49  		if (!(obj instanceof SPLocation)) return false;
50  		SPLocation location = (SPLocation) obj;
51  		return asPoint3d().epsilonEquals(location.asPoint3d(), 1);
52  	}
53  	
54  	public Point3d asPoint3d() {
55  		synchronized(point3DMutex) {
56  			if (point3D != null) return point3D;
57  			point3D = new Point3d(x, y, z);
58  			return point3D;				
59  		}
60  	}
61  	
62  	public Location asLocation() {
63  		synchronized(locationMutex ) {
64  			if (location != null) return location;
65  			location = new Location(x, y, z);
66  			return location;				
67  		}
68  	}
69  
70  	
71  	public double getX() {
72  		return x;
73  	}
74  
75  	public void setX(double x) {
76  		this.x = x;
77  	}
78  
79  	public double getY() {
80  		return y;
81  	}
82  
83  	public void setY(double y) {
84  		this.y = y;
85  	}
86  
87  	public double getZ() {
88  		return z;		
89  	}
90  
91  	public void setZ(double z) {
92  		this.z = z;
93  	}
94  	
95  	public double distance(SPLocation location) {
96  		return asPoint3d().distance(location.asPoint3d());
97  	}
98  	
99  	public String toString() {
100 		return "SPLocation[" + x + ", " + y + ", " + z + "]";
101 	}
102 	
103 }