Commit 17396aef authored by Jérémie Garcia's avatar Jérémie Garcia

refactoring some code

parent 6db68443
......@@ -31,7 +31,7 @@ Traj.OSC = {
return 'b';
break;
case 'number':
return Traj.OSC.isInteger(elem) ? 'i' : 'f';;
return Traj.OSC.isInteger(elem) ? 'i' : 'f'; //not using doubles because Max does not understand them
break;
default:
return 'f';
......
......@@ -33,6 +33,7 @@ TimedCurve.prototype.spaceScale = function (factor) {
this.Z[k] = factor * this.Z[k];
}
}
TimedCurve.prototype.sapceScaleAxis = function(factor,vectorAxis,pointAxis) {
var point = [],
distance =0,
......@@ -66,7 +67,6 @@ TimedCurve.prototype.sapceScaleAxisRange = function(factor,vectorAxis,pointAxis,
}
}
TimedCurve.prototype.timeScale = function (factor) {
for (var k = 0; k < this.X.length; k++) {
this.t[k] = Math.floor(factor * this.t[k]);
......@@ -79,7 +79,6 @@ TimedCurve.prototype.changeTotalTime = function(time) {
this.timeScale(rapport);
}
TimedCurve.prototype.changeXScale = function(factor) {
for (var k=0; k<this.X.length;k++) {
this.X[k] = factor * this.X[k];
......@@ -127,7 +126,6 @@ TimedCurve.prototype.tMiror = function() {
}
}
TimedCurve.prototype.translate = function(x,y,z) {
var actualX = this.X[0];
var actualY = this.Y[0];
......@@ -151,8 +149,6 @@ TimedCurve.prototype.rotate = function(center,angle) {
this.Y[k] = newXY[1];
}
}
// arrange the curve for osc sending
TimedCurve.prototype.getAllTimedPoints = function () {
var allpoints = [];
......@@ -183,4 +179,14 @@ TimedCurve.prototype.lengthTime = function() {
return time;
}
TimedCurve.prototype.getDistanceToPoint = function(pos) {
var distance = Infinity;
var minDistance = Infinity;
for (var k=0;k<this.X.length;k++) {
distance = Traj.Utils.distanceBtwPoints([this.X[k],this.Y[k]],pos)
if (distance<minDistance) {
minDistance = distance;
}
}
return minDistance;
}
/*
Utilities for Traj namespace
Convert canvas position to different coordonates systems.
Mathematical utilities for curves processing
*/
Traj.Utils = {
......@@ -196,35 +202,6 @@ Traj.Utils = {
},
getDistanceCurveFromTouch : function(curve,pos) {
var distance = Infinity;
var minDistance = Infinity;
for (var k=0;k<curve.X.length;k++) {
distance = this.distanceBtwPoints([curve.X[k],curve.Y[k]],pos)
if (distance<minDistance) {
minDistance = distance;
}
}
return minDistance;
},
getClosestCurveFromTouch : function(pos) {
var trajectories = Traj.TrajManager.trajectories;
var curve = {};
var minDistance = Infinity;
var distance = 0;
var index = null;
for (var k = 0 ; k<trajectories.length;k++) {
curve = trajectories[k];
distance = this.getDistanceCurveFromTouch(curve,pos);
if (distance < minDistance){
minDistance = distance;
index = k;
}
}
return index;
},
removeDoublon : function(a) {
return a.sort().filter(function(item, pos, ary) {
return !pos || item != ary[pos - 1];
......
......@@ -7,7 +7,6 @@ Traj.View = {
traj_canvas : {}, // rendering of the curves
traj_ctx : {}, //associated context
bg_canvas : {}, //rendering the background
bg_ctx : {}, //associated context
......
......@@ -285,6 +285,24 @@ Traj.Manager = {
Traj.Session.saveTrajSession();
},
getClosestCurveFromTouch : function(pos) {
var trajectories = Traj.TrajManager.trajectories;
var curve = {};
var minDistance = Infinity;
var distance = 0;
var index = null;
for (var k = 0 ; k<trajectories.length;k++) {
curve = trajectories[k];
distance = curve.getDistanceToPoint(curve,pos);
if (distance < minDistance){
minDistance = distance;
index = k;
}
}
return index;
},
////////////////////////////////////
////////// CALLED FROM HTML ////////
////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment