summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/FloatPoint.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-06-02 12:07:03 +0100
committerBen Murdoch <benm@google.com>2011-06-10 10:47:21 +0100
commit2daae5fd11344eaa88a0d92b0f6d65f8d2255c00 (patch)
treee4964fbd1cb70599f7718ff03e50ea1dab33890b /Source/WebCore/platform/graphics/FloatPoint.cpp
parent87bdf0060a247bfbe668342b87e0874182e0ffa9 (diff)
downloadexternal_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.zip
external_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.tar.gz
external_webkit-2daae5fd11344eaa88a0d92b0f6d65f8d2255c00.tar.bz2
Merge WebKit at r84325: Initial merge by git.
Change-Id: Ic1a909300ecc0a13ddc6b4e784371d2ac6e3d59b
Diffstat (limited to 'Source/WebCore/platform/graphics/FloatPoint.cpp')
-rw-r--r--Source/WebCore/platform/graphics/FloatPoint.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/Source/WebCore/platform/graphics/FloatPoint.cpp b/Source/WebCore/platform/graphics/FloatPoint.cpp
index 226ae71..abe9b86 100644
--- a/Source/WebCore/platform/graphics/FloatPoint.cpp
+++ b/Source/WebCore/platform/graphics/FloatPoint.cpp
@@ -31,6 +31,7 @@
#include "TransformationMatrix.h"
#include "FloatConversion.h"
#include "IntPoint.h"
+#include <limits>
#include <math.h>
namespace WebCore {
@@ -73,4 +74,43 @@ FloatPoint FloatPoint::narrowPrecision(double x, double y)
return FloatPoint(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y));
}
+float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c)
+{
+ if (p2.x() == p1.x())
+ return std::numeric_limits<float>::infinity();
+
+ // y = mx + c
+ float slope = (p2.y() - p1.y()) / (p2.x() - p1.x());
+ c = p1.y() - slope * p1.x();
+ return slope;
+}
+
+bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection)
+{
+ float pOffset = 0;
+ float pSlope = findSlope(p1, p2, pOffset);
+
+ float dOffset = 0;
+ float dSlope = findSlope(d1, d2, dOffset);
+
+ if (dSlope == pSlope)
+ return false;
+
+ if (pSlope == std::numeric_limits<float>::infinity()) {
+ intersection.setX(p1.x());
+ intersection.setY(dSlope * intersection.x() + dOffset);
+ return true;
+ }
+ if (dSlope == std::numeric_limits<float>::infinity()) {
+ intersection.setX(d1.x());
+ intersection.setY(pSlope * intersection.x() + pOffset);
+ return true;
+ }
+
+ // Find x at intersection, where ys overlap; x = (c' - c) / (m - m')
+ intersection.setX((dOffset - pOffset) / (pSlope - dSlope));
+ intersection.setY(pSlope * intersection.x() + pOffset);
+ return true;
+}
+
}