atum
Version:
A Procedural Graph Based Javascript Library
1,035 lines (776 loc) • 33.7 kB
HTML
<html>
<head>
<meta charset="utf-8">
<title>Source: geometry/Vector.js</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<script src="scripts/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="styles/jaguar.css">
<script>
var config = {"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}};
</script>
</head>
<body>
<div id="wrap" class="clearfix">
<div class="navigation">
<h3 class="applicationName"><a href="index.html"></a></h3>
<div class="search">
<input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
</div>
<ul class="list">
<li class="item" data-name="Center">
<span class="title">
<a href="Center.html">Center</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Center#add"><a href="Center.html#add">add</a></li>
<li data-name="Center#cross"><a href="Center.html#cross">cross</a></li>
<li data-name="Center#divide"><a href="Center.html#divide">divide</a></li>
<li data-name="Center#dot"><a href="Center.html#dot">dot</a></li>
<li data-name="Center#key"><a href="Center.html#key">key</a></li>
<li data-name="Center#list"><a href="Center.html#list">list</a></li>
<li data-name="Center#magnitude"><a href="Center.html#magnitude">magnitude</a></li>
<li data-name="Center#multiply"><a href="Center.html#multiply">multiply</a></li>
<li data-name="Center#normalize"><a href="Center.html#normalize">normalize</a></li>
<li data-name="Center#perpendiculars"><a href="Center.html#perpendiculars">perpendiculars</a></li>
<li data-name="Center#rotate"><a href="Center.html#rotate">rotate</a></li>
<li data-name="Center#subtract"><a href="Center.html#subtract">subtract</a></li>
<li data-name="Center#toString"><a href="Center.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Corner">
<span class="title">
<a href="Corner.html">Corner</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Corner#add"><a href="Corner.html#add">add</a></li>
<li data-name="Corner#cross"><a href="Corner.html#cross">cross</a></li>
<li data-name="Corner#divide"><a href="Corner.html#divide">divide</a></li>
<li data-name="Corner#dot"><a href="Corner.html#dot">dot</a></li>
<li data-name="Corner#key"><a href="Corner.html#key">key</a></li>
<li data-name="Corner#list"><a href="Corner.html#list">list</a></li>
<li data-name="Corner#magnitude"><a href="Corner.html#magnitude">magnitude</a></li>
<li data-name="Corner#multiply"><a href="Corner.html#multiply">multiply</a></li>
<li data-name="Corner#normalize"><a href="Corner.html#normalize">normalize</a></li>
<li data-name="Corner#perpendiculars"><a href="Corner.html#perpendiculars">perpendiculars</a></li>
<li data-name="Corner#rotate"><a href="Corner.html#rotate">rotate</a></li>
<li data-name="Corner#subtract"><a href="Corner.html#subtract">subtract</a></li>
<li data-name="Corner#toString"><a href="Corner.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Diagram">
<span class="title">
<a href="Diagram.html">Diagram</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Edge">
<span class="title">
<a href="Edge.html">Edge</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Line">
<span class="title">
<a href="Line.html">Line</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Map">
<span class="title">
<a href="Map.html">Map</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Map#generate"><a href="Map.html#generate">generate</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="PointDistribution">
<span class="title">
<a href="PointDistribution.html">PointDistribution</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="PointDistribution.exports.circular"><a href="PointDistribution.html#.exports.circular">exports.circular</a></li>
<li data-name="PointDistribution.exports.hexagon"><a href="PointDistribution.html#.exports.hexagon">exports.hexagon</a></li>
<li data-name="PointDistribution.exports.jitteredGrid"><a href="PointDistribution.html#.exports.jitteredGrid">exports.jitteredGrid</a></li>
<li data-name="PointDistribution.exports.poisson"><a href="PointDistribution.html#.exports.poisson">exports.poisson</a></li>
<li data-name="PointDistribution.exports.random"><a href="PointDistribution.html#.exports.random">exports.random</a></li>
<li data-name="PointDistribution.exports.recursiveWang"><a href="PointDistribution.html#.exports.recursiveWang">exports.recursiveWang</a></li>
<li data-name="PointDistribution.exports.square"><a href="PointDistribution.html#.exports.square">exports.square</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Polygon">
<span class="title">
<a href="Polygon.html">Polygon</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Polygon#centroid"><a href="Polygon.html#centroid">centroid</a></li>
<li data-name="Polygon#inset"><a href="Polygon.html#inset">inset</a></li>
<li data-name="Polygon#isConvex"><a href="Polygon.html#isConvex">isConvex</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Rand">
<span class="title">
<a href="Rand.html">Rand</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Rand.rand"><a href="Rand.html#.rand">rand</a></li>
<li data-name="Rand.randHex"><a href="Rand.html#.randHex">randHex</a></li>
<li data-name="Rand.randHexColor"><a href="Rand.html#.randHexColor">randHexColor</a></li>
<li data-name="Rand.randInt"><a href="Rand.html#.randInt">randInt</a></li>
<li data-name="Rand.randRange"><a href="Rand.html#.randRange">randRange</a></li>
<li data-name="Rand.setSeed"><a href="Rand.html#.setSeed">setSeed</a></li>
<li data-name="Rand.vector"><a href="Rand.html#.vector">vector</a></li>
<li data-name="Rand#rand"><a href="Rand.html#rand">rand</a></li>
<li data-name="Rand#randHex"><a href="Rand.html#randHex">randHex</a></li>
<li data-name="Rand#randHexColor"><a href="Rand.html#randHexColor">randHexColor</a></li>
<li data-name="Rand#randInt"><a href="Rand.html#randInt">randInt</a></li>
<li data-name="Rand#randRange"><a href="Rand.html#randRange">randRange</a></li>
<li data-name="Rand#setSeed"><a href="Rand.html#setSeed">setSeed</a></li>
<li data-name="Rand#vector"><a href="Rand.html#vector">vector</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Rectangle">
<span class="title">
<a href="Rectangle.html">Rectangle</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Rectangle#centroid"><a href="Rectangle.html#centroid">centroid</a></li>
<li data-name="Rectangle#inset"><a href="Rectangle.html#inset">inset</a></li>
<li data-name="Rectangle#isConvex"><a href="Rectangle.html#isConvex">isConvex</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Redist">
<span class="title">
<a href="Redist.html">Redist</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Redist.exports.exp"><a href="Redist.html#.exports.exp">exports.exp</a></li>
<li data-name="Redist.exports.identity"><a href="Redist.html#.exports.identity">exports.identity</a></li>
<li data-name="Redist.exports.inverse"><a href="Redist.html#.exports.inverse">exports.inverse</a></li>
<li data-name="Redist.exports.pow"><a href="Redist.html#.exports.pow">exports.pow</a></li>
<li data-name="Redist.exports.step"><a href="Redist.html#.exports.step">exports.step</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Shape">
<span class="title">
<a href="Shape.html">Shape</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Triangle">
<span class="title">
<a href="Triangle.html">Triangle</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Triangle#centroid"><a href="Triangle.html#centroid">centroid</a></li>
<li data-name="Triangle#inset"><a href="Triangle.html#inset">inset</a></li>
<li data-name="Triangle#isConvex"><a href="Triangle.html#isConvex">isConvex</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Vector">
<span class="title">
<a href="Vector.html">Vector</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Vector.add"><a href="Vector.html#.add">add</a></li>
<li data-name="Vector.angle"><a href="Vector.html#.angle">angle</a></li>
<li data-name="Vector.avg"><a href="Vector.html#.avg">avg</a></li>
<li data-name="Vector.copy"><a href="Vector.html#.copy">copy</a></li>
<li data-name="Vector.cross"><a href="Vector.html#.cross">cross</a></li>
<li data-name="Vector.dist2"><a href="Vector.html#.dist2">dist2</a></li>
<li data-name="Vector.distance"><a href="Vector.html#.distance">distance</a></li>
<li data-name="Vector.distToSeg"><a href="Vector.html#.distToSeg">distToSeg</a></li>
<li data-name="Vector.distToSegSquared"><a href="Vector.html#.distToSegSquared">distToSegSquared</a></li>
<li data-name="Vector.dot"><a href="Vector.html#.dot">dot</a></li>
<li data-name="Vector.down"><a href="Vector.html#.down">down</a></li>
<li data-name="Vector.left"><a href="Vector.html#.left">left</a></li>
<li data-name="Vector.midpoint"><a href="Vector.html#.midpoint">midpoint</a></li>
<li data-name="Vector.proj"><a href="Vector.html#.proj">proj</a></li>
<li data-name="Vector.right"><a href="Vector.html#.right">right</a></li>
<li data-name="Vector.subtract"><a href="Vector.html#.subtract">subtract</a></li>
<li data-name="Vector.up"><a href="Vector.html#.up">up</a></li>
<li data-name="Vector.zero"><a href="Vector.html#.zero">zero</a></li>
<li data-name="Vector#add"><a href="Vector.html#add">add</a></li>
<li data-name="Vector#cross"><a href="Vector.html#cross">cross</a></li>
<li data-name="Vector#divide"><a href="Vector.html#divide">divide</a></li>
<li data-name="Vector#dot"><a href="Vector.html#dot">dot</a></li>
<li data-name="Vector#key"><a href="Vector.html#key">key</a></li>
<li data-name="Vector#list"><a href="Vector.html#list">list</a></li>
<li data-name="Vector#magnitude"><a href="Vector.html#magnitude">magnitude</a></li>
<li data-name="Vector#multiply"><a href="Vector.html#multiply">multiply</a></li>
<li data-name="Vector#normalize"><a href="Vector.html#normalize">normalize</a></li>
<li data-name="Vector#perpendiculars"><a href="Vector.html#perpendiculars">perpendiculars</a></li>
<li data-name="Vector#rotate"><a href="Vector.html#rotate">rotate</a></li>
<li data-name="Vector#subtract"><a href="Vector.html#subtract">subtract</a></li>
<li data-name="Vector#toString"><a href="Vector.html#toString">toString</a></li>
<li data-name="Vector#toString"><a href="Vector.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="module:Atum">
<span class="title">
<a href="module-Atum.html">module:Atum</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
</ul>
<ul class="events itemMembers">
</ul>
</li>
</ul>
</div>
<div class="main">
<h1 class="page-title" data-filename="geometry_Vector.js.html">Source: geometry/Vector.js</h1>
<section>
<article>
<pre class="prettyprint source "><code>class Vector {
/**
* @class Vector
*
* This is a basic vector class that is used for geometry, position inforamtion,
* movement infomation, and more complex structures.
* The vector class follows a immutable paradigm where changes are not made to the
* vectors themselves. Any change to a vector is returned as a new vector that
* must be captured.
*
* @description This vector class was constructed so that it can mirror two types of common
* point/vector type objects. This is having object properties stored as object
* properties (eg. vector.x, vector.y) or as list properties, [x, y] which can
* be accessed by vector[0], or vector[1].
*
* @summary Create a 2D Vector object
*
* @property {number} x The x vector component
* @property {number} y The y vector component
* @property {number} 0 The x vector component
* @property {number} 1 The y vector component
*
* @param {number|Vector} x The x component or another vector
* @param {number} [y] The y component
*/
constructor(x, y) {
if (x instanceof Vector || (x.x && x.y) && !y) {
this._set(x.x, x.y);
} else {
this._set(x, y);
}
}
//---- Helper Functions ----
/**
* Internal Helper Function for setting variable properties
*
* @private
* @param {number} x The x component
* @param {number} y The y component
* @memberof Vector
*/
_set(x, y) {
this.__proto__[0] = x;
this.__proto__[1] = y;
this.x = x;
this.y = y;
}
/**
* Get the vector key:Symbol representation
*
* @returns {Symbol} The vector key element
* @memberof Vector
*/
key() {
return this.list();
// return Symbol(this.list()); // Not currently working as a key symbol
}
/**
* Get the vector in list form
*
* @returns {number[]} List representation of the vector of length 2
* @memberof Vector
*/
list() {
return [this.x, this.y];
}
/**
* Returns the vector as a string of (x, y)
*
* @returns {string} The string representation of a vector in (x, y) form
* @memberof Vector
*/
toString() {
return `(${this.x}, ${this.y})`;
}
/**
* Get a copy of the input vector
*
* @param {Vector} v the vector to be coppied
* @returns {Vector} The vector copy
* @memberof Vector
*/
static copy(v) {
return new Vector(v.x, v.y);
}
/**
* Returns the vector as a string of (x, y)
*
* @returns {string} The string representation of a vector in (x, y) form
* @memberof Vector
*/
toString() {
return `(${this.x}, ${this.y})`;
}
//---- Basic Math Functions ----
/**
* Add two vectors element wise
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns {Vector} The vector result of adding the two vectors
* @memberof Vector
*/
static add(a, b) {
return new Vector(a.x + b.x, a.y + b.y);
}
/**
* Add this vector with another vector element wise
*
* @param {Vector} other The other vector
* @returns {Vector} The vector result of adding the two vectors
* @memberof Vector
*/
add(other) {
return Vector.add(this, other);
}
/**
* Subtract two vectors element wise
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second Vector
* @returns {Vector} The vector result of subtracting the two vectors
* @memberof Vector
*/
static subtract(a, b) {
return new Vector(a.x - b.x, a.y - b.y);
}
/**
* Subtract this vector with another vector element wise
*
* @param {Vector} other The other vector
* @returns {Vector} The vector result of subtracting the two vectors
* @memberof Vector
*/
subtract(other) {
return Vector.subtract(this, other);
}
/**
* Multiply the vector by a scalar value
*
* @param {number} scalar The number to multiply the vector by
* @returns {Vector} The result of multiplying the vector by a scalar
* element wise
* @memberof Vector
*/
multiply(scalar) {
return new Vector(this.x * scalar, this.y * scalar);
}
/**
* Divide the vector by a scalar value
*
* @param {number} scalar
* @returns {Vector} The result of multiplying the vector by a scalar
* @memberof Vector
*/
divide(scalar) {
return new Vector(this.x / scalar, this.y / scalar);
}
//---- Advanced Vector Functions ----
/**
* Get the magnitude of the vector
*
* @returns {number} The magniture of the vector
* @memberof Vector
*/
magnitude() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
// Get the unit vector
/**
* Get the normal vector of the current vector.
*
* @returns {Vector} A vector that is the normal compenent of the vector
* @memberof Vector
*/
normalize() {
return Vector.divide(this.magnitude());
}
/**
* Get the get the current vector rotated by a certain ammount
*
* @param {number} radians
* @returns {Vector} The vector that results from rotating the current
* vector by a particular ammount
* @memberof Vector
*/
rotate(radians) {
const c = Math.cos(radians);
const s = Math.sin(radians);
return new Vector(c * this.x - s * this.y, s * this.x + c * this.y);
}
/**
* Get the dot product of two vectors
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns {number} The dot product of the two vectors
* @memberof Vector
*/
static dot(a, b) {
return a.x * b.x + a.y * b.y;
}
/**
* Get the average location between several vectors
*
* @param {Vector[]} vectors The list of vectors to average
* @memberof Vector
*/
static avg(vectors) {
let average = Vector.zero();
for (const vector of vectors) {
average = Vector.add(average, vector);
}
return average.divide(vectors.length);
}
/**
* Get the dot product of this vector and another vector
*
* @param {Vector} other The other vector
* @returns {number} The dot product of this and the other vector
* @memberof Vector
*/
dot(other) {
return Vector.dot(this, other);
}
/**
* Get the cross product of two vectors
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns {number} The cross product of the two vectors
* @memberof Vector
*/
static cross(a, b) {
return a.x * b.y - a.y * b.x;
}
/**
* Get the cross product of this and the other vector
*
* @param {Vector} other The other vector
* @returns {number} The cross product of this and the other vector
* @memberof Vector
*/
cross(other) {
return Vector.cross(this, other);
}
//---- Purely Static Vector Functions ----
/**
* Get the midpoint between two vectors
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns The midpoint of two vectors
* @memberof Vector
*/
static midpoint(a, b) {
return new Vector((a.x + b.x) / 2, (a.y + b.y) / 2);
}
/**
* Get the projection of vector a onto vector b
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns The projection vector of a onto b
* @memberof Vector
*
* @todo Add assertion for non-zero length b vector
*/
static proj(a, b) {
return b.multiply(Vector.dot(a, b) / Math.pow(b.magnitude(), 2));
}
/**
* Get the angle between two vectors
*
* @static
* @param {Vector} a The frist vector
* @param {Vector} b The second vector
* @returns The angle between vector a and vector b
* @memberof Vector
*/
static angle(a, b) {
return Math.acos(Vector.dot(a, b) / (a.magnitude() * b.magnitude()));
}
/**
* Get the euclidean distance between two vectors
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns The euclidean distance between a and b
* @see {@link dist2}
* @memberof Vector
*/
static distance(a, b) {
return Math.sqrt(Vector.dist2(a, b));
}
/**
* Get the euclidean distnace squared between two vectors.
* This is used as a helper for the distnace function but can be used
* to save on speed by not doing the square root operation.
*
* @static
* @param {Vector} a The first vector
* @param {Vector} b The second vector
* @returns The euclidean distance squared between vector a and vector b
* @see {@link distnace}
* @memberof Vector
*/
static dist2(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
return dx * dx + dy * dy;
}
/**
* Get the shortest distance between the point p and the line
* segment v to w.
*
* @static
* @param {Vector} p The vector point
* @param {Vector} v The first line segment endpoint
* @param {Vector} w The second line segment endpoint
* @returns The shortest euclidean distance between point
* @see {@link distToSeg2}
* @see {@link http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment}
* @memberof Vector
*/
static distToSeg(p, v, w) {
return Math.sqrt(Vector.distToSeg2(p, v, w));
}
/**
* Get the shortest distance squared between the point p and the line
* segment v to w.
*
* @static
* @param {Vector} p The vector point
* @param {Vector} v The first line segment endpoint
* @param {Vector} w The second line segment endpoint
* @returns The shortest euclidean distance squared between point
* @see {@link distToSeg}
* @see {@link http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment}
* @memberof Vector
*/
static distToSegSquared(p, v, w) {
const l = Vector.dist2(v, w);
if (l === 0) { return Vector.dist2(p, v); }
let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l;
t = Math.max(0, Math.min(1, t));
return Vector.dist2(p, new Vector(v.x + t * (w.x - v.x),
v.y + t * (w.y - v.y)));
}
/**
* Get the two normal vectors that are perpendicular to the current vector
*
* @returns {Vector[]} The two normal vectors that are perpendicular
* to the vector. The first vector is the normal vector that is +90 deg or
* +PI/2 rad. The second vector is the noraml vector that is -90 deg or
* -PI/2 rad.
* @memberof Vector
*/
perpendiculars() {
const plus90 = new Vector(-this.y, this.x).normalize();
const minus90 = new Vector(this.y, -this.x).normalize();
return [plus90, minus90];
}
//---- Standard Static Vector Objects ----
/**
* Get a vector of no magnitude and no direction
*
* @static
* @function
* @returns {Vector} Vector of magnitude zero
* @memberof Vector
*/
static zero() {
"use strict";
return new Vector(0, 0);
}
/**
* Get the unit vector pointing in the positive y direction
*
* @static
* @function
* @returns {Vector} Unit vector pointing up
* @memberof Vector
*/
static up() {
"use strict";
return new Vector(0, 1);
}
/**
* Get the unit vector pointing in the negative y direction
*
* @static
* @function
* @returns {Vector} Unit vector pointing down
* @memberof Vector
*/
static down() {
"use strict";
return new Vector(0, -1);
}
/**
* Get the unit vector pointing in the negative x direction
*
* @static
* @function
* @returns {Vector} Unit vector pointing right
* @memberof Vector
*/
static left() {
"use strict";
return new Vector(-1, 0);
}
/**
* Get the unit vector pointing in the positive x direction
*
* @static
* @function
* @returns {Vector} Unit vector pointing right
* @memberof Vector
*/
static right() {
"use strict";
return new Vector(1, 0);
}
}
export default Vector;</code></pre>
</article>
</section>
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Oct 27 2017 19:20:05 GMT-0400 (Eastern Daylight Time)
</footer>
</div>
</div>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/main.js"></script>
</body>
</html>