Java 8 Line2D - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Line2D class.

This code example shows how to use the following methods:getX1, getX2, getY1, getY2
            draw(g2D, r);
        } x += inc;
    } 
     
    public void draw(Graphics2D g, Line2D r) {
        int x1 = (int)r.getX1();
        int y1 = (int)r.getY1();
        int x2 = (int)r.getX2();
        int y2 = (int)r.getY2();
        g.drawLine(x1, y1, x2, y2);
    } 
     
    public void draw(Graphics2D g, Rectangle2D r) {
        int x = (int)r.getMinX();
        int y = (int)r.getMinY();
        int w = (int)(r.getWidth() +r.getMinX()-x);
        int h = (int)(r.getHeight()+r.getMinY()-y);
        g.drawRect(x, y, w, h);
    } 
     
7
CodeRank
This code example shows how to use the following methods:getP1, getP2, getX1, getX2, getY1

7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
    public void setParameterFromObject(final Object o) throws ObjectFactoryException { 
        if (!(o instanceof Line2D)) {
            throw new ObjectFactoryException("The given object is no java.awt.geom.Line2D."); 
        } 
        final Line2D line = (Line2D) o;
        final float x1 = (float) line.getX1();
        final float x2 = (float) line.getX2();
        final float y1 = (float) line.getY1();
        final float y2 = (float) line.getY2();
 
        setParameter("x1", new Float(x1));
        setParameter("x2", new Float(x2));
        setParameter("y1", new Float(y1));
        setParameter("y2", new Float(y2));
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
     *  
     * @since 1.0.18 
     */ 
    public static Line2D extendLine(Line2D line, double startPercent,
            double endPercent) {
        ParamChecks.nullNotPermitted(line, "line");
        double x1 = line.getX1();
        double x2 = line.getX2();
        double deltaX = x2 - x1;
        double y1 = line.getY1();
        double y2 = line.getY2();
        double deltaY = y2 - y1;
        x1 = x1 - (startPercent * deltaX);
        y1 = y1 - (startPercent * deltaY);
        x2 = x2 + (endPercent * deltaX);
        y2 = y2 + (endPercent * deltaY);
        return new Line2D.Double(x1, y1, x2, y2);
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getP1, getP2, getX1, getX2, getY1
//    	result[3] = createRectangle(cx,minY,maxX,cy); 
//    	return result;	 
//    } 
 
	public static Point2D[] intersectionRectangleLine(Rectangle2D rec, Line2D line) {
		double x1 = line.getX1();
		double x2 = line.getX2();
		double y1 = line.getY1();
		double y2 = line.getY2();
		double xmin = rec.getMinX();
		double xmax = rec.getMaxX();
		double ymin = rec.getMinY();
		double ymax = rec.getMaxY();
		Point2D p0 = null;
		Point2D p1 = null;
		if ((x1==x2) && (xmin<=x1 && xmax>=x1) && ((y1<=ymin && y2>=ymax) || (y2<=ymin && y1>=ymax))) {
			return new Point2D[] {new Point2D.Double(x1,ymin),new Point2D.Double(x1,ymax)};
		}  
		if ((y1==y2) && (ymin<=y1 && ymax>=y1) && ((x1<=xmin && x2>=xmax) || (x2<=xmin && x1>=xmax))) {
			return new Point2D[] {new Point2D.Double(xmin,y1),new Point2D.Double(xmax,y1)};

7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
    style = new FlatStyle();
    insideMargin = new Box(0, 0, 100, 200);
  } 
 
  private void verifyLine(Line2D line, int x1, int y1, int x2, int y2) {
    assertEquals(x1, line.getX1(), 0.1);
    assertEquals(y1, line.getY1(), 0.1);
    assertEquals(x2, line.getX2(), 0.1);
    assertEquals(y2, line.getY2(), 0.1);
  } 
 
  public void testBorderConstruction() throws Exceptionborder = new Border(style, insideMargin);
    assertSame(style, border.getStyle());
  } 
 
  public void testNotHaveBordersWhenBorderWidthIsZero() throws Exceptionstyle.setBorderWidth("0");
7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
    private Line2D extendLine(Line2D line, double startPercent,
                              double endPercent) {
        if (line == null) {
            throw new IllegalArgumentException("Null 'line' argument.");
        } 
        double x1 = line.getX1();
        double x2 = line.getX2();
        double deltaX = x2 - x1;
        double y1 = line.getY1();
        double y2 = line.getY2();
        double deltaY = y2 - y1;
        x1 = x1 - (startPercent * deltaX);
        y1 = y1 - (startPercent * deltaY);
        x2 = x2 + (endPercent * deltaX);
        y2 = y2 + (endPercent * deltaY);
        return new Line2D.Double(x1, y1, x2, y2);
    } 
 
    /** 
     * Provides serialization support. 
7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
 
    private boolean lineEquals(Line2D line, double x1, double y1, double x2,
            double y2) {
        boolean result = true;
        double epsilon = 0.0000000001;
        if (Math.abs(line.getX1() - x1) > epsilon) { result = false; }
        if (Math.abs(line.getY1() - y1) > epsilon) { result = false; }
        if (Math.abs(line.getX2() - x2) > epsilon) { result = false; }
        if (Math.abs(line.getY2() - y2) > epsilon) { result = false; }
 
        return result;
    } 
 
    @Test
 
    public void testClipLine() { 
        Rectangle2D rect = new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0);
        Line2D line = new Line2D.Double();
 
        assertFalse(LineUtils.clipLine(line, rect));
7
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2, setLine
Shape s = getShape();
        if ( s instanceof Line2D ) {
            Line2D l = (Line2D)s;
            repaint(); 
            l.setLine( l.getX1() + x, l.getY1() + y,
                       l.getX2() + x, l.getY2() + y );
            repaint(); 
            fireChanged(); 
        } 
        else { 
            super.translate( x, y );
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getX1, getX2, getY1, getY2
     * 
     * @return A region that surrounds the line. 
     */ 
    public static Shape createLineRegion(final Line2D line, final float width) {
        final GeneralPath result = new GeneralPath();
        final float x1 = (float) line.getX1();
        final float x2 = (float) line.getX2();
        final float y1 = (float) line.getY1();
        final float y2 = (float) line.getY2();
        if ((x2 - x1) != 0.0) {
            final double theta = Math.atan((y2 - y1) / (x2 - x1));
            final float dx = (float) Math.sin(theta) * width;
            final float dy = (float) Math.cos(theta) * width;
            result.moveTo(x1 - dx, y1 + dy);
            result.lineTo(x1 + dx, y1 - dy);
            result.lineTo(x2 + dx, y2 - dy);
            result.lineTo(x2 - dx, y2 + dy);
            result.closePath();
        } 
        else { 
7
CodeRank
See Code Examples for Java 8 Line2D Methods: