Giter Club home page Giter Club logo

vector2's Introduction

Build Status devDependencies docs

Vector2

Description

A Vector 2D class for simulations and games. This class is written in TypeScript and compiled out to a UMD module wrapped for easy consumption. Inspired by Unity and Processings Vector and PVector classes respectively.

Install

Clone this repo and run npm i. A postinstall script will build the files in the src and dist folders.

Usage

This package is wrapped in a UMD wrapper ready for consumption by most common module types. See below for implementations:

// ES2015
import Vector2 from 'vector2';

// CommonJS
const Vector2 = require('vector2');

Run gulp dev to run the file watchers. You can edit and change Vector2 and have the watchers execute the typescript task. When you are done editing you will need to package this for distribution by running the gulp dist task.

When using the Vector2 class, you will have the following methods and properties exposed for use:

Vector2
x: number
y: number
constructor(x: number, y: number)
set(x: number, y: number): void
limit(maxX: number, maxY: number): void
add(v: Vector2): void
sub(v: Vector2): void
mult(scalar: number): void
div(divisor: number): void
cross(v: Vector2): number
dot(v: Vector2): number
dist(v: Vector2): number
getAngle(): number
setAngle(angle: number): number
mag(): number
magSq(): number
normalize(): void
random(): void
copy(): Vector2
toArray(): number[]
toString(): string
isEqual(v: Vector2): boolean
zero(): void
abs(): void

Folder Structure

  • .vscode: Visual Studio Code configs here
  • dist: public distribution and consumption folder
    • lib: Vector2 lib UMD module files here
  • spec: unit tests here
  • src: source code here
    • lib: Vector2 lib source files here

Node Dependencies

As per usual you can find the dependencies in the package.json. They are listed below for ease of use:

Gulp Tasks

The build system makes of use of gulp on node. You can find all the build tasks in the gulpfile. Below find a listing of the tasks available from the command line:

  • gulp default: runs the gulp dev task
  • gulp html: moves HTML files from the src to te dist folder
  • gulp spec: executes Jasmine and runs the unit tests
  • gulp typescript: compiles TypeScript into JavaScript
  • gulp dev: runs gulp html, gulp typescript, gulp spec and gulp watch
  • gulp build: moves HTML files, builds TypeScript and creates dist lib
  • gulp dist: moves transpiled file to the dist folder
  • gulp watch: runs watches for HTML, TypeScript and Specs

Visual Studio Code users

I have included my settings.json file in the .vscode folder. Feel free to add, remove and change the settings to best suit your coding environment.

MIT License

Copyright (c) 2017 Brendon Conradie

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

vector2's People

Contributors

brendoncon avatar

Watchers

 avatar  avatar

vector2's Issues

setMag function

Should normalise and then set your magnitude using the normalise and multiply functions.

'primordials is not defined' on npm install

Hi, is this still maintained?
I'm getting a build error:

[email protected] postinstall
gulp build && gulp dist

[10:02:12] Failed to load external module @babel/register
[10:02:12] Requiring external module babel-register
fs.js:47
} = primordials;
^

ReferenceError: primordials is not defined
at fs.js:47:5
at req_ (/Users/ck/Desktop/vector2/node_modules/natives/index.js:143:24)
at Object.req [as require] (/Users/ck/Desktop/vector2/node_modules/natives/index.js:55:10)
at Object. (/Users/ck/Desktop/vector2/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions. [as .js] (/Users/ck/Desktop/vector2/node_modules/babel-register/lib/node.js:152:7)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR! code 1
npm ERR! path /Users/ck/Desktop/vector2
npm ERR! command failed
npm ERR! command sh -c gulp build && gulp dist

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ck/.npm/_logs/2022-10-10T17_02_12_486Z-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.