diff --git a/src/lib.rs b/src/lib.rs index 0a019df..ca16a82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,9 @@ impl Matrix &T { + if row >= self.rows || column >= self.columns { + panic!("Index given is out of range.") + } let mut index = 0; index += row * self.columns; index += column; @@ -62,6 +65,9 @@ impl Matrix () { + if row >= self.rows || column >= self.columns { + panic!("Index given is out of range.") + } let mut index = 0; index += row * self.columns; index += column; @@ -87,6 +93,20 @@ impl Matrix () { + if column1 >= self.columns || column2 >= self.columns { + panic!("Column index is out of bounds.") + } + + //Get copy of column2 + let temp = self.get_column(column2); + for i in 0..self.rows { + self.data[column2 + (i * self.columns)] = self.data[column1 + (i * self.columns)]; + self.data[column1 + (i * self.columns)] = temp[i]; + } + + } + pub fn get_determinant(&self) -> T { if self.rows != self.columns { panic!("Only nxn matrixes can have a determinant."); @@ -102,9 +122,11 @@ impl Matrix