public PathIterator getPathIterator()

in shadows/framework/src/main/java/org/robolectric/shadows/RoundRectangle.java [269:353]


  public PathIterator getPathIterator(final AffineTransform at) {
    return new PathIterator() {
      int index;

      // ArcIterator.btan(Math.PI/2)
      public static final double CtrlVal = 0.5522847498307933;
      private final double ncv = 1.0 - CtrlVal;

      // Coordinates of control points for Bezier curves approximating the straight lines
      // and corners of the rounded rectangle.
      private final double[][] ctrlpts = {
        {0.0, 0.0, 0.0, ulHeight},
        {0.0, 0.0, 1.0, -llHeight},
        {0.0, 0.0, 1.0, -llHeight * ncv, 0.0, ncv * llWidth, 1.0, 0.0, 0.0, llWidth, 1.0, 0.0},
        {1.0, -lrWidth, 1.0, 0.0},
        {1.0, -lrWidth * ncv, 1.0, 0.0, 1.0, 0.0, 1.0, -lrHeight * ncv, 1.0, 0.0, 1.0, -lrHeight},
        {1.0, 0.0, 0.0, urHeight},
        {1.0, 0.0, 0.0, ncv * urHeight, 1.0, -urWidth * ncv, 0.0, 0.0, 1.0, -urWidth, 0.0, 0.0},
        {0.0, ulWidth, 0.0, 0.0},
        {0.0, ncv * ulWidth, 0.0, 0.0, 0.0, 0.0, 0.0, ncv * ulHeight, 0.0, 0.0, 0.0, ulHeight},
        {}
      };
      private final int[] types = {
        SEG_MOVETO,
        SEG_LINETO,
        SEG_CUBICTO,
        SEG_LINETO,
        SEG_CUBICTO,
        SEG_LINETO,
        SEG_CUBICTO,
        SEG_LINETO,
        SEG_CUBICTO,
        SEG_CLOSE,
      };

      @Override
      public int getWindingRule() {
        return WIND_NON_ZERO;
      }

      @Override
      public boolean isDone() {
        return index >= ctrlpts.length;
      }

      @Override
      public void next() {
        index++;
      }

      @Override
      public int currentSegment(float[] coords) {
        if (isDone()) {
          throw new NoSuchElementException("roundrect iterator out of bounds");
        }
        int nc = 0;
        double ctrls[] = ctrlpts[index];
        for (int i = 0; i < ctrls.length; i += 4) {
          coords[nc++] = (float) (x + ctrls[i] * width + ctrls[i + 1] / 2d);
          coords[nc++] = (float) (y + ctrls[i + 2] * height + ctrls[i + 3] / 2d);
        }
        if (at != null) {
          at.transform(coords, 0, coords, 0, nc / 2);
        }
        return types[index];
      }

      @Override
      public int currentSegment(double[] coords) {
        if (isDone()) {
          throw new NoSuchElementException("roundrect iterator out of bounds");
        }
        int nc = 0;
        double ctrls[] = ctrlpts[index];
        for (int i = 0; i < ctrls.length; i += 4) {
          coords[nc++] = x + ctrls[i] * width + ctrls[i + 1] / 2d;
          coords[nc++] = y + ctrls[i + 2] * height + ctrls[i + 3] / 2d;
        }
        if (at != null) {
          at.transform(coords, 0, coords, 0, nc / 2);
        }
        return types[index];
      }
    };
  }