mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
THREE.js: Vector2 improvements
* Added applyMatrix3 method. * Fixed signature of fromBufferAttribute method. * Added some missing docs.
This commit is contained in:
@@ -3,7 +3,7 @@ declare function ok(cond: any, desc?: string): void;
|
||||
declare function deepEqual<T>(a: T, b: T, desc?: string): void;
|
||||
declare function equal<T>(a: T, b: T, desc?: string): void;
|
||||
|
||||
// https://github.com/mrdoob/three.js/tree/master/test/unit/math
|
||||
// https://github.com/mrdoob/three.js/tree/master/test/unit/src/math
|
||||
|
||||
()=>{
|
||||
// -------------------------------------------- Constants
|
||||
@@ -2743,6 +2743,14 @@ declare function equal<T>(a: T, b: T, desc?: string): void;
|
||||
ok( b.y == -y, "Passed!" );
|
||||
});
|
||||
|
||||
test( "applyMatrix3", function () {
|
||||
var a = new THREE.Vector2( x, y );
|
||||
var m = new THREE.Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
|
||||
|
||||
a.applyMatrix3( m );
|
||||
ok( a.x == 18, "Passed!" );
|
||||
ok( a.y == 60, "Passed!" );
|
||||
});
|
||||
|
||||
test( "min/max/clamp", function() {
|
||||
var a = new THREE.Vector2( x, y );
|
||||
@@ -2898,6 +2906,15 @@ declare function equal<T>(a: T, b: T, desc?: string): void;
|
||||
ok( b.equals( a ), "Passed!" );
|
||||
});
|
||||
|
||||
test( "fromBufferAttribute", function() {
|
||||
var a = new THREE.Vector2();
|
||||
var attr = new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
|
||||
|
||||
a.fromBufferAttribute( attr, 0 );
|
||||
ok( a.x == 1, "Passed!" );
|
||||
ok( a.y == 2, "Passed!" );
|
||||
});
|
||||
|
||||
// -------------------------------------------- Vector3
|
||||
test( "constructor", function() {
|
||||
var a = new THREE.Vector3();
|
||||
|
||||
Vendored
+102
-15
@@ -4319,6 +4319,9 @@ export class Vector2 implements Vector {
|
||||
*/
|
||||
set(x: number, y: number): Vector2;
|
||||
|
||||
/**
|
||||
* Sets the x and y values of this vector both equal to scalar.
|
||||
*/
|
||||
setScalar(scalar: number): Vector2;
|
||||
|
||||
/**
|
||||
@@ -4335,11 +4338,11 @@ export class Vector2 implements Vector {
|
||||
* Sets a component of this vector.
|
||||
*/
|
||||
setComponent(index: number, value: number): void;
|
||||
|
||||
/**
|
||||
* Gets a component of this vector.
|
||||
*/
|
||||
getComponent(index: number): number;
|
||||
|
||||
/**
|
||||
* Clones this vector.
|
||||
*/
|
||||
@@ -4353,29 +4356,44 @@ export class Vector2 implements Vector {
|
||||
* Adds v to this vector.
|
||||
*/
|
||||
add(v: Vector2): Vector2;
|
||||
|
||||
/**
|
||||
* Adds the scalar value s to this vector's x and y values.
|
||||
*/
|
||||
addScalar(s: number): Vector2;
|
||||
/**
|
||||
* Sets this vector to a + b.
|
||||
*/
|
||||
addScalar(s: number): Vector2;
|
||||
addVectors(a: Vector2, b: Vector2): Vector2;
|
||||
addScaledVector( v: Vector2, s: number ): Vector2;
|
||||
/**
|
||||
* Adds the multiple of v and s to this vector.
|
||||
*/
|
||||
addScaledVector(v: Vector2, s: number): Vector2;
|
||||
|
||||
/**
|
||||
* Subtracts v from this vector.
|
||||
*/
|
||||
*/
|
||||
sub(v: Vector2): Vector2;
|
||||
|
||||
/**
|
||||
* Subtracts s from this vector's x and y components.
|
||||
*/
|
||||
subScalar(s: number): Vector2;
|
||||
/**
|
||||
* Sets this vector to a - b.
|
||||
*/
|
||||
subVectors(a: Vector2, b: Vector2): Vector2;
|
||||
|
||||
/**
|
||||
* Multiplies this vector by v.
|
||||
*/
|
||||
multiply(v: Vector2): Vector2;
|
||||
/**
|
||||
* Multiplies this vector by scalar s.
|
||||
*/
|
||||
multiplyScalar(scalar: number): Vector2;
|
||||
|
||||
/**
|
||||
* Divides this vector by v.
|
||||
*/
|
||||
divide(v: Vector2): Vector2;
|
||||
/**
|
||||
* Divides this vector by scalar s.
|
||||
@@ -4383,15 +4401,57 @@ export class Vector2 implements Vector {
|
||||
*/
|
||||
divideScalar(s: number): Vector2;
|
||||
|
||||
min(v: Vector2): Vector2;
|
||||
/**
|
||||
* Multiplies this vector (with an implicit 1 as the 3rd component) by m.
|
||||
*/
|
||||
applyMatrix3(m: Matrix3): Vector2;
|
||||
|
||||
/**
|
||||
* If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.
|
||||
*/
|
||||
min(v: Vector2): Vector2;
|
||||
/**
|
||||
* If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.
|
||||
*/
|
||||
max(v: Vector2): Vector2;
|
||||
|
||||
/**
|
||||
* If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value.
|
||||
* If this vector's x or y value is less than the min vector's x or y value, it is replaced by the corresponding value.
|
||||
* @param min the minimum x and y values.
|
||||
* @param max the maximum x and y values in the desired range.
|
||||
*/
|
||||
clamp(min: Vector2, max: Vector2): Vector2;
|
||||
/**
|
||||
* If this vector's x or y values are greater than the max value, they are replaced by the max value.
|
||||
* If this vector's x or y values are less than the min value, they are replaced by the min value.
|
||||
* @param min the minimum value the components will be clamped to.
|
||||
* @param max the maximum value the components will be clamped to.
|
||||
*/
|
||||
clampScalar(min: number, max: number): Vector2;
|
||||
/**
|
||||
* If this vector's length is greater than the max value, it is replaced by the max value.
|
||||
* If this vector's length is less than the min value, it is replaced by the min value.
|
||||
* @param min the minimum value the length will be clamped to.
|
||||
* @param max the maximum value the length will be clamped to.
|
||||
*/
|
||||
clampLength(min: number, max: number): Vector2;
|
||||
|
||||
/**
|
||||
* The components of the vector are rounded down to the nearest integer value.
|
||||
*/
|
||||
floor(): Vector2;
|
||||
/**
|
||||
* The x and y components of the vector are rounded up to the nearest integer value.
|
||||
*/
|
||||
ceil(): Vector2;
|
||||
/**
|
||||
* The components of the vector are rounded to the nearest integer value.
|
||||
*/
|
||||
round(): Vector2;
|
||||
/**
|
||||
* The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
|
||||
*/
|
||||
roundToZero(): Vector2;
|
||||
|
||||
/**
|
||||
@@ -4433,12 +4493,10 @@ export class Vector2 implements Vector {
|
||||
* Computes distance of this vector to v.
|
||||
*/
|
||||
distanceTo(v: Vector2): number;
|
||||
|
||||
/**
|
||||
* Computes squared distance of this vector to v.
|
||||
*/
|
||||
distanceToSquared(v: Vector2): number;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Vector2#manhattanDistanceTo .manhattanDistanceTo()} instead.
|
||||
*/
|
||||
@@ -4449,8 +4507,18 @@ export class Vector2 implements Vector {
|
||||
*/
|
||||
setLength(length: number): Vector2;
|
||||
|
||||
/**
|
||||
* Linearly interpolates between this vector and v, where alpha is the distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.
|
||||
* @param v vector to interpolate towards.
|
||||
* @param alpha interpolation factor in the closed interval [0, 1].
|
||||
*/
|
||||
lerp(v: Vector2, alpha: number): Vector2;
|
||||
|
||||
/**
|
||||
* Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the distance along the line connecting the two vectors - alpha = 0 will be v1, and alpha = 1 will be v2.
|
||||
* @param v1 the starting vector.
|
||||
* @param v2 vector to interpolate towards.
|
||||
* @param alpha interpolation factor in the closed interval [0, 1].
|
||||
*/
|
||||
lerpVectors(v1: Vector2, v2: Vector2, alpha: number): Vector2;
|
||||
|
||||
/**
|
||||
@@ -4458,13 +4526,32 @@ export class Vector2 implements Vector {
|
||||
*/
|
||||
equals(v: Vector2): boolean;
|
||||
|
||||
fromArray(xy: number[], offset?: number): Vector2;
|
||||
/**
|
||||
* Sets this vector's x value to be array[offset] and y value to be array[offset + 1].
|
||||
* @param array the source array.
|
||||
* @param offset (optional) offset into the array. Default is 0.
|
||||
*/
|
||||
fromArray(array: number[], offset?: number): Vector2;
|
||||
/**
|
||||
* Returns an array [x, y], or copies x and y into the provided array.
|
||||
* @param array (optional) array to store the vector to. If this is not provided, a new array will be created.
|
||||
* @param offset (optional) optional offset into the array.
|
||||
*/
|
||||
toArray(array?: number[], offset?: number): number[];
|
||||
|
||||
toArray(xy?: number[], offset?: number): number[];
|
||||
/**
|
||||
* Sets this vector's x and y values from the attribute.
|
||||
* @param attribute the source attribute.
|
||||
* @param index index in the attribute.
|
||||
*/
|
||||
fromBufferAttribute(attribute: BufferAttribute, index: number): Vector2;
|
||||
|
||||
fromBufferAttribute( attribute: BufferAttribute, index: number, offset?: number): Vector2;
|
||||
|
||||
rotateAround( center: Vector2, angle: number ): Vector2;
|
||||
/**
|
||||
* Rotates the vector around center by angle radians.
|
||||
* @param center the point around which to rotate.
|
||||
* @param angle the angle to rotate, in radians.
|
||||
*/
|
||||
rotateAround(center: Vector2, angle: number): Vector2;
|
||||
|
||||
/**
|
||||
* Computes the Manhattan length of this vector.
|
||||
|
||||
Reference in New Issue
Block a user