cocos creator 向量
/**
!#en
Constructor
see {{#crossLink "cc/vec2:method"}}cc.v2{{/crossLink}} or {{#crossLink "cc/p:method"}}cc.p{{/crossLink}}
!#zh
构造函数,可查看 {{#crossLink "cc/vec2:method"}}cc.v2{{/crossLink}} 或者 {{#crossLink "cc/p:method"}}cc.p{{/crossLink}}
@param x x
@param y y
*/
constructor(x?: number, y?: number);
x: number;
y: number;
/**
!#en clone a Vec2 object
!#zh 克隆一个 Vec2 对象
*/
clone(): Vec2;
/**
!#en Sets vector with another's value
!#zh 设置向量值。
@param newValue !#en new value to set. !#zh 要设置的新值
*/
set(newValue: Vec2): Vec2;
/**
!#en Check whether two vector equal
!#zh 当前的向量是否与指定的向量相等。
@param other other
*/
equals(other: Vec2): boolean;
/**
!#en Check whether two vector equal with some degree of variance.
!#zh
近似判断两个点是否相等。<br/>
判断 2 个向量是否在指定数值的范围之内,如果在则返回 true,反之则返回 false。
@param other other
@param variance variance
*/
fuzzyEquals(other: Vec2, variance: number): boolean;
/**
!#en Transform to string with vector informations
!#zh 转换为方便阅读的字符串。
*/
toString(): string;
/**
!#en Calculate linear interpolation result between this vector and another one with given ratio
!#zh 线性插值。
@param to to
@param ratio the interpolation coefficient
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
*/
lerp(to: Vec2, ratio: number, out?: Vec2): Vec2;
/**
!#en Clamp the vector between from float and to float.
!#zh
返回指定限制区域后的向量。<br/>
向量大于 max_inclusive 则返回 max_inclusive。<br/>
向量小于 min_inclusive 则返回 min_inclusive。<br/>
否则返回自身。
@param min_inclusive min_inclusive
@param max_inclusive max_inclusive
@example
```js
var min_inclusive = cc.v2(0, 0);
var max_inclusive = cc.v2(20, 20);
var v1 = cc.v2(20, 20).clampf(min_inclusive, max_inclusive); // Vec2 {x: 20, y: 20};
var v2 = cc.v2(0, 0).clampf(min_inclusive, max_inclusive); // Vec2 {x: 0, y: 0};
var v3 = cc.v2(10, 10).clampf(min_inclusive, max_inclusive); // Vec2 {x: 10, y: 10};
```
*/
clampf(min_inclusive: Vec2, max_inclusive: Vec2): Vec2;
/**
!#en Adds this vector. If you want to save result to another vector, use add() instead.
!#zh 向量加法。如果你想保存结果到另一个向量,使用 add() 代替。
@param vector vector
@example
```js
var v = cc.v2(10, 10);
v.addSelf(cc.v2(5, 5));// return Vec2 {x: 15, y: 15};
```
*/
addSelf(vector: Vec2): Vec2;
/**
!#en Adds two vectors, and returns the new result.
!#zh 向量加法,并返回新结果。
@param vector vector
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
v.add(cc.v2(5, 5)); // return Vec2 {x: 15, y: 15};
var v1;
v.add(cc.v2(5, 5), v1); // return Vec2 {x: 15, y: 15};
```
*/
add(vector: Vec2, out?: Vec2): Vec2;
/**
!#en Subtracts one vector from this. If you want to save result to another vector, use sub() instead.
!#zh 向量减法。如果你想保存结果到另一个向量,可使用 sub() 代替。
@param vector vector
@example
```js
var v = cc.v2(10, 10);
v.subSelf(cc.v2(5, 5));// return Vec2 {x: 5, y: 5};
```
*/
subSelf(vector: Vec2): Vec2;
/**
!#en Subtracts one vector from this, and returns the new result.
!#zh 向量减法,并返回新结果。
@param vector vector
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
v.sub(cc.v2(5, 5)); // return Vec2 {x: 5, y: 5};
var v1;
v.sub(cc.v2(5, 5), v1); // return Vec2 {x: 5, y: 5};
```
*/
sub(vector: Vec2, out?: Vec2): Vec2;
/**
!#en Multiplies this by a number. If you want to save result to another vector, use mul() instead.
!#zh 缩放当前向量。如果你想结果保存到另一个向量,可使用 mul() 代替。
@param num num
@example
```js
var v = cc.v2(10, 10);
v.mulSelf(5);// return Vec2 {x: 50, y: 50};
```
*/
mulSelf(num: number): Vec2;
/**
!#en Multiplies by a number, and returns the new result.
!#zh 缩放向量,并返回新结果。
@param num num
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
v.mul(5); // return Vec2 {x: 50, y: 50};
var v1;
v.mul(5, v1); // return Vec2 {x: 50, y: 50};
```
*/
mul(num: number, out?: Vec2): Vec2;
/**
!#en Multiplies two vectors.
!#zh 分量相乘。
@param vector vector
@example
```js
var v = cc.v2(10, 10);
v.scaleSelf(cc.v2(5, 5));// return Vec2 {x: 50, y: 50};
```
*/
scaleSelf(vector: Vec2): Vec2;
/**
!#en Multiplies two vectors, and returns the new result.
!#zh 分量相乘,并返回新的结果。
@param vector vector
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
v.scale(cc.v2(5, 5)); // return Vec2 {x: 50, y: 50};
var v1;
v.scale(cc.v2(5, 5), v1); // return Vec2 {x: 50, y: 50};
```
*/
scale(vector: Vec2, out?: Vec2): Vec2;
/**
!#en Divides by a number. If you want to save result to another vector, use div() instead.
!#zh 向量除法。如果你想结果保存到另一个向量,可使用 div() 代替。
@param num num
@example
```js
var v = cc.v2(10, 10);
v.divSelf(5); // return Vec2 {x: 2, y: 2};
```
*/
divSelf(num: number): Vec2;
/**
!#en Divides by a number, and returns the new result.
!#zh 向量除法,并返回新的结果。
@param num num
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
v.div(5); // return Vec2 {x: 2, y: 2};
var v1;
v.div(5, v1); // return Vec2 {x: 2, y: 2};
```
*/
div(num: number, out?: Vec2): Vec2;
/**
!#en Negates the components. If you want to save result to another vector, use neg() instead.
!#zh 向量取反。如果你想结果保存到另一个向量,可使用 neg() 代替。
@example
```js
var v = cc.v2(10, 10);
v.negSelf(); // return Vec2 {x: -10, y: -10};
```
*/
negSelf(): Vec2;
/**
!#en Negates the components, and returns the new result.
!#zh 返回取反后的新向量。
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
@example
```js
var v = cc.v2(10, 10);
var v1;
v.neg(v1); // return Vec2 {x: -10, y: -10};
```
*/
neg(out?: Vec2): Vec2;
/**
!#en Dot product
!#zh 当前向量与指定向量进行点乘。
@param vector vector
@example
```js
var v = cc.v2(10, 10);
v.dot(cc.v2(5, 5)); // return 100;
```
*/
dot(vector?: Vec2): number;
/**
!#en Cross product
!#zh 当前向量与指定向量进行叉乘。
@param vector vector
@example
```js
var v = cc.v2(10, 10);
v.cross(cc.v2(5, 5)); // return 0;
```
*/
cross(vector?: Vec2): number;
/**
!#en Returns the length of this vector.
!#zh 返回该向量的长度。
@example
```js
var v = cc.v2(10, 10);
v.mag(); // return 14.142135623730951;
```
*/
mag(): number;
/**
!#en Returns the squared length of this vector.
!#zh 返回该向量的长度平方。
@example
```js
var v = cc.v2(10, 10);
v.magSqr(); // return 200;
```
*/
magSqr(): number;
/**
!#en Make the length of this vector to 1.
!#zh 向量归一化,让这个向量的长度为 1。
@example
```js
var v = cc.v2(10, 10);
v.normalizeSelf(); // return Vec2 {x: 0.7071067811865475, y: 0.7071067811865475};
```
*/
normalizeSelf(): Vec2;
/**
!#en
Returns this vector with a magnitude of 1.<br/>
<br/>
Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use normalizeSelf function.
!#zh
返回归一化后的向量。<br/>
<br/>
注意,当前向量不变,并返回一个新的归一化向量。如果你想来归一化当前向量,可使用 normalizeSelf 函数。
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
*/
normalize(out?: Vec2): Vec2;
/**
!#en Get angle in radian between this and vector.
!#zh 夹角的弧度。
@param vector vector
*/
angle(vector: Vec2): number;
/**
!#en Get angle in radian between this and vector with direction.
!#zh 带方向的夹角的弧度。
@param vector vector
*/
signAngle(vector: Vec2): number;
/**
!#en rotate
!#zh 返回旋转给定弧度后的新向量。
@param radians radians
@param out optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
*/
rotate(radians: number, out?: Vec2): Vec2;
/**
!#en rotate self
!#zh 按指定弧度旋转向量。
@param radians radians
*/
rotateSelf(radians: number): Vec2;
/**
!#en Calculates the projection of the current vector over the given vector.
!#zh 返回当前向量在指定 vector 向量上的投影向量。
@param vector vector
@example
```js
var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
v1.project(v2); // Vec2 {x: 20, y: 20};
```
*/
project(vector: Vec2): Vec2;
/**
Transforms the vec2 with a mat4. 3rd vector component is implicitly '0', 4th vector component is implicitly '1'
@param m matrix to transform with
@param out the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
*/
transformMat4(m: Mat4, out?: Vec2): Vec2;
/** !#en return a Vec2 object with x = 1 and y = 1.
!#zh 新 Vec2 对象。 */
static ONE: Vec2;
/** !#en return a Vec2 object with x = 0 and y = 0.
!#zh 返回 x = 0 和 y = 0 的 Vec2 对象。 */
static ZERO: Vec2;
/** !#en return a Vec2 object with x = 0 and y = 1.
!#zh 返回 x = 0 和 y = 1 的 Vec2 对象。 */
static UP: Vec2;
/** !#en return a Vec2 object with x = 1 and y = 0.
!#zh 返回 x = 1 和 y = 0 的 Vec2 对象。 */
static RIGHT: Vec2;