Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1567 #2186

Merged
merged 3 commits into from Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -67,3 +67,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 @@ -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))