Skip to content

Commit

Permalink
karm-math: Fast path for Trans2::multiply()
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Apr 7, 2024
1 parent 730c8c7 commit bf36ba9
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/libs/karm-math/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ union Trans2 {
: _els{xx, xy, yx, yy, ox, oy} {}

static constexpr Trans2 identity() {
return Trans2(1, 0, 0, 1, 0, 0);
return {1, 0, 0, 1, 0, 0};
}

static constexpr Trans2 rotate(T angle) {
Expand Down Expand Up @@ -70,14 +70,26 @@ union Trans2 {
}

constexpr Trans2 multiply(Trans2 const &other) const {
return {
xx * other.xx + xy * other.yx,
xx * other.xy + xy * other.yy,
yx * other.xx + yy * other.yx,
yx * other.xy + yy * other.yy,
ox * other.xx + oy * other.yx + other.ox,
ox * other.xy + oy * other.yy + other.oy,
Trans2 res = {
xx * other.xx,
0.0,
0.0,
yy * other.yy,
ox * other.xx + other.ox,
oy * other.yy + other.oy,
};

if (xy != 0.0 || yx != 0.0 ||
other.xy != 0.0 || other.yx != 0.0) {
res.xx += xy * other.yx;
res.xy += xx * other.xy + xy * other.yy;
res.yx += yx * other.xx + yy * other.yx;
res.yy += yx * other.xy;
res.ox += oy * other.yx;
res.oy += ox * other.xy;
}

return res;
}

constexpr Trans2 rotated(T angle) {
Expand Down

0 comments on commit bf36ba9

Please sign in to comment.