< prev index next >

src/java.desktop/share/classes/java/awt/geom/Line2D.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 601                                          double x4, double y4)
 602     {
 603         return ((relativeCCW(x1, y1, x2, y2, x3, y3) *
 604                  relativeCCW(x1, y1, x2, y2, x4, y4) <= 0)
 605                 && (relativeCCW(x3, y3, x4, y4, x1, y1) *
 606                     relativeCCW(x3, y3, x4, y4, x2, y2) <= 0));
 607     }
 608 
 609     /**
 610      * Tests if the line segment from {@code (x1,y1)} to
 611      * {@code (x2,y2)} intersects this line segment.
 612      *
 613      * @param x1 the X coordinate of the start point of the
 614      *           specified line segment
 615      * @param y1 the Y coordinate of the start point of the
 616      *           specified line segment
 617      * @param x2 the X coordinate of the end point of the
 618      *           specified line segment
 619      * @param y2 the Y coordinate of the end point of the
 620      *           specified line segment
 621      * @return {@code <true>} if this line segment and the specified line segment
 622      *                  intersect each other; {@code false} otherwise.
 623      * @since 1.2
 624      */
 625     public boolean intersectsLine(double x1, double y1, double x2, double y2) {
 626         return linesIntersect(x1, y1, x2, y2,
 627                               getX1(), getY1(), getX2(), getY2());
 628     }
 629 
 630     /**
 631      * Tests if the specified line segment intersects this line segment.
 632      * @param l the specified {@code Line2D}
 633      * @return {@code true} if this line segment and the specified line
 634      *                  segment intersect each other;
 635      *                  {@code false} otherwise.
 636      * @since 1.2
 637      */
 638     public boolean intersectsLine(Line2D l) {
 639         return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(),
 640                               getX1(), getY1(), getX2(), getY2());
 641     }


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 601                                          double x4, double y4)
 602     {
 603         return ((relativeCCW(x1, y1, x2, y2, x3, y3) *
 604                  relativeCCW(x1, y1, x2, y2, x4, y4) <= 0)
 605                 && (relativeCCW(x3, y3, x4, y4, x1, y1) *
 606                     relativeCCW(x3, y3, x4, y4, x2, y2) <= 0));
 607     }
 608 
 609     /**
 610      * Tests if the line segment from {@code (x1,y1)} to
 611      * {@code (x2,y2)} intersects this line segment.
 612      *
 613      * @param x1 the X coordinate of the start point of the
 614      *           specified line segment
 615      * @param y1 the Y coordinate of the start point of the
 616      *           specified line segment
 617      * @param x2 the X coordinate of the end point of the
 618      *           specified line segment
 619      * @param y2 the Y coordinate of the end point of the
 620      *           specified line segment
 621      * @return {@code true} if this line segment and the specified line segment
 622      *                  intersect each other; {@code false} otherwise.
 623      * @since 1.2
 624      */
 625     public boolean intersectsLine(double x1, double y1, double x2, double y2) {
 626         return linesIntersect(x1, y1, x2, y2,
 627                               getX1(), getY1(), getX2(), getY2());
 628     }
 629 
 630     /**
 631      * Tests if the specified line segment intersects this line segment.
 632      * @param l the specified {@code Line2D}
 633      * @return {@code true} if this line segment and the specified line
 634      *                  segment intersect each other;
 635      *                  {@code false} otherwise.
 636      * @since 1.2
 637      */
 638     public boolean intersectsLine(Line2D l) {
 639         return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(),
 640                               getX1(), getY1(), getX2(), getY2());
 641     }


< prev index next >