aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/Intersection/QuadraticBezierClip.cpp
diff options
context:
space:
mode:
authorGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-10 21:46:10 +0000
committerGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-10 21:46:10 +0000
commit639df891487e40925a4f8d9a34fd3dc0c18b40a7 (patch)
treec4112e5a92f1bfc41271544792d57331c54ca453 /experimental/Intersection/QuadraticBezierClip.cpp
parent1ae2090d3a77b6be07bd1de134c233038df1f975 (diff)
work in progress for shape operations
A experimental/Intersection A experimental/Intersection/Intersections.h A experimental/Intersection/DataTypes.cpp A experimental/Intersection/QuadraticReduceOrder.cpp A experimental/Intersection/IntersectionUtilities.cpp A experimental/Intersection/CubicIntersection_Tests.h A experimental/Intersection/LineParameteters_Test.cpp A experimental/Intersection/ReduceOrder.cpp A experimental/Intersection/QuadraticIntersection.cpp A experimental/Intersection/Extrema.h A experimental/Intersection/CubicIntersection_TestData.h A experimental/Intersection/QuadraticParameterization_Test.cpp A experimental/Intersection/TestUtilities.cpp A experimental/Intersection/CubicRoots.cpp A experimental/Intersection/QuadraticParameterization.cpp A experimental/Intersection/QuadraticSubDivide.cpp A experimental/Intersection/LineIntersection_Test.cpp A experimental/Intersection/LineIntersection.cpp A experimental/Intersection/CubicParameterizationCode.cpp A experimental/Intersection/LineParameters.h A experimental/Intersection/CubicIntersection.h A experimental/Intersection/CubeRoot.cpp A experimental/Intersection/SkAntiEdge.h A experimental/Intersection/ConvexHull_Test.cpp A experimental/Intersection/CubicBezierClip_Test.cpp A experimental/Intersection/CubicIntersection_Tests.cpp A experimental/Intersection/CubicBezierClip.cpp A experimental/Intersection/CubicIntersectionT.cpp A experimental/Intersection/Inline_Tests.cpp A experimental/Intersection/ReduceOrder_Test.cpp A experimental/Intersection/QuadraticIntersection_TestData.h A experimental/Intersection/DataTypes.h A experimental/Intersection/Extrema.cpp A experimental/Intersection/EdgeApp.cpp A experimental/Intersection/CubicIntersection_TestData.cpp A experimental/Intersection/IntersectionUtilities.h A experimental/Intersection/CubicReduceOrder.cpp A experimental/Intersection/CubicCoincidence.cpp A experimental/Intersection/CubicIntersection_Test.cpp A experimental/Intersection/CubicIntersection.cpp A experimental/Intersection/QuadraticUtilities.h A experimental/Intersection/SkAntiEdge.cpp A experimental/Intersection/TestUtilities.h A experimental/Intersection/CubicParameterization_Test.cpp A experimental/Intersection/LineIntersection.h A experimental/Intersection/CubicSubDivide.cpp A experimental/Intersection/CubicParameterization.cpp A experimental/Intersection/QuadraticBezierClip_Test.cpp A experimental/Intersection/QuadraticBezierClip.cpp A experimental/Intersection/BezierClip_Test.cpp A experimental/Intersection/ConvexHull.cpp A experimental/Intersection/BezierClip.cpp A experimental/Intersection/QuadraticIntersection_TestData.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@3005 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/Intersection/QuadraticBezierClip.cpp')
-rw-r--r--experimental/Intersection/QuadraticBezierClip.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/experimental/Intersection/QuadraticBezierClip.cpp b/experimental/Intersection/QuadraticBezierClip.cpp
new file mode 100644
index 0000000000..1114d74398
--- /dev/null
+++ b/experimental/Intersection/QuadraticBezierClip.cpp
@@ -0,0 +1,57 @@
+#include "CubicIntersection.h"
+#include "LineParameters.h"
+#include <algorithm> // used for std::swap
+
+// return false if unable to clip (e.g., unable to create implicit line)
+// caller should subdivide, or create degenerate if the values are too small
+bool bezier_clip(const Quadratic& q1, const Quadratic& q2, double& minT, double& maxT) {
+ minT = 1;
+ maxT = 0;
+ // determine normalized implicit line equation for pt[0] to pt[3]
+ // of the form ax + by + c = 0, where a*a + b*b == 1
+
+ // find the implicit line equation parameters
+ LineParameters endLine;
+ endLine.quadEndPoints(q1);
+ if (!endLine.normalize()) {
+ printf("line cannot be normalized: need more code here\n");
+ return false;
+ }
+
+ double distance = endLine.controlPtDistance(q1);
+
+ // find fat line
+ double top = 0;
+ double bottom = distance / 2; // http://students.cs.byu.edu/~tom/557/text/cic.pdf (7.6)
+ if (top > bottom) {
+ std::swap(top, bottom);
+ }
+
+ // compute intersecting candidate distance
+ Quadratic distance2y; // points with X of (0, 1/2, 1)
+ endLine.quadDistanceY(q2, distance2y);
+
+ int flags = 0;
+ if (approximately_lesser(distance2y[0].y, top)) {
+ flags |= kFindTopMin;
+ } else if (approximately_greater(distance2y[0].y, bottom)) {
+ flags |= kFindBottomMin;
+ } else {
+ minT = 0;
+ }
+
+ if (approximately_lesser(distance2y[2].y, top)) {
+ flags |= kFindTopMax;
+ } else if (approximately_greater(distance2y[2].y, bottom)) {
+ flags |= kFindBottomMax;
+ } else {
+ maxT = 1;
+ }
+ // Find the intersection of distance convex hull and fat line.
+ x_at(distance2y[0], distance2y[1], top, bottom, flags, minT, maxT);
+ x_at(distance2y[1], distance2y[2], top, bottom, flags, minT, maxT);
+ x_at(distance2y[2], distance2y[0], top, bottom, flags, minT, maxT);
+
+ return minT < maxT; // returns false if distance shows no intersection
+}
+