⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generalpath.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		    break;		}		// NO BREAK;	    case SEG_LINETO:		lineTo(coords[0], coords[1]);		break;	    case SEG_QUADTO:		quadTo(coords[0], coords[1],		       coords[2], coords[3]);		break;	    case SEG_CUBICTO:		curveTo(coords[0], coords[1],			coords[2], coords[3],			coords[4], coords[5]);		break;	    case SEG_CLOSE:		closePath();		break;	    }	    pi.next();	    connect = false;	}    }    /**     * Returns the fill style winding rule.     * @return an integer representing the current winding rule.     * @see #WIND_EVEN_ODD       * @see #WIND_NON_ZERO     * @see #setWindingRule     */    public synchronized int getWindingRule() {        return windingRule;    }    /**     * Sets the winding rule for this path to the specified value.     * @param rule an integer representing the specified      * winding rule     * @exception <code>IllegalArgumentException</code> if      *		<code>rule</code> is not either      *		<code>WIND_EVEN_ODD</code> or     *		<code>WIND_NON_ZERO</code>     * @see #WIND_EVEN_ODD       * @see #WIND_NON_ZERO     * @see #getWindingRule     */    public void setWindingRule(int rule) {	if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) {	    throw new IllegalArgumentException("winding rule must be "+					       "WIND_EVEN_ODD or "+					       "WIND_NON_ZERO");	}	windingRule = rule;    }    /**     * Returns the coordinates most recently added to the end of the path     * as a {@link Point2D} object.     * @return a <code>Point2D</code> object containing the ending      * coordinates of the path or <code>null</code> if there are no points     * in the path.     */    public synchronized Point2D getCurrentPoint() {	if (numTypes < 1 || numCoords < 2) {	    return null;	}	int index = numCoords;	if (pointTypes[numTypes - 1] == SEG_CLOSE) {	loop:	    for (int i = numTypes - 2; i > 0; i--) {		switch (pointTypes[i]) {		case SEG_MOVETO:		    break loop;		case SEG_LINETO:		    index -= 2;		    break;		case SEG_QUADTO:		    index -= 4;		    break;		case SEG_CUBICTO:		    index -= 6;		    break;		case SEG_CLOSE:		    break;		}	    }	}	return new Point2D.Float(pointCoords[index - 2],				 pointCoords[index - 1]);    }    /**     * Resets the path to empty.  The append position is set back to the     * beginning of the path and all coordinates and point types are     * forgotten.     */    public synchronized void reset() {	numTypes = numCoords = 0;    }    /**     * Transforms the geometry of this path using the specified      * {@link AffineTransform}.     * The geometry is transformed in place, which permanently changes the     * boundary defined by this object.     * @param at the <code>AffineTransform</code> used to transform the area     */    public void transform(AffineTransform at) {	at.transform(pointCoords, 0, pointCoords, 0, numCoords / 2);    }    /**     * Returns a new transformed <code>Shape</code>.     * @param at the <code>AffineTransform</code> used to transform a      * new <code>Shape</code>.     * @return a new <code>Shape</code>, transformed with the specified      * <code>AffineTransform</code>.     */    public synchronized Shape createTransformedShape(AffineTransform at) {	GeneralPath gp = (GeneralPath) clone();	if (at != null) {	    gp.transform(at);	}	return gp;    }    /**     * Return the bounding box of the path.     * @return a {@link java.awt.Rectangle} object that     * bounds the current path.     */    public java.awt.Rectangle getBounds() {	return getBounds2D().getBounds();    }    /**     * Returns the bounding box of the path.     * @return a {@link Rectangle2D} object that     *          bounds the current path.     */    public synchronized Rectangle2D getBounds2D() {	float x1, y1, x2, y2;	int i = numCoords;	if (i > 0) {	    y1 = y2 = pointCoords[--i];	    x1 = x2 = pointCoords[--i];	    while (i > 0) {		float y = pointCoords[--i];		float x = pointCoords[--i];		if (x < x1) x1 = x;		if (y < y1) y1 = y;		if (x > x2) x2 = x;		if (y > y2) y2 = y;	    }	} else {	    x1 = y1 = x2 = y2 = 0.0f;	}	return new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1);    }    /**     * Tests if the specified coordinates are inside the boundary of      * this <code>Shape</code>.     * @param x,&nbsp;y the specified coordinates     * @return <code>true</code> if the specified coordinates are inside this      * <code>Shape</code>; <code>false</code> otherwise     */    public boolean contains(double x, double y) {	if (numTypes < 2) {	    return false;	}	int cross = Curve.crossingsForPath(getPathIterator(null), x, y);	if (windingRule == WIND_NON_ZERO) {	    return (cross != 0);	} else {	    return ((cross & 1) != 0);	}    }    /**     * Tests if the specified <code>Point2D</code> is inside the boundary     * of this <code>Shape</code>.     * @param p the specified <code>Point2D</code>     * @return <code>true</code> if this <code>Shape</code> contains the      * specified <code>Point2D</code>, <code>false</code> otherwise.     */    public boolean contains(Point2D p) {	return contains(p.getX(), p.getY());    }    /**     * Tests if the specified rectangular area is inside the boundary of     * this <code>Shape</code>.     * @param x,&nbsp;y the specified coordinates     * @param w the width of the specified rectangular area     * @param h the height of the specified rectangular area     * @return <code>true</code> if this <code>Shape</code> contains      * the specified rectangluar area; <code>false</code> otherwise.     */    public boolean contains(double x, double y, double w, double h) {	Crossings c = Crossings.findCrossings(getPathIterator(null),					      x, y, x+w, y+h);	return (c != null && c.covers(y, y+h));    }    /**     * Tests if the specified <code>Rectangle2D</code>     * is inside the boundary of this <code>Shape</code>.     * @param r a specified <code>Rectangle2D</code>     * @return <code>true</code> if this <code>Shape</code> bounds the      * specified <code>Rectangle2D</code>; <code>false</code> otherwise.     */    public boolean contains(Rectangle2D r) {	return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());    }    /**     * Tests if the interior of this <code>Shape</code> intersects the      * interior of a specified set of rectangular coordinates.     * @param x,&nbsp;y the specified coordinates     * @param w the width of the specified rectangular coordinates     * @param h the height of the specified rectangular coordinates     * @return <code>true</code> if this <code>Shape</code> and the      * interior of the specified set of rectangular coordinates intersect     * each other; <code>false</code> otherwise.     */    public boolean intersects(double x, double y, double w, double h) {	Crossings c = Crossings.findCrossings(getPathIterator(null),					      x, y, x+w, y+h);	return (c == null || !c.isEmpty());    }    /**     * Tests if the interior of this <code>Shape</code> intersects the      * interior of a specified <code>Rectangle2D</code>.     * @param r the specified <code>Rectangle2D</code>     * @return <code>true</code> if this <code>Shape</code> and the interior      * 		of the specified <code>Rectangle2D</code> intersect each     * 		other; <code>false</code> otherwise.     */    public boolean intersects(Rectangle2D r) {	return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());    }    /**     * Returns a <code>PathIterator</code> object that iterates along the      * boundary of this <code>Shape</code> and provides access to the      * geometry of the outline of this <code>Shape</code>.     * The iterator for this class is not multi-threaded safe,     * which means that this <code>GeneralPath</code> class does not     * guarantee that modifications to the geometry of this     * <code>GeneralPath</code> object do not affect any iterations of     * that geometry that are already in process.     * @param at an <code>AffineTransform</code>      * @return a new <code>PathIterator</code> that iterates along the      * boundary of this <code>Shape</code> and provides access to the      * geometry of this <code>Shape</code>'s outline     */    public PathIterator getPathIterator(AffineTransform at) {	return new GeneralPathIterator(this, at);    }    /**     * Returns a <code>PathIterator</code> object that iterates along the      * boundary of the flattened <code>Shape</code> and provides access to the      * geometry of the outline of the <code>Shape</code>.     * The iterator for this class is not multi-threaded safe,     * which means that this <code>GeneralPath</code> class does not     * guarantee that modifications to the geometry of this     * <code>GeneralPath</code> object do not affect any iterations of     * that geometry that are already in process.      * @param at an <code>AffineTransform</code>     * @param flatness the maximum distance that the line segments used to     *		approximate the curved segments are allowed to deviate     *		from any point on the original curve         * @return a new <code>PathIterator</code> that iterates along the flattened     * <code>Shape</code> boundary.     */    public PathIterator getPathIterator(AffineTransform at, double flatness) {	return new FlatteningPathIterator(getPathIterator(at), flatness);    }    /**     * Creates a new object of the same class as this object.     *     * @return     a clone of this instance.     * @exception  OutOfMemoryError            if there is not enough memory.     * @see        java.lang.Cloneable     * @since      1.2     */    public Object clone() {	try {	    GeneralPath copy = (GeneralPath) super.clone();	    copy.pointTypes = (byte[]) pointTypes.clone();	    copy.pointCoords = (float[]) pointCoords.clone();	    return copy;	} catch (CloneNotSupportedException e) {	    // this shouldn't happen, since we are Cloneable	    throw new InternalError();	}    }    GeneralPath(int windingRule, 		byte[] pointTypes,		int numTypes,		float[] pointCoords,		int numCoords) {    // used to construct from native	this.windingRule = windingRule;	this.pointTypes = pointTypes;	this.numTypes = numTypes;	this.pointCoords = pointCoords;	this.numCoords = numCoords;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -