Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Fuzzie on Jan 24, 2015, 12:45 PM

Title: Degrees to Radian and Radian to Degrees
Post by: Fuzzie on Jan 24, 2015, 12:45 PM
Just a small snippet for those who don't know how to use radians. You don't have to give me credits for anything just use it as you wish.

function DegtoRad( degree ){
return degree * ( PI/ 180 );
}

function RadtoDeg( radian ){
return radian * ( 180 / PI );
}
Title: Re: Degrees to Radian and Radian to Degrees
Post by: . on Jan 24, 2015, 12:51 PM
What's the point of declaring a variable inside a function only to use it once :-\ You're just wasting instructions in the Squirrel Virtual Machine. Not to mention the PI is a constant built into the language.

function DegtoRad( degree ){
return degree * ( PI / 180 );
}

function RadtoDeg( radian ){
return radian * ( 180 / PI );
}
Title: Re: Degrees to Radian and Radian to Degrees
Post by: Fuzzie on Jan 24, 2015, 12:56 PM
Updated. It's been awhile since I last coded Squirrel extensively so I may have forgotten several things. Thanks for pointing it out though.
Title: Re: Degrees to Radian and Radian to Degrees
Post by: Gudio on Jan 24, 2015, 01:35 PM
const ToRadian = 0.0174533;
const ToDegrees = 57.2958;

function DegtoRad( degree ) return degree * ToRadian;
function RadtoDeg( radian ) return radian * ToDegrees;

* Gudio wins!
Title: Re: Degrees to Radian and Radian to Degrees
Post by: . on Jan 24, 2015, 01:51 PM
Quote from: Gudio on Jan 24, 2015, 01:35 PMconst ToRadian = 0.0174533;
const ToDegrees = 57.2958;

function DegtoRad( degree ) return degree * ToRadian;
function RadtoDeg( radian ) return radian * ToDegrees;

* Gudio wins!

function DegtoRad( degree ) return degree * 0.0174533;
function RadtoDeg( radian ) return radian * 57.2958;

Easier to push a literal value directly than a reference to a value that must be dereferenced later :D Though it's a waste of time.