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

📄 rectangle2d.java

📁 Hecl编程语言是一个高层次的脚本语言的Java实现。其用意是要小
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	}	/**	 * Constructs and initializes a <code>Rectangle2D</code>          * from the specified double coordinates.	 * @param x,&nbsp;y the coordinates of the upper left corner         * of the newly constructed <code>Rectangle2D</code>	 * @param w the width of the         * newly constructed <code>Rectangle2D</code>	 * @param h the height of the         * newly constructed <code>Rectangle2D</code>	 */	public Double(double x, double y, double w, double h) {	    setRect(x, y, w, h);	}//#ifdef notdef	public Object clone() /*throws CloneNotSupportedException*/ {	    return new Double(x,y,width,height);	}//#endif		/**	 * Returns the X coordinate of this <code>Rectangle2D</code> in         * double precision.         * @return the X coordinate of this <code>Rectangle2D</code>.	 */	public double getX() {	    return x;	}	/**	 * Returns the Y coordinate of this <code>Rectangle2D</code> in         * double precision.         * @return the Y coordinate of this <code>Rectangle2D</code>.	 */	public double getY() {	    return y;	}	/**	 * Returns the width of this <code>Rectangle2D</code> in          * double precision.         * @return the width of this <code>Rectangle2D</code>.	 */	public double getWidth() {	    return width;	}	/**	 * Returns the height of this <code>Rectangle2D</code> in          * double precision.         * @return the height of this <code>Rectangle2D</code>.	 */	public double getHeight() {	    return height;	}	/**	 * Determines whether or not this <code>Rectangle2D</code>          * is empty.         * @return <code>true</code> if this <code>Rectangle2D</code>         * is empty; <code>false</code> otherwise.	 */	public boolean isEmpty() {	    return (width <= 0.0) || (height <= 0.0);	}	/**	 * Sets the location and size of this <code>Rectangle2D</code>         * to the specified double values.         * @param x,&nbsp;y the coordinates to which to set the         * upper left corner of this <code>Rectangle2D</code>         * @param w the value to use to set the width of this         * <code>Rectangle2D</code>         * @param h the value to use to set the height of this         * <code>Rectangle2D</code>	 */	public void setRect(double x, double y, double w, double h) {	    this.x = x;	    this.y = y;	    this.width = w;	    this.height = h;	}	/**	 * Sets this <code>Rectangle2D</code> to be the same as the         * specified <code>Rectangle2D</code>.         * @param r the specified <code>Rectangle2D</code>	 */	public void setRect(Rectangle2D r) {	    this.x = r.getX();	    this.y = r.getY();	    this.width = r.getWidth();	    this.height = r.getHeight();	}	/**	 * Determines where the specified double coordinates lie with respect	 * to this <code>Rectangle2D</code>.         * This method computes a binary OR of the appropriate mask values         * indicating, for each side of this <code>Rectangle2D</code>,         * whether or not the specified coordinates are on the same side         * of the edge as the rest of this <code>Rectangle2D</code>.         * @param x,&nbsp;y the specified coordinates         * @return the logical OR of all appropriate out codes.	         * @see Rectangle2D#OUT_LEFT	 * @see Rectangle2D#OUT_TOP	 * @see Rectangle2D#OUT_RIGHT	 * @see Rectangle2D#OUT_BOTTOM	 */	public int outcode(double x, double y) {	    int out = 0;	    if (this.width <= 0) {		out |= OUT_LEFT | OUT_RIGHT;	    } else if (x < this.x) {		out |= OUT_LEFT;	    } else if (x > this.x + this.width) {		out |= OUT_RIGHT;	    }	    if (this.height <= 0) {		out |= OUT_TOP | OUT_BOTTOM;	    } else if (y < this.y) {		out |= OUT_TOP;	    } else if (y > this.y + this.height) {		out |= OUT_BOTTOM;	    }	    return out;	}	/**	 * Returns the high precision bounding box of this         * <code>Rectangle2D</code>.         * @return the bounding box of this <code>Rectangle2D</code>.	 */	public Rectangle2D getBounds2D() {	    return new Double(x, y, width, height);	}	/**	 * Returns a new <code>Rectangle2D</code> object representing          * the intersection of this <code>Rectangle2D</code> with the         * specified <code>Rectangle2D</code>.	 * @param r the <code>Rectangle2D</code> to be intersected          * with this <code>Rectangle2D</code>	 * @return the largest <code>Rectangle2D</code> contained in          * both the specified <code>Rectangle2D</code> and in this         * <code>Rectangle2D</code>.	 */	public Rectangle2D createIntersection(Rectangle2D r) {	    Rectangle2D dest = new Rectangle2D.Double();	    Rectangle2D.intersect(this, r, dest);	    return dest;	}	/**	 * Returns a new <code>Rectangle2D</code> object representing          * the union of this <code>Rectangle2D</code> with the         * specified <code>Rectangle2D</code>.	 * @param r the <code>Rectangle2D</code> to be combined with         * this <code>Rectangle2D</code>	 * @return  the smallest <code>Rectangle2D</code> containing          * both the specified <code>Rectangle2D</code> and this          * <code>Rectangle2D</code>.	 */	public Rectangle2D createUnion(Rectangle2D r) {	    Rectangle2D dest = new Rectangle2D.Double();	    Rectangle2D.union(this, r, dest);	    return dest;	}	/**	 * Returns the <code>String</code> representation of this         * <code>Rectangle2D</code>.         * @return a <code>String</code> representing this          * <code>Rectangle2D</code>.	 */	public String toString() {	    return getClass().getName()		+ "[x=" + x +		",y=" + y +		",w=" + width +		",h=" + height + "]";	}    }    /**     * 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.     *     * @see java.awt.geom.Rectangle2D.Float     * @see java.awt.geom.Rectangle2D.Double     * @see java.awt.Rectangle     */    protected Rectangle2D() {    }    /**     * Sets the location and size of this <code>Rectangle2D</code>     * to the specified double values.     * @param x,&nbsp;y the coordinates to which to set the     * location of the upper left corner of this     * <code>Rectangle2D</code>     * @param w the value to use to set the width of this     * <code>Rectangle2D</code>     * @param h the value to use to set the height of this     * <code>Rectangle2D</code>     */    public abstract void setRect(double x, double y, double w, double h);    /**     * Sets this <code>Rectangle2D</code> to be the same as the specified     * <code>Rectangle2D</code>.     * @param r the specified <code>Rectangle2D</code>     */    public void setRect(Rectangle2D r) {	setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());    }    /**     * Tests if the specified line segment intersects the interior of this     * <code>Rectangle2D</code>.     * @param x1,&nbsp;y1 the first endpoint of the specified     * line segment     * @param x2,&nbsp;y2 the second endpoint of the specified     * line segment     * @return <code>true</code> if the specified line segment intersects     * the interior of this <code>Rectangle2D</code>; <code>false</code>     * otherwise.     */    public boolean intersectsLine(double x1, double y1, double x2, double y2) {	int out1, out2;	if ((out2 = outcode(x2, y2)) == 0) {	    return true;	}	while ((out1 = outcode(x1, y1)) != 0) {	    if ((out1 & out2) != 0) {		return false;	    }	    if ((out1 & (OUT_LEFT | OUT_RIGHT)) != 0) {		double x = getX();		if ((out1 & OUT_RIGHT) != 0) {		    x += getWidth();		}		y1 = y1 + (x - x1) * (y2 - y1) / (x2 - x1);		x1 = x;	    } else {		double y = getY();		if ((out1 & OUT_BOTTOM) != 0) {		    y += getHeight();		}		x1 = x1 + (y - y1) * (x2 - x1) / (y2 - y1);		y1 = y;	    }	}	return true;    }//#ifdef notdef    /**     * Tests if the specified line segment intersects the interior of this     * <code>Rectangle2D</code>.     * @param l the specified {@link Line2D} to test for intersection     * with the interior of this <code>Rectangle2D</code>     * @return <code>true</code> if the specified <code>Line2D</code>     * intersects the interior of this <code>Rectangle2D</code>;     * <code>false</code> otherwise.     */    public boolean intersectsLine(Line2D l) {	return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());    }//#endif    /**     * Determines where the specified coordinates lie with respect     * to this <code>Rectangle2D</code>.     * This method computes a binary OR of the appropriate mask values     * indicating, for each side of this <code>Rectangle2D</code>,     * whether or not the specified coordinates are on the same side     * of the edge as the rest of this <code>Rectangle2D</code>.     * @param x,&nbsp;y the specified coordinates     * @return the logical OR of all appropriate out codes.     * @see #OUT_LEFT     * @see #OUT_TOP     * @see #OUT_RIGHT     * @see #OUT_BOTTOM     */    public abstract int outcode(double x, double y);    /**     * Determines where the specified {@link Point2D} lies with      * respect to this <code>Rectangle2D</code>.     * This method computes a binary OR of the appropriate mask values     * indicating, for each side of this <code>Rectangle2D</code>,     * whether or not the specified <code>Point2D</code> is on the same     * side of the edge as the rest of this <code>Rectangle2D</code>.     * @param p the specified <code>Point2D</code>       * @return the logical OR of all appropriate out codes.     * @see #OUT_LEFT     * @see #OUT_TOP     * @see #OUT_RIGHT     * @see #OUT_BOTTOM     */    public int outcode(Point2D p) {	return outcode(p.getX(), p.getY());    }    /**     * Sets the location and size of the outer bounds of this      * <code>Rectangle2D</code> to the specified rectangular values.     * @param x,&nbsp;y the coordinates to which to set the     * location of the upper left corner of the outer bounds of      * this <code>Rectangle2D</code>     * @param w the value to use to set the width of the outer     * bounds of this <code>Rectangle2D</code>     * @param h the value to use to set the height of the outer     * bounds of this <code>Rectangle2D</code>     */    public void setFrame(double x, double y, double w, double h) {	setRect(x, y, w, h);    }    /**     * Returns the high precision bounding box of this     * <code>Rectangle2D</code>.     * @return the bounding box of this <code>Rectangle2D</code>.     */

⌨️ 快捷键说明

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