Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rasterisation Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sr1g19
Rasterisation Project
Commits
83e86f7e
Commit
83e86f7e
authored
4 years ago
by
sr1g19
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9d73978f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/matrix/2x2matrix.c
+70
-0
70 additions, 0 deletions
src/matrix/2x2matrix.c
with
70 additions
and
0 deletions
src/matrix/2x2matrix.c
0 → 100644
+
70
−
0
View file @
83e86f7e
#include
"2x2matrix.h"
_2x2Matrix
add_2x2
(
_2x2Matrix
m1
,
_2x2Matrix
m2
){
_2x2Matrix
ma
=
{
m1
.
a11
+
m2
.
a11
,
m1
.
a12
+
m2
.
a12
,
m1
.
a21
+
m2
.
a21
,
m1
.
a22
+
m2
.
a22
};
return
ma
;
}
_2x2Matrix
minus_2x2
(
_2x2Matrix
m1
,
_2x2Matrix
m2
){
_2x2Matrix
ma
=
{
m1
.
a11
-
m2
.
a11
,
m1
.
a12
-
m2
.
a12
,
m1
.
a21
-
m2
.
a21
,
m1
.
a22
-
m2
.
a22
};
return
ma
;
}
_2x2Matrix
multiply_2x2
(
_2x2Matrix
m1
,
_2x2Matrix
m2
){
_2x2Matrix
ma
=
{
(
m1
.
a12
*
m2
.
a21
)
+
(
m1
.
a11
*
m2
.
a11
),(
m1
.
a11
*
m2
.
a12
)
+
(
m1
.
a12
*
m2
.
a22
),
(
m1
.
a22
*
m2
.
a21
)
+
(
m1
.
a21
*
m2
.
a11
),(
m1
.
a21
*
m2
.
a12
)
+
(
m1
.
a22
*
m2
.
a22
)
};
return
ma
;
}
_2x2Matrix
scale_2x2
(
_2x2Matrix
m1
,
float
scale
)
{
_2x2Matrix
ma
=
{
m1
.
a11
*
scale
,
m1
.
a12
*
scale
,
m1
.
a21
*
scale
,
m1
.
a22
*
scale
};
return
ma
;
}
float
det_2x2
(
_2x2Matrix
m
){
return
(
m
.
a11
*
m
.
a22
)
-
(
m
.
a12
*
m
.
a21
);
}
_2x2Matrix
inverse_2x2
(
_2x2Matrix
m
){
float
detM
=
det_2x2
(
m
);
if
(
detM
!=
0
){
_2x2Matrix
specMat
=
{
m
.
a22
,
-
m
.
a12
,
-
m
.
a21
,
m
.
a11
};
return
scale_2x2
(
specMat
,
1
.
0
/
detM
);
}
_2x2Matrix
badM
=
{
1
.
0
f
,
1
.
0
f
,
1
.
0
f
,
1
.
0
f
};
return
badM
;
}
_2x1Matrix
transpose_2x2
(
_2x2Matrix
m1
,
_2x1Matrix
m2
){
_2x1Matrix
ma
=
{
(
m1
.
a12
*
m2
.
a21
)
+
(
m1
.
a11
*
m2
.
a11
),
(
m1
.
a22
*
m2
.
a21
)
+
(
m1
.
a21
*
m2
.
a11
)
};
return
ma
;
}
unsigned
char
equals_2x2
(
_2x2Matrix
m1
,
_2x2Matrix
m2
)
{
if
(
m1
.
a11
==
m2
.
a11
&&
m1
.
a12
==
m2
.
a12
&&
m1
.
a21
==
m2
.
a21
&&
m1
.
a22
==
m2
.
a22
)
return
42
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment