Skip to content

Commit

Permalink
clamp & compare libcamera::Point
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Dec 31, 2024
1 parent f94fb81 commit e482c2f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ clamp(const CTRectangle &val, const CTRectangle &lo, const CTRectangle &hi)

return CTRectangle {x, y, width, height};
}

#if LIBCAMERA_VER_GE(0, 4, 0)
CTPoint
clamp(const CTPoint &val, const CTPoint &lo, const CTPoint &hi)
{
const int x = std::clamp(val.x, lo.x, hi.x);
const int y = std::clamp(val.y, lo.y, hi.y);

return CTPoint {x, y};
}
#endif
} // namespace std


Expand Down Expand Up @@ -169,6 +180,28 @@ operator>(const libcamera::Rectangle &lhs, const libcamera::Rectangle &rhs)
(lhs.y + lhs.height) > (rhs.y + rhs.height);
}

#if LIBCAMERA_VER_GE(0, 4, 0)
int
squared_sum(const libcamera::Point &p)
{
return p.x * p.x + p.y * p.y;
}

bool
operator<(const libcamera::Point &lhs, const libcamera::Point &rhs)
{
// check if lhs point is closer to origin than rhs point
return squared_sum(lhs) < squared_sum(rhs);
}

bool
operator>(const libcamera::Point &lhs, const libcamera::Point &rhs)
{
// check if lhs point is further away from origin than rhs point
return squared_sum(lhs) > squared_sum(rhs);
}
#endif

template<typename T>
bool
less(const libcamera::ControlValue &lhs, const libcamera::ControlValue &rhs)
Expand Down

0 comments on commit e482c2f

Please sign in to comment.