CoordinateRadius.java
5.23 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* ESO Archive
*
* $Id: CoordinateRadius.java,v 1.1.1.1 2009/02/17 22:50:03 abrighto Exp $
*
* who when what
* -------------- ---------- ----------------------------------------
* Allan Brighton 1999/05/18 Created
*/
package jsky.coords;
import java.io.Serializable;
/**
* Represents a generic center coordinate and radius range (or width
* and height), Some methods are provided to check if another
* coordinate point lies within the range. The coordinates and radius
* (or width and height) values are treated in a generic way.
*/
public class CoordinateRadius implements Serializable {
/** Center position in a supported coordinate system */
protected Coordinates centerPosition;
/** Min radius from center in arcmin (or pixel, if using pixel coordinates) */
protected double minRadius;
/** Max radius from center in arcmin (or pixel, if using pixel coordinates) */
protected double maxRadius;
/** Width about the center in arcmin (or pixel, if using pixel coordinates) (optional) */
protected double width;
/** Height about the center in arcmin (or pixel, if using pixel coordinates) (optional) */
protected double height;
/**
* Initialize from the given center position and radius range.
* The units of the radius values depend on the type of the coordinates,
* for example arcmin for world coordinates, pixel for image coordinates.
*
* @param pos the center position.
* @param minRadius the minimum radius from the center position
* @param maxRadius the maximum radius from the center position
*/
public CoordinateRadius(Coordinates pos, double minRadius, double maxRadius) {
this.centerPosition = pos;
this.minRadius = Math.min(minRadius, maxRadius);
this.maxRadius = Math.max(minRadius, maxRadius);
width = height = 2.0 * Math.sqrt(0.5 * maxRadius * maxRadius);
}
/**
* Initialize from the given center position and radius.
* The units of the radius values depend on the type of the coordinates,
* for example arcmin for world coordinates, pixel for image coordinates.
*
* @param pos the center position.
* @param maxRadius the maximum radius from the center position
*/
public CoordinateRadius(Coordinates pos, double maxRadius) {
this.centerPosition = pos;
this.minRadius = 0.0;
this.maxRadius = maxRadius;
width = height = 2.0 * Math.sqrt(0.5 * maxRadius * maxRadius);
}
/**
* Initialize from the given center position, width and height.
* The units of the width and height depend on the type of the coordinates,
* for example arcmin for world coordinates, pixel for image coordinates.
*
* @param pos the center position.
* @param maxRadius the maximum radius from the center position
* @param width the width of the image area, about the center
* @param height the height of the image area, about the center
*/
public CoordinateRadius(Coordinates pos, double maxRadius, double width, double height) {
this.centerPosition = pos;
this.width = width;
this.height = height;
this.minRadius = 0.0;
this.maxRadius = maxRadius;
}
/**
* Initialize from the given center position, width and height.
* The units of the width and height depend on the type of the coordinates,
* for example arcmin for world coordinates, pixel for image coordinates.
*
* @param pos the center position.
* @param width the width of the image area, about the center
* @param height the height of the image area, about the center
* @param minRadius the minimum radius from the center position
* @param maxRadius the maximum radius from the center position
*/
public CoordinateRadius(Coordinates pos, double minRadius, double maxRadius, double width, double height) {
this.centerPosition = pos;
this.width = width;
this.height = height;
this.minRadius = minRadius;
this.maxRadius = maxRadius;
}
/** Return the center position. */
public Coordinates getCenterPosition() {
return centerPosition;
}
/** Return the min radius value in arcmin (or pixel, if using pixel coordinates). */
public double getMinRadius() {
return minRadius;
}
/** Return the max radius value in arcmin (or pixel, if using pixel coordinates). */
public double getMaxRadius() {
return maxRadius;
}
/** Return the width in arcmin (or pixel, if using pixel coordinates), if set, otherwise 0. */
public double getWidth() {
return width;
}
/** Return the height in arcmin (or pixel, if using pixel coordinates), if set, otherwise 0. */
public double getHeight() {
return height;
}
/**
* Return true if the given coordinate position lies within the
* region defined by this object.
*/
public boolean contains(Coordinates pos) {
double dist = centerPosition.dist(pos);
return (dist >= minRadius && dist <= maxRadius);
}
/**
* Return coordinates and radius as a string.
*/
public String toString() {
return "(" + centerPosition + ", " + minRadius + ", " + maxRadius + ")";
}
}