Skip to content

Commit

Permalink
LibGfx: Inline some AffineTransform functions
Browse files Browse the repository at this point in the history
Asking if an AffineTransform is identity or translate-only can be done
inline and avoid the cost of a function call in tight loops.
  • Loading branch information
awesomekling committed Mar 2, 2024
1 parent 2dacd12 commit e46deec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 0 additions & 10 deletions Userland/Libraries/LibGfx/AffineTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@

namespace Gfx {

bool AffineTransform::is_identity() const
{
return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1 && m_values[4] == 0 && m_values[5] == 0;
}

bool AffineTransform::is_identity_or_translation() const
{
return a() == 1 && b() == 0 && c() == 0 && d() == 1;
}

float AffineTransform::x_scale() const
{
return AK::hypot(m_values[0], m_values[1]);
Expand Down
11 changes: 9 additions & 2 deletions Userland/Libraries/LibGfx/AffineTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ class AffineTransform {
{
}

bool is_identity() const;
bool is_identity_or_translation() const;
[[nodiscard]] bool is_identity() const
{
return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1 && m_values[4] == 0 && m_values[5] == 0;
}

[[nodiscard]] bool is_identity_or_translation() const
{
return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1;
}

void map(float unmapped_x, float unmapped_y, float& mapped_x, float& mapped_y) const;

Expand Down

0 comments on commit e46deec

Please sign in to comment.