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

📄 point2d.java

📁 NetWar是一个实时策略游戏
💻 JAVA
字号:
/*
	Netwar
	Copyright (C) 2002  Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.

	This file is part of Netwar.

	Netwar 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 2 of the License, or
	(at your option) any later version.

	Netwar 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 Netwar; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package netwar.utils.vectorgraphics;

/** This class is used to represent a location or vector in screenspace. Although the structure holds two floats, you will generally call the getInt functions to get the integers because screenspace is in pixels. A Point2D can be translated into a Point3D with z = 0.
 * @author Kyle Kakligian
 */
public class Point2D {
    
    /** X-axis value or length.
     */
    public float x;
    
    /** Y-axis value or length.
     */    
	public float y;

        /** Constructs a Point2D at the orgin.
         */        
	public Point2D() {}
        /** Constructs a Point2D at the given point.
         * @param X X-axis value or length.
         * @param Y Y-axis value or length.
         */        
	public Point2D(float X, float Y) {x=X;y=Y;}
        /** Constructs a Point2D at the given point.
         * @param p Copy.
         */        
	public Point2D(Point2D p) {x = p.x; y = p.y;}

        /** Returns a new Point2D that is the scalar product of <B>this</B> one.
         * @param scalar Multiplier
         * @return A new Point2D.
         */        
	public Point2D getProduct(float scalar) {
		return new Point2D(x*scalar, y*scalar);
	}
        /** Returns a new Point2D that is the sum of <B>this</B> one, and the given vector.
         * @param p Vector
         * @return Returns a new Point2D.
         */        
	public Point2D getSum(Point2D p) {
		return new Point2D(x+p.x,y+p.y);
	}
        /** Returns the distance from the point to the orgin. (Or the vector length.)
         * @return Distance to orgin.
         */        
	public double getLength() {
		return Math.sqrt(x*x+y*y);
	}
        /** This method is a shortcut to Math.round(x) which returns an integer.
         * @return Returns <B>x</B> as an integer.
         */        
	public int getIntx() {
		return Math.round(x);
	}
        /** This method is a shortcut to Math.round(y) which returns an integer.
         * @return Returns <B>y</B> as an integer.
         */        
	public int getInty() {
		return Math.round(y);
	}
        /** Sets <B>this</B> point as a copy of the given one.
         * @param p The Point2D to copy.
         * @return Returns a reference to itself.
         */        
	public Point2D set(Point2D p)
	{  x = p.x; y = p.y; return this; }
        /** Sets <B>this</B> point from the given information.
         * @param X The new x-axis value.
         * @param Y The new y-axis value.
         * @return Returns a reference to itself.
         */        
	public Point2D set(float X, float Y)
	{  x = X;   y = Y; return this;  }

}

⌨️ 快捷键说明

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