Class Line2D

  • All Implemented Interfaces:
    Shape2D

    public class Line2D
    extends java.lang.Object
    implements Shape2D
    Simple 2D shape line.
    • Field Detail

      • startX_

        private final double startX_
      • startY_

        private final double startY_
      • endX_

        private final double endX_
      • endY_

        private final double endY_
      • isVertical_

        private final boolean isVertical_
      • slope_

        private final double slope_
      • yIntercept_

        private final double yIntercept_
    • Constructor Detail

      • Line2D

        public Line2D​(Point2D start,
                      Point2D end)
        Ctor.
        Parameters:
        start - the start point
        end - the end point
      • Line2D

        public Line2D​(double x1,
                      double y1,
                      double x2,
                      double y2)
        Ctor.
        Parameters:
        x1 - the x value of the start point
        y1 - the y value of the start point
        x2 - the x value of the end point
        y2 - the y value of the end point
    • Method Detail

      • intersect

        public Point2D intersect​(Line2D line)
        Parameters:
        line - the line to intersect this with
        Returns:
        the intersection point of the two lines or null if they are parallel
      • contains

        public boolean contains​(double x,
                                double y)
        Specified by:
        contains in interface Shape2D
        Parameters:
        x - point x value
        y - point y value
        Returns:
        true if the specified point is inside; false otherwise.
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Shape2D
        Returns:
        true if the Shape is empty.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object