Class ObservableVector2d

Represents a point in a 3D coordinate vector that can be observed for changes.

Constructors

  • Creates a new ObservableVector3d instance.

    Parameters

    • x: number = 0

      The x-coordinate of the vector. Default is 0.

    • y: number = 0

      The y-coordinate of the vector. Default is 0.

    • Optionalcallback: (() => void)

      The callback function to be called when the point changes. Default is undefined.

        • (): void
        • Returns void

    Returns ObservableVector2d

Accessors

Methods

  • Calculates the Euclidean distance between this vector and another vector.

    Parameters

    Returns number

    The Euclidean distance between this vector and the given vector.

    let v1 = new Vector2d(3, 4);
    let v2 = new Vector2d(6, 8);
    v1.distance(v2); // returns 5
  • Checks if this vector is equal to another vector or a pair of coordinates.

    Parameters

    • Rest...args: [number, number] | [Vector2d] | [ObservableVector2d]

      Either two numbers representing x and y coordinates or a single Vector2d object.

    Returns boolean

    True if the coordinates are equal, false otherwise.

    let v1 = new Vector2d(3, 4);
    let v2 = new Vector2d(3, 4);
    v1.equals(v2); // returns true
    let v = new Vector2d(3, 4);
    v.equals(3, 4); // returns true