| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * Copyright (C) 2013 Xidorn Quan (quanxunzhen@gmail.com) | 4 * Copyright (C) 2013 Xidorn Quan (quanxunzhen@gmail.com) |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/geometry/FloatQuad.h" | 32 #include "platform/geometry/FloatQuad.h" |
| 33 | 33 |
| 34 #include <algorithm> | 34 #include <algorithm> |
| 35 #include <limits> | 35 #include <limits> |
| 36 | 36 |
| 37 using namespace std; | |
| 38 | |
| 39 namespace blink { | 37 namespace blink { |
| 40 | 38 |
| 41 static inline float min4(float a, float b, float c, float d) | 39 static inline float min4(float a, float b, float c, float d) |
| 42 { | 40 { |
| 43 return min(min(a, b), min(c, d)); | 41 return std::min(std::min(a, b), std::min(c, d)); |
| 44 } | 42 } |
| 45 | 43 |
| 46 static inline float max4(float a, float b, float c, float d) | 44 static inline float max4(float a, float b, float c, float d) |
| 47 { | 45 { |
| 48 return max(max(a, b), max(c, d)); | 46 return std::max(std::max(a, b), std::max(c, d)); |
| 49 } | 47 } |
| 50 | 48 |
| 51 inline float dot(const FloatSize& a, const FloatSize& b) | 49 inline float dot(const FloatSize& a, const FloatSize& b) |
| 52 { | 50 { |
| 53 return a.width() * b.width() + a.height() * b.height(); | 51 return a.width() * b.width() + a.height() * b.height(); |
| 54 } | 52 } |
| 55 | 53 |
| 56 inline float determinant(const FloatSize& a, const FloatSize& b) | 54 inline float determinant(const FloatSize& a, const FloatSize& b) |
| 57 { | 55 { |
| 58 return a.width() * b.height() - a.height() * b.width(); | 56 return a.width() * b.height() - a.height() * b.width(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 87 float top = min4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y()); | 85 float top = min4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y()); |
| 88 | 86 |
| 89 float right = max4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x()); | 87 float right = max4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x()); |
| 90 float bottom = max4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y()); | 88 float bottom = max4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y()); |
| 91 | 89 |
| 92 return FloatRect(left, top, right - left, bottom - top); | 90 return FloatRect(left, top, right - left, bottom - top); |
| 93 } | 91 } |
| 94 | 92 |
| 95 static inline bool withinEpsilon(float a, float b) | 93 static inline bool withinEpsilon(float a, float b) |
| 96 { | 94 { |
| 97 return fabs(a - b) < numeric_limits<float>::epsilon(); | 95 return fabs(a - b) < std::numeric_limits<float>::epsilon(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 bool FloatQuad::isRectilinear() const | 98 bool FloatQuad::isRectilinear() const |
| 101 { | 99 { |
| 102 return (withinEpsilon(m_p1.x(), m_p2.x()) && withinEpsilon(m_p2.y(), m_p3.y(
)) && withinEpsilon(m_p3.x(), m_p4.x()) && withinEpsilon(m_p4.y(), m_p1.y())) | 100 return (withinEpsilon(m_p1.x(), m_p2.x()) && withinEpsilon(m_p2.y(), m_p3.y(
)) && withinEpsilon(m_p3.x(), m_p4.x()) && withinEpsilon(m_p4.y(), m_p1.y())) |
| 103 || (withinEpsilon(m_p1.y(), m_p2.y()) && withinEpsilon(m_p2.x(), m_p3.x(
)) && withinEpsilon(m_p3.y(), m_p4.y()) && withinEpsilon(m_p4.x(), m_p1.x())); | 101 || (withinEpsilon(m_p1.y(), m_p2.y()) && withinEpsilon(m_p2.x(), m_p3.x(
)) && withinEpsilon(m_p3.y(), m_p4.y()) && withinEpsilon(m_p4.x(), m_p1.x())); |
| 104 } | 102 } |
| 105 | 103 |
| 106 bool FloatQuad::containsPoint(const FloatPoint& p) const | 104 bool FloatQuad::containsPoint(const FloatPoint& p) const |
| 107 { | 105 { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 225 |
| 228 } | 226 } |
| 229 | 227 |
| 230 bool FloatQuad::isCounterclockwise() const | 228 bool FloatQuad::isCounterclockwise() const |
| 231 { | 229 { |
| 232 // Return if the two first vectors are turning clockwise. If the quad is con
vex then all following vectors will turn the same way. | 230 // Return if the two first vectors are turning clockwise. If the quad is con
vex then all following vectors will turn the same way. |
| 233 return determinant(m_p2 - m_p1, m_p3 - m_p2) < 0; | 231 return determinant(m_p2 - m_p1, m_p3 - m_p2) < 0; |
| 234 } | 232 } |
| 235 | 233 |
| 236 } // namespace blink | 234 } // namespace blink |
| OLD | NEW |