SassyMatrix 1.0.0 → 1.0.1
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 +7 -0
- data/CHANGELOG.md +16 -16
- data/README.md +61 -61
- data/lib/SassyMatrix.rb +14 -14
- data/stylesheets/functions/checkers/_is-diagonal.scss +22 -22
- data/stylesheets/functions/checkers/_is-lower-triangular.scss +12 -12
- data/stylesheets/functions/checkers/_is-numeric.scss +18 -18
- data/stylesheets/functions/checkers/_is-square.scss +11 -11
- data/stylesheets/functions/checkers/_is-symmetric.scss +14 -14
- data/stylesheets/functions/checkers/_is-upper-triangular.scss +12 -12
- data/stylesheets/functions/getters/_get-column.scss +29 -29
- data/stylesheets/functions/getters/_get-entry.scss +20 -20
- data/stylesheets/functions/getters/_get-row.scss +21 -21
- data/stylesheets/functions/helpers/_is-triangular.scss +30 -30
- data/stylesheets/functions/helpers/_valid-coords.scss +37 -37
- data/stylesheets/functions/init/_matrix.scss +23 -23
- data/stylesheets/functions/init/_unit-matrix.scss +25 -25
- data/stylesheets/functions/misc/_add-matrices.scss +33 -33
- data/stylesheets/functions/misc/_columns.scss +9 -9
- data/stylesheets/functions/misc/_display.scss +42 -42
- data/stylesheets/functions/misc/_rows.scss +8 -8
- data/stylesheets/functions/misc/_transpose.scss +22 -22
- data/stylesheets/functions/setters/_add-column.scss +34 -34
- data/stylesheets/functions/setters/_add-row.scss +32 -32
- data/stylesheets/functions/setters/_set-column.scss +42 -42
- data/stylesheets/functions/setters/_set-entry.scss +19 -19
- data/stylesheets/functions/setters/_set-row.scss +36 -36
- data/stylesheets/functions/swap/_swap-columns.scss +32 -32
- data/stylesheets/functions/swap/_swap-entries.scss +20 -20
- data/stylesheets/functions/swap/_swap-rows.scss +24 -24
- data/stylesheets/matrix.scss +102 -102
- metadata +7 -9
@@ -1,22 +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);
|
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
22
|
}
|
@@ -1,30 +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
|
-
}
|
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
|
+
}
|
@@ -1,37 +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
|
-
}
|
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
|
+
}
|
@@ -1,23 +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
|
-
}
|
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
|
+
}
|
@@ -1,25 +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
|
-
}
|
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
|
+
}
|
@@ -1,33 +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
|
-
}
|
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
|
+
}
|
@@ -1,9 +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
|
-
}
|
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
|
+
}
|
@@ -1,42 +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
|
-
}
|
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
|
+
}
|