summaryrefslogtreecommitdiff
path: root/src/lib/rect.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-02-25 17:06:44 +0000
committerCarl Hetherington <cth@carlh.net>2016-02-25 17:06:44 +0000
commitd2e8a683eed6fb82d4d255fffaf571ff27057132 (patch)
treebea3ed6db13ab6d5a72673aa2c30a55d9e188f03 /src/lib/rect.h
parent03356464b29ff84f72d252efb22502754f55cfce (diff)
Plot video and subtitle on one track and audio on the rest in the timeline.
Diffstat (limited to 'src/lib/rect.h')
-rw-r--r--src/lib/rect.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/lib/rect.h b/src/lib/rect.h
index 5758dd04e..602acfc4b 100644
--- a/src/lib/rect.h
+++ b/src/lib/rect.h
@@ -21,6 +21,7 @@
#define DCPOMATIC_RECT_H
#include "position.h"
+#include <boost/optional.hpp>
#include <algorithm>
/* Put this inside a namespace as Apple put a Rect in the global namespace */
@@ -67,16 +68,24 @@ public:
return Position<T> (x, y);
}
- Rect<T> intersection (Rect<T> const & other) const
+ boost::optional<Rect<T> > intersection (Rect<T> const & other) const
{
- T const tx = max (x, other.x);
- T const ty = max (y, other.y);
+ /* This isn't exactly the paragon of mathematical precision */
- return Rect (
+ T const tx = std::max (x, other.x);
+ T const ty = std::max (y, other.y);
+
+ Rect r (
tx, ty,
- min (x + width, other.x + other.width) - tx,
- min (y + height, other.y + other.height) - ty
+ std::min (x + width, other.x + other.width) - tx,
+ std::min (y + height, other.y + other.height) - ty
);
+
+ if (r.width < 0 || r.height < 0) {
+ return boost::optional<Rect<T> > ();
+ }
+
+ return r;
}
void extend (Rect<T> const & other)