Created
November 2, 2012 19:32
Revisions
-
guiman revised this gist
Nov 2, 2012 . 1 changed file with 45 additions and 39 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,66 +1,72 @@ /* Javascript Active area. ----------------------- So this is pretty much what it does, you define areas and this code allows you to verify if your data source is retreiving points in any of the defined areas. */ window.areas = new Array(); window.conditions = new Array(); window.callbacks = new Array(); function initialize(areas, conditions, callbacks) { window.areas = areas; window.conditions = conditions; window.callbacks = callbacks; } function run(stream_data) { active_areas = activate_areas(stream_data, window.areas); } function destroy() { window.areas = new Array(); window.conditions = new Array(); window.callbacks = new Array(); } /* = Area should be something like [H,W,P] where: H = height, numeric W = width, numeric P = point, array [x,y] representing the upper left corner = Stream data expected is: [[X,Y,Z], [X,Y,Z], ...] X = horizontal position Y = vertical position Z = magnitued */ function activate_areas(stream_data, areas) { active_areas = new Array(); for (i = 0; i < areas.length ; i++) { x = stream_data[0]; y = stream_data[1]; x_1 = areas[i][2][0]; x_2 = x_1 + areas[i][0]; y_1 = areas[i][2][1]; y_2 = y_1 + areas[i][1]; in_area = (y >= y_1) && (y <= y_2) && (x >= x_1) && (x <= x_2) if (in_area) { active_areas.push(i); callbacks[i](); } } -
guiman created this gist
Nov 2, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ /* So this is a basic mechanism to determin if a flow of positions land in fixed rectangular areas. Depending on certain conditions for each areas a callback is executed or no. = Area should be something like [H,W,P] where: H = height, numeric W = width, numeric P = point, array [x,y] representing the upper left corner = Stream data expected is: [[X,Y,Z], [X,Y,Z], ...] X = horizontal position Y = vertical position Z = magnitued */ var areas = new Array(); var conditions = new Array(); var callbacks = new Array(); function initialize(areas, conditions, callbacks) { areas = areas; conditions = conditions; callbacks = callbacks; } function run(stream_data) { active_areas = activate_areas(stream_data, areas); } function destroy() { areas = new Array(); conditions = new Array(); callbacks = new Array(); } function activate_areas(stream_data, areas) { active_areas = new Array(); for (i = 0; i < areas.length ; i++) { for (j = 0; j < stream_data.length ; j++) { //x_1 = areas[i][2][0]; //x_2 = areas[i][2][0] + areas[i][1]; //y_1 = areas[i][2][1]; //y_2 = areas[i][2][1] + areas[i][0]; in_area = (((stream_data[j][1] < areas[i][2][1]) && ((areas[i][2][1] + areas[i][0]) < stream_data[j][1])) && ((stream_data[j][0] > areas[i][2][0]) && (stream_data[0] < (areas[i][2][0] + areas[i][1])))); if ((in_area) && (conditions.length > 0) && (conditions[i] != undefined) && (conditions[i])) { active_areas.push(i); callbacks[i](); } } } return active_areas; }