| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 static inline float Max4(float a, float b, float c, float d) { | 45 static inline float Max4(float a, float b, float c, float d) { |
| 46 return std::max(std::max(a, b), std::max(c, d)); | 46 return std::max(std::max(a, b), std::max(c, d)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 inline float Dot(const FloatSize& a, const FloatSize& b) { | 49 inline float Dot(const FloatSize& a, const FloatSize& b) { |
| 50 return a.Width() * b.Width() + a.Height() * b.Height(); | 50 return a.Width() * b.Width() + a.Height() * b.Height(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 inline float Determinant(const FloatSize& a, const FloatSize& b) { | 53 inline float Determinant2(const FloatSize& a, const FloatSize& b) { |
| 54 return a.Width() * b.Height() - a.Height() * b.Width(); | 54 return a.Width() * b.Height() - a.Height() * b.Width(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 inline bool IsPointInTriangle(const FloatPoint& p, | 57 inline bool IsPointInTriangle(const FloatPoint& p, |
| 58 const FloatPoint& t1, | 58 const FloatPoint& t1, |
| 59 const FloatPoint& t2, | 59 const FloatPoint& t2, |
| 60 const FloatPoint& t3) { | 60 const FloatPoint& t3) { |
| 61 // Compute vectors | 61 // Compute vectors |
| 62 FloatSize v0 = t3 - t1; | 62 FloatSize v0 = t3 - t1; |
| 63 FloatSize v1 = t2 - t1; | 63 FloatSize v1 = t2 - t1; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 v3 = p4_ - p3_; | 162 v3 = p4_ - p3_; |
| 163 v4 = p1_ - p4_; | 163 v4 = p1_ - p4_; |
| 164 } else { | 164 } else { |
| 165 v1 = p4_ - p1_; | 165 v1 = p4_ - p1_; |
| 166 v2 = p1_ - p2_; | 166 v2 = p1_ - p2_; |
| 167 v3 = p2_ - p3_; | 167 v3 = p2_ - p3_; |
| 168 v4 = p3_ - p4_; | 168 v4 = p3_ - p4_; |
| 169 } | 169 } |
| 170 | 170 |
| 171 FloatPoint p = RightMostCornerToVector(rect, v1); | 171 FloatPoint p = RightMostCornerToVector(rect, v1); |
| 172 if (Determinant(v1, p - p1_) < 0) | 172 if (Determinant2(v1, p - p1_) < 0) |
| 173 return false; | 173 return false; |
| 174 | 174 |
| 175 p = RightMostCornerToVector(rect, v2); | 175 p = RightMostCornerToVector(rect, v2); |
| 176 if (Determinant(v2, p - p2_) < 0) | 176 if (Determinant2(v2, p - p2_) < 0) |
| 177 return false; | 177 return false; |
| 178 | 178 |
| 179 p = RightMostCornerToVector(rect, v3); | 179 p = RightMostCornerToVector(rect, v3); |
| 180 if (Determinant(v3, p - p3_) < 0) | 180 if (Determinant2(v3, p - p3_) < 0) |
| 181 return false; | 181 return false; |
| 182 | 182 |
| 183 p = RightMostCornerToVector(rect, v4); | 183 p = RightMostCornerToVector(rect, v4); |
| 184 if (Determinant(v4, p - p4_) < 0) | 184 if (Determinant2(v4, p - p4_) < 0) |
| 185 return false; | 185 return false; |
| 186 | 186 |
| 187 // If not all of the rectangle is outside one of the quad's four sides, then | 187 // If not all of the rectangle is outside one of the quad's four sides, then |
| 188 // that means at least a part of the rectangle is overlapping the quad. | 188 // that means at least a part of the rectangle is overlapping the quad. |
| 189 return true; | 189 return true; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Tests whether the line is contained by or intersected with the circle. | 192 // Tests whether the line is contained by or intersected with the circle. |
| 193 static inline bool LineIntersectsCircle(const FloatPoint& center, | 193 static inline bool LineIntersectsCircle(const FloatPoint& center, |
| 194 float radius, | 194 float radius, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 transformed_quad.Scale(radii.Height(), radii.Width()); | 238 transformed_quad.Scale(radii.Height(), radii.Width()); |
| 239 | 239 |
| 240 FloatPoint origin_point; | 240 FloatPoint origin_point; |
| 241 return transformed_quad.IntersectsCircle(origin_point, | 241 return transformed_quad.IntersectsCircle(origin_point, |
| 242 radii.Height() * radii.Width()); | 242 radii.Height() * radii.Width()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool FloatQuad::IsCounterclockwise() const { | 245 bool FloatQuad::IsCounterclockwise() const { |
| 246 // Return if the two first vectors are turning clockwise. If the quad is | 246 // Return if the two first vectors are turning clockwise. If the quad is |
| 247 // convex then all following vectors will turn the same way. | 247 // convex then all following vectors will turn the same way. |
| 248 return Determinant(p2_ - p1_, p3_ - p2_) < 0; | 248 return Determinant2(p2_ - p1_, p3_ - p2_) < 0; |
| 249 } | 249 } |
| 250 | 250 |
| 251 String FloatQuad::ToString() const { | 251 String FloatQuad::ToString() const { |
| 252 return String::Format("%s; %s; %s; %s", p1_.ToString().Ascii().data(), | 252 return String::Format("%s; %s; %s; %s", p1_.ToString().Ascii().data(), |
| 253 p2_.ToString().Ascii().data(), | 253 p2_.ToString().Ascii().data(), |
| 254 p3_.ToString().Ascii().data(), | 254 p3_.ToString().Ascii().data(), |
| 255 p4_.ToString().Ascii().data()); | 255 p4_.ToString().Ascii().data()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace blink | 258 } // namespace blink |
| OLD | NEW |