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

📄 erectangle.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ERectangle.java * Written by: Dmitry Nadezhin, Sun Microsystems. * * Copyright (c) 2006 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.database.geometry;import com.sun.electric.database.text.ImmutableArrayList;import java.awt.Rectangle;import java.awt.geom.Rectangle2D;import java.io.Serializable;/** * The <code>ERectangle</code> immutable class defines a point representing * defined by a location (x,&nbsp;y) and dimension (w&nbsp;x&nbsp;h). * <p> * This class is used in Electric database. */public class ERectangle extends Rectangle2D implements Serializable {    public static final ERectangle ORIGIN = new ERectangle(0, 0, 0, 0);    public static final ERectangle[] NULL_ARRAY = {};    public static final ImmutableArrayList<ERectangle> EMPTY_LIST = new ImmutableArrayList<ERectangle>(NULL_ARRAY);        private final long gridMinX;    private final long gridMinY;    private final long gridMaxX;    private final long gridMaxY;    private final double lambdaMinX;    private final double lambdaMinY;    private final double lambdaMaxX;    private final double lambdaMaxY;    private final double lambdaWidth;    private final double lambdaHeight;    private final boolean isSmall;        /**     * Constructs and initializes a <code>ERectangle</code>     * from the specified grid coordinates.     * @param gridX,&nbsp;gridY the coordinates of the upper left corner     * of the newly constructed <code>ERectangle</code> in grid units.     * @param gridWidth the width of the     * newly constructed <code>ERectangle</code> in grid units.     * @param gridHeight the height of the     * newly constructed <code>ERectangle</code> in grid units.     */    private ERectangle(long gridX, long gridY, long gridWidth, long gridHeight) {        gridMinX = gridX;        gridMinY = gridY;        gridMaxX = gridX + gridWidth;        gridMaxY = gridY + gridHeight;        lambdaMinX = DBMath.gridToLambda(gridMinX);        lambdaMinY = DBMath.gridToLambda(gridMinY);        lambdaMaxX = DBMath.gridToLambda(gridMaxX);        lambdaMaxY = DBMath.gridToLambda(gridMaxY);        lambdaWidth = DBMath.gridToLambda(gridWidth);        lambdaHeight = DBMath.gridToLambda(gridHeight);        isSmall = GenMath.isSmallInt(gridMinX) & GenMath.isSmallInt(gridMinY) & GenMath.isSmallInt(gridMaxX) & GenMath.isSmallInt(gridMaxY);    }        /**     * Constructs and initializes a <code>ERectangle</code>     * from the specified long coordinates in lambda units.     * @param x the X coordinates of the upper left corner     * of the newly constructed <code>ERectangle</code>     * @param y the Y coordinates of the upper left corner     * of the newly constructed <code>ERectangle</code>     * @param w the width of the newly constructed <code>ERectangle</code>     * @param h the height of the newly constructed <code>ERectangle</code>     */    public static ERectangle fromLambda(double x, double y, double w, double h) {        return new ERectangle(DBMath.lambdaToGrid(x), DBMath.lambdaToGrid(y), DBMath.lambdaToGrid(w), DBMath.lambdaToGrid(h));    }        /**     * Constructs and initializes a <code>ERectangle</code>     * from the specified long coordinates in grid units.     * @param x the X coordinates of the upper left corner     * of the newly constructed <code>ERectangle</code>     * @param y the Y coordinates of the upper left corner     * of the newly constructed <code>ERectangle</code>     * @param w the width of the newly constructed <code>ERectangle</code>     * @param h the height of the newly constructed <code>ERectangle</code>     */    public static ERectangle fromGrid(long x, long y, long w, long h) {        return new ERectangle(x, y, w, h);    }        /**     * Returns <code>ERectangle</code> from specified <code>Rectangle2D</code> in lambda units     * snapped to the grid.     * @param r specified ERectangle     * @return Snapped ERectangle     */    public static ERectangle fromLambda(Rectangle2D r) {        if (r instanceof ERectangle) return (ERectangle)r;        return fromLambda(r.getX(), r.getY(), r.getWidth(), r.getHeight());    }        /**     * Returns <code>ERectangle</code> from specified <code>Rectangle2D</code> in grid units     * snapped to the grid.     * @param r specified ERectangle     * @return Snapped ERectangle     */    public static ERectangle fromGrid(Rectangle2D r) {//        if (r instanceof ERectangle) return (ERectangle)r;        long x1 = (long)Math.floor(r.getMinX());        long y1 = (long)Math.floor(r.getMinY());        long x2 = (long)Math.ceil(r.getMaxX());        long y2 = (long)Math.ceil(r.getMaxY());        return fromGrid(x1, y1, x2 - x1, y2 - y1);    }        /**     * Returns the X coordinate of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the X coordinate of this <code>ERectangle</code>.     */    @Override    public double getX() {        return lambdaMinX;    }        /**     * Returns the Y coordinate of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the X coordinate of this <code>ERectangle</code>.     */    @Override    public double getY() {        return lambdaMinY;    }        /**     * Returns the width of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the width of this <code>ERectangle</code>.     */    @Override    public double getWidth() {        return lambdaWidth;    }        /**     * Returns the heigth of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the heigth of this <code>ERectangle</code>.     */    @Override    public double getHeight() {        return lambdaHeight;    }        /**     * Returns the largest X coordinate of this <code>ERectangle</code>     * in lambda units in <code>double</code> precision.     * @return the largest x coordinate of this <code>ERectangle</code>.     */    @Override    public double getMaxX() {        return lambdaMaxX;    }        /**     * Returns the largest Y coordinate of this <code>ERectangle</code>     * in lambda units in <code>double</code> precision.     * @return the largest y coordinate of this <code>ERectangle</code>.     */    @Override    public double getMaxY() {        return lambdaMaxY;    }        /**     * Returns the X coordinate of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the X coordinate of this <code>ERectangle</code>.     */    public double getLambdaX() {        return lambdaMinX;    }        /**     * Returns the Y coordinate of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the X coordinate of this <code>ERectangle</code>.     */    public double getLambdaY() {        return lambdaMinY;    }        /**     * Returns the width of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the width of this <code>ERectangle</code>.     */    public double getLambdaWidth() {        return lambdaWidth;    }        /**     * Returns the heigth of this <code>ERectangle</code>     * in lambda units in double precision.     * @return the heigth of this <code>ERectangle</code>.     */    public double getLambdaHeight() {        return lambdaHeight;    }        /**     * Returns the smallest X coordinate of this <code>ERectangle</code>     * in lambda units in <code>double</code> precision.     * @return the smallest x coordinate of this <code>ERectangle</code>.     */

⌨️ 快捷键说明

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