Package java.awt.geom

Examples of java.awt.geom.PathIterator


   */
  public void test(TestHarness harness)      
  {
    double[] c = new double[6];
    Arc2D arc1 = new Arc2D.Double(1.0, 2.0, 3.0, 4.0, 0.0, 90.0, Arc2D.PIE);
    PathIterator iterator = arc1.getPathIterator(null);
    harness.check(!iterator.isDone());
    int segType = iterator.currentSegment(c);
    harness.check(segType == PathIterator.SEG_MOVETO);
    harness.check(c[0], 4.0);
    harness.check(c[1], 4.0);
    harness.check(!iterator.isDone());
    iterator.next();
    segType = iterator.currentSegment(c);
    harness.check(segType == PathIterator.SEG_CUBICTO);
    harness.check(c[0], 4.0);
    harness.check(c[1], 2.8954305003384135);
    harness.check(c[2], 3.3284271247461903);
    harness.check(c[3], 2.0);
    harness.check(c[4], 2.5);
    harness.check(c[5], 2.0);
    iterator.next();
    segType = iterator.currentSegment(c);
    harness.check(segType == PathIterator.SEG_LINETO);
    harness.check(c[0], 2.5);
    harness.check(c[1], 4.0);
    iterator.next();
    segType = iterator.currentSegment(c);
    harness.check(segType == PathIterator.SEG_CLOSE);
    iterator.next();
    harness.check(iterator.isDone());
  }
View Full Code Here


   */
  public void testShapeArgConstructor(TestHarness harness)
  {
    java.awt.geom.GeneralPath path;
    Throwable caught;
    PathIterator piter;
    double[] c = new double[6];

    harness.checkPoint("GeneralPath(Shape)");

    // Check 1
    caught = null;
    try
    {
      path = new java.awt.geom.GeneralPath(null);
    }
    catch (Exception ex)
    {
      caught = ex;
    }
    harness.check(caught instanceof NullPointerException);

    // Check 2 to 4
    path = new java.awt.geom.GeneralPath(new Rectangle2D.Double(10,20,30,40));
    piter = path.getPathIterator(null);
    harness.check(piter.currentSegment(c), PathIterator.SEG_MOVETO);
    harness.check(c[0], 10.0);
    harness.check(c[1], 20.0);

    // Check 5 to 7
    piter.next();
    harness.check(piter.currentSegment(c), PathIterator.SEG_LINETO);
    harness.check(c[0], 40.0);
    harness.check(c[1], 20.0);

    // Check 8 to 10
    piter.next();
    harness.check(piter.currentSegment(c), PathIterator.SEG_LINETO);
    harness.check(c[0], 40.0);
    harness.check(c[1], 60.0);

    // Check 11 to 13
    piter.next();
    harness.check(piter.currentSegment(c), PathIterator.SEG_LINETO);
    harness.check(c[0], 10.0);
    harness.check(c[1], 60.0);

    // Check 14 to 16
    piter.next();
    harness.check(piter.currentSegment(c), PathIterator.SEG_LINETO);
    harness.check(c[0], 10.0);
    harness.check(c[1], 20.0);

    // Check 17
    piter.next();
    harness.check(piter.currentSegment(c), PathIterator.SEG_CLOSE);

    // Check 18
    piter.next();
    harness.check(piter.isDone());

    // Check 19
    harness.check(piter.getWindingRule(), PathIterator.WIND_NON_ZERO);
  }
View Full Code Here

   */
  public void test_notConnecting(TestHarness harness)
  {
    harness.checkPoint("notConnecting");

    PathIterator piter, resPiter;
    GeneralPath path;
    double[] c = new double[6];

    piter = new PathIterator()
    {
      int i = 0;

      public int getWindingRule()
      {
        return PathIterator.WIND_EVEN_ODD;
      }

      public boolean isDone()
      {
        // System.out.println("isDone(), i=" + i);
        return i >= 7;
      }

      public void next()
      {
        ++i;
      }

      public int currentSegment(float[] c)
      {
        double[] d = new double[c.length];
        int r = currentSegment(d);
        for (int i = 0; i < d.length; i++)
          c[i] = (float) d[i];
        return r;
      }

      public int currentSegment(double[] c)
      {
        switch (i)
        {
        case 0:
          c[0] = 10; c[1] = 11;
          return PathIterator.SEG_MOVETO;

        case 1:
          c[0] = 20; c[1] = 21;
          return PathIterator.SEG_LINETO;

        case 2:
          c[0] = 30; c[1] = 31; c[2] = 32; c[3] = 33;
          return PathIterator.SEG_QUADTO;

        case 3:
          c[0] = 40; c[1] = 41; c[2] = 42; c[3] = 43;
          c[4] = 44; c[5] = 45;
          return PathIterator.SEG_CUBICTO;

        case 4:
          return PathIterator.SEG_CLOSE;

        case 5:
          c[0] = 50; c[1] = 51;
          return PathIterator.SEG_MOVETO;

        case 6:
          c[0] = 60; c[1] = 61;
          return PathIterator.SEG_LINETO;

        default:
          throw new IllegalPathStateException();
        }
      }
    };


    path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    path.append(piter, false);
   
    harness.check(path.getWindingRule(),      // 1
                  GeneralPath.WIND_NON_ZERO);

    resPiter = path.getPathIterator(null);
    harness.check(!resPiter.isDone());        // 2

    harness.check(resPiter.currentSegment(c), // 3
                  PathIterator.SEG_MOVETO);
    harness.check(c[0], 10);                  // 4
    harness.check(c[1], 11);                  // 5

    resPiter.next();
    harness.check(!resPiter.isDone());        // 6
    harness.check(resPiter.currentSegment(c), // 7
                  PathIterator.SEG_LINETO);
    harness.check(c[0], 20);                  // 8
    harness.check(c[1], 21);                  // 9

    resPiter.next();
    harness.check(!resPiter.isDone());        // 10
    harness.check(resPiter.currentSegment(c),
                  PathIterator.SEG_QUADTO);   // 11
    harness.check(c[0], 30);                  // 12
    harness.check(c[1], 31);                  // 13
    harness.check(c[2], 32);                  // 14
    harness.check(c[3], 33);                  // 15

    resPiter.next();
    harness.check(!resPiter.isDone());        // 16
    harness.check(resPiter.currentSegment(c),
                  PathIterator.SEG_CUBICTO)// 17
    harness.check(c[0], 40);                  // 18
    harness.check(c[1], 41);                  // 19
    harness.check(c[2], 42);                  // 20
    harness.check(c[3], 43);                  // 21
    harness.check(c[4], 44);                  // 22
    harness.check(c[5], 45);                  // 23

    resPiter.next();
    harness.check(!resPiter.isDone());        // 24
    harness.check(resPiter.currentSegment(c), // 25
                  PathIterator.SEG_CLOSE);

    resPiter.next();
    harness.check(!resPiter.isDone());        // 26
    harness.check(resPiter.currentSegment(c), // 27
                  PathIterator.SEG_MOVETO);
    harness.check(c[0], 50);                  // 28
    harness.check(c[1], 51);                  // 29

    resPiter.next();
    harness.check(!resPiter.isDone());        // 30
    harness.check(resPiter.currentSegment(c), // 31
                  PathIterator.SEG_LINETO);
    harness.check(c[0], 60);                  // 32
    harness.check(c[1], 61);                  // 33

    resPiter.next();
    harness.check(resPiter.isDone());         // 34
    harness.check(piter.isDone());            // 35
  }
View Full Code Here

   * together with a SEG_LINETO segment.
   */
  public void test_connecting(TestHarness harness)
  {
    GeneralPath path;
    PathIterator pit;
    float[] c = new float[6];

    harness.checkPoint("connecting");
    path = new GeneralPath();
    path.moveTo(10, 11);
    path.append(new Line2D.Double(20, 21, 30, 31).getPathIterator(null),
                /* connecting */ true);
    pit = path.getPathIterator(null);
   
    harness.check(!pit.isDone());             // 1
    harness.check(pit.currentSegment(c),      // 2
                  PathIterator.SEG_MOVETO);
    harness.check(c[0], 10);                  // 3
    harness.check(c[1], 11);                  // 4
    pit.next();
    harness.check(!pit.isDone());             // 5
    harness.check(pit.currentSegment(c),      // 6
                  PathIterator.SEG_LINETO);
    harness.check(c[0], 20);                  // 7
    harness.check(c[1], 21);                  // 8
    pit.next();
    harness.check(!pit.isDone());             // 9
    harness.check(pit.currentSegment(c),      // 10
                  PathIterator.SEG_LINETO);
    harness.check(c[0], 30);                  // 11
    harness.check(c[1], 31);                  // 12
    pit.next();
    harness.check(pit.isDone());              // 13
  }
View Full Code Here

  /**
   * Appends an empty path iterator to an empty GeneralPath.
   */
  public void test_empty(TestHarness harness)
  {
    PathIterator pit, respit;
    GeneralPath path;

    harness.checkPoint("empty");
    path = new GeneralPath();

View Full Code Here


  public void test_untransformed(TestHarness harness)
  {
    QuadCurve2D curve;
    PathIterator pit;
    double[] c = new double[6];

    harness.checkPoint("untransformed");
    curve = new QuadCurve2D.Double(1, 2, 3, 4, 5, 6);
    pit = curve.getPathIterator(null);

    harness.check(!pit.isDone());                                   // 1
    harness.check(pit.currentSegment(c), PathIterator.SEG_MOVETO)// 2
    harness.check(c[0], 1.0);                                       // 3
    harness.check(c[1], 2.0);                                       // 4

    pit.next();
    harness.check(!pit.isDone());                                   // 5
    harness.check(pit.currentSegment(c), PathIterator.SEG_QUADTO)// 6
    harness.check(c[0], 3.0);                                       // 7
    harness.check(c[1], 4.0);                                       // 8
    harness.check(c[2], 5.0);                                       // 9
    harness.check(c[3], 6.0);                                       // 10

    pit.next();
    harness.check(pit.isDone());                                    // 11
    harness.check(pit.getWindingRule(), PathIterator.WIND_NON_ZERO);// 12
  }
View Full Code Here


  public void test_transformed(TestHarness harness)
  {
    QuadCurve2D curve;
    PathIterator pit;
    AffineTransform tx;
    double[] c = new double[6];

    harness.checkPoint("transformed");
    tx = new AffineTransform();
    tx.scale(2, 3);
    tx.translate(1, -1);
    curve = new QuadCurve2D.Double(1, 2, 3, 4, 5, 6);
    pit = curve.getPathIterator(tx);

    harness.check(!pit.isDone());                                   // 1
    harness.check(pit.currentSegment(c), PathIterator.SEG_MOVETO)// 2
    harness.check(c[0], 4.0);                                       // 3
    harness.check(c[1], 3.0);                                       // 4

    pit.next();
    harness.check(!pit.isDone());                                   // 5
    harness.check(pit.currentSegment(c), PathIterator.SEG_QUADTO)// 6
    harness.check(c[0], 8.0);                                       // 7
    harness.check(c[1], 9.0);                                       // 8
    harness.check(c[2], 12.0);                                      // 9
    harness.check(c[3], 15.0);                                      // 10

    pit.next();
    harness.check(pit.isDone());                                    // 11

    harness.check(pit.getWindingRule(), PathIterator.WIND_NON_ZERO);// 12
  }
View Full Code Here

   * transform is being passed.
   */
  private void test_untransformed(TestHarness h)
  {
    GeneralPath path;
    PathIterator pit;
    float[] f = new float[6];
    double[] d = new double[6];

    h.checkPoint("untransformed");
    path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    path.moveTo(10, 11);
    path.lineTo(20, 21);
    path.closePath();
    path.moveTo(30, 31);
    path.quadTo(40, 41, 42, 43);
    path.curveTo(50, 51, 52, 53, 54, 55);
   
    pit = path.getPathIterator(null);
    h.check(pit.getWindingRule(), PathIterator.WIND_EVEN_ODD); // 1
    h.check(!pit.isDone());                                    // 2
    h.check(pit.currentSegment(f), PathIterator.SEG_MOVETO);   // 3
    h.check(f[0], 10);                                         // 4
    h.check(f[1], 11);                                         // 5
    h.check(pit.currentSegment(d), PathIterator.SEG_MOVETO);   // 6
    h.check(d[0], 10);                                         // 7
    h.check(d[1], 11);                                         // 8
    pit.next();
    h.check(!pit.isDone());                                    // 9
    h.check(pit.currentSegment(f), PathIterator.SEG_LINETO);   // 10
    h.check(f[0], 20);                                         // 11
    h.check(f[1], 21);                                         // 12
    h.check(pit.currentSegment(d), PathIterator.SEG_LINETO);   // 13
    h.check(d[0], 20);                                         // 14
    h.check(d[1], 21);                                         // 15
    pit.next();
    h.check(!pit.isDone());                                    // 16
    h.check(pit.currentSegment(f), PathIterator.SEG_CLOSE) ;   // 17
    h.check(pit.currentSegment(d), PathIterator.SEG_CLOSE) ;   // 18
    pit.next();
    h.check(!pit.isDone());                                    // 19
    h.check(pit.currentSegment(f), PathIterator.SEG_MOVETO);   // 20
    h.check(f[0], 30);                                         // 21
    h.check(f[1], 31);                                         // 22
    h.check(pit.currentSegment(d), PathIterator.SEG_MOVETO);   // 23
    h.check(d[0], 30);                                         // 24
    h.check(d[1], 31);                                         // 25
    pit.next();
    h.check(!pit.isDone());                                    // 26
    h.check(pit.currentSegment(f), PathIterator.SEG_QUADTO);   // 27
    h.check(f[0], 40);                                         // 28
    h.check(f[1], 41);                                         // 29
    h.check(f[2], 42);                                         // 30
    h.check(f[3], 43);                                         // 31
    h.check(pit.currentSegment(d), PathIterator.SEG_QUADTO);   // 32
    h.check(d[0], 40);                                         // 33
    h.check(d[1], 41);                                         // 34
    h.check(d[2], 42);                                         // 35
    h.check(d[3], 43);                                         // 36
    pit.next();
    h.check(!pit.isDone());                                    // 37
    h.check(pit.currentSegment(f), PathIterator.SEG_CUBICTO)// 38
    h.check(f[0], 50);                                         // 39
    h.check(f[1], 51);                                         // 40
    h.check(f[2], 52);                                         // 41
    h.check(f[3], 53);                                         // 42
    h.check(f[4], 54);                                         // 43
    h.check(f[5], 55);                                         // 44
    h.check(pit.currentSegment(d), PathIterator.SEG_CUBICTO)// 45
    h.check(d[0], 50);                                         // 46
    h.check(d[1], 51);                                         // 47
    h.check(d[2], 52);                                         // 48
    h.check(d[3], 53);                                         // 49
    h.check(d[4], 54);                                         // 50
    h.check(d[5], 55);                                         // 51
    pit.next();
    h.check(pit.isDone());                                     // 52
  }
View Full Code Here

   * transformation is being passed.
   */
  private void test_transformed(TestHarness h)
  {
    GeneralPath path;
    PathIterator pit;
    AffineTransform tx;
    float[] f = new float[6];
    double[] d = new double[6];

    h.checkPoint("transformed");
    path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    path.moveTo(10, 11);
    path.lineTo(20, 21);
    path.closePath();
    path.moveTo(30, 31);
    path.quadTo(40, 41, 42, 43);
    path.curveTo(50, 51, 52, 53, 54, 55);
   
    tx = new AffineTransform();
    tx.translate(2, 3);
    tx.scale(10, 10);

    pit = path.getPathIterator(tx);
    h.check(pit.getWindingRule(), PathIterator.WIND_NON_ZERO); // 1
    h.check(!pit.isDone());                                    // 2
    h.check(pit.currentSegment(f), PathIterator.SEG_MOVETO);   // 3
    h.check(f[0], 102);                                        // 4
    h.check(f[1], 113);                                        // 5
    h.check(pit.currentSegment(d), PathIterator.SEG_MOVETO);   // 6
    h.check(d[0], 102);                                        // 7
    h.check(d[1], 113);                                        // 8
    pit.next();
    h.check(!pit.isDone());                                    // 9
    h.check(pit.currentSegment(f), PathIterator.SEG_LINETO);   // 10
    h.check(f[0], 202);                                        // 11
    h.check(f[1], 213);                                        // 12
    h.check(pit.currentSegment(d), PathIterator.SEG_LINETO);   // 13
    h.check(d[0], 202);                                        // 14
    h.check(d[1], 213);                                        // 15
    pit.next();
    h.check(!pit.isDone());                                    // 16
    h.check(pit.currentSegment(f), PathIterator.SEG_CLOSE) ;   // 17
    h.check(pit.currentSegment(d), PathIterator.SEG_CLOSE) ;   // 18
    pit.next();
    h.check(!pit.isDone());                                    // 19
    h.check(pit.currentSegment(f), PathIterator.SEG_MOVETO);   // 20
    h.check(f[0], 302);                                        // 21
    h.check(f[1], 313);                                        // 22
    h.check(pit.currentSegment(d), PathIterator.SEG_MOVETO);   // 23
    h.check(d[0], 302);                                        // 24
    h.check(d[1], 313);                                        // 25
    pit.next();
    h.check(!pit.isDone());                                    // 26
    h.check(pit.currentSegment(f), PathIterator.SEG_QUADTO);   // 27
    h.check(f[0], 402);                                        // 28
    h.check(f[1], 413);                                        // 29
    h.check(f[2], 422);                                        // 30
    h.check(f[3], 433);                                        // 31
    h.check(pit.currentSegment(d), PathIterator.SEG_QUADTO);   // 32
    h.check(d[0], 402);                                        // 33
    h.check(d[1], 413);                                        // 34
    h.check(d[2], 422);                                        // 35
    h.check(d[3], 433);                                        // 36
    pit.next();
    h.check(!pit.isDone());                                    // 37
    h.check(pit.currentSegment(f), PathIterator.SEG_CUBICTO)// 38
    h.check(f[0], 502);                                        // 39
    h.check(f[1], 513);                                        // 40
    h.check(f[2], 522);                                        // 41
    h.check(f[3], 533);                                        // 42
    h.check(f[4], 542);                                        // 43
    h.check(f[5], 553);                                        // 44
    h.check(pit.currentSegment(d), PathIterator.SEG_CUBICTO)// 45
    h.check(d[0], 502);                                        // 46
    h.check(d[1], 513);                                        // 47
    h.check(d[2], 522);                                        // 48
    h.check(d[3], 533);                                        // 49
    h.check(d[4], 542);                                        // 50
    h.check(d[5], 553);                                        // 51
    pit.next();
    h.check(pit.isDone());                                     // 52
  }
View Full Code Here

            final char ch = s.charAt(i);
            System.out.println("Getting index for char: " + ch);
            final int index = encTable.getTableFormat().getGlyphIndex(ch);
            final TTFGlyph glyph = (TTFGlyph) glyphTable.getGlyph(index);
            final GeneralPath shape = glyph.getShape();
            PathIterator pi = shape.getPathIterator(null);
            final float[] f = new float[6];
            while (!pi.isDone()) {
                final int type = pi.currentSegment(f);
                System.out.println(types[type] + ",\t(" + f[0] + "," + f[1] + "),\t(" + f[2] + "," + f[3] + "),\t(" +
                    f[4] + "," + f[5] + ")");
                pi.next();
            }
        }
    }
View Full Code Here

TOP

Related Classes of java.awt.geom.PathIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.