Commit a158773f authored by rockyl's avatar rockyl

增加toObj返回简单数据对象

parent 168e9845
......@@ -33,7 +33,7 @@ export function releaseVector2D(target) {
/**
* 2D矢量
*/
export default class Vector2D extends HashObject{
export default class Vector2D extends HashObject {
private _x: number;
private _y: number;
private onChange: Function;
......@@ -44,7 +44,7 @@ export default class Vector2D extends HashObject{
* @param y y分量
* @param onChange 当改变时触发
*/
constructor(x:number = 0, y:number = 0, onChange?: Function) {
constructor(x: number = 0, y: number = 0, onChange?: Function) {
super();
this.onChange = onChange;
......@@ -91,7 +91,7 @@ export default class Vector2D extends HashObject{
* @param x
* @param y
*/
setXY(x:number = 0, y:number = 0): Vector2D {
setXY(x: number = 0, y: number = 0): Vector2D {
this.x = x;
this.y = y;
......@@ -229,7 +229,7 @@ export default class Vector2D extends HashObject{
* 向量乘于某个数
* @param value
*/
multiply(value:number): Vector2D {
multiply(value: number): Vector2D {
this.x *= value;
this.y *= value;
return this;
......@@ -239,7 +239,7 @@ export default class Vector2D extends HashObject{
* 向量除于某个数
* @param value
*/
divide(value:number): Vector2D {
divide(value: number): Vector2D {
this.x /= value;
this.y /= value;
return this;
......@@ -309,6 +309,10 @@ export default class Vector2D extends HashObject{
return "[Vector2D (x:" + this.x + ", y:" + this.y + ")]";
}
toObj() {
return {x: this.x, y: this.y}
}
static corner(v1, v2) {
return Math.acos(v1.dotProd(v2) / (v1.length * v2.length));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment