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.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +16 -16
  3. data/README.md +61 -61
  4. data/lib/SassyMatrix.rb +14 -14
  5. data/stylesheets/functions/checkers/_is-diagonal.scss +22 -22
  6. data/stylesheets/functions/checkers/_is-lower-triangular.scss +12 -12
  7. data/stylesheets/functions/checkers/_is-numeric.scss +18 -18
  8. data/stylesheets/functions/checkers/_is-square.scss +11 -11
  9. data/stylesheets/functions/checkers/_is-symmetric.scss +14 -14
  10. data/stylesheets/functions/checkers/_is-upper-triangular.scss +12 -12
  11. data/stylesheets/functions/getters/_get-column.scss +29 -29
  12. data/stylesheets/functions/getters/_get-entry.scss +20 -20
  13. data/stylesheets/functions/getters/_get-row.scss +21 -21
  14. data/stylesheets/functions/helpers/_is-triangular.scss +30 -30
  15. data/stylesheets/functions/helpers/_valid-coords.scss +37 -37
  16. data/stylesheets/functions/init/_matrix.scss +23 -23
  17. data/stylesheets/functions/init/_unit-matrix.scss +25 -25
  18. data/stylesheets/functions/misc/_add-matrices.scss +33 -33
  19. data/stylesheets/functions/misc/_columns.scss +9 -9
  20. data/stylesheets/functions/misc/_display.scss +42 -42
  21. data/stylesheets/functions/misc/_rows.scss +8 -8
  22. data/stylesheets/functions/misc/_transpose.scss +22 -22
  23. data/stylesheets/functions/setters/_add-column.scss +34 -34
  24. data/stylesheets/functions/setters/_add-row.scss +32 -32
  25. data/stylesheets/functions/setters/_set-column.scss +42 -42
  26. data/stylesheets/functions/setters/_set-entry.scss +19 -19
  27. data/stylesheets/functions/setters/_set-row.scss +36 -36
  28. data/stylesheets/functions/swap/_swap-columns.scss +32 -32
  29. data/stylesheets/functions/swap/_swap-entries.scss +20 -20
  30. data/stylesheets/functions/swap/_swap-rows.scss +24 -24
  31. data/stylesheets/matrix.scss +102 -102
  32. metadata +7 -9
@@ -1,9 +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);
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
9
  }
@@ -1,22 +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
- }
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
+ }
@@ -1,35 +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;
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
35
  }
@@ -1,33 +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;
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
33
  }
@@ -1,42 +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
- }
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
+ }
@@ -1,19 +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
- }
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
+ }
@@ -1,37 +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);
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
37
  }
@@ -1,32 +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
- }
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
+ }