Package wprover

Class CLine


  • public class CLine
    extends CClass
    Represents a geometric line with various properties and methods.
    • Constructor Detail

      • CLine

        public CLine​(int type)
        Constructs a CLine with a specified type.
        Parameters:
        type - the type of the line
      • CLine

        public CLine​(CPoint A,
                     int type)
        Constructs a CLine with a specified point and type.
        Parameters:
        A - the point
        type - the type of the line
      • CLine

        public CLine​(CPoint A,
                     CPoint B,
                     int Type)
        Constructs a CLine with two points and a specified type.
        Parameters:
        A - the first point
        B - the second point
        Type - the type of the line
      • CLine

        public CLine​(CPoint A,
                     CPoint B)
        Constructs a CLine with two points.
        Parameters:
        A - the first point
        B - the second point
      • CLine

        public CLine​(CPoint A,
                     CPoint B,
                     java.lang.String color)
        Constructs a CLine with two points and a specified color.
        Parameters:
        A - the first point
        B - the second point
        color - the color of the line
      • CLine

        public CLine​(java.lang.String name,
                     CPoint A,
                     CPoint B)
        Constructs a CLine with a name and two points.
        Parameters:
        name - the name of the line
        A - the first point
        B - the second point
    • Method Detail

      • draw

        public void draw​(java.awt.Graphics2D g2,
                         boolean selected)
        Draws the line on the given graphics context.
        Parameters:
        g2 - the graphics context
        selected - whether the line is selected
      • draw

        public void draw​(java.awt.Graphics2D g2)
        Draws the line on the given graphics context.
        Overrides:
        draw in class CClass
        Parameters:
        g2 - the graphics context
      • TypeString

        public java.lang.String TypeString()
        Returns the type of the line as a string.
        Specified by:
        TypeString in class CClass
        Returns:
        the type of the line
      • getSimpleName

        public java.lang.String getSimpleName()
        Returns the simple name of the line.
        Returns:
        the simple name of the line
      • getDescription

        public java.lang.String getDescription()
        Returns the description of the line.
        Specified by:
        getDescription in class CClass
        Returns:
        the description of the line
      • setExtent

        public void setExtent​(int n)
        Sets the extent of the line.
        Parameters:
        n - the extent to set
      • getExtent

        public int getExtent()
        Returns the extent of the line.
        Returns:
        the extent of the line
      • drawALine

        public static void drawALine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws an ALine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawABLine

        public static void drawABLine​(CLine line,
                                      java.awt.Graphics2D g2)
        Draws an ABLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawTCLine

        public static void drawTCLine​(CLine line,
                                      java.awt.Graphics2D g2)
        Draws a TCLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawBLine

        public static void drawBLine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws a BLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawCCLine

        public static void drawCCLine​(CLine line,
                                      java.awt.Graphics2D g2)
        Draws a CCLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawSLine

        public static void drawSLine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws an SLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawXLine

        public static void drawXLine​(double x0,
                                     double y0,
                                     double k,
                                     java.awt.Graphics2D g2)
        Draws a line given a point and a slope.
        Parameters:
        x0 - the x-coordinate of the point
        y0 - the y-coordinate of the point
        k - the slope of the line
        g2 - the graphics context
      • drawTLine

        public static void drawTLine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws a TLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawPLine

        public static void drawPLine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws a PLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawLLine

        public static void drawLLine​(CLine line,
                                     java.awt.Graphics2D g2)
        Draws an LLine.
        Parameters:
        line - the line to draw
        g2 - the graphics context
      • drawPParaLine

        public static void drawPParaLine​(CLine line,
                                         CPoint pt,
                                         java.awt.Graphics2D g2)
        Draws a parallel line to the given line through the specified point.
        Parameters:
        line - the line to which the parallel line is drawn
        pt - the point through which the parallel line passes
        g2 - the graphics context
      • drawTPerpLine

        public static void drawTPerpLine​(CLine line,
                                         CPoint pt,
                                         java.awt.Graphics2D g2)
        Draws a perpendicular line to the given line through the specified point.
        Parameters:
        line - the line to which the perpendicular line is drawn
        pt - the point through which the perpendicular line passes
        g2 - the graphics context
      • getAllPointName

        public java.lang.String getAllPointName()
        Returns the names of all points on the line.
        Returns:
        a string containing the names of all points on the line
      • getSecondPoint

        public CPoint getSecondPoint​(CPoint t)
        Returns the second point on the line that is not the given point.
        Parameters:
        t - the point to exclude
        Returns:
        the second point on the line, or null if there is no such point
      • getfirstPoint

        public CPoint getfirstPoint()
        Returns the first point on the line.
        Returns:
        the first point on the line, or null if there is no such point
      • getAPointBut

        public CPoint getAPointBut​(CPoint t)
        Returns a point on the line that is not the given point.
        Parameters:
        t - the point to exclude
        Returns:
        a point on the line that is not the given point, or null if there is no such point
      • getMaxXPoint

        public CPoint getMaxXPoint()
        Returns the point on the line with the maximum x-coordinate.
        Returns:
        the point on the line with the maximum x-coordinate, or null if there is no such point
      • isTwoEndFreePoints

        public boolean isTwoEndFreePoints()
        Checks if the line has two free points at its ends.
        Returns:
        true if the line has two free points at its ends, false otherwise
      • get_Lpt1

        public CPoint get_Lpt1​(CPoint px)
        Returns the point on the line with the smallest x-index that is not the given point.
        Parameters:
        px - the point to exclude
        Returns:
        the point on the line with the smallest x-index that is not the given point, or null if there is no such point
      • get_Lptv

        public CPoint get_Lptv​(CPoint px,
                               double x,
                               double y)
        Returns the point on the line that forms a vector with the given point and coordinates.
        Parameters:
        px - the point to exclude
        x - the x-coordinate of the vector
        y - the y-coordinate of the vector
        Returns:
        the point on the line that forms a vector with the given point and coordinates, or null if there is no such point
      • getTowSideOfLine

        public CPoint[] getTowSideOfLine()
        Returns the two points on the line with the smallest and largest x-index.
        Returns:
        an array containing the two points on the line with the smallest and largest x-index, or null if there are not enough points
      • getDiscription

        public java.lang.String getDiscription()
        Returns the description of the line.
        Returns:
        the description of the line
      • getMaxMinPoint

        public CPoint[] getMaxMinPoint()
        Returns the maximum and minimum points of the line.
        Returns:
        an array containing the maximum and minimum points, or null if there are less than 2 points
      • getMaxMinPoint

        public CPoint[] getMaxMinPoint​(boolean ckv)
        Returns the maximum and minimum points of the line, optionally considering visibility.
        Parameters:
        ckv - whether to consider visibility of points
        Returns:
        an array containing the maximum and minimum points, or null if there are less than 2 points
      • getcons

        public Constraint getcons​(int i)
        Returns the constraint at the specified index.
        Parameters:
        i - the index of the constraint
        Returns:
        the constraint at the specified index, or null if the index is out of bounds
      • getconsByType

        public Constraint getconsByType​(int t)
        Returns the first constraint of the specified type.
        Parameters:
        t - the type of the constraint
        Returns:
        the first constraint of the specified type, or null if no such constraint exists
      • containPTs

        public boolean containPTs​(CPoint p1,
                                  CPoint p2)
        Checks if the line contains the specified points.
        Parameters:
        p1 - the first point
        p2 - the second point
        Returns:
        true if the line contains both points, false otherwise
      • containPT

        public boolean containPT​(CPoint p)
        Checks if the line contains the specified point.
        Parameters:
        p - the point
        Returns:
        true if the line contains the point, false otherwise
      • getPtsSize

        public int getPtsSize()
        Returns the number of points in the line.
        Returns:
        the number of points in the line
      • getPoint

        public CPoint getPoint​(int n)
        Returns the point at the specified index.
        Parameters:
        n - the index of the point
        Returns:
        the point at the specified index, or null if the index is out of bounds
      • isVertical

        public boolean isVertical()
        Checks if the line is vertical.
        Returns:
        true if the line is vertical, false otherwise
      • isHorizonal

        public boolean isHorizonal()
        Checks if the line is horizontal.
        Returns:
        true if the line is horizontal, false otherwise
      • getK

        public double getK()
        Calculates the slope (k) of the line.
        Returns:
        the slope of the line
      • getALineK

        public static double getALineK​(CLine ln1,
                                       CLine ln2,
                                       CLine ln3)
        Calculates the slope (k) for a line defined by three other lines.
        Parameters:
        ln1 - the first line
        ln2 - the second line
        ln3 - the third line
        Returns:
        the calculated slope
      • getALineK

        public static double getALineK​(CPoint p1,
                                       CPoint p2,
                                       CPoint p3,
                                       CPoint p4,
                                       CPoint p5,
                                       CPoint p6)
        Calculates the slope (k) for a line defined by six points.
        Parameters:
        p1 - the first point
        p2 - the second point
        p3 - the third point
        p4 - the fourth point
        p5 - the fifth point
        p6 - the sixth point
        Returns:
        the calculated slope
      • addApoint

        public void addApoint​(CPoint a)
        Adds a point to the line.
        Parameters:
        a - the point to add
      • addconstraint

        public void addconstraint​(Constraint cs)
        Adds a constraint to the line.
        Parameters:
        cs - the constraint to add
      • sameLine

        public boolean sameLine​(CPoint A,
                                CPoint B)
        Checks if two points are on the same line.
        Parameters:
        A - the first point
        B - the second point
        Returns:
        true if both points are on the same line, false otherwise
      • pointOnLine

        public boolean pointOnLine​(CPoint p)
        Checks if a point is on the line.
        Parameters:
        p - the point to check
        Returns:
        true if the point is on the line, false otherwise
      • isEqual

        public boolean isEqual​(CPoint A,
                               CPoint B)
        Checks if two points are equal.
        Parameters:
        A - the first point
        B - the second point
        Returns:
        true if both points are equal, false otherwise
      • mouse_on_line

        public static boolean mouse_on_line​(double x,
                                            double y,
                                            double x1,
                                            double y1,
                                            double x2,
                                            double y2)
        Checks if the mouse is on the line.
        Parameters:
        x - the x-coordinate of the mouse
        y - the y-coordinate of the mouse
        x1 - the x-coordinate of the first point of the line
        y1 - the y-coordinate of the first point of the line
        x2 - the x-coordinate of the second point of the line
        y2 - the y-coordinate of the second point of the line
        Returns:
        true if the mouse is on the line, false otherwise
      • distanceToPoint

        public static double distanceToPoint​(CLine ln,
                                             double x,
                                             double y)
        Calculates the distance from a point to a line.
        Parameters:
        ln - the line
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        the distance from the point to the line
      • distanceToPoint

        public static double distanceToPoint​(double x1,
                                             double y1,
                                             double k,
                                             double x,
                                             double y)
        Calculates the distance from a point to a line given the slope.
        Parameters:
        x1 - the x-coordinate of the first point of the line
        y1 - the y-coordinate of the first point of the line
        k - the slope of the line
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        the distance from the point to the line
      • inside

        public boolean inside​(double x,
                              double y)
        Checks if a point is inside the line segment.
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        true if the point is inside the line segment, false otherwise
      • inside

        public boolean inside​(double x,
                              double y,
                              double eps)
        Checks if a point is inside the line segment within a given tolerance.
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        eps - the tolerance
        Returns:
        true if the point is inside the line segment within the tolerance, false otherwise
      • nearline

        public boolean nearline​(double x,
                                double y)
        Checks if a point is near the line.
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        true if the point is near the line, false otherwise
      • select

        public boolean select​(double x,
                              double y)
        Selects the line if a point is near it.
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        true if the line is selected, false otherwise
      • distance

        public double distance​(double x,
                               double y)
        Calculates the distance from a point to this line.
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        the distance from the point to this line
      • pointonMiddle

        public boolean pointonMiddle​(CPoint pt)
        Checks if the given point is on the middle of the line.
        Parameters:
        pt - the point to check
        Returns:
        true if the point is on the middle of the line, false otherwise
      • pointonline

        public void pointonline​(CPoint pt)
        Sets the location of the given point to be on this line.
        Parameters:
        pt - the point to set on the line
      • commonPoint

        public static CPoint[] commonPoint​(CLine ln,
                                           Circle c)
        Finds the common points between a line and a circle.
        Parameters:
        ln - the line
        c - the circle
        Returns:
        an array of common points between the line and the circle
      • commonPoint

        public static CPoint commonPoint​(CLine line0,
                                         CLine line1)
        Finds the common point between two lines.
        Parameters:
        line0 - the first line
        line1 - the second line
        Returns:
        the common point between the two lines, or null if there is no common point
      • sameLine

        public boolean sameLine​(CLine line2)
        Checks if this line is the same as another line.
        Parameters:
        line2 - the other line to compare
        Returns:
        true if the lines are the same, false otherwise
      • Intersect

        public static double[] Intersect​(CPoint p1,
                                         CPoint p2,
                                         CPoint p3,
                                         CPoint p4)
        Calculates the intersection point of two line segments.
        Parameters:
        p1 - the first point of the first line segment
        p2 - the second point of the first line segment
        p3 - the first point of the second line segment
        p4 - the second point of the second line segment
        Returns:
        an array containing the x and y coordinates of the intersection point, or null if there is no intersection
      • isVerticalSlop

        public static boolean isVerticalSlop​(double r)
        Checks if a slope is considered vertical.
        Parameters:
        r - the slope to check
        Returns:
        true if the slope is vertical, false otherwise
      • isPerp

        public static boolean isPerp​(CLine line0,
                                     CLine line1)
        Checks if two lines are perpendicular.
        Parameters:
        line0 - the first line
        line1 - the second line
        Returns:
        true if the lines are perpendicular, false otherwise
      • Intersect

        public static double[] Intersect​(CLine line0,
                                         CLine line1)
        Calculates the intersection point of two lines.
        Parameters:
        line0 - the first line
        line1 - the second line
        Returns:
        an array containing the x and y coordinates of the intersection point, or null if there is no intersection
      • SavePS

        public void SavePS​(java.io.FileOutputStream fp,
                           int stype)
                    throws java.io.IOException
        Saves the line to a PostScript file.
        Specified by:
        SavePS in class CClass
        Parameters:
        fp - the file output stream
        stype - the style type
        Throws:
        java.io.IOException - if an I/O error occurs
      • Save

        public void Save​(java.io.DataOutputStream out)
                  throws java.io.IOException
        Saves the line to a data output stream.
        Overrides:
        Save in class CClass
        Parameters:
        out - the data output stream
        Throws:
        java.io.IOException - if an I/O error occurs
      • Load

        public void Load​(java.io.DataInputStream in,
                         DrawProcess dp)
                  throws java.io.IOException
        Loads the line from a data input stream.
        Overrides:
        Load in class CClass
        Parameters:
        in - the data input stream
        dp - the draw process
        Throws:
        java.io.IOException - if an I/O error occurs