📄 arc2d.java
字号:
} /** * Constructs a new arc, initialized to location (0, 0), * size (0, 0), angular extents (start = 0, extent = 0), and * the specified closure type. * * @param type The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public Double(int type) { super(type); } /** * Constructs a new arc, initialized to the specified location, * size, angular extents, and closure type. * * @param x, y The coordinates of the upper left corner * of the arc. (Specified in double precision.) * @param w The overall width of the full ellipse of which this * arc is a partial section. (Specified in double precision.) * @param h The overall height of the full ellipse of which this * arc is a partial section. (Specified in double precision.) * @param start The starting angle of the arc in degrees. * (Specified in double precision.) * @param extent The angular extent of the arc in degrees. * (Specified in double precision.) * @param type The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public Double(double x, double y, double w, double h, double start, double extent, int type) { super(type); this.x = x; this.y = y; this.width = w; this.height = h; this.start = start; this.extent = extent; } /** * Constructs a new arc, initialized to the specified location, * size, angular extents, and closure type. * * @param ellipseBounds The bounding rectangle that defines the * outer boundary of the full ellipse of which this arc is a * partial section. * @param start The starting angle of the arc in degrees. * (Specified in double precision.) * @param extent The angular extent of the arc in degrees. * (Specified in double precision.) * @param type The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public Double(Rectangle2D ellipseBounds, double start, double extent, int type) { super(type); this.x = ellipseBounds.getX(); this.y = ellipseBounds.getY(); this.width = ellipseBounds.getWidth(); this.height = ellipseBounds.getHeight(); this.start = start; this.extent = extent; } /** * Returns the x coordinate of the upper left corner of the arc. * * @return The x coordinate of arc's upper left coordinate in * double precision. */ public double getX() { return x; } /** * Returns the y coordinate of the upper left corner of the arc. * * @return The y coordinate of arc's upper left coordinate in * double precision. */ public double getY() { return y; } /** * Returns the width of the ellipse of which this arc is * a partial section. * * @return A double value that represents the width of the full * ellipse of which this arc is a partial section. */ public double getWidth() { return width; } /** * Returns the height of the ellipse of which this arc is * a partial section. * * @return A double value that represents the height of the full * ellipse of which this arc is a partial section. */ public double getHeight() { return height; } /** * Returns the starting angle of the arc. * * @return a double value that represents the starting angle * of the arc in degrees. * @see #setAngleStart */ public double getAngleStart() { return start; } /** * Returns the angular extent of the arc. * * @return A double value that represents the angular extent of * the arc in degrees. * @see #setAngleExtent */ public double getAngleExtent() { return extent; } /** * Determines whether the arc is empty. * * @return <CODE>true</CODE> if the arc is empty, <CODE>false</CODE> * if it not. */ public boolean isEmpty() { return (width <= 0.0 || height <= 0.0); } /** * Sets the location, size, angular extents, and closure type of * this arc to the specified double values. * * @param x, y The coordinates of the upper left corner * of the arc. * @param w The overall width of the full ellipse of which * this arc is a partial section. * @param h The overall height of the full ellipse of which * this arc is a partial section. * @param angSt The starting angle of the arc in degrees. * @param angExt The angular extent of the arc in degrees. * @param closure The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public void setArc(double x, double y, double w, double h, double angSt, double angExt, int closure) { this.setArcType(closure); this.x = x; this.y = y; this.width = w; this.height = h; this.start = angSt; this.extent = angExt; } /** * Sets the starting angle of this arc to the specified double * value. * * @param angSt The starting angle of the arc in degrees. * @see #getAngleStart */ public void setAngleStart(double angSt) { this.start = angSt; } /** * Sets the angular extent of this arc to the specified double * value. * * @param angExt The angular extent of the arc in degrees. * @see #getAngleExtent */ public void setAngleExtent(double angExt) { this.extent = angExt; } /** * Returns the high-precision bounding box of the arc. * * @param x, y The coordinates of the upper left corner * of the arc. * @param w The overall width of the full ellipse of which * this arc is a partial section. * @param h The overall height of the full ellipse of which * this arc is a partial section. * * @return The bounding box as a <CODE>Rectangle2D</CODE> object. */ protected Rectangle2D makeBounds(double x, double y, double w, double h) { return new Rectangle2D.Double(x, y, w, h); } } private int type; /** * This is an abstract class that cannot be instantiated directly. * Type-specific implementation subclasses are available for * instantiation and provide a number of formats for storing * the information necessary to satisfy the various accessor * methods below. * * @param type The closure type of this arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. * @see java.awt.geom.Arc2D.Float * @see java.awt.geom.Arc2D.Double */ protected Arc2D(int type) { setArcType(type); } /** * Returns the starting angle of the arc. * * @return A double value that represents the starting angle * of the arc in degrees. * @see #setAngleStart */ public abstract double getAngleStart(); /** * Returns the angular extent of the arc. * * @return A double value that represents the angular extent * of the arc in degrees. * @see #setAngleExtent */ public abstract double getAngleExtent(); /** * Returns the arc closure type of the arc: {@link #OPEN OPEN}, * {@link #CHORD CHORD}, or {@link #PIE PIE}. * @return One of the integer constant closure types defined * in this class. * @see #setArcType */ public int getArcType() { return type; } /** * Returns the starting point of the arc. This point is the * intersection of the ray from the center defined by the * starting angle and the elliptical boundary of the arc. * * @return A <CODE>Point2D</CODE> object representing the * x,y coordinates of the starting point of the arc. */ public Point2D getStartPoint() { double angle = Math.toRadians(-getAngleStart()); double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth(); double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight(); return new Point2D.Double(x, y); } /** * Returns the ending point of the arc. This point is the * intersection of the ray from the center defined by the * starting angle plus the angular extent of the arc and the * elliptical boundary of the arc. * * @return A <CODE>Point2D</CODE> object representing the * x,y coordinates of the ending point of the arc. */ public Point2D getEndPoint() { double angle = Math.toRadians(-getAngleStart() - getAngleExtent()); double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth(); double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight(); return new Point2D.Double(x, y); } /** * Sets the location, size, angular extents, and closure type of * this arc to the specified double values. * * @param x, y The coordinates of the upper left corner of * the arc. * @param w The overall width of the full ellipse of which * this arc is a partial section. * @param h The overall height of the full ellipse of which * this arc is a partial section. * @param angSt The starting angle of the arc in degrees. * @param angExt The angular extent of the arc in degrees. * @param closure The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public abstract void setArc(double x, double y, double w, double h, double angSt, double angExt, int closure); /** * Sets the location, size, angular extents, and closure type of * this arc to the specified values. * * @param loc The <CODE>Point2D</CODE> representing the coordinates of * the upper left corner of the arc. * @param size The <CODE>Dimension2D</CODE> representing the width * and height of the full ellipse of which this arc is * a partial section. * @param angSt The starting angle of the arc in degrees. * (Specified in double precision.) * @param angExt The angular extent of the arc in degrees. * (Specified in double precision.) * @param closure The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public void setArc(Point2D loc, Dimension2D size, double angSt, double angExt, int closure) { setArc(loc.getX(), loc.getY(), size.getWidth(), size.getHeight(), angSt, angExt, closure); } /** * Sets the location, size, angular extents, and closure type of * this arc to the specified values. * * @param rect The bounding rectangle that defines the * outer boundary of the full ellipse of which this arc is a * partial section. * @param angSt The starting angle of the arc in degrees. * (Specified in double precision.) * @param angExt The angular extent of the arc in degrees. * (Specified in double precision.) * @param closure The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public void setArc(Rectangle2D rect, double angSt, double angExt, int closure) { setArc(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), angSt, angExt, closure); } /** * Sets this arc to be the same as the specified arc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -