示例#1
0
  private void drawImageGraph(ImageGraph graph, Graphics2D g, Color color, int pointSize) {
    g.setColor(color);
    g.setStroke(LINE_STROKE);

    for (ImagePoint p : graph.getPoints())
      g.fillOval(
          (int) p.getX() - (pointSize / 2), (int) p.getY() - (pointSize / 2), pointSize, pointSize);

    for (ImageEdge edge : graph.getGraph().edgeSet())
      g.drawLine(
          (int) edge.getStart().getX(),
          (int) edge.getStart().getY(),
          (int) edge.getEnd().getX(),
          (int) edge.getEnd().getY());
  }
示例#2
0
  private void drawImageGraph(
      ImageGraph graph, Graphics2D g, Color color, int pointSize, int unsafeRadius) {
    g.setColor(color);
    g.setStroke(LINE_STROKE);

    for (ImagePoint p : graph.getGraph().vertexSet()) {
      g.fillOval(
          (int) p.getX() - (pointSize / 2), (int) p.getY() - (pointSize / 2), pointSize, pointSize);
      g.drawOval(
          (int) (p.getX() - unsafeRadius),
          (int) (p.getY() - unsafeRadius),
          2 * (int) unsafeRadius,
          2 * (int) unsafeRadius);
    }

    for (ImageEdge edge : graph.getGraph().edgeSet()) {
      g.drawLine(
          (int) edge.getStart().getX(),
          (int) edge.getStart().getY(),
          (int) edge.getEnd().getX(),
          (int) edge.getEnd().getY());
      // Draw lines offset by unsafeRadius to either side
      // Rotate the line by 90 degrees and scale to offset length
      ImagePoint rotated =
          new ImagePoint(-edge.getdY(), edge.getdX()).scale(unsafeRadius / edge.getLength());
      int xOffset = (int) rotated.getX();
      int yOffset = (int) rotated.getY();
      g.drawLine(
          (int) edge.getStart().getX() - xOffset,
          (int) edge.getStart().getY() - yOffset,
          (int) edge.getEnd().getX() - xOffset,
          (int) edge.getEnd().getY() - yOffset);
      g.drawLine(
          (int) edge.getStart().getX() + xOffset,
          (int) edge.getStart().getY() + yOffset,
          (int) edge.getEnd().getX() + xOffset,
          (int) edge.getEnd().getY() + yOffset);
    }
  }