Package java.awt.geom

Examples of java.awt.geom.Line2D


  /**
   * Confirm that two lines with the same end points are NOT considered equal.
   */
  public void test(TestHarness harness)
  {
    Line2D line1 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
    Line2D line2 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
    harness.check(!line1.equals(line2));
  }
View Full Code Here


public class ptLineDistSq
  implements Testlet
{
  public void test(TestHarness harness)
  {
    Line2D line1 = new Line2D.Double(0.0, 0.0, 1.0, 0.0);
    harness.check(0.0, line1.ptLineDistSq(-50.0, 0.0));
    harness.check(0.0, line1.ptLineDistSq(0.0, 0.0));
    harness.check(0.0, line1.ptLineDistSq(1.0, 0.0));
    harness.check(0.0, line1.ptLineDistSq(50.0, 0.0));
    harness.check(1.0, line1.ptLineDistSq(-50.0, 1.0));
    harness.check(1.0, line1.ptLineDistSq(0.0, 1.0));
    harness.check(1.0, line1.ptLineDistSq(1.0, 1.0));
    harness.check(1.0, line1.ptLineDistSq(50.0, 1.0));
    harness.check(1.0, line1.ptLineDistSq(-50.0, -1.0));
    harness.check(1.0, line1.ptLineDistSq(0.0, -1.0));
    harness.check(1.0, line1.ptLineDistSq(1.0, -1.0));
    harness.check(1.0, line1.ptLineDistSq(50.0, -1.0));

    harness.check(0.0, line1.ptLineDistSq(new Point2D.Double(-50.0, 0.0)));
    harness.check(0.0, line1.ptLineDistSq(new Point2D.Double(0.0, 0.0)));
    harness.check(0.0, line1.ptLineDistSq(new Point2D.Double(1.0, 0.0)));
    harness.check(0.0, line1.ptLineDistSq(new Point2D.Double(50.0, 0.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(-50.0, 1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(0.0, 1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(1.0, 1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(50.0, 1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(-50.0, -1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(0.0, -1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(1.0, -1.0)));
    harness.check(1.0, line1.ptLineDistSq(new Point2D.Double(50.0, -1.0)));
 
    boolean pass = false;
    try {
      line1.ptLineDistSq(null);
    }
    catch (NullPointerException e) {
      pass = true;
    }
    harness.check(pass)
View Full Code Here

public class getP1
  implements Testlet
{
  public void test(TestHarness harness)
  {
    Line2D line1 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
    Point2D pt1 = line1.getP1();
    harness.check(pt1.getX() == 1.0);
    harness.check(pt1.getY() == 2.0);
  }
View Full Code Here

public class setLine
  implements Testlet
{
  public void test(TestHarness harness)
  {
    Line2D line1 = new Line2D.Double();
    line1.setLine(1.0, 2.0, 3.0, 4.0);
    harness.check(line1.getX1() == 1.0);
    harness.check(line1.getY1() == 2.0);
    harness.check(line1.getX2() == 3.0);
    harness.check(line1.getY2() == 4.0);
   
    line1.setLine(new Point2D.Double(1.1, 2.2), new Point2D.Double(3.3, 4.4));
    harness.check(line1.getX1() == 1.1);
    harness.check(line1.getY1() == 2.2);
    harness.check(line1.getX2() == 3.3);
    harness.check(line1.getY2() == 4.4);
   
    line1.setLine(new Line2D.Double(1.11, 2.22, 3.33, 4.44));
    harness.check(line1.getX1() == 1.11);
    harness.check(line1.getY1() == 2.22);
    harness.check(line1.getX2() == 3.33);
    harness.check(line1.getY2() == 4.44);   
       
    Line2D line2 = new Line2D.Float();
    line2.setLine(1.1, 2.2, 3.3, 4.4);
    harness.check(line2.getX1() == 1.1f);
    harness.check(line2.getY1() == 2.2f);
    harness.check(line2.getX2() == 3.3f);
    harness.check(line2.getY2() == 4.4f);
   
    line2.setLine(new Point2D.Float(1.1f, 2.2f), new Point2D.Float(3.3f, 4.4f));
    harness.check(line2.getX1() == 1.1f);
    harness.check(line2.getY1() == 2.2f);
    harness.check(line2.getX2() == 3.3f);
    harness.check(line2.getY2() == 4.4f);
   
    line2.setLine(new Line2D.Float(1.11f, 2.22f, 3.33f, 4.44f));
    harness.check(line2.getX1() == 1.11f);
    harness.check(line2.getY1() == 2.22f);
    harness.check(line2.getX2() == 3.33f);
    harness.check(line2.getY2() == 4.44f);
   
    // check that null arguments throw the correct exception
    boolean pass = false;
    try {
        line1.setLine(null, new Point2D.Double());
View Full Code Here

    harness.check(Line2D.relativeCCW(1.0, 1.0, 3.0, 2.0, -1.0, -1.0) == 1);
   
    harness.check(Line2D.relativeCCW(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) == 0);
    harness.check(Line2D.relativeCCW(1.0, 1.0, 1.0, 1.0, 2.0, 2.0) == 0);
     
    Line2D line1 = new Line2D.Double(1.0, 1.0, 3.0, 2.0);
    harness.check(line1.relativeCCW(1.0, 1.0) == 0);
    harness.check(line1.relativeCCW(3.0, 2.0) == 0);
    harness.check(line1.relativeCCW(0.0, 0.0) == 1);
    harness.check(line1.relativeCCW(-1.0, 0.0) == -1);
    harness.check(line1.relativeCCW(5.0, 3.0) == 1);
    harness.check(line1.relativeCCW(5.0, 4.0) == -1);
    harness.check(line1.relativeCCW(-1.0, -1.0) == 1);

    harness.check(line1.relativeCCW(new Point2D.Double(1.0, 1.0)) == 0);
    harness.check(line1.relativeCCW(new Point2D.Double(3.0, 2.0)) == 0);
    harness.check(line1.relativeCCW(new Point2D.Double(0.0, 0.0)) == 1);
    harness.check(line1.relativeCCW(new Point2D.Double(-1.0, 0.0)) == -1);
    harness.check(line1.relativeCCW(new Point2D.Double(5.0, 3.0)) == 1);
    harness.check(line1.relativeCCW(new Point2D.Double(5.0, 4.0)) == -1);
    harness.check(line1.relativeCCW(new Point2D.Double(-1.0, -1.0)) == 1);
   
    boolean pass = false;
    try {
        line1.relativeCCW(null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    harness.check(pass);
View Full Code Here

public class ptSegDistSq
  implements Testlet
{
  public void test(TestHarness harness)
  {
    Line2D line1 = new Line2D.Double(0.0, 0.0, 1.0, 0.0);
    harness.check(2500.0, line1.ptSegDistSq(-50.0, 0.0));
    harness.check(0.0, line1.ptSegDistSq(0.0, 0.0));
    harness.check(0.0, line1.ptSegDistSq(1.0, 0.0));
    harness.check(49.0*49.0, line1.ptSegDistSq(50.0, 0.0));
    harness.check(2501.0, line1.ptSegDistSq(-50.0, 1.0));
    harness.check(1.0, line1.ptSegDistSq(0.0, 1.0));
    harness.check(1.0, line1.ptSegDistSq(1.0, 1.0));
    harness.check(49.0*49.0+1.0, line1.ptSegDistSq(50.0, 1.0));
    harness.check(2501.0, line1.ptSegDistSq(-50.0, -1.0));
    harness.check(1.0, line1.ptSegDistSq(0.0, -1.0));
    harness.check(1.0, line1.ptSegDistSq(1.0, -1.0));
    harness.check(49.0*49.0+1.0, line1.ptSegDistSq(50.0, -1.0));

    harness.check(2500.0, line1.ptSegDistSq(new Point2D.Double(-50.0, 0.0)));
    harness.check(0.0, line1.ptSegDistSq(new Point2D.Double(0.0, 0.0)));
    harness.check(0.0, line1.ptSegDistSq(new Point2D.Double(1.0, 0.0)));
    harness.check(49.0*49.0, line1.ptSegDistSq(new Point2D.Double(50.0, 0.0)));
    harness.check(2501.0, line1.ptSegDistSq(new Point2D.Double(-50.0, 1.0)));
    harness.check(1.0, line1.ptSegDistSq(new Point2D.Double(0.0, 1.0)));
    harness.check(1.0, line1.ptSegDistSq(new Point2D.Double(1.0, 1.0)));
    harness.check(49.0*49.0+1.0, line1.ptSegDistSq(new Point2D.Double(50.0, 1.0)));
    harness.check(2501.0, line1.ptSegDistSq(new Point2D.Double(-50.0, -1.0)));
    harness.check(1.0, line1.ptSegDistSq(new Point2D.Double(0.0, -1.0)));
    harness.check(1.0, line1.ptSegDistSq(new Point2D.Double(1.0, -1.0)));
    harness.check(49.0*49.0+1.0, line1.ptSegDistSq(new Point2D.Double(50.0, -1.0)));

    boolean pass = false;
    try {
      line1.ptSegDistSq(null);
    }
    catch (NullPointerException e) {
      pass = true;
    }
    harness.check(pass)
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    AffineTransform t1 = new AffineTransform();
    Line2D line1 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
    Shape shape1 = t1.createTransformedShape(line1);
    GeneralPath p1 = (GeneralPath) shape1;
    PathIterator iterator = p1.getPathIterator(null);
    double[] c = new double[6];
   
View Full Code Here

      graphics.draw(imageableArea);

      final int pcH = pageDefinition.getPageCountHorizontal();
      final int pcW = pageDefinition.getPageCountVertical();

      final Line2D line = new Line2D.Double();
      for (int splitH = 1; splitH < pcH; splitH += 1)
      {
        final double xPos = gpf.getImageableX() + (splitH * gpf.getImageableWidth());
        line.setLine(xPos, gpf.getImageableY(),
            xPos, gpf.getImageableY() + gpf.getImageableHeight());
        graphics.draw(line);
      }

      for (int splitW = 1; splitW < pcW; splitW += 1)
      {
        final double yPos = gpf.getImageableY() + (splitW * gpf.getImageableHeight());
        line.setLine(gpf.getImageableX(), yPos,
            gpf.getImageableX() + gpf.getImageableWidth(), yPos);
        graphics.draw(line);
      }
    }
View Full Code Here

   * 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;
  }
View Full Code Here

                            offset = y + lineHeight / 2 + 1;
                            break;
                        }
                    }

                    Line2D line = new Line2D.Float(x, offset, x + lineWidth, offset);
                    graphics.draw(line);
                }

                y += textBounds.getHeight();
            }
View Full Code Here

TOP

Related Classes of java.awt.geom.Line2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.