diff --git a/src/clamp.cpp b/src/clamp.cpp index 10c2902..c0a9ea1 100644 --- a/src/clamp.cpp +++ b/src/clamp.cpp @@ -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 @@ -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 bool less(const libcamera::ControlValue &lhs, const libcamera::ControlValue &rhs)