* Calculates the angle between 'this' vector and another.
* @public
* @function
* @returns {Number} The angle between the two vectors as measured in PI.
*/
this.angleTo=function(vectorB){
vardivisor=this.getLength()*vectorB.getLength()
if (divisor===0){
return0
}else{
// JavaScript floating point math is screwed up.
// because of it, the core of the formula can, on occasion, have values
// over 1.0 and below -1.0.
returnMath.acos(
Math.min(
Math.max(
(this.x*vectorB.x+this.y*vectorB.y)/divisor
,-1.0
)
,1.0
)
)/Math.PI
}
}
}
functionPoint(x,y){
this.x=x
this.y=y
this.getVectorToCoordinates=function (x,y){
returnnewVector(x-this.x,y-this.y)
}
this.getVectorFromCoordinates=function (x,y){
returnthis.getVectorToCoordinates(x,y).reverse()
}
this.getVectorToPoint=function (point){
returnnewVector(point.x-this.x,point.y-this.y)
}
this.getVectorFromPoint=function (point){
returnthis.getVectorToPoint(point).reverse()
}
}
/*
* About data structure:
* We don't store / deal with "pictures" this signature capture code captures "vectors"
*
* We don't store bitmaps. We store "strokes" as arrays of arrays. (Actually, arrays of objects containing arrays of coordinates.
*
* Stroke = mousedown + mousemoved * n (+ mouseup but we don't record that as that was the "end / lack of movement" indicator)
*
* Vectors = not classical vectors where numbers indicated shift relative last position. Our vectors are actually coordinates against top left of canvas.
* we could calc the classical vectors, but keeping the the actual coordinates allows us (through Math.max / min)
* to calc the size of resulting drawing very quickly. If we want classical vectors later, we can always get them in backend code.
*
* So, the data structure:
*
* var data = [
* { // stroke starts
* x : [101, 98, 57, 43] // x points
* , y : [1, 23, 65, 87] // y points
* } // stroke ends
* , { // stroke starts
* x : [55, 56, 57, 58] // x points
* , y : [101, 97, 54, 4] // y points
* } // stroke ends
* , { // stroke consisting of just a dot
* x : [53] // x points
* , y : [151] // y points
* } // stroke ends
* ]
*
* we don't care or store stroke width (it's canvas-size-relative), color, shadow values. These can be added / changed on whim post-capture.