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

Print this page
rev 9717 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by:


  30 import java.awt.geom.QuadCurve2D;
  31 import java.util.Vector;
  32 
  33 final class Order2 extends Curve {
  34     private double x0;
  35     private double y0;
  36     private double cx0;
  37     private double cy0;
  38     private double x1;
  39     private double y1;
  40     private double xmin;
  41     private double xmax;
  42 
  43     private double xcoeff0;
  44     private double xcoeff1;
  45     private double xcoeff2;
  46     private double ycoeff0;
  47     private double ycoeff1;
  48     private double ycoeff2;
  49 
  50     public static void insert(Vector curves, double tmp[],
  51                               double x0, double y0,
  52                               double cx0, double cy0,
  53                               double x1, double y1,
  54                               int direction)
  55     {
  56         int numparams = getHorizontalParams(y0, cy0, y1, tmp);
  57         if (numparams == 0) {
  58             // We are using addInstance here to avoid inserting horisontal
  59             // segments
  60             addInstance(curves, x0, y0, cx0, cy0, x1, y1, direction);
  61             return;
  62         }
  63         // assert(numparams == 1);
  64         double t = tmp[0];
  65         tmp[0] = x0;  tmp[1] = y0;
  66         tmp[2] = cx0; tmp[3] = cy0;
  67         tmp[4] = x1;  tmp[5] = y1;
  68         split(tmp, 0, t);
  69         int i0 = (direction == INCREASING)? 0 : 4;
  70         int i1 = 4 - i0;
  71         addInstance(curves, tmp[i0], tmp[i0 + 1], tmp[i0 + 2], tmp[i0 + 3],
  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 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




  30 import java.awt.geom.QuadCurve2D;
  31 import java.util.Vector;
  32 
  33 final class Order2 extends Curve {
  34     private double x0;
  35     private double y0;
  36     private double cx0;
  37     private double cy0;
  38     private double x1;
  39     private double y1;
  40     private double xmin;
  41     private double xmax;
  42 
  43     private double xcoeff0;
  44     private double xcoeff1;
  45     private double xcoeff2;
  46     private double ycoeff0;
  47     private double ycoeff1;
  48     private double ycoeff2;
  49 
  50     public static void insert(Vector<? super Order2> curves, double tmp[],
  51                               double x0, double y0,
  52                               double cx0, double cy0,
  53                               double x1, double y1,
  54                               int direction)
  55     {
  56         int numparams = getHorizontalParams(y0, cy0, y1, tmp);
  57         if (numparams == 0) {
  58             // We are using addInstance here to avoid inserting horisontal
  59             // segments
  60             addInstance(curves, x0, y0, cx0, cy0, x1, y1, direction);
  61             return;
  62         }
  63         // assert(numparams == 1);
  64         double t = tmp[0];
  65         tmp[0] = x0;  tmp[1] = y0;
  66         tmp[2] = cx0; tmp[3] = cy0;
  67         tmp[4] = x1;  tmp[5] = y1;
  68         split(tmp, 0, t);
  69         int i0 = (direction == INCREASING)? 0 : 4;
  70         int i1 = 4 - i0;
  71         addInstance(curves, tmp[i0], tmp[i0 + 1], tmp[i0 + 2], tmp[i0 + 3],
  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<? super Order2> 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