📄 line2d.java
字号:
throw new NoSuchElementException("line iterator out of bounds"); } if (at != null) at.transform(coords, 0, coords, 0, 1); return result; } }; } /** * Return a flat path iterator, possibly applying a transform on the result. * This iterator is not threadsafe. * * @param at the transform, or null * @param flatness ignored, since lines are already flat * @return a new path iterator * @see #getPathIterator(AffineTransform) */ public PathIterator getPathIterator(AffineTransform at, double flatness) { return getPathIterator(at); } /** * Create a new line of the same run-time type with the same contents as * this one. * * @return the clone * * @exception OutOfMemoryError If there is not enough memory available. * * @since 1.2 */ public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { throw (Error) new InternalError().initCause(e); // Impossible } } /** * This class defines a point in <code>double</code> precision. * * @author Eric Blake <ebb9@email.byu.edu> * @since 1.2 * @status updated to 1.4 */ public static class Double extends Line2D { /** The x coordinate of the first point. */ public double x1; /** The y coordinate of the first point. */ public double y1; /** The x coordinate of the second point. */ public double x2; /** The y coordinate of the second point. */ public double y2; /** * Construct the line segment (0,0)->(0,0). */ public Double() { } /** * Construct the line segment with the specified points. * * @param x1 the x coordinate of the first point * @param y1 the y coordinate of the first point * @param x2 the x coordinate of the second point * @param y2 the y coordinate of the second point */ public Double(double x1, double y1, double x2, double y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } /** * Construct the line segment with the specified points. * * @param p1 the first point * @param p2 the second point * @throws NullPointerException if either point is null */ public Double(Point2D p1, Point2D p2) { x1 = p1.getX(); y1 = p1.getY(); x2 = p2.getX(); y2 = p2.getY(); } /** * Return the x coordinate of the first point. * * @return the value of x1 */ public double getX1() { return x1; } /** * Return the y coordinate of the first point. * * @return the value of y1 */ public double getY1() { return y1; } /** * Return the first point. * * @return the point (x1,y1) */ public Point2D getP1() { return new Point2D.Double(x1, y1); } /** * Return the x coordinate of the second point. * * @return the value of x2 */ public double getX2() { return x2; } /** * Return the y coordinate of the second point. * * @return the value of y2 */ public double getY2() { return y2; } /** * Return the second point. * * @return the point (x2,y2) */ public Point2D getP2() { return new Point2D.Double(x2, y2); } /** * Set this line to the given points. * * @param x1 the new x coordinate of the first point * @param y1 the new y coordinate of the first point * @param x2 the new x coordinate of the second point * @param y2 the new y coordinate of the second point */ public void setLine(double x1, double y1, double x2, double y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } /** * Return the exact bounds of this line segment. * * @return the bounding box */ public Rectangle2D getBounds2D() { double x = Math.min(x1, x2); double y = Math.min(y1, y2); double w = Math.abs(x1 - x2); double h = Math.abs(y1 - y2); return new Rectangle2D.Double(x, y, w, h); } } // class Double /** * This class defines a point in <code>float</code> precision. * * @author Eric Blake <ebb9@email.byu.edu> * @since 1.2 * @status updated to 1.4 */ public static class Float extends Line2D { /** The x coordinate of the first point. */ public float x1; /** The y coordinate of the first point. */ public float y1; /** The x coordinate of the second point. */ public float x2; /** The y coordinate of the second point. */ public float y2; /** * Construct the line segment (0,0)->(0,0). */ public Float() { } /** * Construct the line segment with the specified points. * * @param x1 the x coordinate of the first point * @param y1 the y coordinate of the first point * @param x2 the x coordinate of the second point * @param y2 the y coordinate of the second point */ public Float(float x1, float y1, float x2, float y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } /** * Construct the line segment with the specified points. * * @param p1 the first point * @param p2 the second point * @throws NullPointerException if either point is null */ public Float(Point2D p1, Point2D p2) { x1 = (float) p1.getX(); y1 = (float) p1.getY(); x2 = (float) p2.getX(); y2 = (float) p2.getY(); } /** * Return the x coordinate of the first point. * * @return the value of x1 */ public double getX1() { return x1; } /** * Return the y coordinate of the first point. * * @return the value of y1 */ public double getY1() { return y1; } /** * Return the first point. * * @return the point (x1,y1) */ public Point2D getP1() { return new Point2D.Float(x1, y1); } /** * Return the x coordinate of the second point. * * @return the value of x2 */ public double getX2() { return x2; } /** * Return the y coordinate of the second point. * * @return the value of y2 */ public double getY2() { return y2; } /** * Return the second point. * * @return the point (x2,y2) */ public Point2D getP2() { return new Point2D.Float(x2, y2); } /** * Set this line to the given points. * * @param x1 the new x coordinate of the first point * @param y1 the new y coordinate of the first point * @param x2 the new x coordinate of the second point * @param y2 the new y coordinate of the second point */ 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; } /** * Set this line to the given points. * * @param x1 the new x coordinate of the first point * @param y1 the new y coordinate of the first point * @param x2 the new x coordinate of the second point * @param y2 the new y coordinate of the second point */ public void setLine(float x1, float y1, float x2, float y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } /** * Return the exact bounds of this line segment. * * @return the bounding box */ public Rectangle2D getBounds2D() { float x = Math.min(x1, x2); float y = Math.min(y1, y2); float w = Math.abs(x1 - x2); float h = Math.abs(y1 - y2); return new Rectangle2D.Float(x, y, w, h); } } // class Float} // class Line2D
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -