MathSass 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +200 -0
- data/dist/_MathSass.scss +41 -0
- data/dist/_constants.scss +5 -0
- data/dist/functions/_acos.scss +12 -0
- data/dist/functions/_asin.scss +12 -0
- data/dist/functions/_atan.scss +28 -0
- data/dist/functions/_atan2.scss +37 -0
- data/dist/functions/_cos.scss +13 -0
- data/dist/functions/_cot.scss +9 -0
- data/dist/functions/_csc.scss +9 -0
- data/dist/functions/_exp.scss +12 -0
- data/dist/functions/_fact.scss +18 -0
- data/dist/functions/_frexp.scss +21 -0
- data/dist/functions/_ldexp.scss +17 -0
- data/dist/functions/_log.scss +24 -0
- data/dist/functions/_pow.scss +28 -0
- data/dist/functions/_sec.scss +9 -0
- data/dist/functions/_sin.scss +9 -0
- data/dist/functions/_sqrt.scss +16 -0
- data/dist/functions/_tan.scss +9 -0
- data/dist/helpers/_deg-to-rad.scss +4 -0
- data/dist/helpers/_rad-to-deg.scss +4 -0
- data/dist/helpers/_strip-unit.scss +8 -0
- data/dist/helpers/_unitless-rad.scss +13 -0
- data/lib/MathSass.rb +13 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzAzYzQwNDY3ZGFjNzQzZTZhZTg1YzI5ODJiYjRkNGU2NjU2NjI2Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NmVhNzczMTdmYzUyNjFiNDYyNGRlMGQwZDUzMGI2MTA2YmFlZGRjMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzYzYWIzOTdkMmM5ZGEzNDNiZmQyZTdiOTM3YzM4OTk5MGRkYjdjZTZjYzg2
|
10
|
+
NTQ5MDNhMWEzYmEzMWZhNjhhMGQzMGFhYzUxMTkzZDNhMDcyYWM1ZTkwOWI1
|
11
|
+
ODYzNDUyODFlZTMzYWI0MGZhYzNiZTkyM2Q0MzU4M2RhZmViMTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmVhNmU1NWIxNGMyMTY0MDA2YTU5MzE4ZjBlZjNhMjFiODcxMmQ3NzFhNDgz
|
14
|
+
MTM2YmRkMTg1ODZlNzQ1ZjljZWY3YmZhZGJiOTNiOTUxMTA1YWIzYjYzMWEx
|
15
|
+
YTEzODRkNmM5ZmFlODMyYTVhNmU2MTQwY2Y4MGJiNjAwYmY0NjY=
|
data/README.md
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
# MathSass [](http://badge.fury.io/js/mathsass) [](https://travis-ci.org/terkel/mathsass) [](https://david-dm.org/terkel/mathsass) [](https://david-dm.org/terkel/mathsass#info=devDependencies)
|
2
|
+
|
3
|
+
A Sass implementation of mathematical functions.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
#### Git
|
8
|
+
|
9
|
+
```
|
10
|
+
git clone git@github.com:terkel/mathsass.git && cd mathsass
|
11
|
+
```
|
12
|
+
|
13
|
+
#### Bower
|
14
|
+
|
15
|
+
```
|
16
|
+
bower install mathsass --save-dev
|
17
|
+
```
|
18
|
+
|
19
|
+
#### npm
|
20
|
+
|
21
|
+
```
|
22
|
+
npm install mathsass --save-dev
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Import `dist/MathSass.scss` partial to the Sass document.
|
28
|
+
|
29
|
+
```scss
|
30
|
+
@import "path/to/dist/MathSass";
|
31
|
+
|
32
|
+
.content {
|
33
|
+
height: 200px;
|
34
|
+
width: 200px / tan(60deg); // 115.47005px
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
If you installed via Npm the path will be: `node_modules/mathsass/dist/MathSass`
|
39
|
+
|
40
|
+
If you installed via Bower the path will be: `bower_components/mathsass/dist/MathSass`
|
41
|
+
|
42
|
+
|
43
|
+
## Features
|
44
|
+
|
45
|
+
|
46
|
+
### Constants
|
47
|
+
|
48
|
+
* `$E` - Euler's constant (ネイピア数 [オイラー数])
|
49
|
+
* `$PI` - π (円周率)
|
50
|
+
* `$LN2` - The natural logarithm of 2 (2 の自然対数)
|
51
|
+
* `$SQRT2` - The square root of 2 (2 の平方根)
|
52
|
+
|
53
|
+
|
54
|
+
### Functions
|
55
|
+
|
56
|
+
|
57
|
+
#### Exponentiation
|
58
|
+
|
59
|
+
* `pow($base, $exp)`
|
60
|
+
|
61
|
+
```scss
|
62
|
+
@debug pow(4, 2); // 16
|
63
|
+
@debug pow(4, -2); // 0.0625
|
64
|
+
@debug pow(4, 0.2); // 1.31951
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
#### Factorial
|
69
|
+
|
70
|
+
* `fact($x)`
|
71
|
+
|
72
|
+
```scss
|
73
|
+
@debug fact(4); // 24
|
74
|
+
@debug fact(8); // 40320
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
#### Square root
|
79
|
+
|
80
|
+
* `sqrt($x)`
|
81
|
+
|
82
|
+
```scss
|
83
|
+
@debug sqrt(2); // 1.41421
|
84
|
+
@debug sqrt(3); // 1.73205
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
#### Exponential function
|
89
|
+
|
90
|
+
* `exp($x)`
|
91
|
+
* `frexp($x)`
|
92
|
+
* `ldexp($x, $exp)`
|
93
|
+
|
94
|
+
```scss
|
95
|
+
@debug exp(-1); // 0.36788
|
96
|
+
@debug exp(0); // 1
|
97
|
+
@debug exp(1); // 2.71828
|
98
|
+
```
|
99
|
+
|
100
|
+
|
101
|
+
#### Logarithms
|
102
|
+
|
103
|
+
* `log($x)`
|
104
|
+
|
105
|
+
|
106
|
+
#### Trigonometric functions
|
107
|
+
|
108
|
+
* `sin($x)` - Sine (正弦)
|
109
|
+
* `cos($x)` - Cosine (余弦)
|
110
|
+
* `tan($x)` - Tangent (正接)
|
111
|
+
* `csc($x)` - Cosecant (余割)
|
112
|
+
* `sec($x)` - Secant (正割)
|
113
|
+
* `cot($x)` - Cotangent (余接)
|
114
|
+
|
115
|
+
If argument has `deg` unit, converted to `rad`.
|
116
|
+
|
117
|
+
```scss
|
118
|
+
@debug tan(0.5236); // 0.57735
|
119
|
+
@debug tan(30deg); // 0.57735
|
120
|
+
```
|
121
|
+
|
122
|
+
|
123
|
+
#### Inverse trigonometric functions
|
124
|
+
|
125
|
+
* `asin($x)` - Arcsine (逆正弦)
|
126
|
+
* `acos($x)` - Arccosine (逆余弦)
|
127
|
+
* `atan($x)` - Arctangent (逆正接)
|
128
|
+
* `atan2($y, $x)` - Arctangent of the quotient of its arguments (引数の比率での逆正接)
|
129
|
+
|
130
|
+
```scss
|
131
|
+
@debug atan2(0, 0); // 0
|
132
|
+
@debug atan2(0, -0.0); // 3.14159
|
133
|
+
@debug atan2(-0.0, 0); // 0
|
134
|
+
@debug atan2(-0.0, -0.0); // -3.14159
|
135
|
+
```
|
136
|
+
|
137
|
+
### Helper functions
|
138
|
+
|
139
|
+
* `strip-unit($number)`
|
140
|
+
* `deg-to-rad($deg, $unit: true)`
|
141
|
+
* `rad-to-deg($rad, $unit: true)`
|
142
|
+
* `unitless-rad($angle)`
|
143
|
+
|
144
|
+
```scss
|
145
|
+
@debug rad-to-deg(1.0472); // 60.00014deg
|
146
|
+
@debug deg-to-rad(60deg); // 1.0472rad
|
147
|
+
@debug deg-to-rad(60deg, false); // 1.0472
|
148
|
+
@debug unitless-rad(60deg); // 1.0472
|
149
|
+
@debug unitless-rad(1.0472rad); // 1.0472
|
150
|
+
```
|
151
|
+
|
152
|
+
|
153
|
+
## References
|
154
|
+
|
155
|
+
* [adambom/Sass-Math · GitHub](https://github.com/adambom/Sass-Math)
|
156
|
+
* [Team-Sass/Sassy-math · GitHub](https://github.com/Team-Sass/Sassy-math)
|
157
|
+
* [Math - JavaScript | MDN](https://developer.mozilla.org/docs/JavaScript/Reference/Global_Objects/Math)
|
158
|
+
* [404 Blog Not Found:javascript - Mathを再発明してみた](http://blog.livedoor.jp/dankogai/archives/51518565.html)
|
159
|
+
* [C言語による最新アルゴリズム事典](http://www.amazon.co.jp/dp/4874084141?tag=terkel-22)
|
160
|
+
|
161
|
+
…and Wikipedia articles:
|
162
|
+
|
163
|
+
* [Exponentiation](http://en.wikipedia.org/wiki/Exponentiation), [冪乗 (累乗)](http://ja.wikipedia.org/wiki/%E5%86%AA%E4%B9%97)
|
164
|
+
* [Factorial](http://en.wikipedia.org/wiki/Factorial), [階乗](http://ja.wikipedia.org/wiki/%E9%9A%8E%E4%B9%97)
|
165
|
+
* [Square root](http://en.wikipedia.org/wiki/Square_root), [平方根](http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%96%B9%E6%A0%B9)
|
166
|
+
* [Exponential function](http://en.wikipedia.org/wiki/Exponential_function), [指数関数](http://ja.wikipedia.org/wiki/%E6%8C%87%E6%95%B0%E9%96%A2%E6%95%B0)
|
167
|
+
* [Logarithm](http://en.wikipedia.org/wiki/Logarithm), [対数](http://ja.wikipedia.org/wiki/%E5%AF%BE%E6%95%B0)
|
168
|
+
* [Trigonometric functions](http://en.wikipedia.org/wiki/Trigonometric_functions), [三角関数](http://ja.wikipedia.org/wiki/%E4%B8%89%E8%A7%92%E9%96%A2%E6%95%B0)
|
169
|
+
* [Inverse trigonometric functions](http://en.wikipedia.org/wiki/Inverse_trigonometric_functions), [逆三角関数](http://ja.wikipedia.org/wiki/%E4%B8%89%E8%A7%92%E9%96%A2%E6%95%B0#.E9.80.86.E4.B8.89.E8.A7.92.E9.96.A2.E6.95.B0)
|
170
|
+
* [Degree (angle)](http://en.wikipedia.org/wiki/Degree_\(angle\)), [度 (角度)](http://ja.wikipedia.org/wiki/%E5%BA%A6_\(%E8%A7%92%E5%BA%A6\))
|
171
|
+
* [Radian](http://en.wikipedia.org/wiki/Radian), [ラジアン](http://ja.wikipedia.org/wiki/%E3%83%A9%E3%82%B8%E3%82%A2%E3%83%B3)
|
172
|
+
|
173
|
+
## Contributing
|
174
|
+
|
175
|
+
Make sure you have [node.js](http://nodejs.org/) and [grunt](http://gruntjs.com/getting-started) installed.
|
176
|
+
|
177
|
+
**Clone Repository**
|
178
|
+
```
|
179
|
+
git clone git@github.com:terkel/mathsass.git
|
180
|
+
```
|
181
|
+
|
182
|
+
**Install Dependencies***
|
183
|
+
```
|
184
|
+
npm install
|
185
|
+
```
|
186
|
+
|
187
|
+
**Run Sass/Tests**
|
188
|
+
```
|
189
|
+
grunt
|
190
|
+
```
|
191
|
+
|
192
|
+
## Credits
|
193
|
+
|
194
|
+
Special thanks to [@kaminaly](https://github.com/kaminaly), [@pilssalgi](https://github.com/pilssalgi) and [@thejameskyle](https://github.com/thejameskyle)!
|
195
|
+
|
196
|
+
|
197
|
+
## License
|
198
|
+
|
199
|
+
Copyright (c) 2013 [Takeru Suzuki](http://terkel.jp/)
|
200
|
+
Licensed under the [MIT license](http://www.opensource.org/licenses/MIT).
|
data/dist/_MathSass.scss
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
// MathSass v0.9.2
|
2
|
+
// https://github.com/terkel/mathsass
|
3
|
+
//
|
4
|
+
// Copyright (c) 2013 Takeru Suzuki - http://terkel.jp/
|
5
|
+
// Licensed under the MIT license - http://opensource.org/licenses/MIT
|
6
|
+
|
7
|
+
@import "constants";
|
8
|
+
|
9
|
+
@import "functions/pow";
|
10
|
+
@import "functions/fact";
|
11
|
+
@import "functions/sqrt";
|
12
|
+
@import "functions/exp";
|
13
|
+
@import "functions/frexp";
|
14
|
+
@import "functions/ldexp";
|
15
|
+
@import "functions/log";
|
16
|
+
|
17
|
+
// Trigonometric functions
|
18
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
19
|
+
|
20
|
+
@import "functions/sin";
|
21
|
+
@import "functions/cos";
|
22
|
+
@import "functions/tan";
|
23
|
+
@import "functions/csc";
|
24
|
+
@import "functions/sec";
|
25
|
+
@import "functions/cot";
|
26
|
+
|
27
|
+
// Inverse trigonometric functions
|
28
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
29
|
+
|
30
|
+
@import "functions/asin";
|
31
|
+
@import "functions/acos";
|
32
|
+
@import "functions/atan";
|
33
|
+
@import "functions/atan2";
|
34
|
+
|
35
|
+
// Helpers
|
36
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
37
|
+
|
38
|
+
@import "helpers/strip-unit";
|
39
|
+
@import "helpers/deg-to-rad";
|
40
|
+
@import "helpers/rad-to-deg";
|
41
|
+
@import "helpers/unitless-rad";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Returns the arccosine of a number.
|
2
|
+
// @param {Number} $x A number between -1 and 1.
|
3
|
+
// @example
|
4
|
+
// acos(0.1) // 1.47063
|
5
|
+
// acos(-1) // 3.14159
|
6
|
+
@function acos ($x) {
|
7
|
+
@if $x > 1 or $x < -1 {
|
8
|
+
@warn "Argument for `acos()` must be a number between -1 and 1";
|
9
|
+
@return null;
|
10
|
+
}
|
11
|
+
@return $PI / 2 - asin($x);
|
12
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Returns the arcsine of a number.
|
2
|
+
// @param {Number} $x A number between -1 and 1.
|
3
|
+
// @example
|
4
|
+
// asin(0.1) // 0.10017
|
5
|
+
// asin(-1) // -1.5708
|
6
|
+
@function asin ($x) {
|
7
|
+
@if $x > 1 or $x < -1 {
|
8
|
+
@warn "Argument for `asin()` must be a number between -1 and 1";
|
9
|
+
@return null;
|
10
|
+
}
|
11
|
+
@return atan($x / sqrt(1 - $x * $x));
|
12
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// Returns the arctangent of a number.
|
2
|
+
// @param {Number} $x
|
3
|
+
// @example
|
4
|
+
// atan(0.1) // 0.09967
|
5
|
+
// atan(-1) // -0.7854
|
6
|
+
@function atan ($x) {
|
7
|
+
$i: 24;
|
8
|
+
$sgn: 0;
|
9
|
+
$a: 0;
|
10
|
+
@if $x > 1 {
|
11
|
+
$sgn: 1;
|
12
|
+
$x: 1 / $x;
|
13
|
+
} @else if $x < -1 {
|
14
|
+
$sgn: -1;
|
15
|
+
$x: 1 / $x;
|
16
|
+
}
|
17
|
+
@while $i > 0 {
|
18
|
+
$a: ($i * $i * $x * $x) / (2 * $i + 1 + $a);
|
19
|
+
$i: $i - 1;
|
20
|
+
}
|
21
|
+
@if $sgn > 0 {
|
22
|
+
@return $PI / 2 - $x / (1 + $a);
|
23
|
+
} @else if $sgn < 0 {
|
24
|
+
@return -$PI / 2 - $x / (1 + $a);
|
25
|
+
} @else {
|
26
|
+
@return $x / (1 + $a);
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Returns the arctangent of the quotient of its arguments.
|
2
|
+
// @param {Number} $y
|
3
|
+
// @param {Number} $x
|
4
|
+
// @example
|
5
|
+
// atan2(0, 0) // 0
|
6
|
+
// atan2(0, -0.0) // 3.14159
|
7
|
+
// atan2(-0.0, 0) // 0
|
8
|
+
// atan2(-0.0, -0.0) // -3.14159
|
9
|
+
// atan2(0, 1) // 0
|
10
|
+
// atan2(0, -1) // 3.14159
|
11
|
+
@function atan2 ($y, $x) {
|
12
|
+
@if $x > 0 {
|
13
|
+
@return atan($y / $x);
|
14
|
+
} @else if $x < 0 {
|
15
|
+
@if $y < 0 {
|
16
|
+
@return atan($y / $x) - $PI;
|
17
|
+
} @else {
|
18
|
+
@return atan($y / $x) + $PI;
|
19
|
+
}
|
20
|
+
} @else {
|
21
|
+
@if $y < 0 {
|
22
|
+
@return - $PI / 2;
|
23
|
+
} @else if $y > 0 {
|
24
|
+
@return $PI / 2;
|
25
|
+
} @else {
|
26
|
+
@if 1 / $x == 1 / 0 {
|
27
|
+
@return 0;
|
28
|
+
} @else {
|
29
|
+
@if 1 / $y == 1 / 0 {
|
30
|
+
@return $PI;
|
31
|
+
} @else {
|
32
|
+
@return -$PI;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Returns the cosine of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// cos(0.7854) // 0.70711
|
5
|
+
// cos(45deg) // 0.70711
|
6
|
+
@function cos ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
$ret: 0;
|
9
|
+
@for $n from 0 to 24 {
|
10
|
+
$ret: $ret + pow(-1, $n) * pow($x, 2 * $n) / fact(2 * $n);
|
11
|
+
}
|
12
|
+
@return $ret;
|
13
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns the cotangent of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// cot(0.5236) // 1.73205
|
5
|
+
// cot(30deg) // 1.73205
|
6
|
+
@function cot ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
@return 1 / tan($x);
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns the cosecant of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// csc(1.0472) // 1.1547
|
5
|
+
// csc(60deg) // 1.1547
|
6
|
+
@function csc ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
@return 1 / sin($x);
|
9
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Returns E^x, where x is the argument, and E is Euler's constant, the base of the natural logarithms.
|
2
|
+
// @param {Number} $x
|
3
|
+
// @example
|
4
|
+
// exp(1) // 2.71828
|
5
|
+
// exp(-1) // 0.36788
|
6
|
+
@function exp ($x) {
|
7
|
+
$ret: 0;
|
8
|
+
@for $n from 0 to 24 {
|
9
|
+
$ret: $ret + pow($x, $n) / fact($n);
|
10
|
+
}
|
11
|
+
@return $ret;
|
12
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// Returns the factorial of a non-negative integer.
|
2
|
+
// @param {Number} $x A non-negative integer.
|
3
|
+
// @return {Number}
|
4
|
+
// @example
|
5
|
+
// fact(0) // 1
|
6
|
+
// fact(8) // 40320
|
7
|
+
@function fact ($x) {
|
8
|
+
@if $x < 0 or $x != floor($x) {
|
9
|
+
@warn "Argument for `fact()` must be a positive integer.";
|
10
|
+
@return null;
|
11
|
+
}
|
12
|
+
$ret: 1;
|
13
|
+
@while $x > 0 {
|
14
|
+
$ret: $ret * $x;
|
15
|
+
$x: $x - 1;
|
16
|
+
}
|
17
|
+
@return $ret;
|
18
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// Returns a two-element list containing the normalized fraction and exponent of number.
|
2
|
+
// @param {Number} $x
|
3
|
+
// @return {List} fraction, exponent
|
4
|
+
@function frexp ($x) {
|
5
|
+
$exp: 0;
|
6
|
+
@if $x < 0 {
|
7
|
+
$x: $x * -1;
|
8
|
+
}
|
9
|
+
@if $x < 0.5 {
|
10
|
+
@while $x < 0.5 {
|
11
|
+
$x: $x * 2;
|
12
|
+
$exp: $exp - 1;
|
13
|
+
}
|
14
|
+
} @else if $x >= 1 {
|
15
|
+
@while $x >= 1 {
|
16
|
+
$x: $x / 2;
|
17
|
+
$exp: $exp + 1;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
@return $x, $exp;
|
21
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Returns $x * 2^$exp
|
2
|
+
// @param {Number} $x
|
3
|
+
// @param {Number} $exp
|
4
|
+
@function ldexp ($x, $exp) {
|
5
|
+
$b: if($exp >= 0, 2, 1 / 2);
|
6
|
+
@if $exp < 0 {
|
7
|
+
$exp: $exp * -1;
|
8
|
+
}
|
9
|
+
@while $exp > 0 {
|
10
|
+
@if $exp % 2 == 1 {
|
11
|
+
$x: $x * $b;
|
12
|
+
}
|
13
|
+
$b: $b * $b;
|
14
|
+
$exp: floor($exp * 0.5);
|
15
|
+
}
|
16
|
+
@return $x;
|
17
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Returns the natural logarithm of a number.
|
2
|
+
// @param {Number} $x
|
3
|
+
// @example
|
4
|
+
// log(2) // 0.69315
|
5
|
+
// log(10) // 2.30259
|
6
|
+
@function log ($x) {
|
7
|
+
@if $x <= 0 {
|
8
|
+
@return 0 / 0;
|
9
|
+
}
|
10
|
+
$k: nth(frexp($x / $SQRT2), 2);
|
11
|
+
$x: $x / ldexp(1, $k);
|
12
|
+
$x: ($x - 1) / ($x + 1);
|
13
|
+
$x2: $x * $x;
|
14
|
+
$i: 1;
|
15
|
+
$s: $x;
|
16
|
+
$sp: null;
|
17
|
+
@while $sp != $s {
|
18
|
+
$x: $x * $x2;
|
19
|
+
$i: $i + 2;
|
20
|
+
$sp: $s;
|
21
|
+
$s: $s + $x / $i;
|
22
|
+
}
|
23
|
+
@return $LN2 * $k + 2 * $s;
|
24
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// Returns base to the exponent power.
|
2
|
+
// @param {Number} $base The base number
|
3
|
+
// @param {Number} $exp The exponent to which to raise base
|
4
|
+
// @return {Number}
|
5
|
+
// @example
|
6
|
+
// pow(4, 2) // 16
|
7
|
+
// pow(4, -2) // 0.0625
|
8
|
+
// pow(4, 0.2) // 1.31951
|
9
|
+
@function pow ($base, $exp) {
|
10
|
+
@if $exp == floor($exp) {
|
11
|
+
$r: 1;
|
12
|
+
$s: 0;
|
13
|
+
@if $exp < 0 {
|
14
|
+
$exp: $exp * -1;
|
15
|
+
$s: 1;
|
16
|
+
}
|
17
|
+
@while $exp > 0 {
|
18
|
+
@if $exp % 2 == 1 {
|
19
|
+
$r: $r * $base;
|
20
|
+
}
|
21
|
+
$exp: floor($exp * 0.5);
|
22
|
+
$base: $base * $base;
|
23
|
+
}
|
24
|
+
@return if($s != 0, 1 / $r, $r);
|
25
|
+
} @else {
|
26
|
+
@return exp(log($base) * $exp);
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns the secant of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// sec(0.7854) // 1.41422
|
5
|
+
// sec(45deg) // 1.41422
|
6
|
+
@function sec ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
@return 1 / cos($x);
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns the sine of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// sin(1.0472) // 0.86603
|
5
|
+
// sin(60deg) // 0.86603
|
6
|
+
@function sin ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
@return cos($x - $PI / 2);
|
9
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Returns the square root of a number.
|
2
|
+
// @param {Number} $x
|
3
|
+
// @example
|
4
|
+
// sqrt(2) // 1.41421
|
5
|
+
// sqrt(5) // 2.23607
|
6
|
+
@function sqrt ($x) {
|
7
|
+
@if $x < 0 {
|
8
|
+
@warn "Argument for `sqrt()` must be a positive number.";
|
9
|
+
@return null;
|
10
|
+
}
|
11
|
+
$ret: 1;
|
12
|
+
@for $i from 1 through 24 {
|
13
|
+
$ret: $ret - (pow($ret, 2) - $x) / (2 * $ret);
|
14
|
+
}
|
15
|
+
@return $ret;
|
16
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns the tangent of a number.
|
2
|
+
// @param {Number} $x A number in rad or deg. Assuming unitless number to be in rad.
|
3
|
+
// @example
|
4
|
+
// tan(0.5236) // 0.57735
|
5
|
+
// tan(30deg) // 0.57735
|
6
|
+
@function tan ($x) {
|
7
|
+
$x: unitless-rad($x);
|
8
|
+
@return sin($x) / cos($x);
|
9
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Convert to unitless rad
|
2
|
+
@function unitless-rad ($angle) {
|
3
|
+
@if unitless($angle) {
|
4
|
+
@return $angle;
|
5
|
+
} @else if unit($angle) == rad {
|
6
|
+
@return $angle / 1rad;
|
7
|
+
} @else if unit($angle) == deg {
|
8
|
+
@return deg-to-rad($angle, false);
|
9
|
+
} @else if type-of($angle) != number or not unitless($angle) {
|
10
|
+
@warn "#{ $angle } is not a valid number.";
|
11
|
+
@return $angle;
|
12
|
+
}
|
13
|
+
}
|
data/lib/MathSass.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
base_directory = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
MathSass_stylesheets_path = File.join(base_directory, 'dist')
|
3
|
+
|
4
|
+
if (defined? Compass)
|
5
|
+
Compass::Frameworks.register('MathSass', :stylesheets_directory => MathSass_stylesheets_path)
|
6
|
+
else
|
7
|
+
# compass not found, register on the Sass path via the environment.
|
8
|
+
if ENV.has_key?("SASS_PATH")
|
9
|
+
ENV["SASS_PATH"] = ENV["SASS_PATH"] + File::PATH_SEPARATOR + MathSass_stylesheets_path
|
10
|
+
else
|
11
|
+
ENV["SASS_PATH"] = MathSass_stylesheets_path
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: MathSass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takeru Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sass
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
description: A Sass implementation of mathematical functions.
|
28
|
+
email:
|
29
|
+
- terkeljp@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/MathSass.rb
|
36
|
+
- dist/_constants.scss
|
37
|
+
- dist/_MathSass.scss
|
38
|
+
- dist/functions/_acos.scss
|
39
|
+
- dist/functions/_asin.scss
|
40
|
+
- dist/functions/_atan.scss
|
41
|
+
- dist/functions/_atan2.scss
|
42
|
+
- dist/functions/_cos.scss
|
43
|
+
- dist/functions/_cot.scss
|
44
|
+
- dist/functions/_csc.scss
|
45
|
+
- dist/functions/_exp.scss
|
46
|
+
- dist/functions/_fact.scss
|
47
|
+
- dist/functions/_frexp.scss
|
48
|
+
- dist/functions/_ldexp.scss
|
49
|
+
- dist/functions/_log.scss
|
50
|
+
- dist/functions/_pow.scss
|
51
|
+
- dist/functions/_sec.scss
|
52
|
+
- dist/functions/_sin.scss
|
53
|
+
- dist/functions/_sqrt.scss
|
54
|
+
- dist/functions/_tan.scss
|
55
|
+
- dist/helpers/_deg-to-rad.scss
|
56
|
+
- dist/helpers/_rad-to-deg.scss
|
57
|
+
- dist/helpers/_strip-unit.scss
|
58
|
+
- dist/helpers/_unitless-rad.scss
|
59
|
+
homepage: https://github.com/terkel/mathsass
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.6
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project: MathSass
|
79
|
+
rubygems_version: 2.1.10
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Sass mathematical functions.
|
83
|
+
test_files: []
|