Skip to content

Commit

Permalink
implement scalar-array less and greater comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Jun 19, 2024
1 parent 2c65b2c commit 2b29386
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,17 @@ less(const libcamera::ControlValue &lhs, const libcamera::ControlValue &rhs)
return false;
}
}
else if (rhs.isArray()) {
// scalar-array comparison
const libcamera::Span<const T> vb = rhs.get<libcamera::Span<const T>>();
const T va = lhs.get<T>();
for (size_t i = 0; i < vb.size(); i++)
if (va < vb[i])
return true;
return false;
}
else {
assert(!lhs.isArray() && !rhs.isArray());
// scalar-scalar comparison
return lhs.get<T>() < rhs.get<T>();
}
Expand Down Expand Up @@ -211,7 +221,17 @@ greater(const libcamera::ControlValue &lhs, const libcamera::ControlValue &rhs)
return false;
}
}
else if (rhs.isArray()) {
// scalar-array comparison
const libcamera::Span<const T> vb = rhs.get<libcamera::Span<const T>>();
const T va = lhs.get<T>();
for (size_t i = 0; i < vb.size(); i++)
if (va > vb[i])
return true;
return false;
}
else {
assert(!lhs.isArray() && !rhs.isArray());
// scalar-scalar comparison
return lhs.get<T>() > rhs.get<T>();
}
Expand Down

0 comments on commit 2b29386

Please sign in to comment.