Tabnine Logo
BezierPath
Code IndexAdd Tabnine to your IDE (free)

How to use
BezierPath
in
org.jhotdraw.geom

Best Java code snippets using org.jhotdraw.geom.BezierPath (Showing top 20 results out of 315)

origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public Shape createStrokedShape(Shape s) {
  BezierPath bp = new BezierPath();
  Path2D.Double left = new Path2D.Double();
  Path2D.Double right = new Path2D.Double();
        if (bp.size() != 0) {
          traceStroke(bp, left, right);
        bp.clear();
        bp.setClosed(false);
        bp.moveTo(coords[0], coords[1]);
        break;
      case PathIterator.SEG_LINETO:
        if (coords[0] != bp.get(bp.size() - 1).x[0]
            || coords[1] != bp.get(bp.size() - 1).y[0]) {
          bp.lineTo(coords[0], coords[1]);
        bp.quadTo(coords[0], coords[1], coords[2], coords[3]);
        break;
      case PathIterator.SEG_CUBICTO:
        bp.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
        break;
      case PathIterator.SEG_CLOSE:
        bp.setClosed(true);
        break;
  if (bp.size() != 0) {
    traceStroke(bp, left, right);
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void transform(AffineTransform tx) {
  path.transform(tx);
  invalidate();
}
origin: net.imagej/imagej-ui-swing

public static void main(final String[] args) {
  BezierPath path1 = new BezierPath();
  path1.moveTo(0, 0);
  path1.lineTo(100, 0);
  path1.lineTo(100, 100);
  path1.lineTo(0, 0);
  final GeneralPath path2 = new GeneralPath();
  path2.moveTo(0, 0);
  path2.lineTo(100, 0);
  path2.lineTo(100, 100);
  path2.closePath();
  // path1 = toBezierPath(path2.getPathIterator(new AffineTransform()));
  final BezierPath path3 = new BezierPath();
  path3.moveTo(0, 100);
  path3.lineTo(100, 0);
  path3.lineTo(100, 100);
  path3.lineTo(0, 100);
  path1 = subtract(path1, path3);
  show(path1.toGeneralPath());
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Tests if there are more points to read.
 * @return true if there are more points to read
 */
@Override
public boolean isDone() {
  return (index >= path.size() + (path.isClosed() ? 2 : 0));
}

origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * 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;
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Sets all values of this bezier path to that bezier path, so that this
 * path becomes identical to that path.
 */
public void setTo(BezierPath that) {
  while (that.size() < size()) {
    remove(size() - 1);
  }
  for (int i = 0, n = size(); i < n; i++) {
    get(i).setTo(that.get(i));
  }
  while (size() < that.size()) {
    add((Node) that.get(size()).clone());
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

path = new BezierPath();
path.moveTo(p.x, p.y);
nextCommand = 'L';
break;
path = new BezierPath();
path.moveTo(p.x, p.y);
nextCommand = 'l';
p.x = path.get(0).x[0];
p.y = path.get(0).y[0];
if (path.size() > 1) {
  BezierPath.Node first = path.get(0);
  BezierPath.Node last = path.get(path.size() - 1);
  if (first.x[0] == last.x[0]
      && first.y[0] == last.y[0]) {
    path.remove(path.size() - 1);
path.setClosed(true);
path.lineTo(p.x, p.y);
nextCommand = 'L';
path.lineTo(p.x, p.y);
nextCommand = 'l';
origin: net.imagej/imagej-ui-swing

public static BezierPath toBezierPath(final PathIterator iterator) {
  final BezierPath path = new BezierPath();
  final double[] segment = new double[6];
  for (; !iterator.isDone(); iterator.next()) {
    final int type = iterator.currentSegment(segment);
    switch (type) {
      case PathIterator.SEG_MOVETO:
        path.moveTo(segment[0], segment[1]);
        break;
      case PathIterator.SEG_LINETO:
        path.lineTo(segment[0], segment[1]);
        break;
      case PathIterator.SEG_QUADTO:
        path.quadTo(segment[0], segment[1], segment[2], segment[3]);
        break;
      case PathIterator.SEG_CUBICTO:
        path.curveTo(segment[0], segment[1], segment[2], segment[3],
          segment[4], segment[5]);
        break;
      case PathIterator.SEG_CLOSE:
        path.setClosed(true);
        break;
    }
  }
  return path;
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Adds the curve to the bezier path.
 * 
 * @param bezCurve
 * @param bezierPath
 */
private static void addCurveTo(Point2D.Double[] bezCurve, BezierPath bezierPath, double errorSquared, boolean connectsCorners) {
  BezierPath.Node lastNode = bezierPath.get(bezierPath.size() - 1);
  double error = Math.sqrt(errorSquared);
  if (connectsCorners && Geom.lineContainsPoint(lastNode.x[0], lastNode.y[0], bezCurve[3].x, bezCurve[3].y, bezCurve[1].x, bezCurve[1].y, error) &&
      Geom.lineContainsPoint(lastNode.x[0], lastNode.y[0], bezCurve[3].x, bezCurve[3].y, bezCurve[2].x, bezCurve[2].y, error)) {
    bezierPath.lineTo(
        bezCurve[3].x, bezCurve[3].y);
  } else {
    bezierPath.curveTo(
        bezCurve[1].x, bezCurve[1].y,
        bezCurve[2].x, bezCurve[2].y,
        bezCurve[3].x, bezCurve[3].y);
  }
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

BezierPath tempPath = new BezierPath();
Node t1, t2;
tempPath.add(t1 = new Node());
tempPath.add(t2 = new Node());
for (int i = 0, n = size() - 1; i < n; i++) {
  v1 = get(i);
  v2 = get(i + 1);
  if (v1.mask == 0 && v2.mask == 0) {
    if (Geom.lineContainsPoint(v1.x[0], v1.y[0], v2.x[0], v2.y[0], find.x, find.y, tolerance)) {
    t1.setTo(v1);
    t2.setTo(v2);
    tempPath.invalidatePath();
    if (tempPath.outlineContains(find, tolerance)) {
      return i;
if (isClosed && size() > 1) {
  v1 = get(size() - 1);
  v2 = get(0);
  if (v1.mask == 0 && v2.mask == 0) {
    if (Geom.lineContainsPoint(v1.x[0], v1.y[0], v2.x[0], v2.y[0], find.x, find.y, tolerance)) {
      return size() - 1;
    tempPath.invalidatePath();
    if (tempPath.outlineContains(find, tolerance)) {
      return size() - 1;
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

BezierPath triangle = new BezierPath();
switch (get(ORIENTATION)) {
  case NORTH :
  default :
    triangle.moveTo((float) (r.x + r.width / 2), (float) r.y);
    triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height));
    triangle.lineTo((float) r.x, (float) (r.y + r.height));
    break;
  case NORTH_EAST :
    triangle.moveTo((float) (r.x), (float) r.y);
    triangle.lineTo((float) (r.x + r.width), (float) (r.y));
    triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height));
    break;
  case EAST :
    triangle.moveTo((float) (r.x), (float) (r.y));
    triangle.lineTo((float) (r.x  + r.width), (float) (r.y + r.height / 2d));
    triangle.lineTo((float) r.x, (float) (r.y + r.height));
    break;
  case SOUTH_EAST :
    triangle.moveTo((float) (r.x + r.width), (float) (r.y));
    triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height));
    triangle.lineTo((float) (r.x), (float) (r.y + r.height));
    break;
  case SOUTH :
    triangle.moveTo((float) (r.x + r.width / 2), (float) (r.y + r.height));
    triangle.lineTo((float) r.x, (float) r.y);
    triangle.lineTo((float) (r.x + r.width), (float) r.y);
    break;
  case SOUTH_WEST :
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

createdFigure.willChange();
BezierPath figurePath = createdFigure.getBezierPath();
BezierPath digitizedPath = new BezierPath();
for (int i = nodeCountBeforeDrag - 1, n = figurePath.size(); i < n; i++) {
  digitizedPath.add(figurePath.get(nodeCountBeforeDrag - 1));
  figurePath.remove(nodeCountBeforeDrag - 1);
figurePath.addAll(fittedPath);
createdFigure.setBezierPath(figurePath);
createdFigure.changed();
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

cappedPath = (BezierPath) 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) {
      cappedPath.set(0, 0, Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
      BezierPath.Node p0 = cappedPath.get(cappedPath.size() - 1);
      BezierPath.Node p1 = cappedPath.get(cappedPath.size() - 2);
      cappedPath.set(cappedPath.size() - 1, 0, Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
    cappedPath.invalidatePath();
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Gets the node count.
 */
public int getNodeCount() {
  return path.size();
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

BezierPath fittedPath = new BezierPath();
        break;
      case 1:
        fittedPath.add(new BezierPath.Node(seg.get(0)));
        break;
      case 2:
        if (fittedPath.isEmpty()) {
          fittedPath.add(new BezierPath.Node(seg.get(0)));
        fittedPath.lineTo(seg.get(1).x, seg.get(1).y);
        break;
      default:
        if (fittedPath.isEmpty()) {
          fittedPath.add(new BezierPath.Node(seg.get(0)));
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Splits the segment at the given Point2D.Double if a segment was hit.
 * @return the index of the segment or -1 if no segment was hit.
 */
public int splitSegment(Point2D.Double split, double tolerance) {
  int i = findSegment(split, tolerance);
  int nextI = (i + 1) % size();
  if (i != -1) {
    if ((get(i).mask & C2_MASK) == C2_MASK
        && (get(nextI).mask & C1_MASK) == 0) {
      // quadto
      add(i + 1, new Node(C2_MASK, split, split, split));
    } else if ((get(i).mask & C2_MASK) == 0
        && (get(nextI).mask & C1_MASK) == C1_MASK) {
      // quadto
      add(i + 1, new Node(C1_MASK, split, split, split));
    } else if ((get(i).mask & C2_MASK) == C2_MASK
        && (get(nextI).mask & C1_MASK) == C1_MASK) {
      // cubicto
      add(i + 1, new Node(C1_MASK | C2_MASK, split, split, split));
    } else {
      // lineto
      add(i + 1, new Node(split));
    }
  }
  return i + 1;
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public Rectangle2D.Double getDrawingArea() {
  if (cachedDrawingArea == null) {
    if (get(TRANSFORM) == null) {
      cachedDrawingArea = path.getBounds2D();
    } else {
      BezierPath p2 = (BezierPath) path.clone();
      p2.transform(get(TRANSFORM));
      cachedDrawingArea = p2.getBounds2D();
    }
  }
  return (Rectangle2D.Double) cachedDrawingArea.clone();
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Adds a (at least) linear 'curve' to the bezier path.
 * <p>
 * If the previous node has no C2 control point the line will be straight
 * (linear), otherwise the line will be quadratic.
 * <p>
 * This is a convenience method for adding a node with a single control
 * point C0.
 * <p>
 * The bezier path must already have at least one node.
 */
public void lineTo(double x1, double y1) {
  if (size() == 0) {
    throw new IllegalPathStateException("lineTo only allowed when not empty");
  }
  get(size() - 1).keepColinear = false;
  add(new Node(x1, y1));
}
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

public Point2D.Double getPointOnPath(double relative, double flatness) {
  if (size() == 0) {
    return null;
  } else if (size() == 1) {
    return get(0).getControlPoint(0);
    return get(0).getControlPoint(0);
  } else if (relative >= 1) {
    return get(size() - 1).getControlPoint(0);
  validatePath();
  double len = getLengthOfPath(flatness);
  double relativeLen = len * relative;
  double pos = 0;
origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

if (bp.isClosed()) {
  BezierPath.Node prev = bp.get(bp.size() - 1);
  for (int i = 0; i < bp.size(); i++) {
    BezierPath.Node node = bp.get(i);
    if (prev.x[0] == node.x[0] && prev.y[0] == node.y[0]) {
      bp.remove(i--);
  BezierPath.Node prev = bp.get(0);
  for (int i = 1; i < bp.size(); i++) {
    BezierPath.Node node = bp.get(i);
    if (prev.x[0] == node.x[0] && prev.y[0] == node.y[0]) {
      bp.remove(i--);
if (bp.isClosed() && bp.size() > 1) {
  prevCorners = computeThickLine(
      bp.get(bp.size() - 1).x[0], bp.get(bp.size() - 1).y[0],
      bp.get(0).x[0], bp.get(0).y[0],
      innerWidth, prevCorners);
  currentCorners = computeThickLine(
      bp.get(0).x[0], bp.get(0).y[0],
      bp.get(1).x[0], bp.get(1).y[0],
      innerWidth, currentCorners);
  if (bp.size() > 1) {
    currentCorners = computeThickLine(
        bp.get(0).x[0], bp.get(0).y[0],
        bp.get(1).x[0], bp.get(1).y[0],
        innerWidth, currentCorners);
    right.moveTo(currentCorners[0], currentCorners[1]);
org.jhotdraw.geomBezierPath

Javadoc

BezierPath allows the construction of paths consisting of straight lines, quadratic curves and cubic curves.

A BezierPath is defined by its nodes. Each node has three control points: C0, C1, C2. A mask defines which control points are in use. At a node, the path passes through C0. C1 controls the curve going towards C0. C2 controls the curve going away from C0.

Most used methods

  • <init>
    Creates a new instance.
  • curveTo
    Adds a cubic curve to the bezier path. This is a convenience method for adding a node with control p
  • lineTo
    Adds a (at least) linear 'curve' to the bezier path. If the previous node has no C2 control point th
  • moveTo
    Adds the first node to the bezier path. This is a convenience method for adding the first node with
  • quadTo
    Adds a (at least) quadratic curve to the bezier path. If the previous node has no C2 control point t
  • setClosed
  • size
  • transform
    Transforms the BezierPath.
  • toGeneralPath
    Converts the BezierPath into a Path2D.Double.
  • add
  • addAll
  • addPolyline
    Adds a set of nodes to the path. Convenience method for adding multiple nodes with a single control
  • addAll,
  • addPolyline,
  • arcTo,
  • chop,
  • clear,
  • clone,
  • contains,
  • findSegment,
  • get,
  • getBounds2D

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • requestLocationUpdates (LocationManager)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • JLabel (javax.swing)
  • JList (javax.swing)
  • JOptionPane (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now