summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-09-03 18:33:15 +0200
committerCarl Hetherington <cth@carlh.net>2023-09-04 00:23:17 +0200
commitd1ae563da6068da4132bd50e098d442dc4ec1bb0 (patch)
tree75c381a33076ad9330b5b9cdff0a9ee2c998483e /src
parent07ee246249f77517320ee548d5b2bd2bf62a4578 (diff)
Add PixelQuanta::round taking floats.
Diffstat (limited to 'src')
-rw-r--r--src/lib/pixel_quanta.cc13
-rw-r--r--src/lib/pixel_quanta.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/pixel_quanta.cc b/src/lib/pixel_quanta.cc
index 7c1d285cf..30894ddb7 100644
--- a/src/lib/pixel_quanta.cc
+++ b/src/lib/pixel_quanta.cc
@@ -60,6 +60,19 @@ PixelQuanta::round (dcp::Size size) const
}
+dcp::Size
+PixelQuanta::round(float x_, float y_) const
+{
+ auto round_one = [](float v, int q) {
+ return q == 1
+ ? static_cast<int>(std::lround(v))
+ : (static_cast<int>(v) + static_cast<int>(v) % q);
+ };
+
+ return { round_one(x_, x), round_one(y_, y) };
+}
+
+
PixelQuanta
max (PixelQuanta const& a, PixelQuanta const& b)
{
diff --git a/src/lib/pixel_quanta.h b/src/lib/pixel_quanta.h
index 37d2321f4..bef23b2b1 100644
--- a/src/lib/pixel_quanta.h
+++ b/src/lib/pixel_quanta.h
@@ -55,6 +55,7 @@ public:
int round_x (int x_) const;
int round_y (int y_) const;
dcp::Size round (dcp::Size size) const;
+ dcp::Size round(float x, float y) const;
int x;
int y;