--- /dev/null
+/*
+ Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcpomatic_time.h"
+#include "dcpomatic_time_coalesce.h"
+
+
+namespace dcpomatic {
+
+
+template <class T>
+std::list<TimePeriod<T>> overlap (std::list<TimePeriod<T>> const & A, std::list<TimePeriod<T>> const& B)
+{
+ std::list<TimePeriod<T>> result;
+
+ for (auto i: A) {
+ for (auto j: B) {
+ if (auto ov = i.overlap(j)) {
+ result.push_back(*ov);
+ }
+ }
+ }
+
+ return coalesce (result);
+}
+
+
+}
+
#include "lib/dcpomatic_time.h"
#include "lib/dcpomatic_time_coalesce.h"
+#include "lib/dcpomatic_time_overlap.h"
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <list>
/* Check that rounding down to non-integer frame rates works */
BOOST_CHECK_EQUAL (DCPTime(45312).floor(29.976).get(), 44836);
}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test1)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ BOOST_CHECK (overlap(A, std::list<DCPTimePeriod>()).empty());
+ BOOST_CHECK (overlap(std::list<DCPTimePeriod>(), A).empty());
+}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test2)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ list<DCPTimePeriod> B = {
+ { DCPTime(6), DCPTime(10) }
+ };
+
+ BOOST_CHECK (overlap(A, B).empty());
+ BOOST_CHECK (overlap(B, A).empty());
+}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test3)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ list<DCPTimePeriod> B = {
+ { DCPTime(2), DCPTime(3) }
+ };
+
+ std::list<DCPTimePeriod> correct = {
+ { DCPTime(2), DCPTime(3) }
+ };
+
+ BOOST_CHECK (overlap(A, B) == correct);
+ BOOST_CHECK (overlap(B, A) == correct);
+}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test4)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ list<DCPTimePeriod> B = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ std::list<DCPTimePeriod> correct = {
+ { DCPTime(0), DCPTime(5) }
+ };
+
+ BOOST_CHECK (overlap(A, B) == correct);
+ BOOST_CHECK (overlap(B, A) == correct);
+}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test5)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) },
+ { DCPTime(7), DCPTime(12) }
+ };
+
+ list<DCPTimePeriod> B = {
+ { DCPTime(0), DCPTime(15) }
+ };
+
+ std::list<DCPTimePeriod> correct = {
+ { DCPTime(0), DCPTime(5) },
+ { DCPTime(7), DCPTime(12) }
+ };
+
+ BOOST_CHECK (overlap(A, B) == correct);
+ BOOST_CHECK (overlap(B, A) == correct);
+}
+
+
+BOOST_AUTO_TEST_CASE (dcpomatic_time_overlap_test6)
+{
+ list<DCPTimePeriod> A = {
+ { DCPTime(0), DCPTime(5) },
+ { DCPTime(7), DCPTime(12) }
+ };
+
+ list<DCPTimePeriod> B = {
+ { DCPTime(3), DCPTime(10) }
+ };
+
+ std::list<DCPTimePeriod> correct = {
+ { DCPTime(3), DCPTime(5) },
+ { DCPTime(7), DCPTime(10) }
+ };
+
+ BOOST_CHECK (overlap(A, B) == correct);
+ BOOST_CHECK (overlap(B, A) == correct);
+}