Repository: motion-canvas/motion-canvas
File: packages/core/src/types/Vector.ts (TypeScript)

Code before:
  | [T, T]
  | undefined;

export type Vector2Signal<T> = CompoundSignal<
  PossibleVector2,
  Vector2,
  'x' | 'y',
  T
>;

export type SimpleVector2Signal<T> = Signal<PossibleVector2, Vector2, T>;

/**
 * Represents a two-dimensional vector.
 */
export class Vector2 implements Type {
  public static readonly symbol = Symbol.for(
    '@motion-canvas/core/types/Vector2',
  );

  public static readonly zero = new Vector2();
  public static readonly one = new Vector2(1, 1);
  public static readonly right = new Vector2(1, 0);
  public static readonly left = new Vector2(-1, 0);
  public static readonly up = new Vector2(0, 1);
  public static readonly down = new Vector2(0, -1);

  public static readonly middle = new Vector2();
  public static readonly top = new Vector2(0, -1);
  public static readonly bottom = new Vector2(0, 1);
  public static readonly topLeft = new Vector2(-1, -1);
  public static readonly topRight = new Vector2(1, -1);
  public static readonly bottomLeft = new Vector2(-1, 1);
  public static readonly bottomRight = new Vector2(1, 1);

  public x = 0;
  public y = 0;

  public static createSignal(
    initial?: SignalValue<PossibleVector2>,
    interpolation: InterpolationFunction<Vector2> = Vector2.lerp,
    owner?: any,
  ): Vector2Signal<void> {
    return new CompoundSignalContext(
      ['x', 'y'],
      (value: PossibleVector2) => new Vector2(value),
      initial,
      interpolation,
      owner,
    ).toSignal();
  }

Review comment (bug):
These properties appear to be incorrect, but since they belong to a previous commit, and changing them might break existing projects, I elected to leave them alone and flag them for review.

From my understanding of Motion Canvas, the following changes should be made:
```suggestion
  public static readonly up = new Vector2(0, -1);
  public static readonly down = new Vector2(0, 1);
```

Code after:
  | [T, T]
  | undefined;

export type Vector2Signal<T> = CompoundSignal<
  PossibleVector2,
  Vector2,
  'x' | 'y',
  T
>;

export type SimpleVector2Signal<T> = Signal<PossibleVector2, Vector2, T>;

/**
 * Represents a two-dimensional vector.
 */
export class Vector2 implements Type {
  public static readonly symbol = Symbol.for(
    '@motion-canvas/core/types/Vector2',
  );

  public static readonly zero = new Vector2();
  public static readonly one = new Vector2(1, 1);
  public static readonly right = new Vector2(1, 0);
  public static readonly left = new Vector2(-1, 0);
  public static readonly up = new Vector2(0, 1);
  public static readonly down = new Vector2(0, -1);

  /**
   * A constant equal to `Vector2(0, -1)`
   */
  public static readonly top = new Vector2(0, -1);
  /**
   * A constant equal to `Vector2(0, 1)`
   */
  public static readonly bottom = new Vector2(0, 1);
  /**
   * A constant equal to `Vector2(-1, -1)`
   */
  public static readonly topLeft = new Vector2(-1, -1);
  /**
   * A constant equal to `Vector2(1, -1)`
   */
  public static readonly topRight = new Vector2(1, -1);
  /**
   * A constant equal to `Vector2(-1, 1)`
   */
  public static readonly bottomLeft = new Vector2(-1, 1);
  /**
   * A constant equal to `Vector2(1, 1)`
   */
  public static readonly bottomRight = new Vector2(1, 1);