001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package armyc2.c5isr.graphics2d; 006/* 007 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 008 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 009 * 010 * This code is free software; you can redistribute it and/or modify it 011 * under the terms of the GNU General Public License version 2 only, as 012 * published by the Free Software Foundation. Sun designates this 013 * particular file as subject to the "Classpath" exception as provided 014 * by Sun in the LICENSE file that accompanied this code. 015 * 016 * This code is distributed in the hope that it will be useful, but WITHOUT 017 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 018 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 019 * version 2 for more details (a copy is included in the LICENSE file that 020 * accompanied this code). 021 * 022 * You should have received a copy of the GNU General Public License version 023 * 2 along with this work; if not, write to the Free Software Foundation, 024 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 025 * 026 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 027 * CA 95054 USA or visit www.sun.com if you need additional information or 028 * have any questions. 029 */ 030 031import java.io.Serializable; 032 033/** 034 * This <code>Line2D</code> represents a line segment in {@code (x,y)} 035 * coordinate space. This class, like all of the Java 2D API, uses a default 036 * coordinate system called <i>user space</i> in which the y-axis values 037 * increase downward and x-axis values increase to the right. For more 038 * information on the user space coordinate system, see the <a href= 039 * "http://java.sun.com/j2se/1.3/docs/guide/2d/spec/j2d-intro.fm2.html#61857"> 040 * Coordinate Systems</a> section of the Java 2D Programmer's Guide. 041 * <p> 042 * This class is only the abstract superclass for all objects that store a 2D 043 * line segment. The actual storage representation of the coordinates is left to 044 * the subclass. 045 * 046 * @author Jim Graham 047 * @since 1.2 048 */ 049public abstract class Line2D { 050 public Rectangle2D getBounds2D() 051 { 052 double x1=getX1(); 053 double y1=getY1(); 054 double x2=getX1(); 055 double y2=getY1(); 056 double x=x1; 057 double y=y1; 058 if(x2<x1) 059 x=x2; 060 if(y2<y1) 061 y=y2; 062 double width=Math.abs(x1-x2); 063 double height=Math.abs(y1-y2); 064 Rectangle2D rect=new Rectangle2D.Double(x,y,width,height); 065 return rect; 066 } 067 068 public boolean intersectsLine(Line2D edge) { 069 return linesIntersect(edge.getX1(), edge.getY1(), edge.getX2(), edge.getY2(), 070 getX1(), getY1(), getX2(), getY2()); 071 } 072 073 public static boolean linesIntersect(double x1, double y1, 074 double x2, double y2, 075 double x3, double y3, 076 double x4, double y4) 077 { 078 return ((relativeCCW(x1, y1, x2, y2, x3, y3) * 079 relativeCCW(x1, y1, x2, y2, x4, y4) <= 0) 080 && (relativeCCW(x3, y3, x4, y4, x1, y1) * 081 relativeCCW(x3, y3, x4, y4, x2, y2) <= 0)); 082 } 083 084 085 /** 086 * A line segment specified with float coordinates. 087 * 088 * @since 1.2 089 */ 090 public static class Float extends Line2D implements Serializable { 091 092 /** 093 * The X coordinate of the start point of the line segment. 094 * 095 * @since 1.2 096 * @serial 097 */ 098 public float x1; 099 /** 100 * The Y coordinate of the start point of the line segment. 101 * 102 * @since 1.2 103 * @serial 104 */ 105 public float y1; 106 /** 107 * The X coordinate of the end point of the line segment. 108 * 109 * @since 1.2 110 * @serial 111 */ 112 public float x2; 113 /** 114 * The Y coordinate of the end point of the line segment. 115 * 116 * @since 1.2 117 * @serial 118 */ 119 public float y2; 120 121 /** 122 * Constructs and initializes a Line with coordinates (0, 0) -> (0, 0). 123 * 124 * @since 1.2 125 */ 126 public Float() { 127 } 128 129 /** 130 * Constructs and initializes a Line from the specified coordinates. 131 * 132 * @param x1 133 * the X coordinate of the start point 134 * @param y1 135 * the Y coordinate of the start point 136 * @param x2 137 * the X coordinate of the end point 138 * @param y2 139 * the Y coordinate of the end point 140 * @since 1.2 141 */ 142 public Float(float x1, float y1, float x2, float y2) { 143 setLine(x1, y1, x2, y2); 144 } 145 146 /** 147 * Constructs and initializes a <code>Line2D</code> from the specified 148 * <code>Point2D</code> objects. 149 * 150 * @param p1 151 * the start <code>Point2D</code> of this line segment 152 * @param p2 153 * the end <code>Point2D</code> of this line segment 154 * @since 1.2 155 */ 156 public Float(Point2D p1, Point2D p2) { 157 setLine(p1, p2); 158 } 159 160 /** 161 * {@inheritDoc} 162 * 163 * @since 1.2 164 */ 165 public double getX1() { 166 return (double) x1; 167 } 168 169 /** 170 * {@inheritDoc} 171 * 172 * @since 1.2 173 */ 174 public double getY1() { 175 return (double) y1; 176 } 177 178 /** 179 * {@inheritDoc} 180 * 181 * @since 1.2 182 */ 183 public Point2D getP1() { 184 return new Point2D.Float(x1, y1); 185 } 186 187 /** 188 * {@inheritDoc} 189 * 190 * @since 1.2 191 */ 192 public double getX2() { 193 return (double) x2; 194 } 195 196 /** 197 * {@inheritDoc} 198 * 199 * @since 1.2 200 */ 201 public double getY2() { 202 return (double) y2; 203 } 204 205 /** 206 * {@inheritDoc} 207 * 208 * @since 1.2 209 */ 210 public Point2D getP2() { 211 return new Point2D.Float(x2, y2); 212 } 213 214 /** 215 * {@inheritDoc} 216 * 217 * @since 1.2 218 */ 219 public void setLine(double x1, double y1, double x2, double y2) { 220 this.x1 = (float) x1; 221 this.y1 = (float) y1; 222 this.x2 = (float) x2; 223 this.y2 = (float) y2; 224 } 225 226 /** 227 * Sets the location of the end points of this <code>Line2D</code> to 228 * the specified float coordinates. 229 * 230 * @param x1 231 * the X coordinate of the start point 232 * @param y1 233 * the Y coordinate of the start point 234 * @param x2 235 * the X coordinate of the end point 236 * @param y2 237 * the Y coordinate of the end point 238 * @since 1.2 239 */ 240 public void setLine(float x1, float y1, float x2, float y2) { 241 this.x1 = x1; 242 this.y1 = y1; 243 this.x2 = x2; 244 this.y2 = y2; 245 } 246 247 /** 248 * {@inheritDoc} 249 * 250 * @since 1.2 251 */ 252 public Rectangle2D getBounds2D() { 253 float x, y, w, h; 254 if (x1 < x2) { 255 x = x1; 256 w = x2 - x1; 257 } else { 258 x = x2; 259 w = x1 - x2; 260 } 261 if (y1 < y2) { 262 y = y1; 263 h = y2 - y1; 264 } else { 265 y = y2; 266 h = y1 - y2; 267 } 268 return new Rectangle2D.Double(x, y, w, h); 269 } 270 /* 271 * JDK 1.6 serialVersionUID 272 */ 273 private static final long serialVersionUID = 6161772511649436349L; 274 } 275 276 /** 277 * A line segment specified with double coordinates. 278 * 279 * @since 1.2 280 */ 281 public static class Double extends Line2D implements Serializable { 282 283 /** 284 * The X coordinate of the start point of the line segment. 285 * 286 * @since 1.2 287 * @serial 288 */ 289 public double x1; 290 /** 291 * The Y coordinate of the start point of the line segment. 292 * 293 * @since 1.2 294 * @serial 295 */ 296 public double y1; 297 /** 298 * The X coordinate of the end point of the line segment. 299 * 300 * @since 1.2 301 * @serial 302 */ 303 public double x2; 304 /** 305 * The Y coordinate of the end point of the line segment. 306 * 307 * @since 1.2 308 * @serial 309 */ 310 public double y2; 311 312 /** 313 * Constructs and initializes a Line with coordinates (0, 0) -> (0, 0). 314 * 315 * @since 1.2 316 */ 317 public Double() { 318 } 319 320 /** 321 * Constructs and initializes a <code>Line2D</code> from the specified 322 * coordinates. 323 * 324 * @param x1 325 * the X coordinate of the start point 326 * @param y1 327 * the Y coordinate of the start point 328 * @param x2 329 * the X coordinate of the end point 330 * @param y2 331 * the Y coordinate of the end point 332 * @since 1.2 333 */ 334 public Double(double x1, double y1, double x2, double y2) { 335 setLine(x1, y1, x2, y2); 336 } 337 338 /** 339 * Constructs and initializes a <code>Line2D</code> from the specified 340 * <code>Point2D</code> objects. 341 * 342 * @param p1 343 * the start <code>Point2D</code> of this line segment 344 * @param p2 345 * the end <code>Point2D</code> of this line segment 346 * @since 1.2 347 */ 348 public Double(Point2D p1, Point2D p2) { 349 setLine(p1, p2); 350 } 351 352 /** 353 * {@inheritDoc} 354 * 355 * @since 1.2 356 */ 357 public double getX1() { 358 return x1; 359 } 360 361 /** 362 * {@inheritDoc} 363 * 364 * @since 1.2 365 */ 366 public double getY1() { 367 return y1; 368 } 369 370 /** 371 * {@inheritDoc} 372 * 373 * @since 1.2 374 */ 375 public Point2D getP1() { 376 return new Point2D.Double(x1, y1); 377 } 378 379 /** 380 * {@inheritDoc} 381 * 382 * @since 1.2 383 */ 384 public double getX2() { 385 return x2; 386 } 387 388 /** 389 * {@inheritDoc} 390 * 391 * @since 1.2 392 */ 393 public double getY2() { 394 return y2; 395 } 396 397 /** 398 * {@inheritDoc} 399 * 400 * @since 1.2 401 */ 402 public Point2D getP2() { 403 return new Point2D.Double(x2, y2); 404 } 405 406 /** 407 * {@inheritDoc} 408 * 409 * @since 1.2 410 */ 411 public void setLine(double x1, double y1, double x2, double y2) { 412 this.x1 = x1; 413 this.y1 = y1; 414 this.x2 = x2; 415 this.y2 = y2; 416 } 417 418 /** 419 * {@inheritDoc} 420 * 421 * @since 1.2 422 */ 423 public Rectangle2D getBounds2D() { 424 double x, y, w, h; 425 if (x1 < x2) { 426 x = x1; 427 w = x2 - x1; 428 } else { 429 x = x2; 430 w = x1 - x2; 431 } 432 if (y1 < y2) { 433 y = y1; 434 h = y2 - y1; 435 } else { 436 y = y2; 437 h = y1 - y2; 438 } 439 return new Rectangle2D.Double(x, y, w, h); 440 } 441 /* 442 * JDK 1.6 serialVersionUID 443 */ 444 private static final long serialVersionUID = 7979627399746467499L; 445 } 446 447 /** 448 * This is an abstract class that cannot be instantiated directly. 449 * Type-specific implementation subclasses are available for instantiation 450 * and provide a number of formats for storing the information necessary to 451 * satisfy the various accessory methods below. 452 * 453 * @see armyc2.c5isr.graphics2d.Line2D.Float 454 * @see armyc2.c5isr.graphics2d.Line2D.Double 455 * @since 1.2 456 */ 457 protected Line2D() { 458 } 459 460 /** 461 * Returns the X coordinate of the start point in double precision. 462 * 463 * @return the X coordinate of the start point of this {@code Line2D} 464 * object. 465 * @since 1.2 466 */ 467 public abstract double getX1(); 468 469 /** 470 * Returns the Y coordinate of the start point in double precision. 471 * 472 * @return the Y coordinate of the start point of this {@code Line2D} 473 * object. 474 * @since 1.2 475 */ 476 public abstract double getY1(); 477 478 /** 479 * Returns the start <code>Point2D</code> of this <code>Line2D</code>. 480 * 481 * @return the start <code>Point2D</code> of this <code>Line2D</code>. 482 * @since 1.2 483 */ 484 public abstract Point2D getP1(); 485 486 /** 487 * Returns the X coordinate of the end point in double precision. 488 * 489 * @return the X coordinate of the end point of this {@code Line2D} object. 490 * @since 1.2 491 */ 492 public abstract double getX2(); 493 494 /** 495 * Returns the Y coordinate of the end point in double precision. 496 * 497 * @return the Y coordinate of the end point of this {@code Line2D} object. 498 * @since 1.2 499 */ 500 public abstract double getY2(); 501 502 /** 503 * Returns the end <code>Point2D</code> of this <code>Line2D</code>. 504 * 505 * @return the end <code>Point2D</code> of this <code>Line2D</code>. 506 * @since 1.2 507 */ 508 public abstract Point2D getP2(); 509 510 /** 511 * Sets the location of the end points of this <code>Line2D</code> to the 512 * specified double coordinates. 513 * 514 * @param x1 515 * the X coordinate of the start point 516 * @param y1 517 * the Y coordinate of the start point 518 * @param x2 519 * the X coordinate of the end point 520 * @param y2 521 * the Y coordinate of the end point 522 * @since 1.2 523 */ 524 public abstract void setLine(double x1, double y1, double x2, double y2); 525 526 /** 527 * Sets the location of the end points of this <code>Line2D</code> to the 528 * specified <code>Point2D</code> coordinates. 529 * 530 * @param p1 531 * the start <code>Point2D</code> of the line segment 532 * @param p2 533 * the end <code>Point2D</code> of the line segment 534 * @since 1.2 535 */ 536 public void setLine(Point2D p1, Point2D p2) { 537 setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY()); 538 } 539 540 /** 541 * Sets the location of the end points of this <code>Line2D</code> to the 542 * same as those end points of the specified <code>Line2D</code>. 543 * 544 * @param l 545 * the specified <code>Line2D</code> 546 * @since 1.2 547 */ 548 public void setLine(Line2D l) { 549 setLine(l.getX1(), l.getY1(), l.getX2(), l.getY2()); 550 } 551 552 /** 553 * Returns an indicator of where the specified point {@code (px,py)} lies 554 * with respect to the line segment from {@code (x1,y1)} to {@code (x2,y2)}. 555 * The return value can be either 1, -1, or 0 and indicates in which 556 * direction the specified line must pivot around its first end point, 557 * {@code (x1,y1)}, in order to point at the specified point {@code (px,py)} 558 * . 559 * <p> 560 * A return value of 1 indicates that the line segment must turn in the 561 * direction that takes the positive X axis towards the negative Y axis. In 562 * the default coordinate system used by Java 2D, this direction is 563 * counterclockwise. 564 * <p> 565 * A return value of -1 indicates that the line segment must turn in the 566 * direction that takes the positive X axis towards the positive Y axis. In 567 * the default coordinate system, this direction is clockwise. 568 * <p> 569 * A return value of 0 indicates that the point lies exactly on the line 570 * segment. Note that an indicator value of 0 is rare and not useful for 571 * determining colinearity because of floating point rounding issues. 572 * <p> 573 * If the point is colinear with the line segment, but not between the end 574 * points, then the value will be -1 if the point lies "beyond {@code 575 * (x1,y1)}" or 1 if the point lies "beyond {@code (x2,y2)}". 576 * 577 * @param x1 578 * the X coordinate of the start point of the specified line 579 * segment 580 * @param y1 581 * the Y coordinate of the start point of the specified line 582 * segment 583 * @param x2 584 * the X coordinate of the end point of the specified line 585 * segment 586 * @param y2 587 * the Y coordinate of the end point of the specified line 588 * segment 589 * @param px 590 * the X coordinate of the specified point to be compared with 591 * the specified line segment 592 * @param py 593 * the Y coordinate of the specified point to be compared with 594 * the specified line segment 595 * @return an integer that indicates the position of the third specified 596 * coordinates with respect to the line segment formed by the first 597 * two specified coordinates. 598 * @since 1.2 599 */ 600 public static int relativeCCW(double x1, double y1, double x2, double y2, 601 double px, double py) { 602 x2 -= x1; 603 y2 -= y1; 604 px -= x1; 605 py -= y1; 606 double ccw = px * y2 - py * x2; 607 if (ccw == 0.0) { 608// The point is colinear, classify based on which side of 609// the segment the point falls on. We can calculate a 610// relative value using the projection of px,py onto the 611// segment - a negative value indicates the point projects 612// outside of the segment in the direction of the particular 613// endpoint used as the origin for the projection. 614 ccw = px * x2 + py * y2; 615 if (ccw > 0.0) { 616// Reverse the projection to be relative to the original x2,y2 617// x2 and y2 are simply negated. 618// px and py need to have (x2 - x1) or (y2 - y1) subtracted 619// from them (based on the original values) 620// Since we really want to get a positive answer when the 621// point is "beyond (x2,y2)", then we want to calculate 622// the inverse anyway - thus we leave x2 & y2 negated. 623 px -= x2; 624 py -= y2; 625 ccw = px * x2 + py * y2; 626 if (ccw < 0.0) { 627 ccw = 0.0; 628 } 629 } 630 } 631 return (ccw < 0.0) ? -1 : ((ccw > 0.0) ? 1 : 0); 632 } 633 634 /** 635 * Returns an indicator of where the specified point {@code (px,py)} lies 636 * with respect to this line segment. See the method comments of 637 * {@link #relativeCCW(double, double, double, double, double, double)} to 638 * interpret the return value. 639 * 640 * @param px 641 * the X coordinate of the specified point to be compared with 642 * this <code>Line2D</code> 643 * @param py 644 * the Y coordinate of the specified point to be compared with 645 * this <code>Line2D</code> 646 * @return an integer that indicates the position of the specified 647 * coordinates with respect to this <code>Line2D</code> 648 * @see #relativeCCW(double, double, double, double, double, double) 649 * @since 1.2 650 */ 651 public int relativeCCW(double px, double py) { 652 return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py); 653 } 654 655 /** 656 * Returns the square of the distance from a point to a line. The distance 657 * measured is the distance between the specified point and the closest 658 * point on the infinitely-extended line defined by the specified 659 * coordinates. If the specified point intersects the line, this method 660 * returns 0.0. 661 * 662 * @param x1 663 * the X coordinate of the start point of the specified line 664 * @param y1 665 * the Y coordinate of the start point of the specified line 666 * @param x2 667 * the X coordinate of the end point of the specified line 668 * @param y2 669 * the Y coordinate of the end point of the specified line 670 * @param px 671 * the X coordinate of the specified point being measured against 672 * the specified line 673 * @param py 674 * the Y coordinate of the specified point being measured against 675 * the specified line 676 * @return a double value that is the square of the distance from the 677 * specified point to the specified line. 678 * @since 1.2 679 */ 680 public static double ptLineDistSq(double x1, double y1, double x2, 681 double y2, double px, double py) { 682// Adjust vectors relative to x1,y1 683// x2,y2 becomes relative vector from x1,y1 to end of segment 684 x2 -= x1; 685 y2 -= y1; 686// px,py becomes relative vector from x1,y1 to test point 687 px -= x1; 688 py -= y1; 689 double dotprod = px * x2 + py * y2; 690// dotprod is the length of the px,py vector 691// projected on the x1,y1=>x2,y2 vector times the 692// length of the x1,y1=>x2,y2 vector 693 double projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2); 694// Distance to line is now the length of the relative point 695// vector minus the length of its projection onto the line 696 double lenSq = px * px + py * py - projlenSq; 697 if (lenSq < 0) { 698 lenSq = 0; 699 } 700 return lenSq; 701 } 702 703 /** 704 * Returns the distance from a point to a line. The distance measured is the 705 * distance between the specified point and the closest point on the 706 * infinitely-extended line defined by the specified coordinates. If the 707 * specified point intersects the line, this method returns 0.0. 708 * 709 * @param x1 710 * the X coordinate of the start point of the specified line 711 * @param y1 712 * the Y coordinate of the start point of the specified line 713 * @param x2 714 * the X coordinate of the end point of the specified line 715 * @param y2 716 * the Y coordinate of the end point of the specified line 717 * @param px 718 * the X coordinate of the specified point being measured against 719 * the specified line 720 * @param py 721 * the Y coordinate of the specified point being measured against 722 * the specified line 723 * @return a double value that is the distance from the specified point to 724 * the specified line. 725 * @since 1.2 726 */ 727 public static double ptLineDist(double x1, double y1, double x2, double y2, 728 double px, double py) { 729 return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py)); 730 } 731 732 /** 733 * Returns the square of the distance from a point to this line. The 734 * distance measured is the distance between the specified point and the 735 * closest point on the infinitely-extended line defined by this 736 * <code>Line2D</code>. If the specified point intersects the line, this 737 * method returns 0.0. 738 * 739 * @param px 740 * the X coordinate of the specified point being measured against 741 * this line 742 * @param py 743 * the Y coordinate of the specified point being measured against 744 * this line 745 * @return a double value that is the square of the distance from a 746 * specified point to the current line. 747 * @since 1.2 748 */ 749 public double ptLineDistSq(double px, double py) { 750 return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py); 751 } 752 753 /** 754 * Returns the square of the distance from a specified <code>Point2D</code> 755 * to this line. The distance measured is the distance between the specified 756 * point and the closest point on the infinitely-extended line defined by 757 * this <code>Line2D</code>. If the specified point intersects the line, 758 * this method returns 0.0. 759 * 760 * @param pt 761 * the specified <code>Point2D</code> being measured against this 762 * line 763 * @return a double value that is the square of the distance from a 764 * specified <code>Point2D</code> to the current line. 765 * @since 1.2 766 */ 767 public double ptLineDistSq(Point2D pt) { 768 return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), pt.getX(), pt.getY()); 769 } 770 771 /** 772 * Returns the distance from a point to this line. The distance measured is 773 * the distance between the specified point and the closest point on the 774 * infinitely-extended line defined by this <code>Line2D</code>. If the 775 * specified point intersects the line, this method returns 0.0. 776 * 777 * @param px 778 * the X coordinate of the specified point being measured against 779 * this line 780 * @param py 781 * the Y coordinate of the specified point being measured against 782 * this line 783 * @return a double value that is the distance from a specified point to the 784 * current line. 785 * @since 1.2 786 */ 787 public double ptLineDist(double px, double py) { 788 return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py); 789 } 790 791 /** 792 * Returns the distance from a <code>Point2D</code> to this line. The 793 * distance measured is the distance between the specified point and the 794 * closest point on the infinitely-extended line defined by this 795 * <code>Line2D</code>. If the specified point intersects the line, this 796 * method returns 0.0. 797 * 798 * @param pt 799 * the specified <code>Point2D</code> being measured 800 * @return a double value that is the distance from a specified 801 * <code>Point2D</code> to the current line. 802 * @since 1.2 803 */ 804 public double ptLineDist(Point2D pt) { 805 return ptLineDist(getX1(), getY1(), getX2(), getY2(), pt.getX(), pt.getY()); 806 } 807 808 /** 809 * Tests if a specified coordinate is inside the boundary of this 810 * <code>Line2D</code>. This method is required to implement the 811 * {@link Shape} interface, but in the case of <code>Line2D</code> objects 812 * it always returns <code>false</code> since a line contains no area. 813 * 814 * @param x 815 * the X coordinate of the specified point to be tested 816 * @param y 817 * the Y coordinate of the specified point to be tested 818 * @return <code>false</code> because a <code>Line2D</code> contains no 819 * area. 820 * @since 1.2 821 */ 822 public boolean contains(double x, double y) { 823 return false; 824 } 825 826 /** 827 * Tests if a given <code>Point2D</code> is inside the boundary of this 828 * <code>Line2D</code>. This method is required to implement the 829 * {@link Shape} interface, but in the case of <code>Line2D</code> objects 830 * it always returns <code>false</code> since a line contains no area. 831 * 832 * @param p 833 * the specified <code>Point2D</code> to be tested 834 * @return <code>false</code> because a <code>Line2D</code> contains no 835 * area. 836 * @since 1.2 837 */ 838 public boolean contains(Point2D p) { 839 return false; 840 } 841 842 /** 843 * Tests if the interior of this <code>Line2D</code> entirely contains the 844 * specified set of rectangular coordinates. This method is required to 845 * implement the <code>Shape</code> interface, but in the case of 846 * <code>Line2D</code> objects it always returns false since a line contains 847 * no area. 848 * 849 * @param x 850 * the X coordinate of the upper-left corner of the specified 851 * rectangular area 852 * @param y 853 * the Y coordinate of the upper-left corner of the specified 854 * rectangular area 855 * @param w 856 * the width of the specified rectangular area 857 * @param h 858 * the height of the specified rectangular area 859 * @return <code>false</code> because a <code>Line2D</code> contains no 860 * area. 861 * @since 1.2 862 */ 863 public boolean contains(double x, double y, double w, double h) { 864 return false; 865 } 866 867 /** 868 * Tests if the interior of this <code>Line2D</code> entirely contains the 869 * specified <code>Rectangle2D</code>. This method is required to implement 870 * the <code>Shape</code> interface, but in the case of <code>Line2D</code> 871 * objects it always returns <code>false</code> since a line contains no 872 * area. 873 * 874 * @param r 875 * the specified <code>Rectangle2D</code> to be tested 876 * @return <code>false</code> because a <code>Line2D</code> contains no 877 * area. 878 * @since 1.2 879 */ 880 public boolean contains(Rectangle2D r) { 881 return false; 882 } 883 /** 884 * Creates a new object of the same class as this object. 885 * 886 * @return a clone of this instance. 887 * @exception OutOfMemoryError 888 * if there is not enough memory. 889 * @see java.lang.Cloneable 890 * @since 1.2 891 */ 892 public Object clone() { 893 try { 894 return super.clone(); 895 } catch (CloneNotSupportedException e) { 896// this shouldn't happen, since we are Cloneable 897 throw new InternalError(); 898 } 899 } 900}