@@ -405,6 +405,10 @@ describe('Test scatter', function() {
405
405
406
406
// TODO: test coarser decimation outside plot, and removing very near duplicates from the four of a cluster
407
407
408
+ function reverseXY ( v ) { return [ v [ 1 ] , v [ 0 ] ] ; }
409
+
410
+ function reverseXY2 ( v ) { return v . map ( reverseXY ) ; }
411
+
408
412
it ( 'should clip extreme points without changing on-screen paths' , function ( ) {
409
413
var ptsIn = [
410
414
// first bunch: rays going in/out in many directions
@@ -458,8 +462,6 @@ describe('Test scatter', function() {
458
462
[ [ 2100 , 2100 ] , [ - 2000 , 2100 ] , [ - 2000 , - 2000 ] , [ 2100 , - 2000 ] , [ 2100 , 2100 ] ]
459
463
] ;
460
464
461
- function reverseXY ( v ) { return [ v [ 1 ] , v [ 0 ] ] ; }
462
-
463
465
ptsIn . forEach ( function ( ptsIni , i ) {
464
466
// disable clustering for these tests
465
467
var ptsOut = callLinePoints ( ptsIni , { simplify : false } ) ;
@@ -472,6 +474,47 @@ describe('Test scatter', function() {
472
474
expect ( ptsOut2 [ 0 ] ) . toBeCloseTo2DArray ( ptsExpected [ i ] . map ( reverseXY ) , 1 , i ) ;
473
475
} ) ;
474
476
} ) ;
477
+
478
+ it ( 'works when far off-screen points cross the viewport' , function ( ) {
479
+ function _check ( ptsIn , ptsExpected ) {
480
+ var ptsOut = callLinePoints ( ptsIn ) ;
481
+ expect ( JSON . stringify ( ptsOut ) ) . toEqual ( JSON . stringify ( [ ptsExpected ] ) ) ;
482
+
483
+ var ptsOut2 = callLinePoints ( ptsIn . map ( reverseXY ) ) . map ( reverseXY2 ) ;
484
+ expect ( JSON . stringify ( ptsOut2 ) ) . toEqual ( JSON . stringify ( [ ptsExpected ] ) ) ;
485
+ }
486
+
487
+ // first cross the viewport horizontally/vertically
488
+ _check ( [
489
+ [ - 822 , 20 ] , [ - 802 , 2 ] , [ - 801.5 , 1.1 ] , [ - 800 , 0 ] ,
490
+ [ 900 , 0 ] , [ 901.5 , 1.1 ] , [ 902 , 2 ] , [ 922 , 20 ]
491
+ ] , [
492
+ // all that's really important here (and the next check) is that
493
+ // the points [-800, 0] and [900, 0] are connected. What we do
494
+ // with other points beyond those doesn't matter too much.
495
+ [ - 822 , 20 ] , [ - 800 , 0 ] ,
496
+ [ 900 , 0 ] , [ 922 , 20 ]
497
+ ] ) ;
498
+
499
+ _check ( [
500
+ [ - 804 , 4 ] , [ - 802 , 2 ] , [ - 801.5 , 1.1 ] , [ - 800 , 0 ] ,
501
+ [ 900 , 0 ] , [ 901.5 , 1.1 ] , [ 902 , 2 ] , [ 904 , 4 ]
502
+ ] , [
503
+ [ - 804 , 4 ] , [ - 800 , 0 ] ,
504
+ [ 900 , 0 ]
505
+ ] ) ;
506
+
507
+ // now cross the viewport diagonally
508
+ _check ( [
509
+ [ - 801 , 925 ] , [ - 800 , 902 ] , [ - 800.5 , 901.1 ] , [ - 800 , 900 ] ,
510
+ [ 900 , - 800 ] , [ 900.5 , - 801.1 ] , [ 900 , - 802 ] , [ 901 , - 825 ]
511
+ ] , [
512
+ // similarly here, we just care that
513
+ // [-800, 900] connects to [900, -800]
514
+ [ - 801 , 925 ] , [ - 800 , 900 ] ,
515
+ [ 900 , - 800 ] , [ 901 , - 825 ]
516
+ ] ) ;
517
+ } ) ;
475
518
} ) ;
476
519
477
520
} ) ;
0 commit comments