< prev index next >

src/java.desktop/share/classes/sun/awt/geom/Order2.java

Print this page




  72                     tmp[i0 + 4], tmp[i0 + 5], direction);
  73         addInstance(curves, tmp[i1], tmp[i1 + 1], tmp[i1 + 2], tmp[i1 + 3],
  74                     tmp[i1 + 4], tmp[i1 + 5], direction);
  75     }
  76 
  77     public static void addInstance(Vector<Curve> curves,
  78                                    double x0, double y0,
  79                                    double cx0, double cy0,
  80                                    double x1, double y1,
  81                                    int direction) {
  82         if (y0 > y1) {
  83             curves.add(new Order2(x1, y1, cx0, cy0, x0, y0, -direction));
  84         } else if (y1 > y0) {
  85             curves.add(new Order2(x0, y0, cx0, cy0, x1, y1, direction));
  86         }
  87     }
  88 
  89     /*
  90      * Return the count of the number of horizontal sections of the
  91      * specified quadratic Bezier curve.  Put the parameters for the
  92      * horizontal sections into the specified <code>ret</code> array.
  93      * <p>
  94      * If we examine the parametric equation in t, we have:
  95      *     Py(t) = C0*(1-t)^2 + 2*CP*t*(1-t) + C1*t^2
  96      *           = C0 - 2*C0*t + C0*t^2 + 2*CP*t - 2*CP*t^2 + C1*t^2
  97      *           = C0 + (2*CP - 2*C0)*t + (C0 - 2*CP + C1)*t^2
  98      *     Py(t) = (C0 - 2*CP + C1)*t^2 + (2*CP - 2*C0)*t + (C0)
  99      * If we take the derivative, we get:
 100      *     Py(t) = At^2 + Bt + C
 101      *     dPy(t) = 2At + B = 0
 102      *     2*(C0 - 2*CP + C1)t + 2*(CP - C0) = 0
 103      *     2*(C0 - 2*CP + C1)t = 2*(C0 - CP)
 104      *     t = 2*(C0 - CP) / 2*(C0 - 2*CP + C1)
 105      *     t = (C0 - CP) / (C0 - CP + C1 - CP)
 106      * Note that this method will return 0 if the equation is a line,
 107      * which is either always horizontal or never horizontal.
 108      * Completely horizontal curves need to be eliminated by other
 109      * means outside of this method.
 110      */
 111     public static int getHorizontalParams(double c0, double cp, double c1,
 112                                           double ret[]) {




  72                     tmp[i0 + 4], tmp[i0 + 5], direction);
  73         addInstance(curves, tmp[i1], tmp[i1 + 1], tmp[i1 + 2], tmp[i1 + 3],
  74                     tmp[i1 + 4], tmp[i1 + 5], direction);
  75     }
  76 
  77     public static void addInstance(Vector<Curve> curves,
  78                                    double x0, double y0,
  79                                    double cx0, double cy0,
  80                                    double x1, double y1,
  81                                    int direction) {
  82         if (y0 > y1) {
  83             curves.add(new Order2(x1, y1, cx0, cy0, x0, y0, -direction));
  84         } else if (y1 > y0) {
  85             curves.add(new Order2(x0, y0, cx0, cy0, x1, y1, direction));
  86         }
  87     }
  88 
  89     /*
  90      * Return the count of the number of horizontal sections of the
  91      * specified quadratic Bezier curve.  Put the parameters for the
  92      * horizontal sections into the specified {@code ret} array.
  93      * <p>
  94      * If we examine the parametric equation in t, we have:
  95      *     Py(t) = C0*(1-t)^2 + 2*CP*t*(1-t) + C1*t^2
  96      *           = C0 - 2*C0*t + C0*t^2 + 2*CP*t - 2*CP*t^2 + C1*t^2
  97      *           = C0 + (2*CP - 2*C0)*t + (C0 - 2*CP + C1)*t^2
  98      *     Py(t) = (C0 - 2*CP + C1)*t^2 + (2*CP - 2*C0)*t + (C0)
  99      * If we take the derivative, we get:
 100      *     Py(t) = At^2 + Bt + C
 101      *     dPy(t) = 2At + B = 0
 102      *     2*(C0 - 2*CP + C1)t + 2*(CP - C0) = 0
 103      *     2*(C0 - 2*CP + C1)t = 2*(C0 - CP)
 104      *     t = 2*(C0 - CP) / 2*(C0 - 2*CP + C1)
 105      *     t = (C0 - CP) / (C0 - CP + C1 - CP)
 106      * Note that this method will return 0 if the equation is a line,
 107      * which is either always horizontal or never horizontal.
 108      * Completely horizontal curves need to be eliminated by other
 109      * means outside of this method.
 110      */
 111     public static int getHorizontalParams(double c0, double cp, double c1,
 112                                           double ret[]) {


< prev index next >