예제 #1
0
 public Arc2D evaluate(Arc2D v0, Arc2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   double start = v0.getAngleStart() + ((v1.getAngleStart() - v0.getAngleStart()) * fraction);
   double extent = v0.getAngleExtent() + ((v1.getAngleExtent() - v0.getAngleExtent()) * fraction);
   Arc2D value = (Arc2D) v0.clone();
   value.setArc(x, y, w, h, start, extent, v0.getArcType());
   return value;
 }
예제 #2
0
파일: SVGArc.java 프로젝트: Revlin/batik
  /** @param arc the Arc2D object to be converted */
  public Element toSVG(Arc2D arc) {
    double ext = arc.getAngleExtent();
    double width = arc.getWidth();
    double height = arc.getHeight();

    if (width == 0 || height == 0) {
      Line2D line =
          new Line2D.Double(arc.getX(), arc.getY(), arc.getX() + width, arc.getY() + height);
      if (svgLine == null) {
        svgLine = new SVGLine(generatorContext);
      }
      return svgLine.toSVG(line);
    }

    if (ext >= 360 || ext <= -360) {
      Ellipse2D ellipse = new Ellipse2D.Double(arc.getX(), arc.getY(), width, height);
      if (svgEllipse == null) {
        svgEllipse = new SVGEllipse(generatorContext);
      }
      return svgEllipse.toSVG(ellipse);
    }

    Element svgPath = generatorContext.domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_PATH_TAG);
    StringBuffer d = new StringBuffer("");

    Point2D startPt = arc.getStartPoint();
    Point2D endPt = arc.getEndPoint();
    int type = arc.getArcType();

    d.append(PATH_MOVE);
    d.append(doubleString(startPt.getX()));
    d.append(SPACE);
    d.append(doubleString(startPt.getY()));
    d.append(SPACE);

    d.append(PATH_ARC);
    d.append(doubleString(width / 2));
    d.append(SPACE);
    d.append(doubleString(height / 2));
    d.append(SPACE);
    d.append("0"); // no rotation with J2D arc.
    d.append(SPACE);
    if (ext > 0) {
      // CCW sweep case, ext > 0
      if (ext > 180) d.append("1"); // use large arc.
      else d.append("0"); // use small arc.
      d.append(SPACE);
      d.append("0"); // sweep ccw
    } else {
      // CW sweep case, ext < 0
      if (ext < -180) d.append("1"); // use large arc.
      else d.append("0"); // use small arc.
      d.append(SPACE);
      d.append("1"); // sweep cw
    }

    d.append(SPACE);
    d.append(doubleString(endPt.getX()));
    d.append(SPACE);
    d.append(doubleString(endPt.getY()));

    if (type == Arc2D.CHORD) {
      d.append(PATH_CLOSE);
    } else if (type == Arc2D.PIE) {
      double cx = arc.getX() + width / 2;
      double cy = arc.getY() + height / 2;
      d.append(PATH_LINE_TO);
      d.append(SPACE);
      d.append(doubleString(cx));
      d.append(SPACE);
      d.append(doubleString(cy));
      d.append(SPACE);
      d.append(PATH_CLOSE);
    }
    svgPath.setAttributeNS(null, SVG_D_ATTRIBUTE, d.toString());
    return svgPath;
  }