@@ -232,6 +232,7 @@ export let Polyline = (function() {
232
232
return false ;
233
233
}
234
234
235
+
235
236
noSmallCheck = noSmallCheck === true || false ;
236
237
noStroke = noStroke === true || false ;
237
238
@@ -269,28 +270,37 @@ export let Polyline = (function() {
269
270
let ymin = Number . POSITIVE_INFINITY
270
271
let ymax = Number . NEGATIVE_INFINITY ;
271
272
273
+
274
+
275
+ let behind = true ;
272
276
for ( var k = 0 ; k < len ; k ++ ) {
273
277
var xyview = view . aladin . world2pix ( this . raDecArray [ k ] [ 0 ] , this . raDecArray [ k ] [ 1 ] ) ;
278
+
274
279
if ( ! xyview ) {
275
- return false ;
280
+ xyView . push ( undefined ) ;
281
+ } else {
282
+ behind = false ;
283
+ let [ x , y ] = xyview
284
+ xyView . push ( { x, y} ) ;
285
+
286
+ xmin = Math . min ( xmin , x ) ;
287
+ ymin = Math . min ( ymin , y ) ;
288
+ xmax = Math . max ( xmax , x ) ;
289
+ ymax = Math . max ( ymax , y ) ;
276
290
}
277
-
278
- xyView . push ( { x : xyview [ 0 ] , y : xyview [ 1 ] } ) ;
279
-
280
- xmin = Math . min ( xmin , xyview [ 0 ] ) ;
281
- ymin = Math . min ( ymin , xyview [ 1 ] ) ;
282
- xmax = Math . max ( xmax , xyview [ 0 ] ) ;
283
- ymax = Math . max ( ymax , xyview [ 1 ] ) ;
284
291
}
285
292
293
+ if ( behind )
294
+ return false ;
295
+
286
296
// 2. do not draw the polygon if it lies outside the view
287
297
if ( xmax < 0 || xmin > view . width || ymax < 0 || ymin > view . height ) {
288
298
return false ;
289
299
}
290
300
291
301
// do not draw neither if the polygone does not lie inside lineWidth
292
302
if ( ! noSmallCheck ) {
293
- this . isTooSmall = ( xmax - xmin ) < this . lineWidth || ( ymax - ymin ) < this . lineWidth ;
303
+ this . isTooSmall = ( xmax - xmin ) < this . lineWidth && ( ymax - ymin ) < this . lineWidth ;
294
304
295
305
if ( this . isTooSmall ) {
296
306
return false ;
@@ -302,6 +312,10 @@ export let Polyline = (function() {
302
312
303
313
if ( view . projection === ProjectionEnum . SIN ) {
304
314
drawLine = ( v0 , v1 ) => {
315
+ if ( v0 === undefined || v1 === undefined ) {
316
+ return false ;
317
+ }
318
+
305
319
const l = { x1 : v0 . x , y1 : v0 . y , x2 : v1 . x , y2 : v1 . y } ;
306
320
307
321
if ( Polyline . isInsideView ( l . x1 , l . y1 , l . x2 , l . y2 , view . width , view . height ) ) {
@@ -311,6 +325,9 @@ export let Polyline = (function() {
311
325
312
326
if ( this . closed && this . fill ) {
313
327
fillPoly = ( v0 , v1 , index ) => {
328
+ if ( v0 === undefined || v1 === undefined )
329
+ return false ;
330
+
314
331
const l = { x1 : v0 . x , y1 : v0 . y , x2 : v1 . x , y2 : v1 . y } ;
315
332
316
333
if ( index === 0 ) {
@@ -391,7 +408,6 @@ export let Polyline = (function() {
391
408
v1 = v1 + 1 ;
392
409
}
393
410
394
- //ctx.globalAlpha = 1;
395
411
ctx . save ( ) ;
396
412
ctx . fillStyle = this . fillColor ;
397
413
ctx . globalAlpha = this . opacity ;
@@ -409,30 +425,41 @@ export let Polyline = (function() {
409
425
for ( var j = 0 ; j < this . raDecArray . length ; j ++ ) {
410
426
var xy = view . aladin . world2pix ( this . raDecArray [ j ] [ 0 ] , this . raDecArray [ j ] [ 1 ] ) ;
411
427
if ( ! xy ) {
412
- return false ;
428
+ pointXY . push ( undefined )
429
+ } else {
430
+ pointXY . push ( {
431
+ x : xy [ 0 ] ,
432
+ y : xy [ 1 ]
433
+ } ) ;
413
434
}
414
- pointXY . push ( {
415
- x : xy [ 0 ] ,
416
- y : xy [ 1 ]
417
- } ) ;
418
435
}
419
436
420
437
const lastPointIdx = pointXY . length - 1 ;
421
438
for ( var l = 0 ; l < lastPointIdx ; l ++ ) {
422
- const line = { x1 : pointXY [ l ] . x , y1 : pointXY [ l ] . y , x2 : pointXY [ l + 1 ] . x , y2 : pointXY [ l + 1 ] . y } ; // new segment
423
- _drawLine ( line , ctx , true ) ;
439
+ let v1 = pointXY [ l ] ;
440
+ let v2 = pointXY [ l + 1 ] ;
424
441
425
- if ( ctx . isPointInStroke ( x , y ) ) { // x,y is on line?
426
- return true ;
442
+ if ( v1 && v2 ) {
443
+ const line = { x1 : v1 . x , y1 : v1 . y , x2 : v2 . x , y2 : v2 . y } ; // new segment
444
+ _drawLine ( line , ctx , true ) ;
445
+
446
+ if ( ctx . isPointInStroke ( x , y ) ) { // x, y is on line?
447
+ return true ;
448
+ }
427
449
}
428
450
}
429
451
430
452
if ( this . closed ) {
431
- const line = { x1 : pointXY [ lastPointIdx ] . x , y1 : pointXY [ lastPointIdx ] . y , x2 : pointXY [ 0 ] . x , y2 : pointXY [ 0 ] . y } ; // new segment
432
- _drawLine ( line , ctx , true ) ;
453
+ let v1 = pointXY [ lastPointIdx ] ;
454
+ let v2 = pointXY [ 0 ] ;
433
455
434
- if ( ctx . isPointInStroke ( x , y ) ) { // x,y is on line?
435
- return true ;
456
+ if ( v1 && v2 ) {
457
+ const line = { x1 : v1 . x , y1 : v1 . y , x2 : v2 . x , y2 : v2 . y } ; // new segment
458
+ _drawLine ( line , ctx , true ) ;
459
+
460
+ if ( ctx . isPointInStroke ( x , y ) ) { // x,y is on line?
461
+ return true ;
462
+ }
436
463
}
437
464
}
438
465
0 commit comments