tentone 3 years ago
parent
commit
52b69c3711
2 changed files with 33 additions and 5 deletions
  1. 1 2
      build/escher.js
  2. 32 3
      source/math/Vector2.js

+ 1 - 2
build/escher.js

@@ -2493,10 +2493,9 @@
 		this.manager = new EventManager();
 		this.manager = new EventManager();
 
 
 		if(options.disableContextMenu) {
 		if(options.disableContextMenu) {
-			this.manager.add(canvas,"contextmenu",function(e) {
+			this.manager.add(canvas, "contextmenu", function(e) {
 				e.preventDefault();
 				e.preventDefault();
 				e.stopPropagation();
 				e.stopPropagation();
-				return false;
 			}); 
 			}); 
 		}
 		}
 
 

+ 32 - 3
source/math/Vector2.js

@@ -201,6 +201,14 @@ Vector2.prototype.max = function(v)
 	this.y = Math.max(this.y, v.y);
 	this.y = Math.max(this.y, v.y);
 };
 };
 
 
+/**
+ * Clamp the vector coordinates to the range defined by two vectors.
+ * 
+ * Applied to x and y independently.
+ * 
+ * @param {Vector2} min Minimum value.
+ * @param {Vector2} max Maximum value.
+ */
 Vector2.prototype.clamp = function(min, max)
 Vector2.prototype.clamp = function(min, max)
 {
 {
 	// assumes min < max, componentwise
 	// assumes min < max, componentwise
@@ -208,6 +216,12 @@ Vector2.prototype.clamp = function(min, max)
 	this.y = Math.max(min.y, Math.min(max.y, this.y));
 	this.y = Math.max(min.y, Math.min(max.y, this.y));
 };
 };
 
 
+/**
+ * Clamp the vector coordinates to the range defined by two scalars.
+ * 
+ * @param {number} minVal Minimum value.
+ * @param {number} maxVal Maximum value.
+ */
 Vector2.prototype.clampScalar = function(minVal, maxVal)
 Vector2.prototype.clampScalar = function(minVal, maxVal)
 {
 {
 	this.x = Math.max(minVal, Math.min(maxVal, this.x));
 	this.x = Math.max(minVal, Math.min(maxVal, this.x));
@@ -316,13 +330,16 @@ Vector2.prototype.normalize = function()
 };
 };
 
 
 /**
 /**
- * Computes the angle in radians with respect to the positive x-axis
+ * Computes the angle in radians with respect to the positive x-axis.
+ * 
+ * @param {boolean} forcePositive If true, the angle will be forced to be positive.
+ * @return {number} Angle in radians.
  */
  */
-Vector2.prototype.angle = function()
+Vector2.prototype.angle = function(forcePositive)
 {
 {
 	var angle = Math.atan2(this.y, this.x);
 	var angle = Math.atan2(this.y, this.x);
 
 
-	if(angle < 0)
+	if(forcePositive && angle < 0)
 	{
 	{
 		angle += 2 * Math.PI;
 		angle += 2 * Math.PI;
 	}
 	}
@@ -332,6 +349,9 @@ Vector2.prototype.angle = function()
 
 
 /**
 /**
  * Distance between two vector positions.
  * Distance between two vector positions.
+ * 
+ * @param {Vector2} v Vector to compute the distance to.
+ * @return {number} Distance between the two vectors.
  */
  */
 Vector2.prototype.distanceTo = function(v)
 Vector2.prototype.distanceTo = function(v)
 {
 {
@@ -342,6 +362,9 @@ Vector2.prototype.distanceTo = function(v)
  * Distance between two vector positions squared.
  * Distance between two vector positions squared.
  *
  *
  * Faster for comparisons.
  * Faster for comparisons.
+ * 
+ * @param {Vector2} v Vector to compute the distance to.
+ * @return {number} Distance between the two vectors squared.
  */
  */
 Vector2.prototype.distanceToSquared = function(v)
 Vector2.prototype.distanceToSquared = function(v)
 {
 {
@@ -353,6 +376,9 @@ Vector2.prototype.distanceToSquared = function(v)
 
 
 /**
 /**
  * Manhattan distance between two vector positions.
  * Manhattan distance between two vector positions.
+ * 
+ * @param {Vector2} v Vector to compute the distance to.
+ * @return {number} Manhattan distance between the two vectors.
  */
  */
 Vector2.prototype.manhattanDistanceTo = function(v)
 Vector2.prototype.manhattanDistanceTo = function(v)
 {
 {
@@ -361,6 +387,9 @@ Vector2.prototype.manhattanDistanceTo = function(v)
 
 
 /**
 /**
  * Scale the vector to have a defined length value.
  * Scale the vector to have a defined length value.
+ * 
+ * @param {number} length Length to scale the vector to.
+ * @return {Vector2} This vector.
  */
  */
 Vector2.prototype.setLength = function(length)
 Vector2.prototype.setLength = function(length)
 {
 {