shape ops work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@7303 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/CubicIntersection.cpp b/experimental/Intersection/CubicIntersection.cpp
index 2c6cc3f..4ae0d84 100644
--- a/experimental/Intersection/CubicIntersection.cpp
+++ b/experimental/Intersection/CubicIntersection.cpp
@@ -4,6 +4,8 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
+#include "CubicUtilities.h"
 #include "CurveIntersection.h"
 #include "Intersections.h"
 #include "IntersectionUtilities.h"
@@ -162,10 +164,12 @@
 #include "CubicUtilities.h"
 
 // FIXME: ? if needed, compute the error term from the tangent length
+start here;
+// need better delta computation -- assert fails
 static double computeDelta(const Cubic& cubic, double t, double scale) {
-    double attempt = scale / precisionUnit;
+    double attempt = scale / precisionUnit * 2;
 #if SK_DEBUG
-    double precision = calcPrecision(cubic);
+    double precision = calcPrecision(cubic, t, scale);
     _Point dxy;
     dxdy_at_t(cubic, t, dxy);
     _Point p1, p2;
diff --git a/experimental/Intersection/CubicIntersection_Test.cpp b/experimental/Intersection/CubicIntersection_Test.cpp
index c3ddded..8c2263e 100644
--- a/experimental/Intersection/CubicIntersection_Test.cpp
+++ b/experimental/Intersection/CubicIntersection_Test.cpp
@@ -269,7 +269,6 @@
 void CubicIntersection_RandTest() {
     srand(0);
     const int tests = 1000000; // 10000000;
- //   double largestFactor = DBL_MAX;
     for (int test = 0; test < tests; ++test) {
         Cubic cubic1, cubic2;
         for (int i = 0; i < 4; ++i) {
@@ -292,7 +291,6 @@
         rect2.setBounds(cubic2);
         bool boundsIntersect = rect1.left <= rect2.right && rect2.left <= rect2.right
                 && rect1.top <= rect2.bottom && rect2.top <= rect1.bottom;
-        Intersections i1, i2;
         if (test == -1) {
             SkDebugf("ready...\n");
         }
diff --git a/experimental/Intersection/CubicParameterization_Test.cpp b/experimental/Intersection/CubicParameterization_Test.cpp
index 114331a..517ae11 100644
--- a/experimental/Intersection/CubicParameterization_Test.cpp
+++ b/experimental/Intersection/CubicParameterization_Test.cpp
@@ -4,6 +4,7 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+#include "QuadraticUtilities.h"
 #include "CurveIntersection.h"
 #include "Intersection_Tests.h"
 #include "Parameterization_Test.h"
diff --git a/experimental/Intersection/CubicSubDivide.cpp b/experimental/Intersection/CubicSubDivide.cpp
index fa2025f..b7cc127 100644
--- a/experimental/Intersection/CubicSubDivide.cpp
+++ b/experimental/Intersection/CubicSubDivide.cpp
@@ -4,7 +4,7 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
-#include "CurveIntersection.h"
+#include "CubicUtilities.h"
 #include "IntersectionUtilities.h"
 
 /*
diff --git a/experimental/Intersection/CubicUtilities.cpp b/experimental/Intersection/CubicUtilities.cpp
index 36fc17e..19f16c6 100644
--- a/experimental/Intersection/CubicUtilities.cpp
+++ b/experimental/Intersection/CubicUtilities.cpp
@@ -18,6 +18,15 @@
     return (width > height ? width : height) / precisionUnit;
 }
 
+#if SK_DEBUG
+double calcPrecision(const Cubic& cubic, double t, double scale) {
+    Cubic part;
+    sub_divide(cubic, SkMax32(0, t - scale), SkMin32(1, t + scale), part);
+    return calcPrecision(part);
+}
+#endif
+
+
 void coefficients(const double* cubic, double& A, double& B, double& C, double& D) {
     A = cubic[6]; // d
     B = cubic[4] * 3; // 3*c
diff --git a/experimental/Intersection/CubicUtilities.h b/experimental/Intersection/CubicUtilities.h
index 6788b9c..5205574 100644
--- a/experimental/Intersection/CubicUtilities.h
+++ b/experimental/Intersection/CubicUtilities.h
@@ -11,6 +11,10 @@
 #include "SkTDArray.h"
 
 double calcPrecision(const Cubic& cubic);
+#if SK_DEBUG
+double calcPrecision(const Cubic& cubic, double t, double scale);
+#endif
+void chop_at(const Cubic& src, CubicPair& dst, double t);
 double cube_root(double x);
 int cubic_to_quadratics(const Cubic& cubic, double precision,
         SkTDArray<Quadratic>& quadratics);
@@ -24,6 +28,7 @@
 void dxdy_at_t(const Cubic& , double t, _Point& y);
 int find_cubic_inflections(const Cubic& src, double tValues[]);
 bool rotate(const Cubic& cubic, int zero, int index, Cubic& rotPath);
+void sub_divide(const Cubic& src, double t1, double t2, Cubic& dst);
 void xy_at_t(const Cubic& , double t, double& x, double& y);
 
 extern const int precisionUnit;
diff --git a/experimental/Intersection/CurveIntersection.h b/experimental/Intersection/CurveIntersection.h
index 4b34b31..5f27456 100644
--- a/experimental/Intersection/CurveIntersection.h
+++ b/experimental/Intersection/CurveIntersection.h
@@ -15,17 +15,12 @@
 double axialIntersect(const Quadratic& q1, const _Point& p, bool vert);
 bool bezier_clip(const Cubic& cubic1, const Cubic& cubic2, double& minT, double& maxT);
 bool bezier_clip(const Quadratic& q1, const Quadratic& q2, double& minT, double& maxT);
-void chop_at(const Cubic& src, CubicPair& dst, double t);
-void chop_at(const Quadratic& src, QuadraticPair& dst, double t);
 int convex_hull(const Cubic& cubic, char order[4]);
 bool convex_x_hull(const Cubic& cubic, char connectTo0[2], char connectTo3[2]);
 bool implicit_matches(const Cubic& cubic1, const Cubic& cubic2);
 bool implicit_matches(const _Line& line1, const _Line& line2);
 bool implicit_matches_ulps(const _Line& one, const _Line& two, int ulps);
 bool implicit_matches(const Quadratic& quad1, const Quadratic& quad2);
-void sub_divide(const Cubic& src, double t1, double t2, Cubic& dst);
-void sub_divide(const _Line& src, double t1, double t2, _Line& dst);
-void sub_divide(const Quadratic& src, double t1, double t2, Quadratic& dst);
 void tangent(const Cubic& cubic, double t, _Point& result);
 void tangent(const _Line& line, _Point& result);
 void tangent(const Quadratic& quad, double t, _Point& result);
diff --git a/experimental/Intersection/Intersection_Tests.cpp b/experimental/Intersection/Intersection_Tests.cpp
index 8e6e63e..cfa340f 100644
--- a/experimental/Intersection/Intersection_Tests.cpp
+++ b/experimental/Intersection/Intersection_Tests.cpp
@@ -15,9 +15,9 @@
 void Intersection_Tests() {
     int testsRun = 0;
 
+    CubicIntersection_RandTest();
     QuadraticIntersection_Test();
     CubicIntersection_OneOffTest();
-    CubicIntersection_RandTest();
     SimplifyNew_Test();
     CubicsToQuadratics_RandTest();
     CubicToQuadratics_Test();
diff --git a/experimental/Intersection/LineUtilities.h b/experimental/Intersection/LineUtilities.h
index 49e6a32..498b925 100644
--- a/experimental/Intersection/LineUtilities.h
+++ b/experimental/Intersection/LineUtilities.h
@@ -8,7 +8,7 @@
 
 bool implicitLine(const _Line& line, double& slope, double& axisIntercept);
 int reduceOrder(const _Line& line, _Line& reduced);
-
+void sub_divide(const _Line& src, double t1, double t2, _Line& dst);
 double t_at(const _Line&, const _Point& );
 void xy_at_t(const _Line& , double t, double& x, double& y);
 
diff --git a/experimental/Intersection/QuadraticParameterization_Test.cpp b/experimental/Intersection/QuadraticParameterization_Test.cpp
index df239dc..95eaccd 100644
--- a/experimental/Intersection/QuadraticParameterization_Test.cpp
+++ b/experimental/Intersection/QuadraticParameterization_Test.cpp
@@ -7,6 +7,7 @@
 #include "CurveIntersection.h"
 #include "Intersection_Tests.h"
 #include "Parameterization_Test.h"
+#include "QuadraticUtilities.h"
 
 const Quadratic quadratics[] = {
     {{0, 0}, {1, 0}, {1, 1}},
diff --git a/experimental/Intersection/QuadraticSubDivide.cpp b/experimental/Intersection/QuadraticSubDivide.cpp
index 436b5a9..a889825 100644
--- a/experimental/Intersection/QuadraticSubDivide.cpp
+++ b/experimental/Intersection/QuadraticSubDivide.cpp
@@ -6,6 +6,7 @@
  */
 #include "CurveIntersection.h"
 #include "IntersectionUtilities.h"
+#include "QuadraticUtilities.h"
 
 /*
 Given a quadratic q, t1, and t2, find a small quadratic segment.
diff --git a/experimental/Intersection/QuadraticUtilities.h b/experimental/Intersection/QuadraticUtilities.h
index 13893a1..0fe8be8 100644
--- a/experimental/Intersection/QuadraticUtilities.h
+++ b/experimental/Intersection/QuadraticUtilities.h
@@ -9,6 +9,8 @@
 #define QUADRATIC_UTILITIES_H
 
 #include "DataTypes.h"
+
+void chop_at(const Quadratic& src, QuadraticPair& dst, double t);
 double dx_at_t(const Quadratic& , double t);
 double dy_at_t(const Quadratic& , double t);
 void dxdy_at_t(const Quadratic& , double t, _Point& xy);
@@ -30,6 +32,7 @@
 
 int quadraticRoots(double A, double B, double C, double t[2]);
 int quadraticRootsX(const double A, const double B, const double C, double s[2]);
+void sub_divide(const Quadratic& src, double t1, double t2, Quadratic& dst);
 void xy_at_t(const Quadratic& , double t, double& x, double& y);
 
 #endif
diff --git a/experimental/Intersection/TestUtilities.cpp b/experimental/Intersection/TestUtilities.cpp
index 95ed1e0..0477ed4 100644
--- a/experimental/Intersection/TestUtilities.cpp
+++ b/experimental/Intersection/TestUtilities.cpp
@@ -4,6 +4,8 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
+#include "CubicUtilities.h"
 #include "CurveIntersection.h"
 #include "TestUtilities.h"