diff --git a/lib/functions/acos.js b/lib/functions/acos.js new file mode 100644 index 000000000..f4479db97 --- /dev/null +++ b/lib/functions/acos.js @@ -0,0 +1,20 @@ +var utils = require('../utils') + , nodes = require('../nodes') + , convert = require('./convert-angle') + , asin = require('./asin'); + +/** + * Return the arccosine of the given `value`. + * + * @param {Double} trigValue + * @param {Unit} output + * @return {Unit} + * @api public + */ +module.exports = function acos(trigValue, output) { + var output = typeof output !== 'undefined' ? output : 'deg'; + var convertedValue = convert(Math.PI / 2, output) - asin(trigValue, output).val; + var m = Math.pow(10, 9); + convertedValue = Math.round(convertedValue * m) / m; + return new nodes.Unit(convertedValue, output); +}; diff --git a/lib/functions/asin.js b/lib/functions/asin.js new file mode 100644 index 000000000..5cfbcff78 --- /dev/null +++ b/lib/functions/asin.js @@ -0,0 +1,21 @@ +var utils = require('../utils') + , nodes = require('../nodes') + , convert = require('./convert-angle'); + +/** + * Return the arcsine of the given `value`. + * + * @param {Double} trigValue + * @param {Unit} output + * @return {Unit} + * @api public + */ + +module.exports = function atan(trigValue, output) { + var output = typeof output !== 'undefined' ? output : 'deg'; + var m = Math.pow(10, 9); + var value = Math.asin(trigValue) ; + var convertedValue = convert(value, output); + convertedValue = Math.round(convertedValue * m) / m; + return new nodes.Unit(convertedValue, output); +}; diff --git a/lib/functions/atan.js b/lib/functions/atan.js new file mode 100644 index 000000000..90501650d --- /dev/null +++ b/lib/functions/atan.js @@ -0,0 +1,21 @@ +var utils = require('../utils') + , nodes = require('../nodes') + , convert = require('./convert-angle'); + +/** + * Return the arctangent of the given `value`. + * + * @param {Double} trigValue + * @param {Unit} output + * @return {Unit} + * @api public + */ + +module.exports = function atan(trigValue, output) { + var output = typeof output !== 'undefined' ? output : 'deg'; + var value = Math.atan(trigValue) ; + var m = Math.pow(10, 9); + var convertedValue = convert(value, output); + convertedValue = Math.round(convertedValue * m) / m; + return new nodes.Unit(convertedValue, output); +}; diff --git a/lib/functions/convert-angle.js b/lib/functions/convert-angle.js new file mode 100644 index 000000000..d0832f26e --- /dev/null +++ b/lib/functions/convert-angle.js @@ -0,0 +1,19 @@ + +/** + * Convert given value's base into the parameter unitName + * + * @param {Double} value + * @param {String} unitName + * @return {Double} + * @api private + */ + +module.exports = function convertAngle(value, unitName) { + var factors = { + "rad" : 1, + "deg" : 180 / Math.PI, + "turn": 0.5 / Math.PI, + "grad": 200 / Math.PI + } + return value * factors[unitName]; +} diff --git a/lib/functions/index.js b/lib/functions/index.js index e292ed474..ec2a372a2 100644 --- a/lib/functions/index.js +++ b/lib/functions/index.js @@ -46,6 +46,9 @@ exports.red = require('./red'); exports.remove = require('./remove'); exports.replace = require('./replace'); exports.rgb = require('./rgb'); +exports.atan = require('./atan'); +exports.asin = require('./asin'); +exports.acos = require('./acos'); exports.rgba = require('./rgba'); exports.s = require('./s'); exports.saturation = require('./saturation'); diff --git a/test/cases/bifs.math.css b/test/cases/bifs.math.css index 632a7a9fb..d56444912 100644 --- a/test/cases/bifs.math.css +++ b/test/cases/bifs.math.css @@ -67,3 +67,12 @@ test8: -0.707106781; test9: -0.5; } +.math_atan { + test1: 45deg; +} +.math_asin { + test1: 44.999999985deg; +} +.math_acos { + test1: 45.000000015deg; +} diff --git a/test/cases/bifs.math.styl b/test/cases/bifs.math.styl index 0195ea877..aaba9310f 100644 --- a/test/cases/bifs.math.styl +++ b/test/cases/bifs.math.styl @@ -62,3 +62,12 @@ test7: sin(5*PI/3) test8: sin(7*PI/4) test9: sin(11*PI/6) + +.math_atan + test1: atan(tan(45deg)) + +.math_asin + test1: asin(sin(45deg)) + +.math_acos + test1: acos(cos(45deg))