From d2e8a683eed6fb82d4d255fffaf571ff27057132 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Feb 2016 17:06:44 +0000 Subject: Plot video and subtitle on one track and audio on the rest in the timeline. --- src/lib/rect.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/lib') 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 #include /* Put this inside a namespace as Apple put a Rect in the global namespace */ @@ -67,16 +68,24 @@ public: return Position (x, y); } - Rect intersection (Rect const & other) const + boost::optional > intersection (Rect 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 > (); + } + + return r; } void extend (Rect const & other) -- cgit v1.2.3