📄 arc2d.java
字号:
/* * @(#)Arc2D.java 1.22 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.geom;/** * <CODE>Arc2D</CODE> is the abstract superclass for all objects that * store a 2D arc defined by a bounding rectangle, * start angle, angular extent (length of the arc), and a closure type * (<CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or <CODE>PIE</CODE>). * <p> * The bounding rectangle defines the outer boundary of the full ellipse * of which this arc is a partial section. * The angles are specified relative to the non-square extents of the * bounding rectangle such that 45 degrees always falls on the line from * the center of the ellipse to the upper right corner of the bounding * rectangle. * As a result, if the bounding rectangle is noticeably longer along one * axis than the other, the angles to the start and end of the arc segment * will be skewed farther along the longer axis of the bounds. * <p> * The actual storage representation of the coordinates is left to * the subclass. * * @version 10 Feb 1997 * @author Jim Graham */public abstract class Arc2D extends RectangularShape { /** * The closure type for an open arc with no path segments * connecting the two ends of the arc segment. */ public final static int OPEN = 0; /** * The closure type for an arc closed by drawing a straight * line segment from the start of the arc segment to the end of the * arc segment. */ public final static int CHORD = 1; /** * The closure type for an arc closed by drawing straight line * segments from the start of the arc segment to the center * of the full ellipse and from that point to the end of the arc segment. */ public final static int PIE = 2; /** * This class defines an arc specified in float precision. */ public static class Float extends Arc2D { /** * The x coordinate of the upper left corner of the arc. */ public float x; /** * The y coordinate of the upper left corner of the arc. */ public float y; /** * The overall width of the full ellipse of which this arc is * a partial section (not considering the * angular extents). */ public float width; /** * The overall height of the full ellipse of which this arc is * a partial section (not considering the * angular extents). */ public float height; /** * The starting angle of the arc in degrees. */ public float start; /** * The angular extent of the arc in degrees. */ public float extent; /** * Constructs a new OPEN arc, initialized to location (0, 0), * size (0, 0), angular extents (start = 0, extent = 0). */ public Float() { super(OPEN); } /** * 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 Float(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 float precision.) * @param w The overall width of the full ellipse of which * this arc is a partial section. (Specified in float precision.) * @param h The overall height of the full ellipse of which this * arc is a partial section. (Specified in float precision.) * @param start The starting angle of the arc in degrees. * (Specified in float precision.) * @param extent The angular extent of the arc in degrees. * (Specified in float precision.) * @param type The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public Float(float x, float y, float w, float h, float start, float 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 float precision.) * @param extent The angular extent of the arc in degrees. * (Specified in float precision.) * @param type The closure type for the arc: * {@link #OPEN OPEN}, {@link #CHORD CHORD}, or {@link #PIE PIE}. */ public Float(Rectangle2D ellipseBounds, float start, float extent, int type) { super(type); this.x = (float) ellipseBounds.getX(); this.y = (float) ellipseBounds.getY(); this.width = (float) ellipseBounds.getWidth(); this.height = (float) 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 (double) 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 (double) 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 (double) 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 (double) 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 (double) 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 (double) extent; } /** * Determines whether the arc is empty. * * @return <CODE>true</CODE> if the arc is empty, <CODE>false</CODE> * if it is 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 = (float) x; this.y = (float) y; this.width = (float) w; this.height = (float) h; this.start = (float) angSt; this.extent = (float) 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 = (float) 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 = (float) angExt; } /** * Return 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.Float((float) x, (float) y, (float) w, (float) h); } } /** * This class defines an arc specified in double precision. */ public static class Double extends Arc2D { /** * The x coordinate of the upper left corner of the arc. */ public double x; /** * The y coordinate of the upper left corner of the arc. */ public double y; /** * The overall width of the full ellipse (not considering the * angular extents). */ public double width; /** * The overall height of the full ellipse (not considering the * angular extents). */ public double height; /** * The starting angle of the arc in degrees. */ public double start; /** * The angular extent of the arc in degrees. */ public double extent; /** * Constructs a new OPEN arc, initialized to location (0, 0), * size (0, 0), angular extents (start = 0, extent = 0). */ public Double() { super(OPEN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -