Package wprover

Class CPolygon


  • public class CPolygon
    extends CClass
    CPolygon class represents a polygon or circle shape. It extends the CClass class and provides methods for drawing, manipulating, and checking properties of the shape.
    • Constructor Summary

      Constructors 
      Constructor Description
      CPolygon()
      Default constructor for the CPolygon class.
      CPolygon​(Circle c)
      Constructor for the CPolygon class with a specified circle.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean addAPoint​(CPoint p)
      Adds a point to the polygon.
      void addDraggedPoints​(CPoint p1, CPoint p2)
      Adds a pair of dragged points to the vector list.
      boolean allDragged()
      Checks if all points have been dragged.
      static double area​(int[] xPoints, int[] yPoints, int nPoints)
      Calculates the area of a polygon given its vertex coordinates.
      boolean check_eq​(java.util.Vector v)
      Checks if the polygon is equal to another polygon by comparing their points.
      boolean check_rdeq​(java.util.Vector v)
      Checks if the polygon is equal to another polygon by comparing their points in a rotated manner.
      void copy​(CPolygon c)
      Copies the properties of the given polygon to this polygon.
      void draw​(java.awt.Graphics2D g2)
      Draws the polygon on the given graphics context.
      void draw​(java.awt.Graphics2D g2, boolean selected)
      Draws the polygon on the given graphics context with the selected option.
      void draw​(java.awt.Graphics2D g2, boolean selected, boolean overlap, double dx, double dy, boolean rotate, double x, double y, double ang)
      Draws the polygon on the given graphics context with various options.
      void draw​(java.awt.Graphics2D g2, CPoint p)
      Draws the polygon with an additional point on the given graphics context.
      java.util.Vector drawGrid​(java.awt.Graphics2D g2, int[] xpoints, int[] ypoints, int n, int dtype, int gtype)
      Draws a grid pattern on the given graphics context based on the specified points and grid type.
      double getArea()
      Retrieves the area of the polygon.
      java.lang.String getDescription()
      Gets the description of the polygon.
      java.util.Vector getDraggedPoints()
      Retrieves the vector list of dragged points.
      CClass getElement​(int n)
      Retrieves the element at the specified index in the point list.
      CPoint getNextPoint​(CPoint p)
      Gets the next point in the polygon.
      CPoint getPoint​(int n)
      Retrieves the point at the specified index in the point list.
      java.lang.String getPolygonTypeString()
      Deprecated.
      java.lang.String getPolygonTypeString​(java.lang.String s)
      Retrieves the polygon type as a string with a specified format.
      CPoint getPreviousePoint​(CPoint p)
      Gets the previous point in the polygon.
      int getPtn()
      Retrieves the number of points in the polygon.
      java.util.Vector getTransformedPoints()
      Retrieves the transformed points based on the dragged points.
      boolean isAllPointsFree()
      Checks if all points in the polygon are free points.
      boolean isEqual​(Circle c)
      Checks if this polygon is equal to the given circle.
      void Load​(java.io.DataInputStream in, DrawProcess dp)
      Loads the polygon data from a data input stream.
      void Save​(java.io.DataOutputStream out)
      Saves the polygon data to a data output stream.
      void SavePS​(java.io.FileOutputStream fp, int stype)
      Saves the polygon as a PostScript file.
      boolean select​(double x, double y)
      Selects the polygon if the given coordinates are within its bounds.
      void setDraggedPoints​(CPoint p1, CPoint p2, double x, double y)
      Sets the dragged points and their offsets.
      void setDraggedPointsNull()
      Resets the dragged points and their offsets to null and clears the vector list.
      void setPoints​(java.util.Vector v)
      Sets the points of the polygon.
      static double signArea​(int x1, int y1, int x2, int y2, int x3, int y3)
      Calculates the signed area of a triangle given its vertex coordinates.
      java.lang.String TypeString()
      Deprecated.
      java.lang.String TypeString​(java.lang.String s)
      Retrieves the polygon type as a string with a specified format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CPolygon

        public CPolygon()
        Default constructor for the CPolygon class. Initializes the polygon with default values.
      • CPolygon

        public CPolygon​(Circle c)
        Constructor for the CPolygon class with a specified circle. Initializes the polygon as a circle with the given circle's properties.
        Parameters:
        c - the circle to initialize the polygon with
    • Method Detail

      • draw

        public void draw​(java.awt.Graphics2D g2,
                         boolean selected,
                         boolean overlap,
                         double dx,
                         double dy,
                         boolean rotate,
                         double x,
                         double y,
                         double ang)
        Draws the polygon on the given graphics context with various options.
        Parameters:
        g2 - the graphics context
        selected - true if the polygon is selected, false otherwise
        overlap - true if the polygon should be drawn with overlap, false otherwise
        dx - the x-offset for drawing
        dy - the y-offset for drawing
        rotate - true if the polygon should be rotated, false otherwise
        x - the x-coordinate for rotation
        y - the y-coordinate for rotation
        ang - the angle of rotation in radians
      • getElement

        public CClass getElement​(int n)
        Retrieves the element at the specified index in the point list.
        Parameters:
        n - the index of the element
        Returns:
        the element at the specified index, or null if the index is out of bounds
      • getArea

        public double getArea()
        Retrieves the area of the polygon.
        Returns:
        the area of the polygon
      • isAllPointsFree

        public boolean isAllPointsFree()
        Checks if all points in the polygon are free points.
        Returns:
        true if all points are free points, false otherwise
      • signArea

        public static double signArea​(int x1,
                                      int y1,
                                      int x2,
                                      int y2,
                                      int x3,
                                      int y3)
        Calculates the signed area of a triangle given its vertex coordinates.
        Parameters:
        x1 - the x-coordinate of the first vertex
        y1 - the y-coordinate of the first vertex
        x2 - the x-coordinate of the second vertex
        y2 - the y-coordinate of the second vertex
        x3 - the x-coordinate of the third vertex
        Returns:
        the signed area of the triangle
      • area

        public static double area​(int[] xPoints,
                                  int[] yPoints,
                                  int nPoints)
        Calculates the area of a polygon given its vertex coordinates.
        Parameters:
        xPoints - the x-coordinates of the vertices
        yPoints - the y-coordinates of the vertices
        nPoints - the number of vertices
        Returns:
        the area of the polygon
      • isEqual

        public boolean isEqual​(Circle c)
        Checks if this polygon is equal to the given circle.
        Parameters:
        c - the circle to compare with
        Returns:
        true if the polygon is equal to the circle, false otherwise
      • draw

        public void draw​(java.awt.Graphics2D g2,
                         boolean selected)
        Draws the polygon on the given graphics context with the selected option.
        Parameters:
        g2 - the graphics context
        selected - true if the polygon is selected, false otherwise
      • draw

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

        public int getPtn()
        Retrieves the number of points in the polygon.
        Returns:
        the number of points in the polygon
      • getPoint

        public CPoint getPoint​(int n)
        Retrieves the point at the specified index in the point list.
        Parameters:
        n - the index of the point
        Returns:
        the point at the specified index
      • setDraggedPoints

        public void setDraggedPoints​(CPoint p1,
                                     CPoint p2,
                                     double x,
                                     double y)
        Sets the dragged points and their offsets.
        Parameters:
        p1 - the first dragged point
        p2 - the second dragged point
        x - the x-offset
        y - the y-offset
      • setDraggedPointsNull

        public void setDraggedPointsNull()
        Resets the dragged points and their offsets to null and clears the vector list.
      • copy

        public void copy​(CPolygon c)
        Copies the properties of the given polygon to this polygon.
        Parameters:
        c - the polygon to copy from
      • addDraggedPoints

        public void addDraggedPoints​(CPoint p1,
                                     CPoint p2)
        Adds a pair of dragged points to the vector list.
        Parameters:
        p1 - the first point
        p2 - the second point
      • allDragged

        public boolean allDragged()
        Checks if all points have been dragged.
        Returns:
        true if all points have been dragged, false otherwise
      • getDraggedPoints

        public java.util.Vector getDraggedPoints()
        Retrieves the vector list of dragged points.
        Returns:
        the vector list of dragged points
      • getTransformedPoints

        public java.util.Vector getTransformedPoints()
        Retrieves the transformed points based on the dragged points.
        Returns:
        the vector list of transformed points
      • getPolygonTypeString

        @Deprecated
        public java.lang.String getPolygonTypeString()
        Deprecated.
        Retrieves the polygon type as a string.
        Returns:
        the polygon type string
      • getPolygonTypeString

        public java.lang.String getPolygonTypeString​(java.lang.String s)
        Retrieves the polygon type as a string with a specified format.
        Parameters:
        s - the format string
        Returns:
        the formatted polygon type string
      • TypeString

        @Deprecated
        public java.lang.String TypeString()
        Deprecated.
        Retrieves the polygon type as a string.
        Specified by:
        TypeString in class CClass
        Returns:
        the polygon type string
      • TypeString

        public java.lang.String TypeString​(java.lang.String s)
        Retrieves the polygon type as a string with a specified format.
        Parameters:
        s - the format string
        Returns:
        the formatted polygon type string
      • check_rdeq

        public boolean check_rdeq​(java.util.Vector v)
        Checks if the polygon is equal to another polygon by comparing their points in a rotated manner.
        Parameters:
        v - the vector of points to compare with
        Returns:
        true if the polygons are equal, false otherwise
      • check_eq

        public boolean check_eq​(java.util.Vector v)
        Checks if the polygon is equal to another polygon by comparing their points.
        Parameters:
        v - the vector of points to compare with
        Returns:
        true if the polygons are equal, false otherwise
      • setPoints

        public void setPoints​(java.util.Vector v)
        Sets the points of the polygon.
        Parameters:
        v - the vector containing the points
      • addAPoint

        public boolean addAPoint​(CPoint p)
        Adds a point to the polygon.
        Parameters:
        p - the point to add
        Returns:
        true if the point was added, false if the point was already in the list or null
      • select

        public boolean select​(double x,
                              double y)
        Selects the polygon if the given coordinates are within its bounds.
        Parameters:
        x - the x-coordinate to check
        y - the y-coordinate to check
        Returns:
        true if the polygon is selected, false otherwise
      • getPreviousePoint

        public CPoint getPreviousePoint​(CPoint p)
        Gets the previous point in the polygon.
        Parameters:
        p - the current point
        Returns:
        the previous point, or null if not found
      • getNextPoint

        public CPoint getNextPoint​(CPoint p)
        Gets the next point in the polygon.
        Parameters:
        p - the current point
        Returns:
        the next point, or null if not found
      • draw

        public void draw​(java.awt.Graphics2D g2,
                         CPoint p)
        Draws the polygon with an additional point on the given graphics context.
        Parameters:
        g2 - the graphics context
        p - the additional point to draw
      • getDescription

        public java.lang.String getDescription()
        Gets the description of the polygon.
        Specified by:
        getDescription in class CClass
        Returns:
        the description of the polygon
      • drawGrid

        public java.util.Vector drawGrid​(java.awt.Graphics2D g2,
                                         int[] xpoints,
                                         int[] ypoints,
                                         int n,
                                         int dtype,
                                         int gtype)
        Draws a grid pattern on the given graphics context based on the specified points and grid type.
        Parameters:
        g2 - the graphics context
        xpoints - the x-coordinates of the points
        ypoints - the y-coordinates of the points
        n - the number of points
        dtype - the draw type (0: draw, 1: print ps)
        gtype - the grid type (1: vertical, 2: horizontal, 3: both)
        Returns:
        a vector of points if dtype is 1, otherwise null
      • SavePS

        public void SavePS​(java.io.FileOutputStream fp,
                           int stype)
                    throws java.io.IOException
        Saves the polygon as a PostScript file.
        Specified by:
        SavePS in class CClass
        Parameters:
        fp - the file output stream
        stype - the save 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 polygon data 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 polygon data 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