Index: Source/core/dom/DOMQuad.cpp |
diff --git a/Source/core/dom/DOMQuad.cpp b/Source/core/dom/DOMQuad.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ba5f1906532e8868fc33a62754e381bb5e065a9a |
--- /dev/null |
+++ b/Source/core/dom/DOMQuad.cpp |
@@ -0,0 +1,110 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/dom/DOMQuad.h" |
+ |
+#include "core/dom/DOMPointInit.h" |
+#include "core/dom/DOMRectInit.h" |
+ |
+namespace blink { |
+ |
+DOMQuadPoint* DOMQuadPoint::create(const DOMPointInit& point, Member<DOMQuad> quad) |
+{ |
+ return new DOMQuadPoint(point.x(), point.y(), quad); |
+} |
+ |
+DOMQuadPoint* DOMQuadPoint::create(double x, double y, Member<DOMQuad> quad) |
+{ |
+ return new DOMQuadPoint(x, y, quad); |
+} |
+ |
+DOMQuadPoint::DOMQuadPoint(double x, double y, Member<DOMQuad> quad) |
+ : DOMPoint(x, y, 0, 1) |
+ , m_quad(quad) |
+{ |
+} |
+ |
+void DOMQuadPoint::setX(double x) |
+{ |
+ m_x = x; |
+ m_quad->updateHorizontalBounds(); |
+} |
+ |
+void DOMQuadPoint::setY(double y) |
+{ |
+ m_y = y; |
+ m_quad->updateVerticalBounds(); |
+} |
+ |
+DOMQuad* DOMQuad::create(const DOMRectInit& rect) |
+{ |
+ return new DOMQuad(rect); |
+} |
+ |
+DOMQuad* DOMQuad::create(const DOMPointInit& p1, const DOMPointInit& p2, |
+ const DOMPointInit& p3, const DOMPointInit& p4) |
+{ |
+ return new DOMQuad(p1, p2, p3, p4); |
+} |
+ |
+DOMQuad::DOMQuad(const DOMRectInit& rect) |
+ : m_p1(DOMQuadPoint::create(rect.x(), rect.y(), this)) |
+ , m_p2(DOMQuadPoint::create(rect.x() + rect.width(), rect.y(), this)) |
+ , m_p3(DOMQuadPoint::create(rect.x() + rect.width(), rect.y() + rect.height(), this)) |
+ , m_p4(DOMQuadPoint::create(rect.x(), rect.y() + rect.height(), this)) |
+ , m_bounds(DOMRect::create(rect.x(), rect.y(), rect.width(), rect.height())) |
+{ |
+} |
+ |
+DOMQuad::DOMQuad(const DOMPointInit& p1, const DOMPointInit& p2, |
+ const DOMPointInit& p3, const DOMPointInit& p4) |
+ : m_p1(DOMQuadPoint::create(p1, this)) |
+ , m_p2(DOMQuadPoint::create(p2, this)) |
+ , m_p3(DOMQuadPoint::create(p3, this)) |
+ , m_p4(DOMQuadPoint::create(p4, this)) |
+ , m_bounds(nullptr) |
+{ |
+} |
+ |
+DOMRectReadOnly* DOMQuad::bounds() |
+{ |
+ if (!m_bounds) { |
+ m_bounds = DOMRect::create(); |
+ updateHorizontalBounds(); |
+ updateVerticalBounds(); |
+ } |
+ |
+ return m_bounds; |
+} |
+ |
+static inline double min4(double a, double b, double c, double d) |
+{ |
+ return std::min(std::min(a, b), std::min(c, d)); |
+} |
+ |
+static inline double max4(double a, double b, double c, double d) |
+{ |
+ return std::max(std::max(a, b), std::max(c, d)); |
+} |
+ |
+void DOMQuad::updateHorizontalBounds() |
+{ |
+ double left = min4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x()); |
+ double right = max4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x()); |
+ |
+ m_bounds->setX(left); |
+ m_bounds->setWidth(right - left); |
+} |
+ |
+void DOMQuad::updateVerticalBounds() |
+{ |
+ double top = min4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y()); |
+ double bottom = max4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y()); |
+ |
+ m_bounds->setY(top); |
+ m_bounds->setHeight(bottom - top); |
+} |
+ |
+} // namespace blink |