-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
4,723 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
|
||
defaults: &defaults | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:lts | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/mongo:3.4.4 | ||
|
||
working_directory: ~/repo | ||
|
||
jobs: | ||
test: | ||
<<: *defaults | ||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: yarn test --coverage --coverageReporters=text-lcov | ./node_modules/coveralls/bin/coveralls.js | ||
deploy: | ||
<<: *defaults | ||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: yarn build | ||
- run: | ||
name: Authenticate with registry | ||
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc | ||
- run: | ||
name: Publish package | ||
command: npm publish | ||
|
||
workflows: | ||
version: 2 | ||
test-deploy: | ||
jobs: | ||
- test: | ||
filters: | ||
branches: | ||
only: master | ||
- deploy: | ||
requires: | ||
- test | ||
filters: | ||
tags: | ||
only: /^v*/ | ||
branches: | ||
only: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,5 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
# vector-2d [![CircleCI](https://circleci.com/gh/samuraime/vector-2d.svg?style=svg)](https://circleci.com/gh/samuraime/vector-2d) [![Coverage Status](https://coveralls.io/repos/github/samuraime/vector-2d/badge.svg?branch=master)](https://coveralls.io/github/samuraime/vector-2d?branch=master) | ||
|
||
a 2d vector `{ x, y }` for math / physics | ||
|
||
## Install | ||
|
||
```sh | ||
npm install vector-2d | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import Vector from 'vector-2d'; | ||
|
||
const vector = new Vector(1, 2); | ||
vector.mult(2); // { x: 2, y 4} | ||
``` | ||
|
||
or | ||
|
||
```js | ||
import { create, mult } from 'vector-2d'; | ||
|
||
const vector = create(1, 2); | ||
const doubleVector = mult(vector, 2); // { x: 2, y 4} | ||
``` | ||
|
||
## API | ||
|
||
### Vector | ||
|
||
`constructor :: (Number, Number) -> Vector` | ||
|
||
### Properties | ||
|
||
a vector is shape of `{ x, y }` | ||
|
||
- `x` | ||
- `y` | ||
|
||
### Static methods | ||
|
||
All static methods are immutable. | ||
|
||
#### operators | ||
|
||
- `add :: (Vector, Vector) -> Vector` | ||
|
||
add two vectors | ||
|
||
- `sub :: (Vector, Vector) -> Vector` | ||
|
||
subtract one vector from another. | ||
|
||
- `mult :: (Vector, Number) -> Vector` | ||
|
||
multiply by scalar | ||
|
||
- `div :: (Vector, Number) -> Vector` | ||
|
||
divide by scalar | ||
|
||
- `dot :: (Vector, Vector) -> Number` | ||
|
||
dot product | ||
|
||
- `cross :: (Vector, Vector) -> Number` | ||
|
||
cross product | ||
|
||
#### evaluate | ||
|
||
- `mag :: Vector -> Number` | ||
|
||
the magnitude of a vector | ||
|
||
- `magSq :: Vector -> Number` | ||
|
||
the square of the magnitude | ||
|
||
- `dir :: Vector -> Number` | ||
|
||
the direction of a vector | ||
|
||
- `dist :: (Vector, Vector) -> Number` | ||
|
||
the distance between two vectors | ||
|
||
- `distSq :: (Vector, Vector) -> Number` | ||
|
||
the square of the distance between two vectors | ||
|
||
- `angle :: (Vector, Vector) -> Number` | ||
|
||
the angle between two vectors, range [0, PI] | ||
|
||
#### create | ||
|
||
- `create :: (Number, Number) -> Vector` | ||
|
||
create a vector by rectangular form | ||
|
||
- `fromAngle :: (Number, Number) -> Vector` | ||
|
||
create a vector by angle | ||
|
||
- `normalize :: Vector -> Vector` | ||
|
||
normalize the vector to a length of 1 | ||
|
||
- `clone :: Vector -> Vector` | ||
|
||
create a new vector copy | ||
|
||
### Instance methods | ||
|
||
All instance methods are very similar to the statics. there're two differences. | ||
|
||
- `first argument` | ||
|
||
instance methods don't need first argument, it's itself. | ||
|
||
- `mutable` | ||
|
||
most of methods are mutable. | ||
|
||
#### operators | ||
|
||
- `add :: Vector -> Vector` | ||
|
||
adds a vector | ||
|
||
- `sub :: Vector -> Vector` | ||
|
||
subtract from another vector | ||
|
||
- `mult :: Number -> Vector` | ||
|
||
multiply a vector by a scalar | ||
|
||
- `div :: Number -> Vector` | ||
|
||
divide a vector by a scalar | ||
|
||
- `dot :: Vector -> Number` | ||
|
||
dot product | ||
|
||
- `cross :: Vector -> Number` | ||
|
||
cross product | ||
|
||
#### evaluate | ||
|
||
- `mag :: () -> Number` | ||
|
||
the magnitude of a vector | ||
|
||
- `magSq :: () -> Number` | ||
|
||
the square of the magnitude | ||
|
||
- `dir :: () -> Number` | ||
|
||
the direction of a vector | ||
|
||
- `dist :: Vector -> Number` | ||
|
||
the distance between two vectors | ||
|
||
- `distSq :: Vector -> Number` | ||
|
||
the square of the distance between two vectors | ||
|
||
- `angle :: Vector -> Number` | ||
|
||
the angle between two vectors, range [0, PI] | ||
|
||
#### create | ||
|
||
- `clone :: () -> Vector` | ||
|
||
create a vector copy, this's an immutable method | ||
|
||
- `normalize :: () -> Vector` | ||
|
||
create a unit vector | ||
|
||
#### manipulate | ||
|
||
- `set :: (Number, Number) -> Vector` | ||
|
||
set x, y of this vector | ||
|
||
- `setX :: Number -> Vector` | ||
|
||
set x of this vector | ||
|
||
- `setY :: Number -> Vector` | ||
|
||
set y of this vector | ||
|
||
- `setMag :: Number -> Vector` | ||
|
||
set the magnitude of this vector | ||
|
||
- `limit :: Number -> Vector` | ||
|
||
limit the magnitude of this vector | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "vector-2d", | ||
"version": "0.1.0", | ||
"description": "2d vector for math / physics", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"/lib" | ||
], | ||
"scripts": { | ||
"build": "babel src -d lib", | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/samuraime/vector-2d.git" | ||
}, | ||
"keywords": [ | ||
"vector", | ||
"2d", | ||
"math", | ||
"physics" | ||
], | ||
"author": "SamuraiMe", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/samuraime/vector-2d/issues" | ||
}, | ||
"homepage": "https://github.com/samuraime/vector-2d#readme", | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"coveralls": "^3.0.4", | ||
"jest": "^24.8.0" | ||
} | ||
} |
Oops, something went wrong.