@@ -222,21 +222,50 @@ export let Circle = (function() {
222
222
223
223
let hidden = true ;
224
224
225
- var ra , dec , vertOnCircle , dx , dy ;
226
- this . radius = Number . NEGATIVE_INFINITY ;
227
225
228
226
// Project 4 points lying on the circle and take the minimal dist with the center as radius
229
- [ [ - 1 , 0 ] , [ 1 , 0 ] , [ 0 , - 1 ] , [ 0 , 1 ] ] . forEach ( ( [ cardDirRa , cardDirDec ] ) => {
230
- ra = this . centerRaDec [ 0 ] + cardDirRa * this . radiusDegrees ;
231
- dec = this . centerRaDec [ 1 ] + cardDirDec * this . radiusDegrees ;
227
+ const degToRad = Math . PI / 180 ;
228
+ const radToDeg = 180 / Math . PI ;
229
+ const sampleCoordinates = [ ] ;
230
+ const radiusRadians = this . radiusDegrees * degToRad ;
231
+ const raCenterRadians = this . centerRaDec [ 0 ] * degToRad ;
232
+ const decCenterRadians = this . centerRaDec [ 1 ] * degToRad ;
233
+ // compute 4 sample coordinates lying on the circle
234
+ for ( let i = 0 ; i < 4 ; i ++ ) {
235
+ const phi = i * 2 * Math . PI / 4 ;
236
+
237
+ const sampleDec = Math . asin (
238
+ Math . sin ( decCenterRadians ) * Math . cos ( radiusRadians ) +
239
+ Math . cos ( decCenterRadians ) * Math . sin ( radiusRadians ) * Math . cos ( phi )
240
+ ) ;
241
+
242
+ const sampleRa = raCenterRadians + Math . atan2 (
243
+ Math . sin ( phi ) * Math . sin ( radiusRadians ) * Math . cos ( decCenterRadians ) ,
244
+ Math . cos ( radiusRadians ) - Math . sin ( decCenterRadians ) * Math . sin ( sampleDec )
245
+ ) ;
246
+
247
+ // Normalize RA to [0, 2π] and convert to degrees
248
+ const sampleRaDeg = radToDeg * ( ( sampleRa + 2 * Math . PI ) % ( 2 * Math . PI ) ) ;
249
+ const sampleDecDeg = radToDeg * sampleDec ;
250
+
251
+ sampleCoordinates . push ( [ sampleRaDeg , sampleDecDeg ] ) ;
252
+ }
232
253
254
+ let vertOnCircle , dx , dy ;
255
+ this . radius = Number . NEGATIVE_INFINITY ;
256
+ sampleCoordinates . forEach ( ( [ ra , dec ] ) => {
233
257
vertOnCircle = view . aladin . world2pix ( ra , dec ) ;
234
258
235
259
if ( vertOnCircle ) {
236
260
dx = vertOnCircle [ 0 ] - this . center . x ;
237
261
dy = vertOnCircle [ 1 ] - this . center . y ;
238
262
239
- this . radius = Math . max ( Math . sqrt ( dx * dx + dy * dy ) , this . radius ) ;
263
+ if ( this . radius !== Number . NEGATIVE_INFINITY ) {
264
+ this . radius = Math . min ( Math . sqrt ( dx * dx + dy * dy ) , this . radius ) ;
265
+ }
266
+ else {
267
+ this . radius = Math . sqrt ( dx * dx + dy * dy ) ;
268
+ }
240
269
241
270
hidden = false ;
242
271
}
@@ -245,6 +274,7 @@ export let Circle = (function() {
245
274
if ( hidden ) {
246
275
return false ;
247
276
}
277
+
248
278
// Then we can draw
249
279
250
280
var baseColor = this . color ;
0 commit comments