Skip to content

sajmoni/vcr-2d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vcr-2d

2d vector functions

✨ Features

  • Uses TypeScript
  • Immutable and mutable APIs
  • Zero dependencies

🔧 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 }

📦 Install

npm

npm install vcr-2d

yarn

yarn add vcr-2d

📰 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 }

Source

Source - Pure

About

2d vector functions

Resources

Stars

Watchers

Forks

Packages

No packages published