Class DirectionalLine

    • Constructor Detail

      • DirectionalLine

        public DirectionalLine​(double x1,
                               double y1,
                               double x2,
                               double y2)
        Creates a new DirectionalLine based on the specified coordinates.
        Parameters:
        x1 - double; Coordinate x1
        y1 - double; Coordinate y1
        x2 - double; Coordinate x2
        y2 - double; Coordinate y2
      • DirectionalLine

        public DirectionalLine​(float x1,
                               float y1,
                               float x2,
                               float y2)
        Creates a new DirectionalLine based on the specified (float) coordinates.
        Parameters:
        x1 - float; Coordinate x1
        y1 - float; Coordinate y1
        x2 - float; Coordinate x2
        y2 - float; Coordinate y2
    • Method Detail

      • calcNormal

        public void calcNormal()
        Calculates the normal to this line. The normal of (a, b) is (-b, a).
      • normalize

        public void normalize()
        Normalizes the normal of this line (make the normal's length 1).
      • setLine

        public void setLine​(float x1,
                            float y1,
                            float x2,
                            float y2)
        Set the line using floats.
        Parameters:
        x1 - float; x1 coordinate
        y1 - float; y1 coordinate
        x2 - float; x2 coordinate
        y2 - float; y2 coordinate
      • setLine

        public void setLine​(double x1,
                            double y1,
                            double x2,
                            double y2)
        Overrides:
        setLine in class Line2D.Double
      • flip

        public void flip()
        Flips this line so that the end points are reversed (in other words, (x1,y1) becomes (x2,y2) and vice versa) and the normal is changed to point the opposite direction.
      • equalsCoordinates

        public boolean equalsCoordinates​(DirectionalLine line)
        Returns true if the endpoints of this line match the endpoints of the specified line. Ignores normal and height values.
        Parameters:
        line - DirectionalLine; another line
        Returns:
        true if this line's coordinates are equal to the other line's coordinates
      • equalsCoordinatesIgnoreOrder

        public boolean equalsCoordinatesIgnoreOrder​(DirectionalLine line)
        Returns true if the endpoints of this line match the endpoints of the specified line, ignoring endpoint order (if the first point of this line is equal to the second point of the specified line, and vice versa, returns true). Ignores normal and height values.
        Parameters:
        line - DirectionalLine; another line
        Returns:
        true if coordinates match independent of the order
      • getSideThick

        public DirectionalLine.Side getSideThick​(double x,
                                                 double y)
        Gets the side of this line the specified point is on. This method treats the line as 1-unit thick, so points within this 1-unit border are considered collinear. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONTSIDE, BACKSIDE, or COLLINEAR.
        Parameters:
        x - double; coordinate x
        y - double; coordinate y
        Returns:
        the side
      • getSideThin

        public DirectionalLine.Side getSideThin​(double x,
                                                double y)
        Gets the side of this line the specified point is on. Because of doubling point inaccuracy, a collinear line will be rare. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONTSIDE, BACKSIDE, or COLLINEAR.
        Parameters:
        x - double; coordinate x
        y - double; coordinate y
        Returns:
        the side
      • getSide

        public DirectionalLine.Side getSide​(Line2D.Double line)
        Gets the side of this line that the specified line segment is on. Returns either FRONT, BACK, COLINEAR, or SPANNING.
        Parameters:
        line - Line2D.Double; line segment
        Returns:
        the side
      • getIntersection

        public double getIntersection​(Line2D.Double line)
        Returns the fraction of intersection along this line. Returns a value from 0 to 1 if the segments intersect. For example, a return value of 0 means the intersection occurs at point (x1, y1), 1 means the intersection occurs at point (x2, y2), and .5 mean the intersection occurs halfway between the two endpoints of this line. Returns -1 if the lines are parallel.
        Parameters:
        line - Line2D.Double; a line
        Returns:
        the intersection
      • getIntersectionPoint

        public Point2D.Double getIntersectionPoint​(Line2D.Double line)
        Returns the intersection point of this line with the specified line.
        Parameters:
        line - Line2D.Double; a line
        Returns:
        intersection point
      • getLineThickness

        public double getLineThickness()
        Gets the thickness of the line.
        Returns:
        returns the lineThickness
      • setLineThickness

        public void setLineThickness​(double lineThickness)
        Sets the thickness of the line.
        Parameters:
        lineThickness - double; the lineThickness to set
      • getNormalx

        public double getNormalx()
        Returns:
        returns the normalX
      • getNormaly

        public double getNormaly()
        Returns:
        returns the normalY