Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensor: Standardize Vector2, Vector3, Vector4, Color3, Color4, Quaternion, and Matrix #14235

Merged
merged 74 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
35af7f2
Added new types
james-pre Aug 30, 2023
0f5e219
Added Member, Flatten, and tensor
james-pre Aug 30, 2023
09ca803
Updated classes in vector.ts to use Constructor
james-pre Aug 30, 2023
bd84e4a
Removed TensorValue and fixed comments
james-pre Aug 30, 2023
dfeb3b1
Fixed wikipedia link
james-pre Aug 30, 2023
78fc212
Added Tensor to vector and color classes
james-pre Aug 31, 2023
1438578
Added IsTuple types
james-pre Aug 31, 2023
ab26305
Added public to Tensor and Vector members
james-pre Sep 1, 2023
f6fe9da
Fixed types being or not being DeepImmutable
james-pre Aug 24, 2023
1e989fd
Formatting
james-pre Sep 5, 2023
9f9e655
Added Tuple
james-pre Sep 5, 2023
9fda9b5
Updated arrayTools to use new Tuple type
james-pre Sep 11, 2023
1083709
Updated to use object.defineProperty for dimension
james-pre Sep 11, 2023
ecf9981
Fixed dimension values
james-pre Sep 12, 2023
df6d705
Added Dimension
james-pre Sep 12, 2023
94bdb99
Fixed Dimension import
james-pre Sep 12, 2023
57a238e
Fixed Tensor not working with non `number[]` types
james-pre Nov 10, 2023
1474e02
Fixed equalsToFloats not using Flatten
james-pre Nov 10, 2023
21b6534
Made Matrix Tensor-compatible
james-pre Nov 10, 2023
de01663
Updated Quaternion to be Tensor compatible
james-pre Nov 10, 2023
b4d8d06
Renamed I<Math>Like to <Math>Like
james-pre Nov 10, 2023
25769e7
Moved <Math>Like to correct files
james-pre Nov 10, 2023
539f1e6
Merge branch 'master' into tensor
james-pre Nov 10, 2023
25879aa
Fixed duplicate function implementation
james-pre Nov 10, 2023
706709f
Changed dimension to be Readonly
james-pre Nov 10, 2023
5501d33
Fixed mispelling
james-pre Nov 11, 2023
7728fe2
Updated Vector3.asArray and Matrix.asArray
james-pre Nov 11, 2023
e6d5a73
Updated test Playground
james-pre Nov 11, 2023
8094c96
Changed default Tensor value type to unknown[]
james-pre Nov 11, 2023
5e2253b
Added TensorValue
james-pre Nov 11, 2023
4c41e80
Merge branch 'master' into tensor
james-pre Nov 14, 2023
451a316
Fixed stuff from merge
james-pre Nov 14, 2023
e45c03f
Fixed JSDoc comment parameter order
james-pre Nov 14, 2023
9150d62
Added Tensor.rank
james-pre Nov 15, 2023
7ce70a9
Fixed typo
james-pre Nov 15, 2023
25d7989
Formatting
james-pre Nov 15, 2023
a8be563
Merge branch 'master' into tensor
james-pre Jan 6, 2024
ed6f9f0
Formatting
james-pre Jan 8, 2024
ec2ad1a
Merge remote-tracking branch 'upstream/master' into tensor
james-pre Jan 10, 2024
a59d834
Made Matrix.asArray zero-copy
james-pre Jan 10, 2024
3ccba05
Moved from defineProperty to defineProperties
james-pre Jan 11, 2024
2d06268
Reverted *Like changes
james-pre Feb 5, 2024
10f388f
Merge branch 'master' into tensor
james-pre Feb 5, 2024
a853276
Fixed JSDoc comments
james-pre Feb 5, 2024
2ae66a2
Formatting
james-pre Feb 5, 2024
584590e
Formatting (clean install)
james-pre Feb 5, 2024
6e95392
Fixed eslint warnings
james-pre Feb 5, 2024
934b667
Reverted IViewportLike
james-pre Feb 5, 2024
4a0c5cf
Reverted flloat -> number change in math.like
james-pre Feb 5, 2024
3edd805
Fixed imports
james-pre Feb 5, 2024
d30689d
Fixed more imports
james-pre Feb 6, 2024
75fef20
Reverted more organization changes
james-pre Feb 6, 2024
a148331
Updated directionalLightFrustumViewer._createGeometry vectors
james-pre Feb 7, 2024
d009e1a
Added Matrix.toArray backwards compatibility
james-pre Feb 12, 2024
509d5d1
Fixed RecursiveArray spelling
james-pre Feb 13, 2024
193f542
Fixed Tensor description
james-pre Feb 13, 2024
897a071
Fixed Vector description
james-pre Feb 13, 2024
4e38dc4
Comment overhaul
james-pre Feb 13, 2024
1dac6f5
Changed m.length to 16
james-pre Feb 13, 2024
f3fe026
Removed some method implementations from Color3 and Color4
james-pre Feb 13, 2024
9f20dfe
Added internal to doc comment for color methods
james-pre Feb 14, 2024
36d71d1
Removed methods from Quaternion
james-pre Feb 14, 2024
3431e55
Fixed Vector not implementing Vector
james-pre Feb 14, 2024
f1b41b5
made all Tensor instance methods abstract
james-pre Feb 14, 2024
cd2d360
Added abstract to Vector
james-pre Feb 14, 2024
038a9c9
Removed unused types
james-pre Feb 15, 2024
6d4c2ec
Removed Tensor.toString
james-pre Feb 15, 2024
24cd34a
Seperated instance and static of Tensor and Vector into interfaces
james-pre Feb 20, 2024
266017c
Added TensorStatic.prototype
james-pre Feb 20, 2024
0691ccf
Removed type parameters in Tensor and Vector methods
james-pre Feb 20, 2024
60f0496
Added Vector4 static side
james-pre Feb 20, 2024
2bd3676
Added static side to Quaternion
james-pre Feb 21, 2024
55efc41
Merge branch 'master' into tensor
james-pre Mar 2, 2024
c3764d8
Formatting
james-pre Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/dev/core/src/Maths/math.color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function colorChannelToGammaSpaceExact(color: number): number {
* Class used to hold a RGB color
*/
export class Color3 implements Tensor<Tuple<number, 3>> {
public readonly dimension: [number] = [3];
public declare readonly dimension: [4];
james-pre marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a new Color3 object from red, green, blue values, all between 0 and 1
Expand Down Expand Up @@ -997,12 +997,13 @@ export class Color3 implements Tensor<Tuple<number, 3>> {
return new Color3(Math.random(), Math.random(), Math.random());
}
}
Object.defineProperty(Color3.prototype, "dimension", { value: 3 });
james-pre marked this conversation as resolved.
Show resolved Hide resolved

/**
* Class used to hold a RBGA color
*/
export class Color4 implements Tensor<Tuple<number, 4>> {
public readonly dimension: [number] = [4];
public declare readonly dimension: [4];

/**
* Creates a new Color4 object from red, green, blue values, all between 0 and 1
Expand Down Expand Up @@ -1865,6 +1866,7 @@ export class Color4 implements Tensor<Tuple<number, 4>> {
return colors;
}
}
Object.defineProperty(Color4.prototype, "dimension", { value: 4 });

/**
* @internal
Expand Down
13 changes: 9 additions & 4 deletions packages/dev/core/src/Maths/math.vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Scalar } from "./math.scalar";
import { Epsilon } from "./math.constants";
import type { Viewport } from "./math.viewport";
import type { DeepImmutable, Nullable, FloatArray, float, Constructor, Tuple } from "../types";
import type { DeepImmutable, Nullable, FloatArray, float, Constructor, Tuple, Length } from "../types";
import { ArrayTools } from "../Misc/arrayTools";
import type { IPlaneLike } from "./math.like";
import { RegisterClass } from "../Misc/typeStore";
Expand All @@ -21,6 +21,8 @@ const _ExtractAsInt = (value: number) => {
* Reprents a vector of any dimension
james-pre marked this conversation as resolved.
Show resolved Hide resolved
*/
export declare abstract class Vector<N extends number[] = number[]> extends Tensor<N> {
james-pre marked this conversation as resolved.
Show resolved Hide resolved
public readonly dimension: [Length<N>];

/**
* Gets the length of the vector
* @returns the vector length (float)
Expand Down Expand Up @@ -199,7 +201,7 @@ export declare abstract class Vector<N extends number[] = number[]> extends Tens
export class Vector2 implements Vector<Tuple<number, 2>> {
private static _ZeroReadOnly = Vector2.Zero() as DeepImmutable<Vector2>;

public readonly dimension: [number] = [2];
public declare readonly dimension: [2];

/**
* Creates a new Vector2 from the given x and y coordinates
Expand Down Expand Up @@ -1197,6 +1199,7 @@ export class Vector2 implements Vector<Tuple<number, 2>> {
return Vector2.Distance(p, proj);
}
}
Object.defineProperty(Vector2.prototype, "dimension", { value: 2 });

/**
* Class used to store (x,y,z) vector representation
Expand All @@ -1217,7 +1220,7 @@ export class Vector3 implements Vector<Tuple<number, 3>> {
private static _ZeroReadOnly = Vector3.Zero() as DeepImmutable<Vector3>;
private static _OneReadOnly = Vector3.One() as DeepImmutable<Vector3>;

public readonly dimension: [number] = [3];
public declare readonly dimension: [3];

/** @internal */
public _x: number;
Expand Down Expand Up @@ -3353,14 +3356,15 @@ export class Vector3 implements Vector<Tuple<number, 3>> {
return ref;
}
}
Object.defineProperty(Vector3.prototype, "dimension", { value: 3 });

/**
* Vector4 class created for EulerAngle class conversion to Quaternion
*/
export class Vector4 implements Vector<Tuple<number, 4>> {
private static _ZeroReadOnly = Vector4.Zero() as DeepImmutable<Vector4>;

public readonly dimension: [4] = [4];
public declare readonly dimension: [4];

/**
* Creates a Vector4 object from the given floats.
Expand Down Expand Up @@ -4308,6 +4312,7 @@ export class Vector4 implements Vector<Tuple<number, 4>> {
return new Vector4(source._x, source._y, source._z, w);
}
}
Object.defineProperty(Vector4.prototype, "dimension", { value: 4 });

/**
* Class used to store quaternion data
Expand Down
22 changes: 2 additions & 20 deletions packages/dev/core/src/Misc/arrayTools.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */

import type { Nullable } from "../types";

/** @internal */
interface TupleTypes<T> {
2: [T, T];
3: [T, T, T];
4: [T, T, T, T];
5: [T, T, T, T, T];
6: [T, T, T, T, T, T];
7: [T, T, T, T, T, T, T];
8: [T, T, T, T, T, T, T, T];
9: [T, T, T, T, T, T, T, T, T];
10: [T, T, T, T, T, T, T, T, T, T];
11: [T, T, T, T, T, T, T, T, T, T, T];
12: [T, T, T, T, T, T, T, T, T, T, T, T];
13: [T, T, T, T, T, T, T, T, T, T, T, T, T];
14: [T, T, T, T, T, T, T, T, T, T, T, T, T, T];
15: [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T];
}
import type { Nullable, Tuple } from "../types";

/**
* Class containing a set of static utilities functions for arrays.
Expand All @@ -44,7 +26,7 @@ export class ArrayTools {
* @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
* @returns a new tuple filled with new objects.
*/
public static BuildTuple<T, N extends keyof TupleTypes<unknown>>(size: N, itemBuilder: () => T): TupleTypes<T>[N] {
public static BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N> {
return ArrayTools.BuildArray(size, itemBuilder) as any;
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ export type FromLength<N extends number> = _FromLength<N>;
/**
* Increments N
*/
export type Increment<N extends number> = Length<Unshift<FromLength<N>, 0>>;
export type Increment<N extends number> = Length<Unshift<_FromLength<N>, 0>>;

/**
* Decrements N
*/
export type Decrement<N extends number> = Length<Shift<FromLength<N>>>;
export type Decrement<N extends number> = Length<Shift<_FromLength<N>>>;

/**
* Gets the sum of A and B
*/
export type Add<A extends number, B extends number> = Length<Concat<FromLength<A>, FromLength<B>>>;
export type Add<A extends number, B extends number> = Length<Concat<_FromLength<A>, _FromLength<B>>>;

/**
* Subtracts B from A
*/
export type Subtract<A extends number, B extends number> = Length<Remove<FromLength<A>, FromLength<B>>>;
export type Subtract<A extends number, B extends number> = Length<Remove<_FromLength<A>, _FromLength<B>>>;

/**
* Gets the type of an array's members
Expand Down