@@ -163,15 +163,21 @@ public static int wrapDegrees(int angle) {
163163 }
164164
165165 public static float sin (float v ) {
166- return MathHelper .sin (v );
166+ // MathHelper.sin doesn't account for negative numbers
167+ // with the point symmetry property of sin we can easily fix it
168+ // if v is negative, negate the input and then the output
169+ float s = Math .signum (v );
170+ return s * MathHelper .sin (s * v );
167171 }
168172
169173 public static float cos (float v ) {
170- return MathHelper .cos (v );
174+ // MathHelper.cos doesn't account for negative numbers
175+ // with the axis symmetry property of cos we can easily fix it
176+ return MathHelper .cos (Math .abs (v ));
171177 }
172178
173179 public static float tan (float v ) {
174- return MathHelper . sin (v ) / MathHelper . cos (v );
180+ return sin (v ) / cos (v );
175181 }
176182
177183 public static double sqrt (double v ) {
@@ -181,21 +187,4 @@ public static double sqrt(double v) {
181187 public static float sqrt (float v ) {
182188 return (float ) Math .sqrt (v );
183189 }
184-
185- /**
186- * Computes 1/sqrt(n) using <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">the fast inverse square
187- * root</a> with a constant of 0x5FE6EB50C7B537AA.
188- */
189- public static double fastInvSqrt (double v ) {
190- double d0 = 0.5D * v ;
191- long i = Double .doubleToRawLongBits (v );
192- i = 6910469410427058090L - (i >> 1 );
193- v = Double .longBitsToDouble (i );
194- v = v * (1.5D - d0 * v * v );
195- return v ;
196- }
197-
198- public static float fastInvSqrt (float v ) {
199- return (float ) fastInvSqrt ((double ) v );
200- }
201190}
0 commit comments