go-gl / mathgl

A pure Go 3D math library.
BSD 3-Clause "New" or "Revised" License
554 stars 65 forks source link

Add common method for number of colums and rows #92

Closed stewi1014 closed 11 months ago

stewi1014 commented 1 year ago

Currently the library's open methods on matrices do not easily conform to a single unified interface very well.

The At(row, col) -> n function is the only function (save me being blind) that is commonly implemented across all matrix implementations.

I propose that all matrix implementations implement a common interface;

interface {
    At(row, col int) float32 | float64
    NumRows() int
    NumCols() int
}

I personally like the garbage-in garbage-out approach from implementations of .At in this library, but I do feel that all matrices should also provide .NumRows() and .NumCols() like MatMxN does, or some equivalent.

In the case of generalized methods that can operate on matrices of varying dimensions, this would allow one to implement methods that can operate on all matrix implementations in this library using an interface, avoiding the need to duplicate functions or type-switch to find the dimensions of a matrix.

pwaller commented 11 months ago

Closing as complete from #93.