Permalink
Browse files

rename to vector

  • Loading branch information...
tj committed Sep 30, 2012
1 parent 87be7f6 commit 50120a98de9d166057514816a307bc35a6f51814
Showing with 47 additions and 154 deletions.
  1. +3 −3 component.json
  2. +38 −38 index.js
  3. +4 −4 package.json
  4. +2 −2 test/index.html
  5. +0 −107 test/point.js
View
@@ -1,8 +1,8 @@
{
- "name": "point",
+ "name": "vector",
"version": "0.0.1",
- "description": "Point component",
- "keywords": ["point", "canvas"],
+ "description": "Vector component",
+ "keywords": ["vector", "canvas"],
"scripts": ["index.js"],
"dependencies": {},
"development": {
View
@@ -1,104 +1,104 @@
/**
- * Expose `Point`.
+ * Expose `Vector`.
*/
-module.exports = Point;
+module.exports = Vector;
/**
- * Initialize a new `Point` with x / y.
+ * Initialize a new `Vector` with x / y.
*
* @param {Number} x
* @param {Number} y
* @api public
*/
-function Point(x, y) {
- if (!(this instanceof Point)) return new Point(x, y);
+function Vector(x, y) {
+ if (!(this instanceof Vector)) return new Vector(x, y);
this.x = x;
this.y = y;
}
/**
- * Return a negated point.
+ * Return a negated vector.
*
- * @return {Point}
+ * @return {Vector}
* @api public
*/
-Point.prototype.negate = function(){
- return new Point(-this.x, -this.y);
+Vector.prototype.negate = function(){
+ return new Vector(-this.x, -this.y);
};
/**
* Add x / y.
*
- * @param {Point} p
- * @return {Point} new point
+ * @param {Vector} p
+ * @return {Vector} new vector
* @api public
*/
-Point.prototype.add = function(p){
- return new Point(this.x + p.x, this.y + p.y);
+Vector.prototype.add = function(p){
+ return new Vector(this.x + p.x, this.y + p.y);
};
/**
* Sub x / y.
*
- * @param {Point} p
- * @return {Point} new point
+ * @param {Vector} p
+ * @return {Vector} new vector
* @api public
*/
-Point.prototype.sub = function(p){
- return new Point(this.x - p.x, this.y - p.y);
+Vector.prototype.sub = function(p){
+ return new Vector(this.x - p.x, this.y - p.y);
};
/**
* Multiply x / y.
*
- * @param {Point} p
- * @return {Point} new point
+ * @param {Vector} p
+ * @return {Vector} new vector
* @api public
*/
-Point.prototype.mul = function(p){
- return new Point(this.x * p.x, this.y * p.y);
+Vector.prototype.mul = function(p){
+ return new Vector(this.x * p.x, this.y * p.y);
};
/**
* Divide x / y.
*
- * @param {Point} p
- * @return {Point} new point
+ * @param {Vector} p
+ * @return {Vector} new vector
* @api public
*/
-Point.prototype.div = function(p){
- return new Point(this.x / p.x, this.y / p.y);
+Vector.prototype.div = function(p){
+ return new Vector(this.x / p.x, this.y / p.y);
};
/**
- * Check if these points are the same.
+ * Check if these vectors are the same.
*
- * @param {Point} p
+ * @param {Vector} p
* @return {Boolean}
* @api public
*/
-Point.prototype.equals = function(p){
+Vector.prototype.equals = function(p){
return this.x == p.x && this.y == p.y;
};
/**
- * Return a clone of this point.
+ * Return a clone of this vector.
*
- * @return {Point} new point
+ * @return {Vector} new vector
* @api public
*/
-Point.prototype.clone = function(){
- return new Point(this.x, this.y);
+Vector.prototype.clone = function(){
+ return new Vector(this.x, this.y);
};
/**
@@ -108,7 +108,7 @@ Point.prototype.clone = function(){
* @api public
*/
-Point.prototype.angle = function(){
+Vector.prototype.angle = function(){
return Math.atan2(this.x, this.y);
};
@@ -119,19 +119,19 @@ Point.prototype.angle = function(){
* @api public
*/
-Point.prototype.degrees = function(){
+Vector.prototype.degrees = function(){
return this.angle() * 180 / Math.PI;
};
/**
- * Return the distance between points.
+ * Return the distance between vectors.
*
- * @param {Point} p
+ * @param {Vector} p
* @return {Number}
* @api public
*/
-Point.prototype.distance = function(p){
+Vector.prototype.distance = function(p){
var x = this.x - p.x;
var y = this.y - p.y;
return Math.sqrt(x * x + y * y);
@@ -144,7 +144,7 @@ Point.prototype.distance = function(p){
* @api public
*/
-Point.prototype.toString = function(){
+Vector.prototype.toString = function(){
return '(' + this.x + ', ' + this.y + ')';
};
View
@@ -1,11 +1,11 @@
{
- "name": "point-component",
+ "name": "vector-component",
"version": "0.0.1",
- "description": "Point",
- "keywords": ["point"],
+ "description": "Vector",
+ "keywords": ["vector"],
"component": {
"scripts": {
- "point/index.js": "index.js"
+ "vector/index.js": "index.js"
}
}
}
View
@@ -1,6 +1,6 @@
<html>
<head>
- <title>point tests</title>
+ <title>vector tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="mocha/mocha.css" />
<script src="mocha/mocha.js"></script>
@@ -14,7 +14,7 @@
<body>
<div id="mocha"></div>
<script src="../build/build.js"></script>
- <script src="point.js"></script>
+ <script src="vector.js"></script>
<script>
mocha.run();
</script>
View
@@ -1,107 +0,0 @@
-
-var Point = require('point')
- , assert = require('component-assert');
-
-describe('Point(x, y)', function(){
- it('should return a new point', function(){
- var p = Point(5, 10);
- assert(p instanceof Point);
- assert(5 == p.x);
- assert(10 == p.y);
- })
-
- describe('#negate()', function(){
- it('should return a negated point', function(){
- var p = Point(5, 10).negate();
- assert(-5 == p.x);
- assert(-10 == p.y);
- })
- })
-
- describe('#add(p)', function(){
- it('should add', function(){
- var p = Point(0, 5).add(Point(5, 10));
- assert(5 == p.x);
- assert(15 == p.y);
- })
- })
-
- describe('#sub(p)', function(){
- it('should subtract', function(){
- var p = Point(10, 10).sub(Point(5, 2));
- assert(5 == p.x);
- assert(8 == p.y);
- })
- })
-
- describe('#mul(p)', function(){
- it('should multiply', function(){
- var p = Point(10, 10).mul(Point(5, 5));
- assert(50 == p.x);
- assert(50 == p.y);
- })
- })
-
- describe('#div(p)', function(){
- it('should divide', function(){
- var p = Point(50, 50).div(Point(5, 5));
- assert(10 == p.x);
- assert(10 == p.y);
- })
- })
-
- describe('#angle()', function(){
- it('should return the angle in radians', function(){
- var rad = Point(50, 50).angle();
- assert('0.79' == rad.toFixed(2));
- })
- })
-
- describe('#degress()', function(){
- it('should return the angle in degrees', function(){
- var deg = Point(50, 50).degrees();
- assert(45 == deg);
- })
- })
-
- describe('#clone()', function(){
- it('should return a clone of the point', function(){
- var p = Point(5, 5);
- var a = p.clone();
- assert(p !== a);
- assert(5 == a.x);
- assert(5 == a.y);
- })
- })
-
- describe('#distance(p)', function(){
- it('should return the distance between points', function(){
- var a = Point(5, 5);
- var b = Point(5, 5);
- assert(0 == a.distance(b));
-
- a = Point(2, 2);
- b = Point(10, 10);
- assert('11.3' == a.distance(b).toFixed(1));
- })
- })
-
- describe('#equals(p)', function(){
- it('should check if the points are equivalent', function(){
- var a = Point(5, 5);
- var b = Point(5, 10);
- var c = Point(5, 5);
- assert(false == a.equals(b));
- assert(true == a.equals(c));
- })
- })
-
- describe('#toString()', function(){
- it('should return a string representation', function(){
- var p = new Point(15, 30);
- assert('(15, 30)' == p.toString());
- var p = new Point(-5, 0);
- assert('(-5, 0)' == p.toString());
- })
- })
-})

0 comments on commit 50120a9

Please sign in to comment.