-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move 2x2 and 4x4 matrices into their own modules
- Loading branch information
Showing
4 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import vec | ||
|
||
// A 2x2 matrix representated as a 4 length vector of x,y,z,w so that | ||
// |x y| | ||
// |z w| | ||
|
||
struct mat2x2 : float4 | ||
|
||
def operator*(o:mat2x2): | ||
return mat2x2 { dot(o.xz, this), dot(o.yw, this), | ||
dot(o.xz, this.zw), dot(o.yw, this.zw) } | ||
|
||
def operator*(o:float2): | ||
return float2 { dot(o, this), | ||
dot(o, this.zw) } | ||
|
||
def determinant(): | ||
return x*w - y*z | ||
|
||
def adjugate(): | ||
return mat2x2 { w, -y, -z, x } | ||
|
||
def inverse(): | ||
return adjugate() / determinant() | ||
|
||
def trace(): | ||
return x*w | ||
|
||
|
||
// The identity matrix: | ||
// |1 0| | ||
// |0 1| | ||
let mat2x2_identity = mat2x2 { 1.0, 0.0, 0.0, 1.0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import testing | ||
import matrix | ||
import mat2x2 | ||
|
||
run_test("matrix"): | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters