@@ -954,25 +954,28 @@ <h4 style="font-size:160%;margin:7px">Trigonometry</h4>
954954 // 🔹 Case 1: Exact match
955955 if ( trig [ radKey ] ?. tan !== undefined ) return trig [ radKey ] . tan ;
956956
957- // 🔹 Case 2: 0.8 > x > 0.1 → Use sine reflection
958- if ( radian > 0.1 && radian < 0.8 ) {
957+ // 🔹 Case 2: Reflective zone: 0 < x < 0.8
958+ if ( radian > 0 && radian < 0.8 ) {
959959 const reflected = 1.6 - radian ;
960960 const reflectedKey = `rad(${ reflected . toFixed ( 3 ) } )` ;
961961
962- if ( trig [ reflectedKey ] ?. tan !== undefined ) return trig [ reflectedKey ] . tan ;
962+ let reflectedTan = trig [ reflectedKey ] ? .tan ;
963963
964- const fallbackKey = closestRad ( reflected ) ;
965- const reflectedTan = trig [ fallbackKey ] ?. tan ?? null ;
966- const reciprocal = parseFloat ( ( 1 / reflectedTan ) . toFixed ( 3 ) ) ;
967- return reciprocal
964+ if ( reflectedTan === undefined ) {
965+ const fallbackKey = closestRad ( reflected ) ;
966+ reflectedTan = trig [ fallbackKey ] ?. tan ?? null ;
967+ }
968+
969+ if ( typeof reflectedTan !== 'number' || reflectedTan === 0 ) return null ;
970+
971+ return parseFloat ( ( 1 / reflectedTan ) . toFixed ( 3 ) ) ;
968972 }
969973
970- // 🔹 Case 3: Otherwise, search sin column directly
974+ // 🔹 Case 3: Fallback
971975 const fallbackKey = closestRad ( radian ) ;
972- return trig [ fallbackKey ] ?. tan ?? null ;
976+ return trig [ fallbackKey ] ?. tan ?? null ;
973977}
974978
975-
976979function closestValue ( input , funcType ) {
977980 let bestMatch = null ;
978981 let minDiff = Infinity ;
@@ -1014,7 +1017,7 @@ <h4 style="font-size:160%;margin:7px">Trigonometry</h4>
10141017 const parsed = match . angle . match ( / r a d \( ( [ \d . ] + ) \) / ) ;
10151018 if ( ! parsed ) return null ;
10161019 const reflected = parseFloat ( parsed [ 1 ] ) ;
1017- radian = 1.6 - reflected ;
1020+ radian = parseFloat ( ( 1.6 - reflected ) . toFixed ( 3 ) ) ;
10181021 }
10191022
10201023 return radian ;
0 commit comments