Beispiel #1
0
  /**
   * Returns a path which is cappedPath at the ends, to prevent it from drawing under the end caps.
   */
  protected BezierPath getCappedPath() {
    if (cappedPath == null) {
      cappedPath = path.clone();
      if (isClosed()) {
        cappedPath.setClosed(true);
      } else {
        if (cappedPath.size() > 1) {
          if (get(START_DECORATION) != null) {
            BezierPath.Node p0 = cappedPath.get(0);
            BezierPath.Node p1 = cappedPath.get(1);
            Point2D.Double pp;
            if ((p0.getMask() & BezierPath.C2_MASK) != 0) {
              pp = p0.getControlPoint(2);
            } else if ((p1.getMask() & BezierPath.C1_MASK) != 0) {
              pp = p1.getControlPoint(1);
            } else {
              pp = p1.getControlPoint(0);
            }
            double radius = get(START_DECORATION).getDecorationRadius(this);
            double lineLength = Geom.length(p0.getControlPoint(0), pp);
            cappedPath.set(
                0, 0, Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
          }
          if (get(END_DECORATION) != null) {
            BezierPath.Node p0 = cappedPath.get(cappedPath.size() - 1);
            BezierPath.Node p1 = cappedPath.get(cappedPath.size() - 2);

            Point2D.Double pp;
            if ((p0.getMask() & BezierPath.C1_MASK) != 0) {
              pp = p0.getControlPoint(1);
            } else if ((p1.getMask() & BezierPath.C2_MASK) != 0) {
              pp = p1.getControlPoint(2);
            } else {
              pp = p1.getControlPoint(0);
            }

            double radius = get(END_DECORATION).getDecorationRadius(this);
            double lineLength = Geom.length(p0.getControlPoint(0), pp);
            cappedPath.set(
                cappedPath.size() - 1,
                0,
                Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
          }
          cappedPath.invalidatePath();
        }
      }
    }
    return cappedPath;
  }
Beispiel #2
0
 /**
  * Finds a control point index. Returns -1 if no control point could be found. FIXME - Move this
  * to BezierPath
  */
 public int findNode(Point2D.Double p) {
   BezierPath tp = path;
   for (int i = 0; i < tp.size(); i++) {
     BezierPath.Node p2 = tp.get(i);
     if (p2.x[0] == p.x && p2.y[0] == p.y) {
       return i;
     }
   }
   return -1;
 }
Beispiel #3
0
 /** Sets the point coordinate of control point 0 at the specified node. */
 public void setPoint(int index, Point2D.Double p) {
   BezierPath.Node node = path.get(index);
   double dx = p.x - node.x[0];
   double dy = p.y - node.y[0];
   for (int i = 0; i < node.x.length; i++) {
     node.x[i] += dx;
     node.y[i] += dy;
   }
   invalidate();
 }
Beispiel #4
0
 @Override
 public boolean contains(Point2D.Double p) {
   double tolerance = Math.max(2f, AttributeKeys.getStrokeTotalWidth(this) / 2d);
   if (isClosed() || get(FILL_COLOR) != null && get(UNCLOSED_PATH_FILLED)) {
     if (path.contains(p)) {
       return true;
     }
     double grow = AttributeKeys.getPerpendicularHitGrowth(this) * 2d;
     GrowStroke gs =
         new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT));
     if (gs.createStrokedShape(path).contains(p)) {
       return true;
     } else {
       if (isClosed()) {
         return false;
       }
     }
   }
   if (!isClosed()) {
     if (getCappedPath().outlineContains(p, tolerance)) {
       return true;
     }
     if (get(START_DECORATION) != null) {
       BezierPath cp = getCappedPath();
       Point2D.Double p1 = path.get(0, 0);
       Point2D.Double p2 = cp.get(0, 0);
       // FIXME - Check here, if caps path contains the point
       if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, p.x, p.y, tolerance)) {
         return true;
       }
     }
     if (get(END_DECORATION) != null) {
       BezierPath cp = getCappedPath();
       Point2D.Double p1 = path.get(path.size() - 1, 0);
       Point2D.Double p2 = cp.get(path.size() - 1, 0);
       // FIXME - Check here, if caps path contains the point
       if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, p.x, p.y, tolerance)) {
         return true;
       }
     }
   }
   return false;
 }
Beispiel #5
0
 protected void drawCaps(Graphics2D g) {
   if (getNodeCount() > 1) {
     if (get(START_DECORATION) != null) {
       BezierPath cp = getCappedPath();
       Point2D.Double p1 = path.get(0, 0);
       Point2D.Double p2 = cp.get(0, 0);
       if (p2.equals(p1)) {
         p2 = path.get(1, 0);
       }
       get(START_DECORATION).draw(g, this, p1, p2);
     }
     if (get(END_DECORATION) != null) {
       BezierPath cp = getCappedPath();
       Point2D.Double p1 = path.get(path.size() - 1, 0);
       Point2D.Double p2 = cp.get(path.size() - 1, 0);
       if (p2.equals(p1)) {
         p2 = path.get(path.size() - 2, 0);
       }
       get(END_DECORATION).draw(g, this, p1, p2);
     }
   }
 }
Beispiel #6
0
 public Point2D.Double getOutermostPoint() {
   return path.get(path.indexOfOutermostNode()).getControlPoint(0);
 }
Beispiel #7
0
 /** Sets the point coordinate of a control point. */
 public void setPoint(int index, int coord, Point2D.Double p) {
   BezierPath.Node cp = new BezierPath.Node(path.get(index));
   cp.setControlPoint(coord, p);
   setNode(index, cp);
 }
Beispiel #8
0
 /** Gets the point coordinate of a control point. */
 public Point2D.Double getPoint(int index, int coord) {
   return path.get(index).getControlPoint(coord);
 }
Beispiel #9
0
 /**
  * Convenience method for getting the point coordinate of the first control point of the specified
  * node.
  */
 public Point2D.Double getPoint(int index) {
   return path.get(index).getControlPoint(0);
 }
Beispiel #10
0
 /** Gets a control point. */
 public BezierPath.Node getNode(int index) {
   return (BezierPath.Node) path.get(index).clone();
 }