Java Code Examples for java.awt.geom.PathIterator#SEG_LINETO

The following examples show how to use java.awt.geom.PathIterator#SEG_LINETO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathIteratorSegmentObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parses the given string representation and returns the path iterator type or -1 if the string does not represent a
 * path iterator value.
 *
 * @param segment
 *          the string that contains the PathIterator type.
 * @return the parsed PathIterator type or -1.
 */
private int parseSegmentType( final String segment ) {
  if ( segment == null ) {
    return -1;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_CLOSE ) ) {
    return PathIterator.SEG_CLOSE;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_CUBIC_TO ) ) {
    return PathIterator.SEG_CUBICTO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_LINE_TO ) ) {
    return PathIterator.SEG_LINETO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_MOVE_TO ) ) {
    return PathIterator.SEG_MOVETO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_QUAD_TO ) ) {
    return PathIterator.SEG_QUADTO;
  }
  return -1;
}
 
Example 2
Source File: lineutility.java    From mil-sym-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GeneralPath from a Path2D
 *
 * @param shape
 * @return
 */
protected static Shape createStrokedShape(Shape shape) {
    GeneralPath newshape = new GeneralPath(); // Start with an empty shape
    try {
        // Iterate through the specified shape, perturb its coordinates, and
        // use them to build up the new shape.
        float[] coords = new float[6];
        for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
            int type = i.currentSegment(coords);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    //perturb(coords, 2);
                    newshape.moveTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    //perturb(coords, 2);
                    newshape.lineTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_QUADTO:
                    //perturb(coords, 4);
                    newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
                    break;
                case PathIterator.SEG_CUBICTO:
                    //perturb(coords, 6);
                    newshape.curveTo(coords[0], coords[1], coords[2], coords[3],
                            coords[4], coords[5]);
                    break;
                case PathIterator.SEG_CLOSE:
                    newshape.closePath();
                    break;
            }

        }
    } catch (Exception exc) {
        ErrorLogger.LogException(_className, "createStrokedShape",
                new RendererException("Failed inside createStrokedShape", exc));
    }
    return newshape;
}
 
Example 3
Source File: SWTGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 4
Source File: ShapeUtils.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Return true if two shapes are equal. */
public static boolean equals(Shape shape, Shape shape2) {
	PathIterator iter1 = shape.getPathIterator(null);
	PathIterator iter2 = shape.getPathIterator(null);
	double[] coords1 = new double[6];
	double[] coords2 = new double[6];
	while ((!iter1.isDone()) && (!iter2.isDone())) {
		int k1 = iter1.currentSegment(coords1);
		int k2 = iter2.currentSegment(coords2);
		if (k1 != k2)
			return false;
		if (k1 == PathIterator.SEG_MOVETO
				|| k1 == PathIterator.SEG_LINETO) {
			if (!equals(coords1, coords2, 2))
				return false;
		} else if (k1 == PathIterator.SEG_QUADTO) {
			if (!equals(coords1, coords2, 4))
				return false;
		} else if (k1 == PathIterator.SEG_CUBICTO) {
			if (!equals(coords1, coords2, 6))
				return false;
		} else if (k1 == PathIterator.SEG_CLOSE) {
			// do nothing
		} else {
			throw new RuntimeException("unrecognized segment " + k1);
		}

		iter1.next();
		iter2.next();
	}
	return iter1.isDone() && iter2.isDone();
}
 
Example 5
Source File: ShapeReader.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Coordinate[] nextCoordinateArray(PathIterator pathIt)
{
  double[] pathPt = new double[6];
  CoordinateList coordList = null;
  boolean isDone = false;
  while (! pathIt.isDone()) {
    int segType = pathIt.currentSegment(pathPt);
    switch (segType) {
    case PathIterator.SEG_MOVETO:
      if (coordList != null) {
        // don't advance pathIt, to retain start of next path if any
        isDone = true;
      }
      else {
        coordList = new CoordinateList();
        coordList.add(new Coordinate(pathPt[0], pathPt[1]));
        pathIt.next();
      }
      break;
    case PathIterator.SEG_LINETO:
      coordList.add(new Coordinate(pathPt[0], pathPt[1]));
      pathIt.next();
      break;
    case PathIterator.SEG_CLOSE:  
      coordList.closeRing();
      pathIt.next();
      isDone = true;   
      break;
    default:
    	throw new IllegalArgumentException("unhandled (non-linear) segment type encountered");
    }
    if (isDone) 
      break;
  }
  return coordList.toCoordinateArray();
}
 
Example 6
Source File: PathSegment.java    From pumpernickel with MIT License 4 votes vote down vote up
public float[] getXCoeffs(AffineTransform transform) {
	if (prev == null) {
		System.err.println(this);
		throw new NullPointerException("prev was null");
	}
	if (prev.data == null) {
		System.err.println(this);
		throw new NullPointerException("prev.data was null");
	}
	if (transform != null && transform.isIdentity())
		transform = null;
	if (xCoeffs != null && transform == null)
		return xCoeffs;

	double[] last = new double[] { prev.data[prev.data.length - 2],
			prev.data[prev.data.length - 1] };
	if (transform != null) {
		transform.transform(last, 0, last, 0, 1);
	}
	float[] myData;
	if (transform != null) {
		myData = new float[data.length];
		transform.transform(data, 0, myData, 0, data.length / 2);
	} else {
		myData = data;
	}
	float[] rValue = null;
	if (type == PathIterator.SEG_CUBICTO) {
		rValue = new float[4];
		rValue[0] = (float) (-last[0] + 3 * myData[0] - 3 * myData[2] + myData[4]);
		rValue[1] = (float) (3 * last[0] - 6 * myData[0] + 3 * myData[2]);
		rValue[2] = (float) (-3 * last[0] + 3 * myData[0]);
		rValue[3] = (float) (last[0]);
	} else if (type == PathIterator.SEG_QUADTO) {
		rValue = new float[3];
		rValue[0] = (float) (last[0] - 2 * myData[0] + myData[2]);
		rValue[1] = (float) (-2 * last[0] + 2 * myData[0]);
		rValue[2] = (float) (last[0]);
	} else if (type == PathIterator.SEG_LINETO) {
		rValue = new float[2];
		rValue[0] = (float) (-last[0] + myData[0]);
		rValue[1] = (float) (last[0]);
	} else if (type == PathIterator.SEG_MOVETO) {
		throw new UnsupportedOperationException(
				"MOVETO segments cannot be broken down into parametric equations.");
	} else if (type == PathIterator.SEG_CLOSE) {
		throw new UnsupportedOperationException(
				"CLOSE segments cannot be broken down into parametric equations.");
	}
	if (transform == null)
		xCoeffs = rValue;
	return rValue;
}
 
Example 7
Source File: ZigzagStroke.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Shape createStrokedShape ( final Shape shape )
{
    final GeneralPath result = new GeneralPath ();
    final PathIterator it = new FlatteningPathIterator ( shape.getPathIterator ( null ), FLATNESS );
    final float[] points = new float[ 6 ];
    float moveX = 0;
    float moveY = 0;
    float lastX = 0;
    float lastY = 0;
    float thisX;
    float thisY;
    int type;
    float next = 0;
    int phase = 0;

    while ( !it.isDone () )
    {
        type = it.currentSegment ( points );
        switch ( type )
        {
            case PathIterator.SEG_MOVETO:
                moveX = lastX = points[ 0 ];
                moveY = lastY = points[ 1 ];
                result.moveTo ( moveX, moveY );
                next = wavelength / 2;
                break;

            case PathIterator.SEG_CLOSE:
                points[ 0 ] = moveX;
                points[ 1 ] = moveY;
                // Fall into....

            case PathIterator.SEG_LINETO:
                thisX = points[ 0 ];
                thisY = points[ 1 ];
                final float dx = thisX - lastX;
                final float dy = thisY - lastY;
                final float distance = ( float ) Math.sqrt ( dx * dx + dy * dy );
                if ( distance >= next )
                {
                    final float r = 1.0f / distance;
                    while ( distance >= next )
                    {
                        final float x = lastX + next * dx * r;
                        final float y = lastY + next * dy * r;
                        if ( ( phase & 1 ) == 0 )
                        {
                            result.lineTo ( x + amplitude * dy * r, y - amplitude * dx * r );
                        }
                        else
                        {
                            result.lineTo ( x - amplitude * dy * r, y + amplitude * dx * r );
                        }
                        next += wavelength;
                        phase++;
                    }
                }
                next -= distance;
                lastX = thisX;
                lastY = thisY;
                if ( type == PathIterator.SEG_CLOSE )
                {
                    result.closePath ();
                }
                break;
        }
        it.next ();
    }

    return stroke.createStrokedShape ( result );
}
 
Example 8
Source File: PFont.java    From CPE552-Java with GNU General Public License v3.0 4 votes vote down vote up
public PShape getShape(char ch, float detail) {
    Font font = (Font) getNative();
    if (font == null) {
      throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
    }

    PShape s = new PShape(PShape.PATH);

    // six element array received from the Java2D path iterator
    float[] iterPoints = new float[6];
    // array passed to createGylphVector
    char[] textArray = new char[] { ch };

    //Graphics2D graphics = (Graphics2D) this.getGraphics();
    //FontRenderContext frc = graphics.getFontRenderContext();
    @SuppressWarnings("deprecation")
    FontRenderContext frc =
      Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, textArray);
    Shape shp = gv.getOutline();
    // make everything into moveto and lineto
    PathIterator iter = (detail == 0) ?
      shp.getPathIterator(null) :  // maintain curves
      shp.getPathIterator(null, detail);  // convert to line segments

    int contours = 0;
    //boolean outer = true;
//    boolean contour = false;
    while (!iter.isDone()) {
      int type = iter.currentSegment(iterPoints);
      switch (type) {
      case PathIterator.SEG_MOVETO:   // 1 point (2 vars) in textPoints
//        System.out.println("moveto");
//        if (!contour) {
        if (contours == 0) {
          s.beginShape();
        } else {
          s.beginContour();
//          contour = true;
        }
        contours++;
        s.vertex(iterPoints[0], iterPoints[1]);
        break;

      case PathIterator.SEG_LINETO:   // 1 point
//        System.out.println("lineto");
//        PApplet.println(PApplet.subset(iterPoints, 0, 2));
        s.vertex(iterPoints[0], iterPoints[1]);
        break;

      case PathIterator.SEG_QUADTO:   // 2 points
//        System.out.println("quadto");
//        PApplet.println(PApplet.subset(iterPoints, 0, 4));
        s.quadraticVertex(iterPoints[0], iterPoints[1],
                          iterPoints[2], iterPoints[3]);
        break;

      case PathIterator.SEG_CUBICTO:  // 3 points
//        System.out.println("cubicto");
//        PApplet.println(iterPoints);
        s.quadraticVertex(iterPoints[0], iterPoints[1],
                          iterPoints[2], iterPoints[3],
                          iterPoints[4], iterPoints[5]);
        break;

      case PathIterator.SEG_CLOSE:
//        System.out.println("close");
        if (contours > 1) {
//        contours--;
//        if (contours == 0) {
////          s.endShape();
//        } else {
          s.endContour();
        }
        break;
      }
//      PApplet.println(iterPoints);
      iter.next();
    }
    s.endShape(CLOSE);
    return s;
  }
 
Example 9
Source File: DuctusRenderingEngine.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void feedConsumer(PathConsumer consumer, PathIterator pi) {
    try {
        consumer.beginPath();
        boolean pathClosed = false;
        float mx = 0.0f;
        float my = 0.0f;
        float point[]  = new float[6];

        while (!pi.isDone()) {
            int type = pi.currentSegment(point);
            if (pathClosed == true) {
                pathClosed = false;
                if (type != PathIterator.SEG_MOVETO) {
                    // Force current point back to last moveto point
                    consumer.beginSubpath(mx, my);
                }
            }
            switch (type) {
            case PathIterator.SEG_MOVETO:
                mx = point[0];
                my = point[1];
                consumer.beginSubpath(point[0], point[1]);
                break;
            case PathIterator.SEG_LINETO:
                consumer.appendLine(point[0], point[1]);
                break;
            case PathIterator.SEG_QUADTO:
                consumer.appendQuadratic(point[0], point[1],
                                         point[2], point[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                consumer.appendCubic(point[0], point[1],
                                     point[2], point[3],
                                     point[4], point[5]);
                break;
            case PathIterator.SEG_CLOSE:
                consumer.closedSubpath();
                pathClosed = true;
                break;
            }
            pi.next();
        }

        consumer.endPath();
    } catch (PathException e) {
        throw new InternalError("Unable to Stroke shape ("+
                                e.getMessage()+")", e);
    }
}
 
Example 10
Source File: PiscesRenderingEngine.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public int currentSegment(float[] coords) {
    int type = src.currentSegment(coords);

    int lastCoord;
    switch(type) {
    case PathIterator.SEG_CUBICTO:
        lastCoord = 4;
        break;
    case PathIterator.SEG_QUADTO:
        lastCoord = 2;
        break;
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_MOVETO:
        lastCoord = 0;
        break;
    case PathIterator.SEG_CLOSE:
        // we don't want to deal with this case later. We just exit now
        curx_adjust = movx_adjust;
        cury_adjust = movy_adjust;
        return type;
    default:
        throw new InternalError("Unrecognized curve type");
    }

    // normalize endpoint
    float x_adjust = (float)Math.floor(coords[lastCoord] + lval) +
                 rval - coords[lastCoord];
    float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) +
                 rval - coords[lastCoord + 1];

    coords[lastCoord    ] += x_adjust;
    coords[lastCoord + 1] += y_adjust;

    // now that the end points are done, normalize the control points
    switch(type) {
    case PathIterator.SEG_CUBICTO:
        coords[0] += curx_adjust;
        coords[1] += cury_adjust;
        coords[2] += x_adjust;
        coords[3] += y_adjust;
        break;
    case PathIterator.SEG_QUADTO:
        coords[0] += (curx_adjust + x_adjust) / 2;
        coords[1] += (cury_adjust + y_adjust) / 2;
        break;
    case PathIterator.SEG_LINETO:
        break;
    case PathIterator.SEG_MOVETO:
        movx_adjust = x_adjust;
        movy_adjust = y_adjust;
        break;
    case PathIterator.SEG_CLOSE:
        throw new InternalError("This should be handled earlier.");
    }
    curx_adjust = x_adjust;
    cury_adjust = y_adjust;
    return type;
}
 
Example 11
Source File: Crossings.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static Crossings findCrossings(PathIterator pi,
                                      double xlo, double ylo,
                                      double xhi, double yhi)
{
    Crossings cross;
    if (pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        cross = new EvenOdd(xlo, ylo, xhi, yhi);
    } else {
        cross = new NonZero(xlo, ylo, xhi, yhi);
    }
    // coords array is big enough for holding:
    //     coordinates returned from currentSegment (6)
    //     OR
    //         two subdivided quadratic curves (2+4+4=10)
    //         AND
    //             0-1 horizontal splitting parameters
    //             OR
    //             2 parametric equation derivative coefficients
    //     OR
    //         three subdivided cubic curves (2+6+6+6=20)
    //         AND
    //             0-2 horizontal splitting parameters
    //             OR
    //             3 parametric equation derivative coefficients
    double coords[] = new double[23];
    double movx = 0;
    double movy = 0;
    double curx = 0;
    double cury = 0;
    double newx, newy;
    while (!pi.isDone()) {
        int type = pi.currentSegment(coords);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            if (movy != cury &&
                cross.accumulateLine(curx, cury, movx, movy))
            {
                return null;
            }
            movx = curx = coords[0];
            movy = cury = coords[1];
            break;
        case PathIterator.SEG_LINETO:
            newx = coords[0];
            newy = coords[1];
            if (cross.accumulateLine(curx, cury, newx, newy)) {
                return null;
            }
            curx = newx;
            cury = newy;
            break;
        case PathIterator.SEG_QUADTO:
            newx = coords[2];
            newy = coords[3];
            if (cross.accumulateQuad(curx, cury, coords)) {
                return null;
            }
            curx = newx;
            cury = newy;
            break;
        case PathIterator.SEG_CUBICTO:
            newx = coords[4];
            newy = coords[5];
            if (cross.accumulateCubic(curx, cury, coords)) {
                return null;
            }
            curx = newx;
            cury = newy;
            break;
        case PathIterator.SEG_CLOSE:
            if (movy != cury &&
                cross.accumulateLine(curx, cury, movx, movy))
            {
                return null;
            }
            curx = movx;
            cury = movy;
            break;
        }
        pi.next();
    }
    if (movy != cury) {
        if (cross.accumulateLine(curx, cury, movx, movy)) {
            return null;
        }
    }
    if (debug) {
        cross.print();
    }
    return cross;
}
 
Example 12
Source File: PSPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
* Given a Java2D <code>PathIterator</code> instance,
* this method translates that into a PostScript path..
*/
void convertToPSPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    /* Map the PathIterator's fill rule into the PostScript
     * fill rule.
     */
    int fillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        fillRule = FILL_EVEN_ODD;
    } else {
        fillRule = FILL_WINDING;
    }

    beginPath();

    setFillMode(fillRule);

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            float lastX = getPenX();
            float lastY = getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            bezierTo(c1x, c1y,
                     c2x, c2y,
                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            bezierTo(segment[0], segment[1],
                     segment[2], segment[3],
                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            closeSubpath();
            break;
        }


        pathIter.next();
    }
}
 
Example 13
Source File: ImageMapEmitter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Convert AWT shape to image map coordinates.
 * 
 * @param shape
 * @return
 */
private String shape2polyCoords( Shape shape )
{
	if ( shape == null )
	{
		return null;
	}

	ArrayList<Double> al = new ArrayList<Double>( );

	FlatteningPathIterator pitr = new FlatteningPathIterator( shape.getPathIterator( null ),
			1 );
	double[] data = new double[6];

	while ( !pitr.isDone( ) )
	{
		int type = pitr.currentSegment( data );

		switch ( type )
		{
			case PathIterator.SEG_MOVETO :
				al.add( new Double( data[0] ) );
				al.add( new Double( data[1] ) );
				break;
			case PathIterator.SEG_LINETO :
				al.add( new Double( data[0] ) );
				al.add( new Double( data[1] ) );
				break;
			case PathIterator.SEG_QUADTO :
				al.add( new Double( data[0] ) );
				al.add( new Double( data[1] ) );
				al.add( new Double( data[2] ) );
				al.add( new Double( data[3] ) );
				break;
			case PathIterator.SEG_CUBICTO :
				al.add( new Double( data[0] ) );
				al.add( new Double( data[1] ) );
				al.add( new Double( data[2] ) );
				al.add( new Double( data[3] ) );
				al.add( new Double( data[4] ) );
				al.add( new Double( data[5] ) );
				break;
			case PathIterator.SEG_CLOSE :
				break;
		}

		pitr.next( );
	}

	if ( al.size( ) == 0 )
	{
		return null;
	}

	StringBuffer sb = new StringBuffer( );

	for ( int i = 0; i < al.size( ); i++ )
	{
		Double db = al.get( i );
		if ( i > 0 )
		{
			sb.append( "," ); //$NON-NLS-1$
		}
		sb.append( (int) translateCoor( db.doubleValue( ) ) );
	}

	return sb.toString( );
}
 
Example 14
Source File: SerializedPathIterator.java    From pumpernickel with MIT License 4 votes vote down vote up
public void next() {
	consumeWhiteSpace(false);

	if (ctr >= c.length) {
		ctr = c.length + 2;
		return;
	}
	int terms;
	char k = c[ctr];

	switch (k) {
	case 'm':
	case 'M':
		currentSegment = PathIterator.SEG_MOVETO;
		terms = 2;
		break;
	case 'l':
	case 'L':
		currentSegment = PathIterator.SEG_LINETO;
		terms = 2;
		break;
	case 'q':
	case 'Q':
		currentSegment = PathIterator.SEG_QUADTO;
		terms = 4;
		break;
	case 'c':
	case 'C':
		currentSegment = PathIterator.SEG_CUBICTO;
		terms = 6;
		break;
	case 'z':
	case 'Z':
		currentSegment = PathIterator.SEG_CLOSE;
		terms = 0;
		break;
	default:
		throw new ParserException(
				"Unrecognized character in shape data: \'" + c[ctr] + "\'",
				ctr, 1);

	}
	ctr++;
	if (terms > 0) {
		parseTerms(terms);
	} else {
		if (ctr < c.length) {
			if (Character.isWhitespace(c[ctr]) == false)
				throw new ParserException("expected whitespace after z",
						ctr, 1);
		}
	}
}
 
Example 15
Source File: KmlRenderer.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
public Set<KmlPolygon> renderPolygons(AExtrusion ext) {
	Set<KmlPolygon> polys = new HashSet<KmlPolygon>();
	
	ext.setMaxDistance(200000);
	//ext.setFlatness(1);
	//ext.setLimit(3);
	ext.setFlatness(2);
	ext.setLimit(8);
	
	// Render perimeter polys
	List<Point> perimeterPoints = new ArrayList<Point>();
	PathIterator it = ext.getShape().getPathIterator(null);
	Point pre = null;                
               
	while (!it.isDone()) {
                       
                   double[] strokePoints = new double[6];                            
                   int type = it.currentSegment(strokePoints);

                   double longitudeDegrees = strokePoints[0];
                   double latitudeDegrees = strokePoints[1];
                   switch (type) {
                           case PathIterator.SEG_MOVETO:
                           case PathIterator.SEG_LINETO:
                                   if (pre != null) {
                                           List<Point> ps = new ArrayList<Point>();
                                           ps.add(new Point(pre.getLongitude(), pre.getLatitude(), ext.getMinAltitude()));
                                           ps.add(new Point(pre.getLongitude(), pre.getLatitude(), ext.getMaxAltitude()));
                                           ps.add(new Point(longitudeDegrees, latitudeDegrees, ext.getMaxAltitude()));
                                           ps.add(new Point(longitudeDegrees, latitudeDegrees, ext.getMinAltitude()));
                                           ps.add(new Point(pre.getLongitude(), pre.getLatitude(), ext.getMinAltitude()));
                                           polys.add(new KmlPolygon(ps, ext.getAltitudeMode()));
                                   }
                                   pre = new Point(longitudeDegrees, latitudeDegrees);
                                   perimeterPoints.add(pre);
                   }
                   it.next();
	}
	                
	// Render top and bottom poly if the perimeter is complete
	if (perimeterPoints.size() > 0) {
                   // In some weird cases, for routes, when it builds an area, it will drop the closing
                   // point in the shape.   Route uses an area.  This causes this condition to not execute.
                   // adding the first point to the perimeterPoints fixes the issue, not sure if it causes any
                   // side effects.
                   if (perimeterPoints.get(0).equals(perimeterPoints.get(perimeterPoints.size() - 1))) {

                       polys.add(new KmlPolygon(transformPoints(perimeterPoints, ext.getMinAltitude()), ext.getAltitudeMode()));
                       polys.add(new KmlPolygon(transformPoints(perimeterPoints, ext.getMaxAltitude()), ext.getAltitudeMode()));
                   } else {
                       perimeterPoints.add(perimeterPoints.get(0));

                       polys.add(new KmlPolygon(transformPoints(perimeterPoints, ext.getMinAltitude()), ext.getAltitudeMode()));
                       polys.add(new KmlPolygon(transformPoints(perimeterPoints, ext.getMaxAltitude()), ext.getAltitudeMode()));
                   }
	}
               
	
	return polys;
}
 
Example 16
Source File: PSPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
* Given a Java2D <code>PathIterator</code> instance,
* this method translates that into a PostScript path..
*/
void convertToPSPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    /* Map the PathIterator's fill rule into the PostScript
     * fill rule.
     */
    int fillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        fillRule = FILL_EVEN_ODD;
    } else {
        fillRule = FILL_WINDING;
    }

    beginPath();

    setFillMode(fillRule);

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            float lastX = getPenX();
            float lastY = getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            bezierTo(c1x, c1y,
                     c2x, c2y,
                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            bezierTo(segment[0], segment[1],
                     segment[2], segment[3],
                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            closeSubpath();
            break;
        }


        pathIter.next();
    }
}
 
Example 17
Source File: GeneralPathSerializer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Writes a serializable object description to the given object output stream.
 *
 * @param o   the to be serialized object.
 * @param out the outputstream that should receive the object.
 * @throws java.io.IOException if an I/O error occured.
 */
public void writeObject( final Object o, final ObjectOutputStream out )
  throws IOException {
  final GeneralPath gp = (GeneralPath) o;
  final PathIterator it = gp.getPathIterator( new AffineTransform() );
  out.writeInt( it.getWindingRule() );
  while ( it.isDone() == false ) {
    final float[] corrds = new float[ 6 ];
    final int type = it.currentSegment( corrds );
    out.writeInt( type );

    switch( type ) {
      case PathIterator.SEG_MOVETO: {
        out.writeFloat( corrds[ 0 ] );
        out.writeFloat( corrds[ 1 ] );
        break;
      }
      case PathIterator.SEG_LINETO: {
        out.writeFloat( corrds[ 0 ] );
        out.writeFloat( corrds[ 1 ] );
        break;
      }
      case PathIterator.SEG_QUADTO: {
        out.writeFloat( corrds[ 0 ] );
        out.writeFloat( corrds[ 1 ] );
        out.writeFloat( corrds[ 2 ] );
        out.writeFloat( corrds[ 3 ] );
        break;
      }
      case PathIterator.SEG_CUBICTO: {
        out.writeFloat( corrds[ 0 ] );
        out.writeFloat( corrds[ 1 ] );
        out.writeFloat( corrds[ 2 ] );
        out.writeFloat( corrds[ 3 ] );
        out.writeFloat( corrds[ 4 ] );
        out.writeFloat( corrds[ 5 ] );
        break;
      }
      case PathIterator.SEG_CLOSE: {
        break;
      }
      default:
        throw new IOException( "Unexpected type encountered: " + type );
    }
    it.next();
  }
  out.writeInt( -1 );
}
 
Example 18
Source File: PiscesRenderingEngine.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public int currentSegment(float[] coords) {
    int type = src.currentSegment(coords);

    int lastCoord;
    switch(type) {
    case PathIterator.SEG_CUBICTO:
        lastCoord = 4;
        break;
    case PathIterator.SEG_QUADTO:
        lastCoord = 2;
        break;
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_MOVETO:
        lastCoord = 0;
        break;
    case PathIterator.SEG_CLOSE:
        // we don't want to deal with this case later. We just exit now
        curx_adjust = movx_adjust;
        cury_adjust = movy_adjust;
        return type;
    default:
        throw new InternalError("Unrecognized curve type");
    }

    // normalize endpoint
    float x_adjust = (float)Math.floor(coords[lastCoord] + lval) +
                 rval - coords[lastCoord];
    float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) +
                 rval - coords[lastCoord + 1];

    coords[lastCoord    ] += x_adjust;
    coords[lastCoord + 1] += y_adjust;

    // now that the end points are done, normalize the control points
    switch(type) {
    case PathIterator.SEG_CUBICTO:
        coords[0] += curx_adjust;
        coords[1] += cury_adjust;
        coords[2] += x_adjust;
        coords[3] += y_adjust;
        break;
    case PathIterator.SEG_QUADTO:
        coords[0] += (curx_adjust + x_adjust) / 2;
        coords[1] += (cury_adjust + y_adjust) / 2;
        break;
    case PathIterator.SEG_LINETO:
        break;
    case PathIterator.SEG_MOVETO:
        movx_adjust = x_adjust;
        movy_adjust = y_adjust;
        break;
    case PathIterator.SEG_CLOSE:
        throw new InternalError("This should be handled earlier.");
    }
    curx_adjust = x_adjust;
    cury_adjust = y_adjust;
    return type;
}
 
Example 19
Source File: MarlinRenderingEngine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final int currentSegment(final float[] coords) {
    if (doMonitors) {
        RendererContext.stats.mon_npi_currentSegment.start();
    }
    int lastCoord;
    final int type = src.currentSegment(coords);

    switch(type) {
        case PathIterator.SEG_MOVETO:
        case PathIterator.SEG_LINETO:
            lastCoord = 0;
            break;
        case PathIterator.SEG_QUADTO:
            lastCoord = 2;
            break;
        case PathIterator.SEG_CUBICTO:
            lastCoord = 4;
            break;
        case PathIterator.SEG_CLOSE:
            // we don't want to deal with this case later. We just exit now
            curx_adjust = movx_adjust;
            cury_adjust = movy_adjust;

            if (doMonitors) {
                RendererContext.stats.mon_npi_currentSegment.stop();
            }
            return type;
        default:
            throw new InternalError("Unrecognized curve type");
    }

    // TODO: handle NaN, Inf and overflow

    // normalize endpoint
    float coord, x_adjust, y_adjust;

    coord = coords[lastCoord];
    x_adjust = normCoord(coord); // new coord
    coords[lastCoord] = x_adjust;
    x_adjust -= coord;

    coord = coords[lastCoord + 1];
    y_adjust = normCoord(coord); // new coord
    coords[lastCoord + 1] = y_adjust;
    y_adjust -= coord;

    // now that the end points are done, normalize the control points
    switch(type) {
        case PathIterator.SEG_MOVETO:
            movx_adjust = x_adjust;
            movy_adjust = y_adjust;
            break;
        case PathIterator.SEG_LINETO:
            break;
        case PathIterator.SEG_QUADTO:
            coords[0] += (curx_adjust + x_adjust) / 2f;
            coords[1] += (cury_adjust + y_adjust) / 2f;
            break;
        case PathIterator.SEG_CUBICTO:
            coords[0] += curx_adjust;
            coords[1] += cury_adjust;
            coords[2] += x_adjust;
            coords[3] += y_adjust;
            break;
        case PathIterator.SEG_CLOSE:
            // handled earlier
        default:
    }
    curx_adjust = x_adjust;
    cury_adjust = y_adjust;

    if (doMonitors) {
        RendererContext.stats.mon_npi_currentSegment.stop();
    }
    return type;
}
 
Example 20
Source File: ShapeProperties.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * {@link #coordinates(double)} implementation for the double-precision case.
 * The {@link #isPolygon} field needs to be set before to invoke this method.
 */
private List<double[]> coordinatesAsDoubles(final PathIterator it) {
    final List<double[]> polylines = new ArrayList<>();
    double[] polyline = new double[10];
    final double[] coords = new double[6];
    /*
     * Double-precision variant of this method. Source code below is identical to the single-precision variant,
     * but the methods invoked are different because of method overloading. Trying to have a common code is too
     * complex (too many code are different despite looking the same).
     */
    int i = 0;
    while (!it.isDone()) {
        switch (it.currentSegment(coords)) {
            case PathIterator.SEG_MOVETO: {
                if (i > 2) {
                    isPolygon = false;          // MOVETO without CLOSE: this is a linestring instead than a polygon.
                    polylines.add(Arrays.copyOf(polyline, i));
                }
                System.arraycopy(coords, 0, polyline, 0, 2);
                i = 2;
                break;
            }
            case PathIterator.SEG_LINETO: {
                polyline = addPoint(coords, polyline, i);
                i += 2;
                break;
            }
            case PathIterator.SEG_CLOSE: {
                if (i > 2) {
                    if (polyline[0] != polyline[i-2] || polyline[1] != polyline[i-1]) {
                        polyline = addPoint(polyline, polyline, i);
                        i += 2;
                    }
                    polylines.add(Arrays.copyOf(polyline, i));
                }
                i = 0;
                break;
            }
            default: throw new IllegalPathStateException();
        }
        it.next();
    }
    if (i > 2) {
        isPolygon = false;          // LINETO without CLOSE: this is a linestring instead than a polygon.
        polylines.add(Arrays.copyOf(polyline, i));
    }
    return polylines;
}