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

📄 line2d.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)Line2D.java	1.27 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.geom;import java.awt.Shape;import java.awt.Rectangle;/** * This <code>Line2D</code> represents a line segment in (x,&nbsp;y) * coordinate space.  This class, like all of the Java 2D API, uses a * default coordinate system called <i>user space</i> in which the y-axis * values increase downward and x-axis values increase to the right.  For * more information on the user space coordinate system, see the  * <a href="http://java.sun.com/j2se/1.3/docs/guide/2d/spec/j2d-intro.fm2.html#61857"> * Coordinate Systems</a> section of the Java 2D Programmer's Guide.   * <p> * This class is only the abstract superclass for all objects that * store a 2D line segment. * The actual storage representation of the coordinates is left to * the subclass. * * @version 	1.27, 01/23/03 * @author	Jim Graham */public abstract class Line2D implements Shape, Cloneable {    /**     * A line segment specified with float coordinates.     */    public static class Float extends Line2D {	/**	 * The X coordinate of the start point of the line segment.	 */	public float x1;	/**	 * The Y coordinate of the start point of the line segment.	 */	public float y1;	/**	 * The X coordinate of the end point of the line segment.	 */	public float x2;	/**	 * The Y coordinate of the end point of the line segment.	 */	public float y2;	/**	 * Constructs and initializes a Line with coordinates (0, 0) -> (0, 0).	 */	public Float() {	}	/**	 * Constructs and initializes a Line from the specified coordinates.	 * @param X1,&nbsp;Y1 the first specified coordinates	 * @param X2,&nbsp;Y2 the second specified coordinates	 */	public Float(float X1, float Y1, float X2, float Y2) {	    setLine(X1, Y1, X2, Y2);	}	/**	 * Constructs and initializes a <code>Line2D</code> from the	 * specified {@link Point2D} objects.	 * @param p1 the first specified <code>Point2D</code>	 * @param p2 the second specified <code>Point2D</code>	 */	public Float(Point2D p1, Point2D p2) {	    setLine(p1, p2);	}	/**	 * Returns the X coordinate of the start point in double precision.	 * @return the x coordinate of this <code>Line2D</code> object's 	 * 	starting point in double precision. 	 */	public double getX1() {	    return (double) x1;	} 	/**	 * Returns the Y coordinate of the start point in double precision.         * @return the x coordinate of this <code>Line2D</code> object's 	 *	starting point in double precision.	 */	public double getY1() {	    return (double) y1;	}	/**	 * Returns the start point.	 * @return the starting <code>Point2D</code> object of this	 * 	<code>Line2D</code>.	 */	public Point2D getP1() {	    return new Point2D.Float(x1, y1);	}	/**	 * Returns the X coordinate of the end point in double precision.         * @return the x coordinate of this <code>Line2D</code> object's 	 * 	ending point in double precision.		 */	public double getX2() {	    return (double) x2;	}	/**	 * Returns the Y coordinate of the end point in double precision.         * @return the Y coordinate of this <code>Line2D</code> object's 	 *	ending point in double precision.	 */	public double getY2() {	    return (double) y2;	}	/**	 * Returns the end point.         * @return the ending <code>Point2D</code> object of this         *      <code>Line2D</code>.	 */	public Point2D getP2() {	    return new Point2D.Float(x2, y2);	}	/**	 * Sets the location of the endpoints of this <code>Line2D</code> 	 * to the specified double coordinates.	 * @param X1,&nbsp;Y1 the first specified coordinate	 * @param X2,&nbsp;Y2 the second specified coordinate	 */	public void setLine(double X1, double Y1, double X2, double Y2) {	    this.x1 = (float) X1;	    this.y1 = (float) Y1;	    this.x2 = (float) X2;	    this.y2 = (float) Y2;	}	/**	 * Sets the location of the endpoints of this <code>Line2D</code> 	 * to the specified float coordinates.	 * @param X1,&nbsp;Y1 the first specified coordinate	 * @param X2,&nbsp;Y2 the second specified coordinate	 */	public void setLine(float X1, float Y1, float X2, float Y2) {	    this.x1 = X1;	    this.y1 = Y1;	    this.x2 = X2;	    this.y2 = Y2;	}	/**	 * Returns the high-precision bounding box of this	 * <code>Line2D</code>.	 * @return a {@link Rectangle2D} that is the high-precision	 * 	bounding box of this <code>Line2D</code>.	 */	public Rectangle2D getBounds2D() {	    float x, y, w, h;	    if (x1 < x2) {		x = x1;		w = x2 - x1;	    } else {		x = x2;		w = x1 - x2;	    }	    if (y1 < y2) {		y = y1;		h = y2 - y1;	    } else {		y = y2;		h = y1 - y2;	    }	    return new Rectangle2D.Float(x, y, w, h);	}    }    /**     * A line segment specified with double coordinates.     */    public static class Double extends Line2D {	/**	 * The X coordinate of the start point of the line segment.	 */	public double x1;	/**	 * The Y coordinate of the start point of the line segment.	 */	public double y1;	/**	 * The X coordinate of the end point of the line segment.	 */	public double x2;	/**	 * The Y coordinate of the end point of the line segment.	 */	public double y2;	/**	 * Constructs and initializes a Line with coordinates (0, 0) -> (0, 0).	 */	public Double() {	}	/**	 * Constructs and initializes a <code>Line2D</code> from the         * specified coordinates.	 * @param X1,&nbsp;Y1 the first specified coordinate	 * @param X2,&nbsp;Y2 the second specified coordinate	 */	public Double(double X1, double Y1, double X2, double Y2) {	    setLine(X1, Y1, X2, Y2);	}	/**	 * Constructs and initializes a <code>Line2D</code> from the	 * specified <code>Point2D</code> objects.	 * @param p1,&nbsp;p2 the specified <code>Point2D</code> objects	 */	public Double(Point2D p1, Point2D p2) {	    setLine(p1, p2);	}	/**	 * Returns the X coordinate of the start point in double precision.         * @return the X coordinate of this <code>Line2D</code> object's 	 * 	starting point.	 */	public double getX1() {	    return x1;	}	/**	 * Returns the Y coordinate of the start point in double precision.         * @return the X coordinate of this <code>Line2D</code> object's 	 *	starting point.		 */	public double getY1() {	    return y1;	}	/**	 * Returns the starting <code>Point2D</code> of this	 * <code>Line2D</code>.	 * @return the starting <code>Point2D</code> of this	 * 	<code>Line2D</code>	 */	public Point2D getP1() {	    return new Point2D.Double(x1, y1);	}	/**	 * Returns the X coordinate of the end point in double precision.         * @return the X coordinate of this <code>Line2D</code> object's 	 * 	ending point.	 */	public double getX2() {	    return x2;	}	/**	 * Returns the Y coordinate of the end point in double precision.         * @return the Y coordinate of this <code>Line2D</code> object's 	 * 	starting point.		 */	public double getY2() {	    return y2;	}	/**	 * Returns the end <code>Point2D</code> of this	 * <code>Line2D</code>.	 * @return the ending <code>Point2D</code> of this 	 * 	<code>Line2D</code>.	 */	public Point2D getP2() {	    return new Point2D.Double(x2, y2);	}	/**	 * Sets the location of the endpoints of this <code>Line2D</code> 	 * to the specified double coordinates.	 * @param X1,&nbsp;Y1 the first specified coordinate	 * @param X2,&nbsp;Y2 the second specified coordinate	 */	public void setLine(double X1, double Y1, double X2, double Y2) {	    this.x1 = X1;	    this.y1 = Y1;	    this.x2 = X2;	    this.y2 = Y2;	}	/**	 * Returns the high-precision bounding box of this	 * <code>Line2D</code>.	 * @return a <code>Rectangle2D</code> that is the high-precision	 * 	bounding box of this <code>Line2D</code>.	 */	public Rectangle2D getBounds2D() {	    double x, y, w, h;	    if (x1 < x2) {		x = x1;		w = x2 - x1;	    } else {		x = x2;		w = x1 - x2;	    }	    if (y1 < y2) {		y = y1;		h = y2 - y1;	    } else {		y = y2;		h = y1 - y2;	    }	    return new Rectangle2D.Double(x, y, w, h);	}    }    /**     * 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 accessory

⌨️ 快捷键说明

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