@@ -106,4 +106,36 @@ describe('Chart.helpers.math', function() {
106106 expect ( math . isNumber ( undefined ) ) . toBe ( false ) ;
107107 expect ( math . isNumber ( 'cbc' ) ) . toBe ( false ) ;
108108 } ) ;
109+
110+ it ( 'should compute shortest distance between angles' , function ( ) {
111+ expect ( math . _angleDiff ( 1 , 2 ) ) . toEqual ( - 1 ) ;
112+ expect ( math . _angleDiff ( 2 , 1 ) ) . toEqual ( 1 ) ;
113+ expect ( math . _angleDiff ( 0 , 3.15 ) ) . toBeCloseTo ( 3.13 , 2 ) ;
114+ expect ( math . _angleDiff ( 0 , 3.13 ) ) . toEqual ( - 3.13 ) ;
115+ expect ( math . _angleDiff ( 6.2 , 0 ) ) . toBeCloseTo ( - 0.08 , 2 ) ;
116+ expect ( math . _angleDiff ( 6.3 , 0 ) ) . toBeCloseTo ( 0.02 , 2 ) ;
117+ expect ( math . _angleDiff ( 4 * Math . PI , - 4 * Math . PI ) ) . toBeCloseTo ( 0 , 4 ) ;
118+ expect ( math . _angleDiff ( 4 * Math . PI , - 3 * Math . PI ) ) . toBeCloseTo ( - 3.14 , 2 ) ;
119+ expect ( math . _angleDiff ( 6.28 , 3.1 ) ) . toBeCloseTo ( - 3.1 , 2 ) ;
120+ expect ( math . _angleDiff ( 6.28 , 3.2 ) ) . toBeCloseTo ( 3.08 , 2 ) ;
121+ } ) ;
122+
123+ it ( 'should normalize angles correctly' , function ( ) {
124+ expect ( math . _normalizeAngle ( - Math . PI ) ) . toEqual ( Math . PI ) ;
125+ expect ( math . _normalizeAngle ( Math . PI ) ) . toEqual ( Math . PI ) ;
126+ expect ( math . _normalizeAngle ( 2 ) ) . toEqual ( 2 ) ;
127+ expect ( math . _normalizeAngle ( 5 * Math . PI ) ) . toEqual ( Math . PI ) ;
128+ expect ( math . _normalizeAngle ( - 50 * Math . PI ) ) . toBeCloseTo ( 6.28 , 2 ) ;
129+ } ) ;
130+
131+ it ( 'should determine if angle is between boundaries' , function ( ) {
132+ expect ( math . _angleBetween ( 2 , 1 , 3 ) ) . toBeTrue ( ) ;
133+ expect ( math . _angleBetween ( 2 , 3 , 1 ) ) . toBeFalse ( ) ;
134+ expect ( math . _angleBetween ( - 3.14 , 2 , 4 ) ) . toBeTrue ( ) ;
135+ expect ( math . _angleBetween ( - 3.14 , 4 , 2 ) ) . toBeFalse ( ) ;
136+ expect ( math . _angleBetween ( 0 , - 1 , 1 ) ) . toBeTrue ( ) ;
137+ expect ( math . _angleBetween ( - 1 , 0 , 1 ) ) . toBeFalse ( ) ;
138+ expect ( math . _angleBetween ( - 15 * Math . PI , 3.1 , 3.2 ) ) . toBeTrue ( ) ;
139+ expect ( math . _angleBetween ( 15 * Math . PI , - 3.2 , - 3.1 ) ) . toBeTrue ( ) ;
140+ } ) ;
109141} ) ;
0 commit comments