Package wprover
Class CPolygon
- java.lang.Object
-
- wprover.CClass
-
- wprover.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddAPoint(CPoint p)Adds a point to the polygon.voidaddDraggedPoints(CPoint p1, CPoint p2)Adds a pair of dragged points to the vector list.booleanallDragged()Checks if all points have been dragged.static doublearea(int[] xPoints, int[] yPoints, int nPoints)Calculates the area of a polygon given its vertex coordinates.booleancheck_eq(java.util.Vector v)Checks if the polygon is equal to another polygon by comparing their points.booleancheck_rdeq(java.util.Vector v)Checks if the polygon is equal to another polygon by comparing their points in a rotated manner.voidcopy(CPolygon c)Copies the properties of the given polygon to this polygon.voiddraw(java.awt.Graphics2D g2)Draws the polygon on the given graphics context.voiddraw(java.awt.Graphics2D g2, boolean selected)Draws the polygon on the given graphics context with the selected option.voiddraw(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.voiddraw(java.awt.Graphics2D g2, CPoint p)Draws the polygon with an additional point on the given graphics context.java.util.VectordrawGrid(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.doublegetArea()Retrieves the area of the polygon.java.lang.StringgetDescription()Gets the description of the polygon.java.util.VectorgetDraggedPoints()Retrieves the vector list of dragged points.CClassgetElement(int n)Retrieves the element at the specified index in the point list.CPointgetNextPoint(CPoint p)Gets the next point in the polygon.CPointgetPoint(int n)Retrieves the point at the specified index in the point list.java.lang.StringgetPolygonTypeString()Deprecated.UsegetPolygonTypeString(String)instead.java.lang.StringgetPolygonTypeString(java.lang.String s)Retrieves the polygon type as a string with a specified format.CPointgetPreviousePoint(CPoint p)Gets the previous point in the polygon.intgetPtn()Retrieves the number of points in the polygon.java.util.VectorgetTransformedPoints()Retrieves the transformed points based on the dragged points.booleanisAllPointsFree()Checks if all points in the polygon are free points.booleanisEqual(Circle c)Checks if this polygon is equal to the given circle.voidLoad(java.io.DataInputStream in, DrawProcess dp)Loads the polygon data from a data input stream.voidSave(java.io.DataOutputStream out)Saves the polygon data to a data output stream.voidSavePS(java.io.FileOutputStream fp, int stype)Saves the polygon as a PostScript file.booleanselect(double x, double y)Selects the polygon if the given coordinates are within its bounds.voidsetDraggedPoints(CPoint p1, CPoint p2, double x, double y)Sets the dragged points and their offsets.voidsetDraggedPointsNull()Resets the dragged points and their offsets to null and clears the vector list.voidsetPoints(java.util.Vector v)Sets the points of the polygon.static doublesignArea(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.StringTypeString()Deprecated.UsegetPolygonTypeString(String)instead.java.lang.StringTypeString(java.lang.String s)Retrieves the polygon type as a string with a specified format.-
Methods inherited from class wprover.CClass
copy, get_type, getColor, getColorIndex, getname, getPSLineString, hasNameSet, isdraw, saveSuper, saveSuperColor, setAttr, setAttrAux, setColor, setDash, setInFlashing, setWidth, stopFlash, toString, visible
-
-
-
-
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 contextselected- true if the polygon is selected, false otherwiseoverlap- true if the polygon should be drawn with overlap, false otherwisedx- the x-offset for drawingdy- the y-offset for drawingrotate- true if the polygon should be rotated, false otherwisex- the x-coordinate for rotationy- the y-coordinate for rotationang- 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 vertexy1- the y-coordinate of the first vertexx2- the x-coordinate of the second vertexy2- the y-coordinate of the second vertexx3- 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 verticesyPoints- the y-coordinates of the verticesnPoints- 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 contextselected- true if the polygon is selected, false otherwise
-
draw
public void draw(java.awt.Graphics2D g2)
Draws the polygon on the given 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 pointp2- the second dragged pointx- the x-offsety- 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 pointp2- 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.UsegetPolygonTypeString(String)instead.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.UsegetPolygonTypeString(String)instead.Retrieves the polygon type as a string.- Specified by:
TypeStringin classCClass- 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 checky- 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 contextp- the additional point to draw
-
getDescription
public java.lang.String getDescription()
Gets the description of the polygon.- Specified by:
getDescriptionin classCClass- 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 contextxpoints- the x-coordinates of the pointsypoints- the y-coordinates of the pointsn- the number of pointsdtype- 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.IOExceptionSaves the polygon as a PostScript file.
-
Save
public void Save(java.io.DataOutputStream out) throws java.io.IOExceptionSaves the polygon data to a data output stream.
-
Load
public void Load(java.io.DataInputStream in, DrawProcess dp) throws java.io.IOExceptionLoads the polygon data from a data input stream.
-
-