kld-affine
Advanced tools
Comparing version 0.0.6 to 0.1.0
@@ -21,8 +21,46 @@ /** | ||
function Matrix2D(a, b, c, d, e, f) { | ||
this.a = (a !== undefined) ? a : 1; | ||
this.b = (b !== undefined) ? b : 0; | ||
this.c = (c !== undefined) ? c : 0; | ||
this.d = (d !== undefined) ? d : 1; | ||
this.e = (e !== undefined) ? e : 0; | ||
this.f = (f !== undefined) ? f : 0; | ||
Object.defineProperties(this, { | ||
"a": { | ||
value: (a !== undefined) ? a : 1, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"b": { | ||
value: (b !== undefined) ? b : 0, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"c": { | ||
value: (c !== undefined) ? c : 0, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"d": { | ||
value: (d !== undefined) ? d : 1, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"e": { | ||
value: (e !== undefined) ? e : 0, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"f": { | ||
value: (f !== undefined) ? f : 0, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
} | ||
}); | ||
// this.a = (a !== undefined) ? a : 1; | ||
// this.b = (b !== undefined) ? b : 0; | ||
// this.c = (c !== undefined) ? c : 0; | ||
// this.d = (d !== undefined) ? d : 1; | ||
// this.e = (e !== undefined) ? e : 0; | ||
// this.f = (f !== undefined) ? f : 0; | ||
} | ||
@@ -341,2 +379,14 @@ | ||
/** | ||
* getScale | ||
* | ||
* @returns {scaleX: Number, scaleY: Number} | ||
*/ | ||
Matrix2D.prototype.getScale = function() { | ||
return { | ||
scaleX: Math.sqrt(this.a * this.a + this.c * this.c), | ||
scaleY: Math.sqrt(this.b * this.b + this.d * this.d) | ||
}; | ||
}; | ||
/** | ||
* equals | ||
@@ -359,14 +409,2 @@ * | ||
/** | ||
* getScale | ||
* | ||
* @returns {scaleX: Number, scaleY: Number} | ||
*/ | ||
Matrix2D.prototype.getScale = function() { | ||
return { | ||
scaleX: Math.sqrt(this.a * this.a + this.c * this.c), | ||
scaleY: Math.sqrt(this.b * this.b + this.d * this.d) | ||
}; | ||
}; | ||
/** | ||
* toString | ||
@@ -373,0 +411,0 @@ * |
@@ -17,4 +17,18 @@ /** | ||
function Point2D(x, y) { | ||
this.x = x; | ||
this.y = y; | ||
Object.defineProperties(this, { | ||
"x": { | ||
value: x, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"y": { | ||
value: y, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
} | ||
}); | ||
// this.x = x; | ||
// this.y = y; | ||
} | ||
@@ -42,53 +56,2 @@ | ||
/** | ||
* addEquals | ||
* | ||
* @deprecated | ||
* @param {Point2D|Vector2D} that | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.addEquals = function(that) { | ||
this.x += that.x; | ||
this.y += that.y; | ||
return this; | ||
}; | ||
/** | ||
* rmoveto | ||
* | ||
* @deprecated | ||
* @param {Number} dx | ||
* @param {Number} dy | ||
*/ | ||
Point2D.prototype.rmoveto = function(dx, dy) { | ||
this.x += dx; | ||
this.y += dy; | ||
}; | ||
/** | ||
* scalarAdd | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.scalarAdd = function(scalar) { | ||
return new Point2D(this.x+scalar, this.y+scalar); | ||
}; | ||
/** | ||
* scalarAddEquals | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.scalarAddEquals = function(scalar) { | ||
this.x += scalar; | ||
this.y += scalar; | ||
return this; | ||
}; | ||
/** | ||
* subtract | ||
@@ -104,41 +67,2 @@ * | ||
/** | ||
* subtractEquals | ||
* | ||
* @deprecated | ||
* @param { Vector2D | Point2D } that | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.subtractEquals = function(that) { | ||
this.x -= that.x; | ||
this.y -= that.y; | ||
return this; | ||
}; | ||
/** | ||
* scalarSubtract | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @rertuns {Point2D} | ||
*/ | ||
Point2D.prototype.scalarSubtract = function(scalar) { | ||
return new Point2D(this.x-scalar, this.y-scalar); | ||
}; | ||
/** | ||
* scalarSubtractEquals | ||
* | ||
* @deprecated | ||
* @param {Number} | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.scalarSubtractEquals = function(scalar) { | ||
this.x -= scalar; | ||
this.y -= scalar; | ||
return this; | ||
}; | ||
/** | ||
* multiply | ||
@@ -154,16 +78,2 @@ * | ||
/** | ||
* multiplyEquals | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.multiplyEquals = function(scalar) { | ||
this.x *= scalar; | ||
this.y *= scalar; | ||
return this; | ||
}; | ||
/** | ||
* divide | ||
@@ -179,27 +89,2 @@ * | ||
/** | ||
* divideEquals | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Point2D} | ||
*/ | ||
Point2D.prototype.divideEquals = function(scalar) { | ||
this.x /= scalar; | ||
this.y /= scalar; | ||
return this; | ||
}; | ||
/** | ||
* compare | ||
* | ||
* @deprecated | ||
* @param {Point2D} that | ||
* @returns {Integer} | ||
*/ | ||
Point2D.prototype.compare = function(that) { | ||
return (this.x - that.x || this.y - that.y); | ||
}; | ||
/** | ||
* equals | ||
@@ -293,47 +178,4 @@ * | ||
// getters and setters | ||
/** | ||
* setXY | ||
* | ||
* @deprecated | ||
* @param {Number} x | ||
* @param {Number} y | ||
*/ | ||
Point2D.prototype.setXY = function(x, y) { | ||
this.x = x; | ||
this.y = y; | ||
}; | ||
/** | ||
* setFromPoint | ||
* | ||
* @deprecated | ||
* @param {Point2D} that | ||
*/ | ||
Point2D.prototype.setFromPoint = function(that) { | ||
this.x = that.x; | ||
this.y = that.y; | ||
}; | ||
/** | ||
* swap | ||
* | ||
* @deprecated | ||
* @param {Point2D} | ||
*/ | ||
Point2D.prototype.swap = function(that) { | ||
var x = this.x; | ||
var y = this.y; | ||
this.x = that.x; | ||
this.y = that.y; | ||
that.x = x; | ||
that.y = y; | ||
}; | ||
if (typeof module !== "undefined") { | ||
module.exports = Point2D; | ||
} |
@@ -17,7 +17,35 @@ /** | ||
function Vector2D(x, y) { | ||
this.x = x; | ||
this.y = y; | ||
Object.defineProperties(this, { | ||
"x": { | ||
value: x, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
"y": { | ||
value: y, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
} | ||
}); | ||
// this.x = x; | ||
// this.y = y; | ||
} | ||
/** | ||
* fromPoints | ||
* | ||
* @param {Point2D} p1 | ||
* @param {Point2D} p2 | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.fromPoints = function(p1, p2) { | ||
return new Vector2D( | ||
p2.x - p1.x, | ||
p2.y - p1.y | ||
); | ||
}; | ||
/** | ||
* length | ||
@@ -32,2 +60,11 @@ * | ||
/** | ||
* magnitude | ||
* | ||
* @returns {Number} | ||
*/ | ||
Vector2D.prototype.magnitude = function() { | ||
return this.x*this.x + this.y*this.y; | ||
}; | ||
/** | ||
* dot | ||
@@ -53,20 +90,18 @@ * | ||
/** | ||
* unit | ||
* determinant | ||
* | ||
* @returns {Vector2D} | ||
* @param {Vector2D} that | ||
* @returns {Number} | ||
*/ | ||
Vector2D.prototype.unit = function() { | ||
return this.divide( this.length() ); | ||
Vector2D.prototype.determinant = function(that) { | ||
return this.x*that.y - this.y*that.x; | ||
}; | ||
/** | ||
* unitEquals | ||
* unit | ||
* | ||
* @deprecated | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.prototype.unitEquals = function() { | ||
this.divideEquals( this.length() ); | ||
return this; | ||
Vector2D.prototype.unit = function() { | ||
return this.divide( this.length() ); | ||
}; | ||
@@ -85,16 +120,2 @@ | ||
/** | ||
* addEquals | ||
* | ||
* @deprecated | ||
* @param {Vector2D} that | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.prototype.addEquals = function(that) { | ||
this.x += that.x; | ||
this.y += that.y; | ||
return this; | ||
}; | ||
/** | ||
* subtract | ||
@@ -110,16 +131,2 @@ * | ||
/** | ||
* subtractEquals | ||
* | ||
* @deprecated | ||
* @param {Vector2D} that | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.prototype.subtractEquals = function(that) { | ||
this.x -= that.x; | ||
this.y -= that.y; | ||
return this; | ||
}; | ||
/** | ||
* multiply | ||
@@ -135,16 +142,2 @@ * | ||
/** | ||
* multiplyEquals | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.prototype.multiplyEquals = function(scalar) { | ||
this.x *= scalar; | ||
this.y *= scalar; | ||
return this; | ||
}; | ||
/** | ||
* divide | ||
@@ -160,13 +153,18 @@ * | ||
/** | ||
* divideEquals | ||
* angleBetween | ||
* | ||
* @deprecated | ||
* @param {Number} scalar | ||
* @returns {Vector2D} | ||
* @param {Vector2D} that | ||
* @returns {Number} | ||
*/ | ||
Vector2D.prototype.divideEquals = function(scalar) { | ||
this.x /= scalar; | ||
this.y /= scalar; | ||
Vector2D.prototype.angleBetween = function(that) { | ||
var cos = this.dot(that) / (this.length() * that.length()); | ||
if (cos < -1) { | ||
cos = -1; | ||
} | ||
else if (cos > 1) { | ||
cos = 1; | ||
} | ||
var radians = Math.acos(cos); | ||
return this; | ||
return (this.cross(that) < 0.0) ? -radians : radians; | ||
}; | ||
@@ -238,21 +236,7 @@ | ||
Vector2D.prototype.toString = function() { | ||
return this.x + "," + this.y; | ||
return "vector(" + this.x + "," + this.y + ")"; | ||
}; | ||
/** | ||
* fromPoints | ||
* | ||
* @param {Point2D} p1 | ||
* @param {Point2D} p2 | ||
* @returns {Vector2D} | ||
*/ | ||
Vector2D.fromPoints = function(p1, p2) { | ||
return new Vector2D( | ||
p2.x - p1.x, | ||
p2.y - p1.y | ||
); | ||
}; | ||
if (typeof module !== "undefined") { | ||
module.exports = Vector2D; | ||
} |
{ | ||
"name": "kld-affine", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"description": "A collection of classes used in affine geometry", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -10,4 +10,6 @@ kld-affine | ||
These have been extracted from kld-intersections so they can stand alone. As such, there are some parts of the API that I want to remove, but I will need to update kld-intersections before being able to do that. Specifically, I would like to remove all self-mutable methods in preference of a more functional approach that creates a new instance with each modification. | ||
These have been extracted from kld-intersections so they can stand alone. | ||
Please note that as of version 0.0.7, all of the self-modifying functions (like addEquals, subtractEquals, etc.) have been removed. | ||
Install | ||
@@ -24,15 +26,5 @@ ------- | ||
* add | ||
* addEquals - deprecated | ||
* rmoveTo - deprecated | ||
* scalarAdd - deprecated | ||
* scalarAddEquals - deprecated | ||
* subtract | ||
* subtractEquals - deprecated | ||
* scalarSubtract - deprecated | ||
* scalarSubtractEquals - deprecated | ||
* multiply | ||
* multiplyEquals - deprecated | ||
* divide | ||
* divideEquals - deprecated | ||
* compare - deprecated | ||
* equals | ||
@@ -45,5 +37,2 @@ * lerp | ||
* toString | ||
* setXY - deprecated | ||
* setFromPoint - deprecated | ||
* swap - deprecated | ||
@@ -56,14 +45,12 @@ Vector2D | ||
* length | ||
* magnitude | ||
* dot | ||
* cross | ||
* determinant | ||
* unit | ||
* unitEquals - deprecated | ||
* add | ||
* addEquals - deprecated | ||
* subtract | ||
* subtractEquals - deprecated | ||
* multiply | ||
* multiplyEquals - deprecated | ||
* divide | ||
* divideEquals - deprecated | ||
* angleBetween | ||
* perp | ||
@@ -95,6 +82,6 @@ * perpendicular | ||
* skewY | ||
* equals | ||
* isIdentity | ||
* isInvertible | ||
* getScale | ||
* equals | ||
* toString |
@@ -6,3 +6,97 @@ var Matrix2D = require('./../lib/Matrix2D'); | ||
assert.equal(m.a, 1); | ||
assert.equal(m.b, 0); | ||
assert.equal(m.c, 0); | ||
assert.equal(m.d, 1); | ||
assert.equal(m.e, 0); | ||
assert.equal(m.f, 0); | ||
}; | ||
exports.IDENTITY = function(beforeExit, assert) { | ||
var m = Matrix2D.IDENTITY; | ||
assert.equal(m.a, 1); | ||
assert.equal(m.b, 0); | ||
assert.equal(m.c, 0); | ||
assert.equal(m.d, 1); | ||
assert.equal(m.e, 0); | ||
assert.equal(m.f, 0); | ||
}; | ||
exports.multiply = function(beforeExit, assert) { | ||
}; | ||
exports.inverse = function(beforeExit, assert) { | ||
}; | ||
exports.translate = function(beforeExit, assert) { | ||
}; | ||
exports.scale = function(beforeExit, assert) { | ||
}; | ||
exports.scaleAt = function(beforeExit, assert) { | ||
}; | ||
exports.scaleNonUniform = function(beforeExit, assert) { | ||
}; | ||
exports.scaleNonUniformAt = function(beforeExit, assert) { | ||
}; | ||
exports.rotate = function(beforeExit, assert) { | ||
}; | ||
exports.rotateAt = function(beforeExit, assert) { | ||
}; | ||
exports.rotateFromVector = function(beforeExit, assert) { | ||
}; | ||
exports.flipX = function(beforeExit, assert) { | ||
}; | ||
exports.flipY = function(beforeExit, assert) { | ||
}; | ||
exports.skewX = function(beforeExit, assert) { | ||
}; | ||
exports.skewY = function(beforeExit, assert) { | ||
}; | ||
exports.isIdentity = function(beforeExit, assert) { | ||
}; | ||
exports.isInvertible = function(beforeExit, assert) { | ||
}; | ||
exports.getScale = function(beforeExit, assert) { | ||
}; | ||
exports.equals = function(beforeExit, assert) { | ||
}; | ||
exports.toString = function(beforeExit, assert) { | ||
var m = new Matrix2D(); | ||
assert.equal(m.toString(), "matrix(1,0,0,1,0,0)"); | ||
}; |
@@ -205,1 +205,9 @@ var Point2D = require('../lib/Point2D'), | ||
}; | ||
// exports.setX = function(beforeExit, assert) { | ||
// var p = new Point2D(10, 20); | ||
// p.x = 20; | ||
// console.log(p.toString()); | ||
// }; |
@@ -9,1 +9,63 @@ var Vector2D = require('../lib/Vector2D'); | ||
}; | ||
exports.fromPoints = function(beforeExit, assert) { | ||
}; | ||
exports.length = function(beforeExit, assert) { | ||
}; | ||
exports.magnitude = function(beforeExit, assert) { | ||
}; | ||
exports.dot = function(beforeExit, assert) { | ||
}; | ||
exports.cross = function(beforeExit, assert) { | ||
}; | ||
exports.determinant = function(beforeExit, assert) { | ||
}; | ||
exports.unit = function(beforeExit, assert) { | ||
}; | ||
exports.add = function(beforeExit, assert) { | ||
}; | ||
exports.subtract = function(beforeExit, assert) { | ||
}; | ||
exports.multiply = function(beforeExit, assert) { | ||
}; | ||
exports.divide = function(beforeExit, assert) { | ||
}; | ||
exports.angleBetween = function(beforeExit, assert) { | ||
}; | ||
exports.perp = function(beforeExit, assert) { | ||
}; | ||
exports.perpendicular = function(beforeExit, assert) { | ||
}; | ||
exports.project = function(beforeExit, assert) { | ||
}; | ||
exports.transform = function(beforeExit, assert) { | ||
}; | ||
exports.equals = function(beforeExit, assert) { | ||
}; | ||
exports.toString = function(beforeExit, assert) { | ||
}; | ||
// exports.setX = function(beforeExit, assert) { | ||
// var v = new Vector2D(10, 20); | ||
// v.x = 20; | ||
// console.log(v.toString()); | ||
// }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27246
1032
83