vcr-2d
v0.0.2
Published
<h1 align="center"> vcr-2d </h1> <h4 align="center"> 2d vector functions </h4>
Downloads
6
Readme
:sparkles: Features
- Uses TypeScript
- Immutable and mutable APIs
- Zero dependencies
:wrench: Example usage
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 }
Pure
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 }
:package: Install
npm
npm install vcr-2d
yarn
yarn add vcr-2d
:newspaper: API
Standard
import * as vcr from 'vcr-2d'
Pure
import * as vcr from 'vcr-2d/pure'
create
create({ x: 10, y: 10 })
// { x: 10, y: 10 }
add
add({ x: 10, y: 10 }, 5)
// { x: 15, y: 15 }
subtract
subtract({ x: 10, y: 10 }, 5)
// { x: 5, y: 5 }
divide
divide({ x: 15, y: 15 }, 5)
// { x: 3, y: 3 }
multiply
multiply({ x: 10, y: 10 }, 5)
// { x: 50, y: 50 }
floor
floor({ x: 10.456, y: 10.789 })
// { x: 10, y: 10 }
ceil
ceil({ x: 10.456, y: 10.789 })
// { x: 11, y: 11 }
normalize
normalize({ x: 1, y: 1 })
// { x: 0.7071067811865475, y: 0.7071067811865475 }
clone
clone({ x: 10, y: 10 })
// { x: 10, y: 10 }