Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: Source/platform/geometry/FloatBoxTestHelpers.h

Issue 328333003: Adding Blink-side 3d Box and Bounds calculations to TransformOperations (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/geometry/FloatBoxTestHelpers.h
diff --git a/Source/platform/geometry/FloatBoxTestHelpers.h b/Source/platform/geometry/FloatBoxTestHelpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..f49316fadf84690bcdcf31ebb18aa03c59fab845
--- /dev/null
+++ b/Source/platform/geometry/FloatBoxTestHelpers.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "platform/geometry/FloatBox.h"
+
+#include <gtest/gtest.h>
+
+namespace WebCore {
+inline void PrintTo(const FloatBox& box, ::std::ostream* os)
+{
+ *os << "FloatBox("
+ << box.x() << ", "
+ << box.y() << ", "
+ << box.z() << ", "
+ << box.width() << ", "
+ << box.height() << ", "
+ << box.depth() << ")";
+}
+
+namespace FloatBoxTest {
+#define TEST_EPSILON 1e-3
+inline bool ApproximatelyEqual(const FloatBox& a, const FloatBox& b)
+{
+ if (::fabsf(a.x() - b.x()) > TEST_EPSILON
Ian Vollick 2014/06/16 15:23:37 Why not make an inline, "approximately equal" help
awoloszyn 2014/06/17 14:26:00 Done.
+ || ::fabsf(a.y() - b.y()) > TEST_EPSILON
+ || ::fabsf(a.z() - b.z()) > TEST_EPSILON
+ || ::fabsf(a.width() - b.width()) > TEST_EPSILON
+ || ::fabsf(a.height() - b.height()) > TEST_EPSILON
+ || ::fabsf(a.depth() - b.depth()) > TEST_EPSILON) {
+ return(false);
+ }
+ return(true);
+}
+
+inline ::testing::AssertionResult AssertAlmostEqual(const char* m_expr, const char* n_expr, const FloatBox& m, const FloatBox& n)
+{
+ if (!ApproximatelyEqual(m, n)) {
+ return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl
+ << " Actual:" << testing::PrintToString(n) << std::endl
+ << "Expected Approx:" << m_expr << std::endl
+ << " Which is:" << ::testing::PrintToString(m);
+ }
+ return ::testing::AssertionSuccess();
+}
+
+inline ::testing::AssertionResult AssertContains(const char* m_expr, const char* n_expr, const FloatBox& m, const FloatBox& n)
+{
+ FloatBox newM = m;
+ newM.expandTo(n);
+ if (!ApproximatelyEqual(m, newM)) {
+ return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl
+ << " Actual:" << testing::PrintToString(n) << std::endl
+ << "Not Contained in:" << m_expr << std::endl
+ << " Which is:" << ::testing::PrintToString(m);
+ }
+ return ::testing::AssertionSuccess();
+}
+
+}
+}
+

Powered by Google App Engine
This is Rietveld 408576698