SassyMatrix 1.0.0
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.
- data/CHANGELOG.md +16 -0
- data/README.md +61 -0
- data/lib/SassyMatrix.rb +14 -0
- data/stylesheets/functions/checkers/_is-diagonal.scss +22 -0
- data/stylesheets/functions/checkers/_is-lower-triangular.scss +12 -0
- data/stylesheets/functions/checkers/_is-numeric.scss +18 -0
- data/stylesheets/functions/checkers/_is-square.scss +12 -0
- data/stylesheets/functions/checkers/_is-symmetric.scss +15 -0
- data/stylesheets/functions/checkers/_is-upper-triangular.scss +12 -0
- data/stylesheets/functions/getters/_get-column.scss +29 -0
- data/stylesheets/functions/getters/_get-entry.scss +20 -0
- data/stylesheets/functions/getters/_get-row.scss +22 -0
- data/stylesheets/functions/helpers/_is-triangular.scss +30 -0
- data/stylesheets/functions/helpers/_valid-coords.scss +37 -0
- data/stylesheets/functions/init/_matrix.scss +23 -0
- data/stylesheets/functions/init/_unit-matrix.scss +25 -0
- data/stylesheets/functions/misc/_add-matrices.scss +33 -0
- data/stylesheets/functions/misc/_columns.scss +9 -0
- data/stylesheets/functions/misc/_display.scss +42 -0
- data/stylesheets/functions/misc/_rows.scss +9 -0
- data/stylesheets/functions/misc/_transpose.scss +22 -0
- data/stylesheets/functions/setters/_add-column.scss +35 -0
- data/stylesheets/functions/setters/_add-row.scss +33 -0
- data/stylesheets/functions/setters/_set-column.scss +42 -0
- data/stylesheets/functions/setters/_set-entry.scss +19 -0
- data/stylesheets/functions/setters/_set-row.scss +37 -0
- data/stylesheets/functions/swap/_swap-columns.scss +32 -0
- data/stylesheets/functions/swap/_swap-entries.scss +20 -0
- data/stylesheets/functions/swap/_swap-rows.scss +24 -0
- data/stylesheets/matrix.scss +103 -0
- metadata +77 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
* `1.0.11`: fixing an issue with scientific number parsing
|
4
|
+
* `1.0.10`: improving number and string helpers
|
5
|
+
* `1.0.9`: fixing a bug in `_find-exponent`
|
6
|
+
* `1.0.8`: fixing a major issue in Ruby Gem
|
7
|
+
* `1.0.7`: minor fixes and stable Ruby Gem
|
8
|
+
* `1.0.6`: released a Ruby Gem
|
9
|
+
* `1.0.5`: improved the encoding mixin
|
10
|
+
* `1.0.4`: fixed an error in map parsing
|
11
|
+
* `1.0.3`: slightly edited the mixin to dump JSON to CSS
|
12
|
+
* `1.0.2`: fixed an issue with string parsing
|
13
|
+
* `1.0.1`: fixed an issue with alpha color parsing
|
14
|
+
* `1.0.0`: Stable API. `json-encode` and `json-decode`
|
15
|
+
* `0.0.2`: added `json-decode` and test
|
16
|
+
* `0.0.1`: initial commit
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# SassyMatrix [](https://travis-ci.org/HugoGiraudel/SassyMatrix)
|
2
|
+
|
3
|
+
All you ever wanted to deal with matrices in Sass.
|
4
|
+
|
5
|
+
## What's in there?
|
6
|
+
|
7
|
+
### Instanciating matrix
|
8
|
+
* `matrix($x, $y: $x)`: create a matrix of `$x` rows by `$y` columns filled with 0s
|
9
|
+
* `unit-matrix($x, $y)`: create a matrix of `$x` rows by `$y` columns filled with 0s except the diagonal which is filled with 1s
|
10
|
+
|
11
|
+
### Writing in matrix
|
12
|
+
* `set-entry($matrix, $coords, $value)`: set `$value` at `$matrix[$coords[1], $coords[2]]`
|
13
|
+
* `set-column($matrix, $index, $column: ())`: set `$column` at `$index` in `$matrix`
|
14
|
+
* `set-row($matrix, $index, $row: ())`: set `$row` at `$index` in `$matrix`
|
15
|
+
* `add-column($matrix, $column: (), $index: null)`: add `$column` at `$index` in `$matrix`
|
16
|
+
* `add-row($matrix, $row: (), $index: null)`: add `$row` at `$index` in `$matrix`
|
17
|
+
|
18
|
+
### Reading matrix
|
19
|
+
* `get-entry($matrix, $coords)`: get entry at `$matrix[$coords[1], $coords[2]]`
|
20
|
+
* `get-column($matrix, $index)`: get column at `$index` from `$matrix`
|
21
|
+
* `get-row($matrix, $index)`: get row at `$index` from `$matrix`
|
22
|
+
|
23
|
+
### Displaying matrix
|
24
|
+
* `display($matrix)`: display matrix
|
25
|
+
|
26
|
+
### Altering matrix
|
27
|
+
* `swap-entries($matrix, $e1, $e2)`: swaps values `$e1` and `$e2` from `$matrix`
|
28
|
+
* `swap-rows($matrix, $r1, $r2)`: swaps rows `$r1` and `$r2` from `$matrix`
|
29
|
+
* `swap-columns($matrix, $c1, $c2)`: swaps columns `$c1` and `$c2` from `$matrix`
|
30
|
+
* `transpose($matrix)`: rotates `$matrix` around its diagonal
|
31
|
+
* `add-matrices($matrix1, $matrix2)`: add `$matrix1` and `$matrix2`
|
32
|
+
|
33
|
+
### Checking for matrix properties
|
34
|
+
* `columns($matrix)`: return number of columns in `$matrix`
|
35
|
+
* `rows($matrix)`: return number of rows in `$matrix`
|
36
|
+
* `is-numeric($matrix)`: check whether `$matrix` has only numeric values
|
37
|
+
* `is-square($matrix)`: check whether `$matrix` has as many rows as columns
|
38
|
+
* `is-diagonal($matrix)`: check whether all values from the main diagonal of `$matrix` are set while all other values are equal to 0
|
39
|
+
* `is-lower-triangular($matrix, $flag: null)`: check whether all value below `$matrix` diagonal are equal to 0
|
40
|
+
* `is-upper-triangular($matrix, $flag: null)`: check whether all value above `$matrix` diagonal are equal to 0
|
41
|
+
|
42
|
+
## Requirements
|
43
|
+
|
44
|
+
All you need is a clean version of Sass 3.3. Otherwise it's just pure Sass madness.
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
### You need
|
49
|
+
|
50
|
+
* [NodeJS](http://nodejs.org)
|
51
|
+
* [Ruby](https://www.ruby-lang.org/)
|
52
|
+
* Sass 3.3 via `gem instal sass --pre`
|
53
|
+
* `grunt-cli` via `npm install -g grunt-cli`
|
54
|
+
|
55
|
+
### How to
|
56
|
+
|
57
|
+
1. Fork this repository
|
58
|
+
2. Run `npm install`
|
59
|
+
3. `grunt dev`
|
60
|
+
4. Make your changes + write tests
|
61
|
+
5. Commit + Pull request
|
data/lib/SassyMatrix.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'compass'
|
2
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
+
Compass::Frameworks.register('SassyJSON', :path => extension_path)
|
4
|
+
|
5
|
+
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
+
# Date is in the form of YYYY-MM-DD
|
7
|
+
module SassyMatrix
|
8
|
+
VERSION = "1.0.0"
|
9
|
+
DATE = "2014-01-23"
|
10
|
+
end
|
11
|
+
|
12
|
+
module Sass::Script::Functions
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Checks whether all entries from the main diagonal of `$matrix`
|
2
|
+
// are set while all other entries are equal to the 0
|
3
|
+
// --------------------------------------------------------------------------------
|
4
|
+
// @require `get-entry`
|
5
|
+
// @require `columns`
|
6
|
+
// @require `rows`
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @param $matrix: matrix
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return boolean
|
11
|
+
|
12
|
+
@function is-diagonal($matrix) {
|
13
|
+
@for $i from 1 through rows($matrix) {
|
14
|
+
@for $j from 1 through columns($matrix) {
|
15
|
+
$entry: get-entry($matrix, ($i $j));
|
16
|
+
@if ($i != $j and $entry != 0) or ($i == $j and $entry == 0) {
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
@return true;
|
22
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Checks whether `$matrix` is lower triangular with `$flag` option
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_is-triangular`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix
|
6
|
+
// @param $flag: advanced option (null | strict | unit | atom)
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return boolean
|
9
|
+
|
10
|
+
@function is-lower-triangular($matrix, $flag: null) {
|
11
|
+
@return _is-triangular($matrix, bottom, $flag);
|
12
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// Checks whether all entries from `$matrix` are numeric
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `columns`
|
5
|
+
// @require `get-entry`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @return boolean
|
8
|
+
|
9
|
+
@function is-numeric($matrix) {
|
10
|
+
@for $i from 1 through rows($matrix) {
|
11
|
+
@for $j from 1 through columns($matrix) {
|
12
|
+
@if type-of(get-entry($matrix, ($i $j))) != number {
|
13
|
+
@return false;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
@return true;
|
18
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Returns whether `$matrix` has as many rows as columns
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `columns`
|
4
|
+
// @require `rows`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return boolean
|
9
|
+
|
10
|
+
@function is-square($matrix) {
|
11
|
+
@return columns($matrix) == rows($matrix);
|
12
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// Checks whether a matrix is symetric
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `transpose`
|
4
|
+
// @require `is-square`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return boolean
|
9
|
+
|
10
|
+
@function is-symmetric($matrix) {
|
11
|
+
@if not is-square($matrix) {
|
12
|
+
@return false;
|
13
|
+
}
|
14
|
+
@return $matrix == transpose($matrix);
|
15
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// Checks whether `$matrix` is upper triangular with `$flag` option
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_is-triangular`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix
|
6
|
+
// @param $flag: advanced option (null | strict | unit | atom)
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return boolean
|
9
|
+
|
10
|
+
@function is-upper-triangular($matrix, $flag: null) {
|
11
|
+
@return _is-triangular($matrix, top, $flag);
|
12
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// Return column at `$index` from `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `get-entry`
|
4
|
+
// @require `rows`
|
5
|
+
// @require `columns`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @param $matrix: matrix
|
8
|
+
// @param $index: index
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return list
|
11
|
+
|
12
|
+
@function get-column($matrix, $index) {
|
13
|
+
@if type-of($index) != number {
|
14
|
+
@warn "Invalid column index.";
|
15
|
+
@return false;
|
16
|
+
}
|
17
|
+
|
18
|
+
@if abs($index) > columns($matrix) {
|
19
|
+
@warn "Out of bound column index.";
|
20
|
+
@return false;
|
21
|
+
}
|
22
|
+
|
23
|
+
$column: ();
|
24
|
+
@for $i from 1 through rows($matrix) {
|
25
|
+
$column: append($column, get-entry($matrix, ($i $index)))
|
26
|
+
}
|
27
|
+
|
28
|
+
@return $column;
|
29
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// Returns entry at `$matrix[$coords[1], $coords[2]]`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_valid-coords`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix
|
6
|
+
// @param $coords: (x y) coordinates
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return literal
|
9
|
+
|
10
|
+
@function get-entry($matrix, $coords) {
|
11
|
+
@if length($coords) == 1 {
|
12
|
+
$coords: ($coords $coords);
|
13
|
+
}
|
14
|
+
|
15
|
+
@if _valid-coords($coords, $matrix) {
|
16
|
+
@return nth(nth($matrix, nth($coords, 1)), nth($coords, 2));
|
17
|
+
}
|
18
|
+
|
19
|
+
@return false;
|
20
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Return row at `$index` from `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix
|
6
|
+
// @param $index: index
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return list
|
9
|
+
|
10
|
+
@function get-row($matrix, $index) {
|
11
|
+
@if type-of($index) != number {
|
12
|
+
@warn "Invalid row index.";
|
13
|
+
@return false;
|
14
|
+
}
|
15
|
+
|
16
|
+
@if abs($index) > rows($matrix) {
|
17
|
+
@warn "Out of bound row index.";
|
18
|
+
@return false;
|
19
|
+
}
|
20
|
+
|
21
|
+
@return nth($matrix, $index);
|
22
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// Checks whether `$matrix` is `$side` triangular with `$flag` options
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `columns`
|
5
|
+
// @require `get-entry`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @param $matrix: matrix
|
8
|
+
// @param $side: side (top | bottom)
|
9
|
+
// @param $flag: advanced options (null | strict | unit | atom)
|
10
|
+
// --------------------------------------------------------------------------------
|
11
|
+
// @return boolean
|
12
|
+
|
13
|
+
@function _is-triangular($matrix, $side: top, $flag: null) {
|
14
|
+
@for $i from 1 through rows($matrix) {
|
15
|
+
@for $j from 1 through columns($matrix) {
|
16
|
+
$entry: get-entry($matrix, ($i $j));
|
17
|
+
@if $i > $j {
|
18
|
+
@if $side == top and $entry != 0 { @return false; }
|
19
|
+
}
|
20
|
+
@else if $i < $j {
|
21
|
+
@if $side == bottom and $entry != 0 { @return false; }
|
22
|
+
}
|
23
|
+
@else {
|
24
|
+
@if $flag == strict and $entry != 0 { @return false; }
|
25
|
+
@if $flag == unit and $entry != 1 { @return false; }
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
@return true;
|
30
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Checks whether `$coords` are valid coordinates
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `columns`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// @param $coords: coordinates
|
8
|
+
// --------------------------------------------------------------------------------
|
9
|
+
// @return boolean
|
10
|
+
|
11
|
+
@function _valid-coords($coords, $matrix: null) {
|
12
|
+
@if length($coords) == 1 {
|
13
|
+
$coords: ($coords, $coords);
|
14
|
+
}
|
15
|
+
|
16
|
+
$x: nth($coords, 1);
|
17
|
+
$y: nth($coords, 2);
|
18
|
+
|
19
|
+
@if length($coords) != 2 {
|
20
|
+
@warn "Wrong number of coordinates.";
|
21
|
+
@return false;
|
22
|
+
}
|
23
|
+
|
24
|
+
@if type-of($x) != number or type-of($y) != number {
|
25
|
+
@warn "Invalid coordinates.";
|
26
|
+
@return false;
|
27
|
+
}
|
28
|
+
|
29
|
+
@if $matrix {
|
30
|
+
@if abs($x) > rows($matrix) or abs($y) > columns($matrix) {
|
31
|
+
@warn "Out of bound coordinates.";
|
32
|
+
@return false;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
@return true;
|
37
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// Initializing a matrix of `$x` by `$y` with 0s
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_valid-coords`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $x: number of rows
|
6
|
+
// @param $y: number of columns
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return matrix
|
9
|
+
|
10
|
+
@function matrix($x, $y: $x) {
|
11
|
+
@if _valid-coords(($x $y)) {
|
12
|
+
$matrix: ();
|
13
|
+
@for $i from 1 through $x {
|
14
|
+
$tmp: ();
|
15
|
+
@for $y from 1 through $y {
|
16
|
+
$tmp: append($tmp, 0)
|
17
|
+
}
|
18
|
+
$matrix: append($matrix, $tmp);
|
19
|
+
}
|
20
|
+
@return $matrix;
|
21
|
+
}
|
22
|
+
@return false;
|
23
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// Initializing a matrix of `$x` by `$y` with its diagonal filled with 1s
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_valid-coords`
|
4
|
+
// @require `matrix`
|
5
|
+
// @require `set-entry`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @param $x: number of rows
|
8
|
+
// @param $y: number of columns
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return matrix
|
11
|
+
|
12
|
+
@function unit-matrix($x, $y: $x) {
|
13
|
+
@if _valid-coords(($x $y)) {
|
14
|
+
$matrix: matrix($x, $y);
|
15
|
+
@for $i from 1 through $x {
|
16
|
+
@for $j from 1 through $y {
|
17
|
+
@if $i == $j {
|
18
|
+
$matrix: set-entry($matrix, ($i $j), 1);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
@return $matrix;
|
23
|
+
}
|
24
|
+
@return false;
|
25
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// Add `$matrices`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `columns`
|
5
|
+
// @require `get-entry`
|
6
|
+
// @require `set-entry`
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @param $matrices: matrices
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return matrix
|
11
|
+
|
12
|
+
@function add-matrices($matrices...) {
|
13
|
+
$matrix: nth($matrices, 1);
|
14
|
+
@each $m in $matrices {
|
15
|
+
@if columns($matrix) != columns($m)
|
16
|
+
or rows($matrix) != rows($m) {
|
17
|
+
@warn "All matrices do not have same dimensions.";
|
18
|
+
@return false;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
@for $i from 1 through rows($matrix) {
|
23
|
+
@for $j from 1 through columns($matrix) {
|
24
|
+
$value: null;
|
25
|
+
@each $m in $matrices {
|
26
|
+
$entry: get-entry($m, ($i $j));
|
27
|
+
$value: if($value == null, $entry, $value + $entry);
|
28
|
+
}
|
29
|
+
$matrix: set-entry($matrix, ($i $j), $value);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
@return $matrix;
|
33
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns number of columns in `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $matrix: matrix
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return number
|
6
|
+
|
7
|
+
@function columns($matrix) {
|
8
|
+
@return length(nth($matrix, 1));
|
9
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Returns the visual representation of `$matrix` as a string
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $matrix: matrix to display
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return string
|
6
|
+
|
7
|
+
@function display($matrix) {
|
8
|
+
$str: "";
|
9
|
+
@each $line in $matrix {
|
10
|
+
$tmp: "";
|
11
|
+
@each $item in $line {
|
12
|
+
$tmp: $tmp + " " + $item;
|
13
|
+
}
|
14
|
+
$str: $str + $tmp + "\A ";
|
15
|
+
}
|
16
|
+
@return $str;
|
17
|
+
}
|
18
|
+
|
19
|
+
// Mixin displaying the matrix
|
20
|
+
// using body pseudo-elements
|
21
|
+
//
|
22
|
+
// @param $matrix: matrix to display
|
23
|
+
// @param $pseudo: pseudo element to use
|
24
|
+
|
25
|
+
@mixin display($matrix, $pseudo: before) {
|
26
|
+
body:#{$pseudo} {
|
27
|
+
content: display($matrix) !important;
|
28
|
+
|
29
|
+
display: block !important;
|
30
|
+
margin: 1em !important;
|
31
|
+
padding: .5em !important;
|
32
|
+
|
33
|
+
background: #EFEFEF !important;
|
34
|
+
border: 1px solid #DDD !important;
|
35
|
+
border-radius: .2em !important;
|
36
|
+
|
37
|
+
color: #333 !important;
|
38
|
+
font: 1.5em/1.5 "Courier New", monospace !important;
|
39
|
+
text-shadow: 0 1px white !important;
|
40
|
+
white-space: pre-wrap !important;
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Returns number of rows in `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $matrix: matrix
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return number
|
6
|
+
|
7
|
+
@function rows($matrix) {
|
8
|
+
@return length($matrix);
|
9
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Translate `$matrix` on its diagonal axe
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `matrix`
|
4
|
+
// @require `columns`
|
5
|
+
// @require `rows`
|
6
|
+
// @require `get-entry`
|
7
|
+
// @require `set-entry`
|
8
|
+
// --------------------------------------------------------------------------------
|
9
|
+
// @param $matrix: matrix
|
10
|
+
// --------------------------------------------------------------------------------
|
11
|
+
// @return matrix
|
12
|
+
|
13
|
+
@function transpose($matrix) {
|
14
|
+
$new-matrix: matrix(columns($matrix), rows($matrix));
|
15
|
+
@for $i from 1 through rows($matrix) {
|
16
|
+
@for $j from 1 through columns($matrix) {
|
17
|
+
$entry: get-entry($matrix, ($i $j));
|
18
|
+
$new-matrix: set-entry($new-matrix, ($j $i), $entry);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
@return $new-matrix;
|
22
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// Add a new `$column` to `$matrix` at `$index`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `swap-columns`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// @param $column: column to add
|
8
|
+
// @param $index: index to add column at
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return matrix
|
11
|
+
|
12
|
+
@function add-column($matrix, $column: (), $index: null) {
|
13
|
+
$desired-length: rows($matrix);
|
14
|
+
|
15
|
+
@if $column == () {
|
16
|
+
@for $i from 1 through $desired-length {
|
17
|
+
$column: append($column, 0);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
@if length($column) != $desired-length {
|
22
|
+
@warn "Wrong length for new column; should be #{$desired-length}.";
|
23
|
+
@return false;
|
24
|
+
}
|
25
|
+
|
26
|
+
@for $i from 1 through $desired-length {
|
27
|
+
$matrix: set-nth($matrix, $i, append(nth($matrix, $i), nth($column, $i)));
|
28
|
+
}
|
29
|
+
|
30
|
+
@if $index != null {
|
31
|
+
$matrix: swap-columns($matrix, -1, $index);
|
32
|
+
}
|
33
|
+
|
34
|
+
@return $matrix;
|
35
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// Add a new `$row` to `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `swap-rows`
|
4
|
+
// @require `columns`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// @param $row: row to add
|
8
|
+
// @param $index: index to add row at
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return matrix
|
11
|
+
|
12
|
+
@function add-row($matrix, $row: (), $index: null) {
|
13
|
+
$desired-length: columns($matrix);
|
14
|
+
|
15
|
+
@if $row == () {
|
16
|
+
@for $i from 1 through $desired-length {
|
17
|
+
$row: append($row, 0);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
@if length($row) != $desired-length {
|
22
|
+
@warn "Wrong length for new row; should be #{$desired-length}.";
|
23
|
+
@return false;
|
24
|
+
}
|
25
|
+
|
26
|
+
$matrix: append($matrix, $row);
|
27
|
+
|
28
|
+
@if $index != null {
|
29
|
+
$matrix: swap-rows($matrix, -1, $index);
|
30
|
+
}
|
31
|
+
|
32
|
+
@return $matrix;
|
33
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Set `$column` at `$index` in `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `set-entry`
|
4
|
+
// @require `rows`
|
5
|
+
// @require `columns`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @param $matrix: matrix
|
8
|
+
// @param $column: column
|
9
|
+
// @param $index: index
|
10
|
+
// --------------------------------------------------------------------------------
|
11
|
+
// @return matrix
|
12
|
+
|
13
|
+
@function set-column($matrix, $index, $column: ()) {
|
14
|
+
$desired-length: rows($matrix);
|
15
|
+
|
16
|
+
@if type-of($index) != number {
|
17
|
+
@warn "Invalid column index.";
|
18
|
+
@return false;
|
19
|
+
}
|
20
|
+
|
21
|
+
@if abs($index) > columns($matrix) {
|
22
|
+
@warn "Out of bound column index.";
|
23
|
+
@return false;
|
24
|
+
}
|
25
|
+
|
26
|
+
@if $column == () {
|
27
|
+
@for $i from 1 through $desired-length {
|
28
|
+
$column: append($column, 0);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
@if length($column) != $desired-length {
|
33
|
+
@warn "Wrong length for new column; should be #{$desired-length}.";
|
34
|
+
@return false;
|
35
|
+
}
|
36
|
+
|
37
|
+
@for $i from 1 through $desired-length {
|
38
|
+
$matrix: set-entry($matrix, $i $index, nth($column, $i));
|
39
|
+
}
|
40
|
+
|
41
|
+
@return $matrix;
|
42
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Assign `$value` at `$matrix[$coords[1], $coords[2]]`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_valid-coords`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix to update
|
6
|
+
// @param $coords: (x y) coordinates
|
7
|
+
// @param $value: value to assign at $matrix[$x, $y]
|
8
|
+
// --------------------------------------------------------------------------------
|
9
|
+
// @return matrix
|
10
|
+
|
11
|
+
@function set-entry($matrix, $coords, $value) {
|
12
|
+
@if length($coords) == 1 {
|
13
|
+
$coords: ($coords $coords);
|
14
|
+
}
|
15
|
+
@if _valid-coords($coords, $matrix) {
|
16
|
+
@return set-nth($matrix, nth($coords, 1), set-nth(nth($matrix, nth($coords, 1)), nth($coords, 2), $value));
|
17
|
+
}
|
18
|
+
@return false;
|
19
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Set `$row` at `$index` in `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `columns`
|
4
|
+
// @require `rows`
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @param $matrix: matrix
|
7
|
+
// @param $row: row
|
8
|
+
// @param $index: index
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return matrix
|
11
|
+
|
12
|
+
@function set-row($matrix, $index, $row: ()) {
|
13
|
+
$desired-length: columns($matrix);
|
14
|
+
|
15
|
+
@if type-of($index) != number {
|
16
|
+
@warn "Invalid row index.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if abs($index) > rows($matrix) {
|
21
|
+
@warn "Out of bound row index.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@if $row == () {
|
26
|
+
@for $i from 1 through $desired-length {
|
27
|
+
$row: append($row, 0);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
@if length($row) != $desired-length {
|
32
|
+
@warn "Wrong length for new row; should be #{$desired-length}.";
|
33
|
+
@return false;
|
34
|
+
}
|
35
|
+
|
36
|
+
@return set-nth($matrix, $index, $row);
|
37
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// Swaps columns `$c1` and `$c2` from `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// @require `columns`
|
5
|
+
// @require `get-entry`
|
6
|
+
// @require `set-entry`
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @param $matrix: matrix
|
9
|
+
// @param $c1: index of column 1
|
10
|
+
// @param $c2: index of column 2
|
11
|
+
// --------------------------------------------------------------------------------
|
12
|
+
// @return $matrix
|
13
|
+
|
14
|
+
@function swap-columns($matrix, $c1, $c2) {
|
15
|
+
@if type-of($c1) != number or type-of($c2) != number {
|
16
|
+
@warn "Invalid column index.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if abs($c1) > columns($matrix) or abs($c2) > columns($matrix) {
|
21
|
+
@warn "Out of bounds column index.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@for $i from 1 through rows($matrix) {
|
26
|
+
$tmp: get-entry($matrix, ($i $c1));
|
27
|
+
$matrix: set-entry($matrix, ($i $c1), get-entry($matrix, ($i $c2)));
|
28
|
+
$matrix: set-entry($matrix, ($i $c2), $tmp);
|
29
|
+
}
|
30
|
+
|
31
|
+
@return $matrix;
|
32
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// Swaps entries `$e1` and `$e2` from `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `_valid-coords`
|
4
|
+
// @require `get-entry`
|
5
|
+
// @require `set-entry`
|
6
|
+
// --------------------------------------------------------------------------------
|
7
|
+
// @param $matrix: matrix
|
8
|
+
// @param $e1: (x y) coordinates of first entry
|
9
|
+
// @param $e2: (x y) coordinates of second entry
|
10
|
+
// --------------------------------------------------------------------------------
|
11
|
+
// @return $matrix
|
12
|
+
|
13
|
+
@function swap-entries($matrix, $e1, $e2) {
|
14
|
+
@if _valid-coords($e1, $matrix) and _valid-coords($e2, $matrix) {
|
15
|
+
$tmp: get-entry($matrix, $e1);
|
16
|
+
$matrix: set-entry(set-entry($matrix, $e1, get-entry($matrix, $e2)), $e2, $tmp);
|
17
|
+
@return $matrix;
|
18
|
+
}
|
19
|
+
@return false;
|
20
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Swaps rows `$r1` and `$r2` from `$matrix`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @require `rows`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @param $matrix: matrix
|
6
|
+
// @param $r1: index of row 1
|
7
|
+
// @param $r2: index of row 2
|
8
|
+
// --------------------------------------------------------------------------------
|
9
|
+
// @return $matrix
|
10
|
+
|
11
|
+
@function swap-rows($matrix, $r1, $r2) {
|
12
|
+
@if type-of($r1) != number or type-of($r2) != number {
|
13
|
+
@warn "Invalid row index.";
|
14
|
+
@return false;
|
15
|
+
}
|
16
|
+
|
17
|
+
@if abs($r1) > rows($matrix) or abs($r2) > rows($matrix) {
|
18
|
+
@warn "Out of bounds row index.";
|
19
|
+
@return false;
|
20
|
+
}
|
21
|
+
|
22
|
+
$tmp: nth($matrix, $r1);
|
23
|
+
@return set-nth(set-nth($matrix, $r1, nth($matrix, $r2)), $r2, $tmp);
|
24
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
// Displaying matrix
|
2
|
+
// @dep: none
|
3
|
+
@import "functions/misc/display";
|
4
|
+
|
5
|
+
// Getting number of rows in matrix
|
6
|
+
// @dep: none
|
7
|
+
@import "functions/misc/rows";
|
8
|
+
|
9
|
+
// Getting number of columns in matrix
|
10
|
+
// @dep: none
|
11
|
+
@import "functions/misc/columns";
|
12
|
+
|
13
|
+
// Validate coordinates pairs
|
14
|
+
// @dep: none
|
15
|
+
@import "functions/helpers/valid-coords";
|
16
|
+
|
17
|
+
// Creating a matrix
|
18
|
+
// @dep: `_valid-coords`
|
19
|
+
@import "functions/init/matrix";
|
20
|
+
|
21
|
+
// Assigning values to matrix
|
22
|
+
// @dep: `_valid-coords`
|
23
|
+
@import "functions/setters/set-entry";
|
24
|
+
|
25
|
+
// Reading values from matrix
|
26
|
+
// @dep: `_valid-coords`
|
27
|
+
@import "functions/getters/get-entry";
|
28
|
+
|
29
|
+
// Reading values from matrix
|
30
|
+
// @dep: `rows`
|
31
|
+
@import "functions/getters/get-row";
|
32
|
+
|
33
|
+
// Swapper two rows from matrix
|
34
|
+
// @dep: `rows`
|
35
|
+
@import "functions/swap/swap-rows";
|
36
|
+
|
37
|
+
// Assigning values to matrix
|
38
|
+
// @dep: `rows`, `columns`
|
39
|
+
@import "functions/setters/set-row";
|
40
|
+
|
41
|
+
// Checking if matrix is square
|
42
|
+
// @dep: `rows`, `columns`
|
43
|
+
@import "functions/checkers/is-square";
|
44
|
+
|
45
|
+
// Transpose a matrix
|
46
|
+
// @dep: `columns`, `swap-rows`
|
47
|
+
@import "functions/setters/add-row";
|
48
|
+
|
49
|
+
// Transpose a matrix
|
50
|
+
// @dep: `rows`, `swap-columns`
|
51
|
+
@import "functions/setters/add-column";
|
52
|
+
|
53
|
+
// Assigning values to matrix
|
54
|
+
// @dep: `rows`, `columns`, `set-entry`
|
55
|
+
@import "functions/setters/set-column";
|
56
|
+
|
57
|
+
// Reading values from matrix
|
58
|
+
// @dep: `rows`, `columns`, `get-entry`
|
59
|
+
@import "functions/getters/get-column";
|
60
|
+
|
61
|
+
// Checking if all values from matrix are numbers
|
62
|
+
// @dep: `rows`, `columns`, `get-entry`
|
63
|
+
@import "functions/checkers/is-numeric";
|
64
|
+
|
65
|
+
// Checking if matrix is diagonal
|
66
|
+
// @dep: `rows`, `columns`, `get-entry`
|
67
|
+
@import "functions/checkers/is-diagonal";
|
68
|
+
|
69
|
+
// Is triangular helper
|
70
|
+
// @dep: `rows`, `columns`, `get-entry`
|
71
|
+
@import "functions/helpers/is-triangular";
|
72
|
+
|
73
|
+
// Creating a matrix with diagonal filled
|
74
|
+
// @dep: `matrix`, `_valid-coords`, `set-entry`
|
75
|
+
@import "functions/init/unit-matrix";
|
76
|
+
|
77
|
+
// Swapping two values from matrix
|
78
|
+
// @dep: `_valid-coords`, `get-entry`, `set-entry`
|
79
|
+
@import "functions/swap/swap-entries";
|
80
|
+
|
81
|
+
// Swapper two columns from matrix
|
82
|
+
// @dep: `rows`, `columns`, `get-entry`, `set-entry`
|
83
|
+
@import "functions/swap/swap-columns";
|
84
|
+
|
85
|
+
// Checking if matrix is diagonal
|
86
|
+
// @dep: `rows`, `columns`, `get-entry`, `_is-triangular`
|
87
|
+
@import "functions/checkers/is-upper-triangular";
|
88
|
+
|
89
|
+
// Checking if matrix is diagonal
|
90
|
+
// @dep: `rows`, `columns`, `get-entry`, `_is-triangular`
|
91
|
+
@import "functions/checkers/is-lower-triangular";
|
92
|
+
|
93
|
+
// Add two matrices
|
94
|
+
// @dep: `rows`, `columns`, `get-entry`, `set-entry`
|
95
|
+
@import "functions/misc/add-matrices";
|
96
|
+
|
97
|
+
// Transpose a matrix
|
98
|
+
// @dep: `rows`, `columns`, `get-entry`, `set-entry`
|
99
|
+
@import "functions/misc/transpose";
|
100
|
+
|
101
|
+
// Displaying matrix
|
102
|
+
// @dep: `is-square`, `transpose`
|
103
|
+
@import "functions/checkers/is-symmetric";
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SassyMatrix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hugo Giraudel
|
9
|
+
- Fabrice Weinberg
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Sass API for matrices
|
16
|
+
email:
|
17
|
+
- hugo.giraudel@gmail.com
|
18
|
+
- fabrice@weinberg.me
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- README.md
|
24
|
+
- CHANGELOG.md
|
25
|
+
- lib/SassyMatrix.rb
|
26
|
+
- stylesheets/functions/checkers/_is-diagonal.scss
|
27
|
+
- stylesheets/functions/checkers/_is-lower-triangular.scss
|
28
|
+
- stylesheets/functions/checkers/_is-numeric.scss
|
29
|
+
- stylesheets/functions/checkers/_is-square.scss
|
30
|
+
- stylesheets/functions/checkers/_is-symmetric.scss
|
31
|
+
- stylesheets/functions/checkers/_is-upper-triangular.scss
|
32
|
+
- stylesheets/functions/getters/_get-column.scss
|
33
|
+
- stylesheets/functions/getters/_get-entry.scss
|
34
|
+
- stylesheets/functions/getters/_get-row.scss
|
35
|
+
- stylesheets/functions/helpers/_is-triangular.scss
|
36
|
+
- stylesheets/functions/helpers/_valid-coords.scss
|
37
|
+
- stylesheets/functions/init/_matrix.scss
|
38
|
+
- stylesheets/functions/init/_unit-matrix.scss
|
39
|
+
- stylesheets/functions/misc/_add-matrices.scss
|
40
|
+
- stylesheets/functions/misc/_columns.scss
|
41
|
+
- stylesheets/functions/misc/_display.scss
|
42
|
+
- stylesheets/functions/misc/_rows.scss
|
43
|
+
- stylesheets/functions/misc/_transpose.scss
|
44
|
+
- stylesheets/functions/setters/_add-column.scss
|
45
|
+
- stylesheets/functions/setters/_add-row.scss
|
46
|
+
- stylesheets/functions/setters/_set-column.scss
|
47
|
+
- stylesheets/functions/setters/_set-entry.scss
|
48
|
+
- stylesheets/functions/setters/_set-row.scss
|
49
|
+
- stylesheets/functions/swap/_swap-columns.scss
|
50
|
+
- stylesheets/functions/swap/_swap-entries.scss
|
51
|
+
- stylesheets/functions/swap/_swap-rows.scss
|
52
|
+
- stylesheets/matrix.scss
|
53
|
+
homepage: https://github.com/HugoGiraudel/SassyMatrix/
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.3.6
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: SassyMatrix
|
73
|
+
rubygems_version: 1.8.24
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: SassyMatrix is a Sass-powered API for matrices.
|
77
|
+
test_files: []
|