Skip to content

Commit

Permalink
Merge pull request #2186 from royels/1567
Browse files Browse the repository at this point in the history
issue-1567
  • Loading branch information
xdan committed Jul 16, 2020
2 parents 775537b + 21d0cc8 commit 8f42760
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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);
};
21 changes: 21 additions & 0 deletions 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);
};
21 changes: 21 additions & 0 deletions 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);
};
19 changes: 19 additions & 0 deletions 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];
}
3 changes: 3 additions & 0 deletions lib/functions/index.js
Expand Up @@ -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');
Expand Down
9 changes: 9 additions & 0 deletions test/cases/bifs.math.css
Expand Up @@ -71,3 +71,12 @@
test8: -0.707106781;
test9: -0.5;
}
.math_atan {
test1: 45deg;
}
.math_asin {
test1: 44.999999985deg;
}
.math_acos {
test1: 45.000000015deg;
}
9 changes: 9 additions & 0 deletions test/cases/bifs.math.styl
Expand Up @@ -66,3 +66,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))

0 comments on commit 8f42760

Please sign in to comment.