https://github.com/anthonyec/vector2
↔️ Simple 2D vector library
https://github.com/anthonyec/vector2
library typescript vector2d vectors
Last synced: 2 months ago
JSON representation
↔️ Simple 2D vector library
- Host: GitHub
- URL: https://github.com/anthonyec/vector2
- Owner: anthonyec
- Created: 2023-01-26T14:11:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-20T11:08:25.000Z (almost 2 years ago)
- Last Synced: 2025-02-13T00:26:35.506Z (4 months ago)
- Topics: library, typescript, vector2d, vectors
- Language: TypeScript
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vector2
> Utility class written in TypeScript for dealing with 2D vectors in an immutable way.
## Why
I made this to better understand vectors and I like working with vectors that behave like primitive types (like in Godot), where the result is always a new value.## Usage
```ts
// Adding two vectors together.
const a = new Vector(10, 10);
const b = new Vector(50, 80);// Adding `a` to `b` will not modify `a`, it returns a new vector.
const result = a.add(b);// Methods can be chained.
const scaled = a.add(b).normalized().scale(10);
```