java.awt.geom.Line2D Java Examples

The following examples show how to use java.awt.geom.Line2D. 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: mxEdgeHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
public void paint(Graphics g) {
  Graphics2D g2 = (Graphics2D)g;

  Stroke stroke = g2.getStroke();
  g2.setStroke(getSelectionStroke());
  g.setColor(getSelectionColor());

  Point last = state.getAbsolutePoint(0).getPoint();

  for (int i = 1; i < state.getAbsolutePointCount(); i++) {
    Point current = state.getAbsolutePoint(i).getPoint();
    Line2D line = new Line2D.Float(last.x, last.y, current.x, current.y);

    Rectangle bounds = g2.getStroke().createStrokedShape(line).getBounds();

    if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) {
      g2.draw(line);
    }

    last = current;
  }

  g2.setStroke(stroke);
  super.paint(g);
}
 
Example #2
Source File: jMutRepair_0021_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke (<code>null</code> not permitted).
 * @param paint  the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
        double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, 
            getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, 
                dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, 
                dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example #3
Source File: GeometryUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Shape getArrowShape(Line2D line, Point2D intersectionPoint) {
  final double deltaY = line.getP2().getY() - line.getP1().getY();
  final double length = Math.sqrt(Math.pow(deltaY, 2) + Math.pow(line.getP2().getX() - line.getP1().getX(), 2));

  double theta = Math.asin(deltaY / length);

  if (line.getP1().getX() > line.getP2().getX()) {
    theta = Math.PI - theta;
  }

  AffineTransform rotate = AffineTransform.getRotateInstance(theta, myArrowSize, myArrowSize / 2);
  Shape polygon = rotate.createTransformedShape(myArrowPolygon);

  AffineTransform move = AffineTransform.getTranslateInstance(intersectionPoint.getX() - myArrowSize, intersectionPoint.getY() - myArrowSize /2);
  polygon = move.createTransformedShape(polygon);
  return polygon;
}
 
Example #4
Source File: SubstanceColorSelectorPanelUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void paintBottomDivider(Graphics g, int x, int y, int width, int height) {
    Color borderColor = SubstanceCoreUtilities.getSkin(this.colorSelectorPanel).getOverlayColor(
            SubstanceSlices.ColorOverlayType.LINE,
            DecorationPainterUtils.getDecorationType(this.colorSelectorPanel), ComponentState.ENABLED);
    if (borderColor == null) {
        SubstanceColorScheme bgBorderScheme = SubstanceColorSchemeUtilities.getColorScheme(
                this.colorSelectorPanel, ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
                ComponentState.ENABLED);
        borderColor = bgBorderScheme.getLineColor();
    }
    float lineThickness = SubstanceSizeUtils.getBorderStrokeWidth();
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setStroke(new BasicStroke(lineThickness));
    g2d.setColor(borderColor);
    float lineY = y + height - lineThickness;
    g2d.draw(new Line2D.Float(x, lineY, x + width, lineY));
    g2d.dispose();
}
 
Example #5
Source File: jMutRepair_0038_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    
    Line2D axisLine = null;
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    g2.draw(axisLine);
    
}
 
Example #6
Source File: Renderer.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a grid of short lines indicating local illumination directions into
 * displayImage.
 */
private void renderLightDirections() {
    if (showLocalLightDirection && model.isLocalLightDirection()) {
        Graphics2D g2d = (Graphics2D) displayImage.getGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(Color.BLACK);

        int scale = displayImage.getWidth() / model.getGrid().getCols();
        g2d.setStroke(new BasicStroke(LOCAL_DIRECTION_LINES_STROKE_WIDTH_PX * scale));
        int width = model.getGrid().getCols();
        int height = model.getGrid().getRows();
        for (int row = LOCAL_DIRECTION_LINES_SPACING_PX / 2; row < height; row += LOCAL_DIRECTION_LINES_SPACING_PX) {
            for (int col = LOCAL_DIRECTION_LINES_SPACING_PX / 2; col < width; col += LOCAL_DIRECTION_LINES_SPACING_PX) {
                double dirX = model.getLocalLightDirectionX(col, row);
                double dirY = model.getLocalLightDirectionY(col, row);
                double dx = dirX * LOCAL_DIRECTION_LINES_LENGTH_PX / 2;
                double dy = -dirY * LOCAL_DIRECTION_LINES_LENGTH_PX / 2;
                Line2D line = new Line2D.Double((col - dx) * scale, (row - dy) * scale,
                        (col + dx) * scale, (row + dy) * scale);
                g2d.draw(line);
            }
        }
    }
}
 
Example #7
Source File: MfCmdLineTo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Replays the command on the given WmfFile.
 *
 * @param file the meta file.
 */
public void replay( final WmfFile file ) {
  final Graphics2D graph = file.getGraphics2D();
  final MfDcState state = file.getCurrentState();

  final int cx = state.getCurPosX();
  final int cy = state.getCurPosY();

  final Point destP = getScaledDestination();

  if ( state.getLogPen().isVisible() ) {
    state.prepareDraw();
    graph.draw( new Line2D.Double( cx, cy, destP.x, destP.y ) );
    state.postDraw();

  }
  state.setCurPos( destP.x, destP.y );
}
 
Example #8
Source File: jMutRepair_001_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a range crosshair.
 * 
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, 
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
   
}
 
Example #9
Source File: Cardumen_006_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a range crosshair.
 * 
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, 
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
   
}
 
Example #10
Source File: JGenProg2017_005_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a range crosshair.
 * 
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, 
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
   
}
 
Example #11
Source File: JGenProg2017_000_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #12
Source File: AddRemoveControlPointAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Adds or removes a control point on a specified location
 * @param widget the connection widget
 * @param localLocation the local location
 */
private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) {
    ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ());
    if (!removeControlPoint (localLocation, list, deleteSensitivity)) {
        Point exPoint = null;
        int index = 0;
        for (Point elem : list) {
            if (exPoint != null) {
                Line2D l2d = new Line2D.Double (exPoint, elem);
                if (l2d.ptSegDist (localLocation) < createSensitivity) {
                    list.add (index, localLocation);
                    break;
                }
            }
            exPoint = elem;
            index++;
        }
    }
    if (routingPolicy != null)
        widget.setRoutingPolicy (routingPolicy);
    widget.setControlPoints (list, false);
}
 
Example #13
Source File: CompositionGuideTest.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
@Test
@DisplayName("golden sections")
void draw_Type_GOLDEN_SECTIONS() {
    var rect = new Rectangle2D.Double(0, 0, 90, 12);
    compositionGuide.setType(GOLDEN_SECTIONS);
    compositionGuide.draw(rect, g2);

    double phi = 1.618;
    double sectionWidth = rect.getWidth() / phi;
    double sectionHeight = rect.getHeight() / phi;

    Line2D[] lines = new Line2D[4];
    lines[0] = new Line2D.Double(sectionWidth, 0, sectionWidth, 12);
    lines[1] = new Line2D.Double(90 - sectionWidth, 0, 90 - sectionWidth, 12);
    lines[2] = new Line2D.Double(0, sectionHeight, 90, sectionHeight);
    lines[3] = new Line2D.Double(0, 12 - sectionHeight, 90, 12 - sectionHeight);

    verify(guidesRenderer).draw(refEq(g2), argThat(new DrawMatcherLine2D(Arrays.asList(lines))));
}
 
Example #14
Source File: Chart_14_CategoryPlot_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke (<code>null</code> not permitted).
 * @param paint  the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
        double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, 
            getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, 
                dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, 
                dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example #15
Source File: AbstractAngleUI.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
void drawArrow(Graphics2D g2, double angle, float startX, float startY, float endX, float endY) {
    if (enabled) {
        g2.setColor(ENABLED_ARROW_COLOR);
    } else {
        g2.setColor(DISABLED_ARROW_COLOR);
    }
    g2.setStroke(ARROW_STROKE);

    g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);

    g2.draw(new Line2D.Float(startX, startY, endX, endY));

    double backAngle1 = 2.8797926 + angle;
    double backAngle2 = 3.4033926 + angle;
    int arrowRadius = 10;

    float arrowEnd1X = (float) (endX + arrowRadius * Math.cos(backAngle1));
    float arrowEnd1Y = (float) (endY + arrowRadius * Math.sin(backAngle1));
    float arrowEnd2X = (float) (endX + arrowRadius * Math.cos(backAngle2));
    float arrowEnd2Y = (float) (endY + arrowRadius * Math.sin(backAngle2));

    g2.draw(new Line2D.Float(endX, endY, arrowEnd1X, arrowEnd1Y));
    g2.draw(new Line2D.Float(endX, endY, arrowEnd2X, arrowEnd2Y));
}
 
Example #16
Source File: IJImager.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void show(RealSignal signal, String title, Imager.Type type, int z, ArrayList<Line2D.Double> overlayLines) {
	ImagePlus imp = build(signal, type);
	if (imp != null) {
		imp.setTitle(title);
		int nz = imp.getStackSize();
		imp.show();
		imp.setSlice(Math.max(1, Math.min(nz, z)));
		imp.getProcessor().resetMinAndMax();
	}
	
	if (imp != null) {
		Overlay overlay = imp.getOverlay() == null ? new Overlay() : imp.getOverlay();
		for(Line2D.Double line : overlayLines) {
			ij.gui.Line roi = new ij.gui.Line(round(line.x1), round(line.y1), round(line.x2), round(line.y2));
			overlay.add(roi);
		}
		imp.setOverlay(overlay);
	}
}
 
Example #17
Source File: Elixir_000_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #18
Source File: SegmentSorter.java    From maze-harvester with GNU General Public License v3.0 6 votes vote down vote up
public void paint(Graphics2D g2d) {
  g2d.setStroke(new BasicStroke(0.16f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

  // Greedily gather segments into polyline paths.
  List<Line2D> polyLine = new ArrayList<>();
  Point2D lastPoint = null;
  for (Color color : collector.getColors()) {
    g2d.setPaint(color);
    List<Line2D> sortedSegments = quadraticSort(collector.getSegments(color));
    for (Line2D seg : sortedSegments) {
      if (lastPoint == null || lastPoint.distance(seg.getP1()) > COLLAPSE_THRESH) {
        polyLine = emitCurrentPolyLine(g2d, polyLine);
      }
      polyLine.add(seg);
      lastPoint = seg.getP2();
    }
    polyLine = emitCurrentPolyLine(g2d, polyLine);
  }
}
 
Example #19
Source File: Arrow.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the arrow.
 *
 * @param panel  the drawing panel in which the arrow is viewed
 * @param g  the graphics context upon which to draw
 */
public void draw(DrawingPanel panel, Graphics g) {
  Graphics2D g2 = (Graphics2D) g;
  AffineTransform toPixels = panel.getPixelTransform();
  g2.setPaint(color);
  // draw the shaft
  g2.draw(toPixels.createTransformedShape(new Line2D.Double(x, y, x+a, y+b)));
  Point2D pt = new Point2D.Double(x+a, y+b);
  pt = toPixels.transform(pt, pt);
  double aspect = panel.isSquareAspect() ? 1 : -toPixels.getScaleX()/toPixels.getScaleY();
  Shape head = getHead(Math.atan2(b, aspect*a));
  Shape temp = AffineTransform.getTranslateInstance(pt.getX(), pt.getY()).createTransformedShape(head);
  // draw the head
  g2.fill(temp);
  g2.setPaint(Color.BLACK);
}
 
Example #20
Source File: PathGraphics.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a sequence of connected lines defined by
 * arrays of <i>x</i> and <i>y</i> coordinates.
 * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 * The figure is not closed if the first point
 * differs from the last point.
 * @param       xPoints an array of <i>x</i> points
 * @param       yPoints an array of <i>y</i> points
 * @param       nPoints the total number of points
 * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
 * @since       JDK1.1
 */
public void drawPolyline(int xPoints[], int yPoints[],
                         int nPoints) {
    float fromX;
    float fromY;
    float toX;
    float toY;

    if (nPoints > 0) {
        fromX = xPoints[0];
        fromY = yPoints[0];
        for(int i = 1; i < nPoints; i++) {
            toX = xPoints[i];
            toY = yPoints[i];
            draw(new Line2D.Float(fromX, fromY, toX, toY));
            fromX = toX;
            fromY = toY;
        }
    }

}
 
Example #21
Source File: CompositionGuide.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
private void drawGrid(Rectangle2D rect) {
    int gridSize = 50;
    int gridCountH = 1 + 2 * (int) (rect.getHeight() / 2 / gridSize);
    int gridCountV = 1 + 2 * (int) (rect.getWidth() / 2 / gridSize);
    double gridOffsetH = (rect.getHeight() - (gridCountH + 1) * gridSize) / 2;
    double gridOffsetV = (rect.getWidth() - (gridCountV + 1) * gridSize) / 2;
    Line2D[] lines = new Line2D.Double[gridCountH + gridCountV];

    // horizontal lines (change only y position)
    double x1 = rect.getX();
    double x2 = rect.getX() + rect.getWidth();
    for (int i = 0; i < gridCountH; i++) {
        double yh = rect.getY() + (i + 1) * gridSize + gridOffsetH;
        lines[i] = new Line2D.Double(x1, yh, x2, yh);
    }

    // vertical lines (change only x position)
    double y1 = rect.getY();
    double y2 = rect.getY() + rect.getHeight();
    for (int i = 0; i < gridCountV; i++) {
        double xv = rect.getX() + (i + 1) * gridSize + gridOffsetV;
        lines[gridCountH + i] = new Line2D.Double(xv, y1, xv, y2);
    }

    drawShapes(lines);
}
 
Example #22
Source File: DotPattern.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Lookup for a TextLine that embraces the provided glyph.
 *
 * @param the (dot) glyph to check
 * @return glyph the embracing line if any, otherwise null
 */
private TextLine getEmbracingLine (Glyph glyph)
{
    Rectangle glyphBox = glyph.getBounds();

    for (TextLine sentence : system.getSentences()) {
        Line2D baseline = sentence.getBaseline();

        // Check in abscissa: not before sentence beginning
        if ((glyphBox.x + glyphBox.width) <= baseline.getX1()) {
            continue;
        }

        // Check in abscissa: not too far after sentence end
        if ((glyphBox.x - baseline.getX2()) > maxLineDx) {
            continue;
        }

        // Check in abscissa: not overlapping any sentence word
        for (TextWord word : sentence.getWords()) {
            if (word.getBounds()
                    .intersects(glyphBox)) {
                continue;
            }
        }

        // Check in ordinate: distance from baseline
        double dy = baseline.ptLineDist(glyph.getAreaCenter());

        if (dy > maxLineDy) {
            continue;
        }

        // This line is OK, take it
        return sentence;
    }

    // Nothing found
    return null;
}
 
Example #23
Source File: CurvedFilament.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public double getMeanCurvature ()
{
    Point2D prevPoint = null;
    Line2D prevBisector = null;
    Line2D bisector = null;
    Population curvatures = new Population();

    if (spline == null) {
        computeLine();
    }

    for (Point2D point : points) {
        if (prevPoint != null) {
            bisector = LineUtil.bisector(new Line2D.Double(prevPoint, point));
        }

        if (prevBisector != null) {
            Point2D inter = LineUtil.intersection(
                    prevBisector.getP1(),
                    prevBisector.getP2(),
                    bisector.getP1(),
                    bisector.getP2());
            double radius = Math.hypot(
                    inter.getX() - point.getX(),
                    inter.getY() - point.getY());

            curvatures.includeValue(1 / radius);
        }

        prevBisector = bisector;
        prevPoint = point;
    }

    if (curvatures.getCardinality() > 0) {
        return 1 / curvatures.getMeanValue();
    } else {
        return Double.POSITIVE_INFINITY;
    }
}
 
Example #24
Source File: AbstractCategoryItemRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    // TODO: In JFreeChart 1.2.0, put this method in the
    // CategoryItemRenderer interface
    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example #25
Source File: FXGraphics2D.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a line from {@code (x1, y1)} to {@code (x2, y2)} using 
 * the current {@code paint} and {@code stroke}.
 * 
 * @param x1  the x-coordinate of the start point.
 * @param y1  the y-coordinate of the start point.
 * @param x2  the x-coordinate of the end point.
 * @param y2  the x-coordinate of the end point.
 */
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
    if (this.line == null) {
        this.line = new Line2D.Double(x1, y1, x2, y2);
    } else {
        this.line.setLine(x1, y1, x2, y2);
    }
    draw(this.line);
}
 
Example #26
Source File: JGenProg2017_0078_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis
 * is the domain axis. If this is not the case, you will need to override
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 *
 * @since 1.2.0
 */
public void drawDomainLine(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    }
    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value,
                dataArea.getMaxX(), value);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value,
                dataArea.getMaxY());
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #27
Source File: PolylineShape.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Checks if one of the lines in the polyline intersects
 * with a given rectangle.
 * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
 */
public boolean intersects(Rectangle2D r) {
	if(np==0)return false;
	Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
	for (int i = 1; i < np; i++) {
		line.setLine(x[i-1], y[i-1], x[i], y[i]);
		if(line.intersects(r))return true;
	}
	return false;
}
 
Example #28
Source File: MinMaxCategoryRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.groupStroke = SerialUtilities.readStroke(stream);
    this.groupPaint = SerialUtilities.readPaint(stream);

    this.minIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.maxIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0), false, true);
}
 
Example #29
Source File: MultiAxisLineGraph2DRenderer.java    From diirt with MIT License 5 votes vote down vote up
@Override
protected void drawHorizontalReferenceLines() {
    g.setColor(referenceLineColor);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    ListNumber yTicks = yReferenceCoords.get(0);
    for (int b = 0; b < yTicks.size(); b++) {
        Shape line = new Line2D.Double(xAreaCoordStart, yTicks.getDouble(b), xAreaCoordEnd - 1, yTicks.getDouble(b));
        g.draw(line);
    }
}
 
Example #30
Source File: Underline.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
Shape getUnderlineShape(float thickness,
                        float x1,
                        float x2,
                        float y) {

    Stroke ulStroke = getStroke(thickness);
    Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
    return ulStroke.createStrokedShape(line);
}