- Uses TypeScript
- Immutable and mutable APIs
- Zero dependencies
import * as vcr from 'vcr-2d'
const vector = vcr.create(10, 10)
console.log(vector)
// { x: 10, y: 10}
vcr.add(vector, 5)
console.log(vector)
// { x: 15, y: 15 }
import * as vcr from 'vcr-2d/pure'
const vector = vcr.create(10, 10)
console.log(vector)
// { x: 10, y: 10}
const newVector = vcr.add(vector, 5)
console.log(newVector)
// { x: 15, y: 15 }
console.log(vector)
// { x: 10, y: 10 }
npm
npm install vcr-2d
yarn
yarn add vcr-2d
Standard
import * as vcr from 'vcr-2d'
Pure
import * as vcr from 'vcr-2d/pure'
create({ x: 10, y: 10 })
// { x: 10, y: 10 }
add({ x: 10, y: 10 }, 5)
// { x: 15, y: 15 }
subtract({ x: 10, y: 10 }, 5)
// { x: 5, y: 5 }
divide({ x: 15, y: 15 }, 5)
// { x: 3, y: 3 }
multiply({ x: 10, y: 10 }, 5)
// { x: 50, y: 50 }
floor({ x: 10.456, y: 10.789 })
// { x: 10, y: 10 }
ceil({ x: 10.456, y: 10.789 })
// { x: 11, y: 11 }
normalize({ x: 1, y: 1 })
// { x: 0.7071067811865475, y: 0.7071067811865475 }
clone({ x: 10, y: 10 })
// { x: 10, y: 10 }