File tree Expand file tree Collapse file tree 5 files changed +88
-0
lines changed
Expand file tree Collapse file tree 5 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ var util = require('./util');
77var MatrixTransposeView = require ( './views/transpose' ) ;
88var MatrixRowView = require ( './views/row' ) ;
99var MatrixColumnView = require ( './views/column' ) ;
10+ var MatrixFlipRowView = require ( './views/flipRow' ) ;
11+ var MatrixFlipColumnView = require ( './views/flipColumn' ) ;
1012
1113function abstractMatrix ( superCtor ) {
1214 if ( superCtor === undefined ) superCtor = Object ;
@@ -1192,6 +1194,14 @@ function abstractMatrix(superCtor) {
11921194 util . checkColumnIndex ( this , column ) ;
11931195 return new MatrixColumnView ( this , column ) ;
11941196 }
1197+
1198+ flipRowView ( ) {
1199+ return new MatrixFlipRowView ( this ) ;
1200+ }
1201+
1202+ flipColumnView ( ) {
1203+ return new MatrixFlipColumnView ( this ) ;
1204+ }
11951205 }
11961206
11971207 Matrix . prototype . klass = 'Matrix' ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var BaseView = require ( './base' ) ;
4+
5+ class MatrixFlipColumnView extends BaseView {
6+ constructor ( matrix ) {
7+ super ( matrix , matrix . rows , matrix . columns ) ;
8+ }
9+
10+ set ( rowIndex , columnIndex , value ) {
11+ this . matrix . set ( rowIndex , this . columns - columnIndex - 1 , value ) ;
12+ return this ;
13+ }
14+
15+ get ( rowIndex , columnIndex ) {
16+ return this . matrix . get ( rowIndex , this . columns - columnIndex - 1 ) ;
17+ }
18+ }
19+
20+ module . exports = MatrixFlipColumnView ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var BaseView = require ( './base' ) ;
4+
5+ class MatrixFlipRowView extends BaseView {
6+ constructor ( matrix ) {
7+ super ( matrix , matrix . rows , matrix . columns ) ;
8+ }
9+
10+ set ( rowIndex , columnIndex , value ) {
11+ this . matrix . set ( this . rows - rowIndex - 1 , columnIndex , value ) ;
12+ return this ;
13+ }
14+
15+ get ( rowIndex , columnIndex ) {
16+ return this . matrix . get ( this . rows - rowIndex - 1 , columnIndex ) ;
17+ }
18+ }
19+
20+ module . exports = MatrixFlipRowView ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var Matrix = require ( '../..' ) ;
4+
5+ describe ( 'Flip column view' , function ( ) {
6+ it ( 'should set and get values' , function ( ) {
7+ var m = Matrix . ones ( 5 , 8 ) ;
8+ var view = m . flipColumnView ( ) ;
9+
10+ m . set ( 0 , 3 , 5 ) ;
11+ view . get ( 0 , 4 ) . should . equal ( 5 ) ;
12+
13+ view . set ( 0 , 0 , 10 ) ;
14+ m . get ( 0 , 7 ) . should . equal ( 10 ) ;
15+
16+ view . rows . should . equal ( 5 ) ;
17+ view . columns . should . equal ( 8 ) ;
18+ } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var Matrix = require ( '../..' ) ;
4+
5+ describe ( 'Flip row view' , function ( ) {
6+ it ( 'should set and get values' , function ( ) {
7+ var m = Matrix . ones ( 5 , 8 ) ;
8+ var view = m . flipRowView ( ) ;
9+
10+ m . set ( 0 , 3 , 5 ) ;
11+ view . get ( 4 , 3 ) . should . equal ( 5 ) ;
12+
13+ view . set ( 0 , 0 , 10 ) ;
14+ m . get ( 4 , 0 ) . should . equal ( 10 ) ;
15+
16+ view . rows . should . equal ( 5 ) ;
17+ view . columns . should . equal ( 8 ) ;
18+ } ) ;
19+ } ) ;
You can’t perform that action at this time.
0 commit comments