1+ import { describe , it , expect } from 'vitest'
2+ import { geodeticToAuthalic , authalicToGeodetic } from 'a5/core/authalic'
3+ import type { Radians } from 'a5/core/coordinate-systems'
4+
5+ describe ( 'Authalic Conversion' , ( ) => {
6+ describe ( 'geodeticToAuthalic' , ( ) => {
7+ it ( 'converts zero latitude' , ( ) => {
8+ const result = geodeticToAuthalic ( 0 as Radians )
9+ expect ( result ) . toBeCloseTo ( 0 , 10 )
10+ } )
11+
12+ it ( 'converts small latitudes' , ( ) => {
13+ const input = Math . PI / 180 as Radians // 1 degree
14+ const result = geodeticToAuthalic ( input )
15+ expect ( result ) . toBeCloseTo ( input , 2 )
16+ } )
17+
18+ it ( 'converts medium latitudes' , ( ) => {
19+ const input = Math . PI / 4 as Radians // 45 degrees
20+ const result = geodeticToAuthalic ( input )
21+ expect ( result ) . toBeCloseTo ( input , 2 )
22+ } )
23+
24+ it ( 'converts large latitudes' , ( ) => {
25+ const input = Math . PI / 2 as Radians // 90 degrees
26+ const result = geodeticToAuthalic ( input )
27+ expect ( result ) . toBeCloseTo ( input , 2 )
28+ } )
29+
30+ it ( 'converts negative latitudes' , ( ) => {
31+ const input = - Math . PI / 4 as Radians // -45 degrees
32+ const result = geodeticToAuthalic ( input )
33+ expect ( result ) . toBeCloseTo ( input , 2 )
34+ } )
35+ } )
36+
37+ describe ( 'authalicToGeodetic' , ( ) => {
38+ it ( 'converts zero latitude' , ( ) => {
39+ const result = authalicToGeodetic ( 0 as Radians )
40+ expect ( result ) . toBeCloseTo ( 0 , 10 )
41+ } )
42+
43+ it ( 'converts small latitudes' , ( ) => {
44+ const input = Math . PI / 180 as Radians // 1 degree
45+ const result = authalicToGeodetic ( input )
46+ expect ( result ) . toBeCloseTo ( input , 2 )
47+ } )
48+
49+ it ( 'converts medium latitudes' , ( ) => {
50+ const input = Math . PI / 4 as Radians // 45 degrees
51+ const result = authalicToGeodetic ( input )
52+ expect ( result ) . toBeCloseTo ( input , 2 )
53+ } )
54+
55+ it ( 'converts large latitudes' , ( ) => {
56+ const input = Math . PI / 2 as Radians // 90 degrees
57+ const result = authalicToGeodetic ( input )
58+ expect ( result ) . toBeCloseTo ( input , 2 )
59+ } )
60+
61+ it ( 'converts negative latitudes' , ( ) => {
62+ const input = - Math . PI / 4 as Radians // -45 degrees
63+ const result = authalicToGeodetic ( input )
64+ expect ( result ) . toBeCloseTo ( input , 2 )
65+ } )
66+ } )
67+
68+ describe ( 'round-trip conversion' , ( ) => {
69+ it ( 'preserves latitude through geodetic->authalic->geodetic conversion for all latitudes' , ( ) => {
70+ for ( let deg = - 90 ; deg <= 90 ; deg ++ ) {
71+ const lat = ( deg * Math . PI / 180 ) as Radians
72+ const authalic = geodeticToAuthalic ( lat )
73+ const geodetic = authalicToGeodetic ( authalic )
74+ expect ( geodetic ) . toBeCloseTo ( lat , 15 )
75+ }
76+ } )
77+
78+ it ( 'preserves latitude through authalic->geodetic->authalic conversion for all latitudes' , ( ) => {
79+ for ( let deg = - 90 ; deg <= 90 ; deg ++ ) {
80+ const lat = ( deg * Math . PI / 180 ) as Radians
81+ const geodetic = authalicToGeodetic ( lat )
82+ const authalic = geodeticToAuthalic ( geodetic )
83+ expect ( authalic ) . toBeCloseTo ( lat , 15 )
84+ }
85+ } )
86+ } )
87+
88+ describe ( 'specific conversion values' , ( ) => {
89+ it ( 'matches reference conversion values' , ( ) => {
90+ const testCases = [
91+ { geodetic : - 90 , authalic : - 90.0000 } ,
92+ { geodetic : - 67.5 , authalic : - 67.4092 } ,
93+ { geodetic : - 45 , authalic : - 44.8717 } ,
94+ { geodetic : - 22.5 , authalic : - 22.4094 } ,
95+ { geodetic : 0 , authalic : 0 } ,
96+ { geodetic : 22.5 , authalic : 22.4094 } ,
97+ { geodetic : 45 , authalic : 44.8717 } ,
98+ { geodetic : 67.5 , authalic : 67.4092 } ,
99+ { geodetic : 90 , authalic : 90.0000 }
100+ ]
101+
102+ testCases . forEach ( ( { geodetic, authalic } ) => {
103+ const geodeticRad = ( geodetic * Math . PI / 180 ) as Radians
104+ const authalicRad = ( authalic * Math . PI / 180 ) as Radians
105+ const result = geodeticToAuthalic ( geodeticRad )
106+ expect ( result ) . toBeCloseTo ( authalicRad , 5 )
107+ } )
108+ } )
109+ } )
110+ } )
0 commit comments