reformat code
This commit is contained in:
@@ -11,7 +11,7 @@ module es {
|
||||
* @param self
|
||||
* @param flag
|
||||
*/
|
||||
public static isFlagSet(self: number, flag: number): boolean{
|
||||
public static isFlagSet(self: number, flag: number): boolean {
|
||||
return (self & flag) != 0;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ module es {
|
||||
* @param self
|
||||
* @param flag
|
||||
*/
|
||||
public static isUnshiftedFlagSet(self: number, flag: number): boolean{
|
||||
public static isUnshiftedFlagSet(self: number, flag: number): boolean {
|
||||
flag = 1 << flag;
|
||||
return (self & flag) != 0;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ module es {
|
||||
* @param self
|
||||
* @param flag
|
||||
*/
|
||||
public static setFlagExclusive(self: number, flag: number){
|
||||
public static setFlagExclusive(self: number, flag: number) {
|
||||
return 1 << flag;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ module es {
|
||||
* @param self
|
||||
* @param flag
|
||||
*/
|
||||
public static setFlag(self: number, flag: number){
|
||||
public static setFlag(self: number, flag: number) {
|
||||
return (self | 1 << flag);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ module es {
|
||||
* @param self
|
||||
* @param flag
|
||||
*/
|
||||
public static unsetFlag(self: number, flag: number){
|
||||
public static unsetFlag(self: number, flag: number) {
|
||||
flag = 1 << flag;
|
||||
return (self & (~flag));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ module es {
|
||||
* 反转数值集合位
|
||||
* @param self
|
||||
*/
|
||||
public static invertFlags(self: number){
|
||||
public static invertFlags(self: number) {
|
||||
return ~self;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ module es {
|
||||
* 将弧度转换成角度。
|
||||
* @param radians 用弧度表示的角
|
||||
*/
|
||||
public static toDegrees(radians: number){
|
||||
public static toDegrees(radians: number) {
|
||||
return radians * 57.295779513082320876798154814105;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ module es {
|
||||
* 将角度转换为弧度
|
||||
* @param degrees
|
||||
*/
|
||||
public static toRadians(degrees: number){
|
||||
public static toRadians(degrees: number) {
|
||||
return degrees * 0.017453292519943295769236907684886;
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ module es {
|
||||
* @param rightMin
|
||||
* @param rightMax
|
||||
*/
|
||||
public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number){
|
||||
public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number) {
|
||||
return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin);
|
||||
}
|
||||
|
||||
public static lerp(value1: number, value2: number, amount: number){
|
||||
public static lerp(value1: number, value2: number, amount: number) {
|
||||
return value1 + (value2 - value1) * amount;
|
||||
}
|
||||
|
||||
public static clamp(value: number, min: number, max: number){
|
||||
public static clamp(value: number, min: number, max: number) {
|
||||
if (value < min)
|
||||
return min;
|
||||
|
||||
@@ -46,7 +46,7 @@ module es {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number){
|
||||
public static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number) {
|
||||
let radians = MathHelper.toRadians(angleInDegrees);
|
||||
return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ module es {
|
||||
* 如果值为偶数,返回true
|
||||
* @param value
|
||||
*/
|
||||
public static isEven(value: number){
|
||||
public static isEven(value: number) {
|
||||
return value % 2 == 0;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ module es {
|
||||
* 数值限定在0-1之间
|
||||
* @param value
|
||||
*/
|
||||
public static clamp01(value: number){
|
||||
public static clamp01(value: number) {
|
||||
if (value < 0)
|
||||
return 0;
|
||||
|
||||
@@ -73,7 +73,7 @@ module es {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static angleBetweenVectors(from: Vector2, to: Vector2){
|
||||
public static angleBetweenVectors(from: Vector2, to: Vector2) {
|
||||
return Math.atan2(to.y - from.y, to.x - from.x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,69 @@
|
||||
module es {
|
||||
export var matrixPool = [];
|
||||
|
||||
/**
|
||||
* 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。
|
||||
*/
|
||||
export class Matrix2D extends egret.Matrix{
|
||||
public get m11(): number{
|
||||
export class Matrix2D extends egret.Matrix {
|
||||
public get m11(): number {
|
||||
return this.a;
|
||||
}
|
||||
public set m11(value: number){
|
||||
|
||||
public set m11(value: number) {
|
||||
this.a = value;
|
||||
}
|
||||
public get m12(): number{
|
||||
|
||||
public get m12(): number {
|
||||
return this.b;
|
||||
}
|
||||
public set m12(value: number){
|
||||
|
||||
public set m12(value: number) {
|
||||
this.b = value;
|
||||
}
|
||||
public get m21(): number{
|
||||
|
||||
public get m21(): number {
|
||||
return this.c;
|
||||
}
|
||||
public set m21(value: number){
|
||||
|
||||
public set m21(value: number) {
|
||||
this.c = value;
|
||||
}
|
||||
public get m22(): number{
|
||||
|
||||
public get m22(): number {
|
||||
return this.d;
|
||||
}
|
||||
public set m22(value: number){
|
||||
|
||||
public set m22(value: number) {
|
||||
this.d = value;
|
||||
}
|
||||
|
||||
public get m31(): number {
|
||||
return this.tx;
|
||||
}
|
||||
public set m31(value: number){
|
||||
|
||||
public set m31(value: number) {
|
||||
this.tx = value;
|
||||
}
|
||||
public get m32(): number{
|
||||
|
||||
public get m32(): number {
|
||||
return this.ty;
|
||||
}
|
||||
public set m32(value: number){
|
||||
|
||||
public set m32(value: number) {
|
||||
this.ty = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从对象池中取出或创建一个新的Matrix对象。
|
||||
*/
|
||||
public static create(): Matrix2D{
|
||||
public static create(): Matrix2D {
|
||||
let matrix = matrixPool.pop();
|
||||
if (!matrix)
|
||||
matrix = new Matrix2D();
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public identity(): Matrix2D{
|
||||
public identity(): Matrix2D {
|
||||
this.a = this.d = 1;
|
||||
this.b = this.c = this.tx = this.ty = 0;
|
||||
return this;
|
||||
@@ -64,12 +76,12 @@ module es {
|
||||
}
|
||||
|
||||
public scale(sx: number, sy: number): Matrix2D {
|
||||
if (sx !== 1){
|
||||
if (sx !== 1) {
|
||||
this.a *= sx;
|
||||
this.c *= sx;
|
||||
this.tx *= sx;
|
||||
}
|
||||
if (sy !== 1){
|
||||
if (sy !== 1) {
|
||||
this.b *= sy;
|
||||
this.d *= sy;
|
||||
this.ty *= sy;
|
||||
@@ -108,7 +120,7 @@ module es {
|
||||
* 创建一个新的matrix, 它包含两个矩阵的和。
|
||||
* @param matrix
|
||||
*/
|
||||
public add(matrix: Matrix2D): Matrix2D{
|
||||
public add(matrix: Matrix2D): Matrix2D {
|
||||
this.m11 += matrix.m11;
|
||||
this.m12 += matrix.m12;
|
||||
|
||||
@@ -134,7 +146,7 @@ module es {
|
||||
return this;
|
||||
}
|
||||
|
||||
public divide(matrix: Matrix2D): Matrix2D{
|
||||
public divide(matrix: Matrix2D): Matrix2D {
|
||||
this.m11 /= matrix.m11;
|
||||
this.m12 /= matrix.m12;
|
||||
|
||||
@@ -147,15 +159,15 @@ module es {
|
||||
return this;
|
||||
}
|
||||
|
||||
public multiply(matrix: Matrix2D): Matrix2D{
|
||||
let m11 = ( this.m11 * matrix.m11 ) + ( this.m12 * matrix.m21 );
|
||||
let m12 = ( this.m11 * matrix.m12 ) + ( this.m12 * matrix.m22 );
|
||||
public multiply(matrix: Matrix2D): Matrix2D {
|
||||
let m11 = (this.m11 * matrix.m11) + (this.m12 * matrix.m21);
|
||||
let m12 = (this.m11 * matrix.m12) + (this.m12 * matrix.m22);
|
||||
|
||||
let m21 = ( this.m21 * matrix.m11 ) + ( this.m22 * matrix.m21 );
|
||||
let m22 = ( this.m21 * matrix.m12 ) + ( this.m22 * matrix.m22 );
|
||||
let m21 = (this.m21 * matrix.m11) + (this.m22 * matrix.m21);
|
||||
let m22 = (this.m21 * matrix.m12) + (this.m22 * matrix.m22);
|
||||
|
||||
let m31 = ( this.m31 * matrix.m11 ) + ( this.m32 * matrix.m21 ) + matrix.m31;
|
||||
let m32 = ( this.m31 * matrix.m12 ) + ( this.m32 * matrix.m22 ) + matrix.m32;
|
||||
let m31 = (this.m31 * matrix.m11) + (this.m32 * matrix.m21) + matrix.m31;
|
||||
let m32 = (this.m31 * matrix.m12) + (this.m32 * matrix.m22) + matrix.m32;
|
||||
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
@@ -169,7 +181,7 @@ module es {
|
||||
return this;
|
||||
}
|
||||
|
||||
public determinant(){
|
||||
public determinant() {
|
||||
return this.m11 * this.m22 - this.m12 * this.m21;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ module es {
|
||||
export class Rectangle extends egret.Rectangle {
|
||||
public _tempMat: Matrix2D;
|
||||
public _transformMat: Matrix2D;
|
||||
|
||||
/**
|
||||
* 获取矩形的最大点,即右下角
|
||||
*/
|
||||
@@ -18,6 +19,7 @@ module es {
|
||||
public get location() {
|
||||
return new Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
/** 左上角的坐标 */
|
||||
public set location(value: Vector2) {
|
||||
this.x = value.x;
|
||||
@@ -33,6 +35,41 @@ module es {
|
||||
this.height = value.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个矩形的最小/最大点(左上角,右下角的点)
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
*/
|
||||
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
|
||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定多边形的点,计算边界
|
||||
* @param points
|
||||
*/
|
||||
public static rectEncompassingPoints(points: Vector2[]) {
|
||||
// 我们需要求出x/y的最小值/最大值
|
||||
let minX = Number.POSITIVE_INFINITY;
|
||||
let minY = Number.POSITIVE_INFINITY;
|
||||
let maxX = Number.NEGATIVE_INFINITY;
|
||||
let maxY = Number.NEGATIVE_INFINITY;
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
let pt = points[i];
|
||||
|
||||
if (pt.x < minX) minX = pt.x;
|
||||
if (pt.x > maxX) maxX = pt.x;
|
||||
|
||||
if (pt.y < minY) minY = pt.y;
|
||||
if (pt.y > maxY) maxY = pt.y;
|
||||
}
|
||||
|
||||
return this.fromMinMax(minX, minY, maxX, maxY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否与另一个矩形相交
|
||||
* @param value
|
||||
@@ -58,17 +95,6 @@ module es {
|
||||
return new Vector2(this.width * 0.5, this.height * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个矩形的最小/最大点(左上角,右下角的点)
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
*/
|
||||
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
|
||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取矩形边界上与给定点最近的点
|
||||
* @param point
|
||||
@@ -142,8 +168,8 @@ module es {
|
||||
return boundsPoint;
|
||||
}
|
||||
|
||||
public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number){
|
||||
if (rotation == 0){
|
||||
public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number) {
|
||||
if (rotation == 0) {
|
||||
this.x = parentPosition.x + position.x - origin.x * scale.x;
|
||||
this.y = parentPosition.y + position.y - origin.y * scale.y;
|
||||
this.width = width * scale.x;
|
||||
@@ -183,29 +209,5 @@ module es {
|
||||
this.height = maxY - minY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定多边形的点,计算边界
|
||||
* @param points
|
||||
*/
|
||||
public static rectEncompassingPoints(points: Vector2[]) {
|
||||
// 我们需要求出x/y的最小值/最大值
|
||||
let minX = Number.POSITIVE_INFINITY;
|
||||
let minY = Number.POSITIVE_INFINITY;
|
||||
let maxX = Number.NEGATIVE_INFINITY;
|
||||
let maxY = Number.NEGATIVE_INFINITY;
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
let pt = points[i];
|
||||
|
||||
if (pt.x < minX) minX = pt.x;
|
||||
if (pt.x > maxX) maxX = pt.x;
|
||||
|
||||
if (pt.y < minY) minY = pt.y;
|
||||
if (pt.y > maxY) maxY = pt.y;
|
||||
}
|
||||
|
||||
return this.fromMinMax(minX, minY, maxX, maxY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,37 @@
|
||||
module es {
|
||||
/** 2d 向量 */
|
||||
export class Vector2 {
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
|
||||
private static readonly unitYVector = new Vector2(0, 1);
|
||||
private static readonly unitXVector = new Vector2(1, 0);
|
||||
private static readonly unitVector2 = new Vector2(1, 1);
|
||||
private static readonly zeroVector2 = new Vector2(0, 0);
|
||||
public static get zero(){
|
||||
return Vector2.zeroVector2;
|
||||
}
|
||||
|
||||
public static get one(){
|
||||
return Vector2.unitVector2;
|
||||
}
|
||||
|
||||
public static get unitX(){
|
||||
return Vector2.unitXVector;
|
||||
}
|
||||
|
||||
public static get unitY(){
|
||||
return Vector2.unitYVector;
|
||||
}
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
|
||||
/**
|
||||
* 从两个值构造一个带有X和Y的二维向量。
|
||||
* @param x 二维空间中的x坐标
|
||||
* @param y 二维空间的y坐标
|
||||
*/
|
||||
constructor(x? : number, y?: number){
|
||||
constructor(x?: number, y?: number) {
|
||||
this.x = x ? x : 0;
|
||||
this.y = y ? y : this.x;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public add(value: Vector2): Vector2{
|
||||
this.x += value.x;
|
||||
this.y += value.y;
|
||||
return this;
|
||||
public static get zero() {
|
||||
return Vector2.zeroVector2;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public divide(value: Vector2): Vector2{
|
||||
this.x /= value.x;
|
||||
this.y /= value.y;
|
||||
return this;
|
||||
public static get one() {
|
||||
return Vector2.unitVector2;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public multiply(value: Vector2): Vector2{
|
||||
this.x *= value.x;
|
||||
this.y *= value.y;
|
||||
return this;
|
||||
public static get unitX() {
|
||||
return Vector2.unitXVector;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public subtract(value: Vector2){
|
||||
this.x -= value.x;
|
||||
this.y -= value.y;
|
||||
return this;
|
||||
public static get unitY() {
|
||||
return Vector2.unitYVector;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +39,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static add(value1: Vector2, value2: Vector2){
|
||||
public static add(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
result.x = value1.x + value2.x;
|
||||
result.y = value1.y + value2.y;
|
||||
@@ -91,7 +51,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static divide(value1: Vector2, value2: Vector2){
|
||||
public static divide(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
result.x = value1.x / value2.x;
|
||||
result.y = value1.y / value2.y;
|
||||
@@ -103,7 +63,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static multiply(value1: Vector2, value2: Vector2){
|
||||
public static multiply(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
result.x = value1.x * value2.x;
|
||||
result.y = value1.y * value2.y;
|
||||
@@ -115,36 +75,19 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static subtract(value1: Vector2, value2: Vector2){
|
||||
public static subtract(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
result.x = value1.x - value2.x;
|
||||
result.y = value1.y - value2.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 变成一个方向相同的单位向量 */
|
||||
public normalize(){
|
||||
let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||
this.x *= val;
|
||||
this.y *= val;
|
||||
}
|
||||
|
||||
/** 返回它的长度 */
|
||||
public length(){
|
||||
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||
}
|
||||
|
||||
/** 对x和y值四舍五入 */
|
||||
public round(): Vector2{
|
||||
return new Vector2(Math.round(this.x), Math.round(this.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的Vector2
|
||||
* 它包含来自另一个向量的标准化值。
|
||||
* @param value
|
||||
*/
|
||||
public static normalize(value: Vector2){
|
||||
public static normalize(value: Vector2) {
|
||||
let val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
|
||||
value.x *= val;
|
||||
value.y *= val;
|
||||
@@ -156,7 +99,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static dot(value1: Vector2, value2: Vector2): number{
|
||||
public static dot(value1: Vector2, value2: Vector2): number {
|
||||
return (value1.x * value2.x) + (value1.y * value2.y);
|
||||
}
|
||||
|
||||
@@ -165,7 +108,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static distanceSquared(value1: Vector2, value2: Vector2){
|
||||
public static distanceSquared(value1: Vector2, value2: Vector2) {
|
||||
let v1 = value1.x - value2.x, v2 = value1.y - value2.y;
|
||||
return (v1 * v1) + (v2 * v2);
|
||||
}
|
||||
@@ -176,7 +119,7 @@ module es {
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
public static clamp(value1: Vector2, min: Vector2, max: Vector2){
|
||||
public static clamp(value1: Vector2, min: Vector2, max: Vector2) {
|
||||
return new Vector2(MathHelper.clamp(value1.x, min.x, max.x),
|
||||
MathHelper.clamp(value1.y, min.y, max.y));
|
||||
}
|
||||
@@ -187,7 +130,7 @@ module es {
|
||||
* @param value2 第二个向量
|
||||
* @param amount 权重值(0.0到1.0之间)
|
||||
*/
|
||||
public static lerp(value1: Vector2, value2: Vector2, amount: number){
|
||||
public static lerp(value1: Vector2, value2: Vector2, amount: number) {
|
||||
return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
|
||||
}
|
||||
|
||||
@@ -196,7 +139,7 @@ module es {
|
||||
* @param position
|
||||
* @param matrix
|
||||
*/
|
||||
public static transform(position: Vector2, matrix: Matrix2D){
|
||||
public static transform(position: Vector2, matrix: Matrix2D) {
|
||||
return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31,
|
||||
(position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32);
|
||||
}
|
||||
@@ -206,7 +149,7 @@ module es {
|
||||
* @param value1
|
||||
* @param value2
|
||||
*/
|
||||
public static distance(value1: Vector2, value2: Vector2){
|
||||
public static distance(value1: Vector2, value2: Vector2) {
|
||||
let v1 = value1.x - value2.x, v2 = value1.y - value2.y;
|
||||
return Math.sqrt((v1 * v1) + (v2 * v2));
|
||||
}
|
||||
@@ -215,7 +158,7 @@ module es {
|
||||
* 矢量反演的结果
|
||||
* @param value
|
||||
*/
|
||||
public static negate(value: Vector2){
|
||||
public static negate(value: Vector2) {
|
||||
let result: Vector2 = new Vector2();
|
||||
result.x = -value.x;
|
||||
result.y = -value.y;
|
||||
@@ -223,7 +166,64 @@ module es {
|
||||
return result;
|
||||
}
|
||||
|
||||
public equals(other: Vector2){
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public add(value: Vector2): Vector2 {
|
||||
this.x += value.x;
|
||||
this.y += value.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public divide(value: Vector2): Vector2 {
|
||||
this.x /= value.x;
|
||||
this.y /= value.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public multiply(value: Vector2): Vector2 {
|
||||
this.x *= value.x;
|
||||
this.y *= value.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public subtract(value: Vector2) {
|
||||
this.x -= value.x;
|
||||
this.y -= value.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** 变成一个方向相同的单位向量 */
|
||||
public normalize() {
|
||||
let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||
this.x *= val;
|
||||
this.y *= val;
|
||||
}
|
||||
|
||||
/** 返回它的长度 */
|
||||
public length() {
|
||||
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||
}
|
||||
|
||||
/** 对x和y值四舍五入 */
|
||||
public round(): Vector2 {
|
||||
return new Vector2(Math.round(this.x), Math.round(this.y));
|
||||
}
|
||||
|
||||
public equals(other: Vector2) {
|
||||
return other.x == this.x && other.y == this.y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ module es {
|
||||
public y: number;
|
||||
public z: number;
|
||||
|
||||
constructor(x: number, y: number, z: number){
|
||||
constructor(x: number, y: number, z: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
Reference in New Issue
Block a user