<h1 align="center"> vcr-2d </h1> <h4 align="center"> 2d vector functions </h4>
npm install vcr-2d- Immutable and mutable APIs
- Zero dependencies
- Fully typed
---
- :wrench: Example usage
- Pure
- :package: Install
- :newspaper: API
- create
- add
- subtract
- divide
- multiply
- floor
- ceil
- normalize
- clone
``ts
import * as vcr from 'vcr-2d'
const vector = vcr.create(10, 10)
console.log(vector)
// { x: 10, y: 10}
vcr.add(vector, { x: 5, y: 5 })
// If both x and y are the same, you can use the shorthand
vcr.add(vector, 5)
console.log(vector)
// { x: 15, y: 15 }
`
`ts
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 }
`
---
`console`
npm install vcr-2d
---
> Standard
`ts`
import * as vcr from 'vcr-2d'
> Pure
`ts`
import * as vcr from 'vcr-2d/pure'
`ts`
create({ x: 10, y: 10 })
// { x: 10, y: 10 }
`ts`
add({ x: 10, y: 10 }, 5)
// { x: 15, y: 15 }
`ts`
subtract({ x: 10, y: 10 }, 5)
// { x: 5, y: 5 }
`ts`
divide({ x: 15, y: 15 }, 5)
// { x: 3, y: 3 }
`ts`
multiply({ x: 10, y: 10 }, 5)
// { x: 50, y: 50 }
`ts`
floor({ x: 10.456, y: 10.789 })
// { x: 10, y: 10 }
`ts`
ceil({ x: 10.456, y: 10.789 })
// { x: 11, y: 11 }
`ts`
normalize({ x: 1, y: 1 })
// { x: 0.7071067811865475, y: 0.7071067811865475 }
`ts``
clone({ x: 10, y: 10 })
// { x: 10, y: 10 }