<commit_before>// VCE Project - boundary_builder.js
//
// This tool can be used to place vce_boundary.Boundary objects and
// particle feeds using the mouse and keys (as opposed to adjusting
// the coordinates through trial and error). Images can be imported
// and displayed on the canvas to aid placement of the boundaries.
//
// Note: This is a work in progress.
//
// Requires:
// - p5.js or p5.min.js
// - matter.js
// - vce_utils.js
// - vce_particle.js
// - vce_ensemble.js
// - vce_boundary.js
// - setting.js (temporarily for boundary positional info)
//
// <NAME> 2018
// <EMAIL>
//
// To do:
// - testing
// - allow user to place particle feed(s)
//
// --------------------------------------------------
//               set-up variables
// --------------------------------------------------
var debug = false;
var particles_log = false;
var ensemble;
var boundaries = [];
var Engine = Matter.Engine,
    World = Matter.World,
    Bodies = Matter.Bodies,
    Body = Matter.Body,
    Vector = Matter.Vector;
var sid;
var show_boundaries = true;
var my_image;
var y_max;
var feed_blocks = [];

// --------------------------------------------------
//             Visualisation functionality
// --------------------------------------------------
function preload() {
    // load the default image
    var my_image_url = "../../resources/reactor_ni.svg";
    my_image = loadImage(my_image_url, pic => print(pic), loadImgErrFix);
    $('#filename_input').val(my_image_url);
};

function setup(new_canvas) {

    /* This function is called upon entry to create the
       simulation canvas which we draw onto  */

    // set-up the canvas
    var dimensions = getSimBoxDimensions();
    xmax = dimensions.xmax;
    ymax = dimensions.ymax;
    var canvas= createCanvas(xmax, ymax);
    canvas.parent("sim_container");
    sid = getImgScaledDimensions(my_image, 0.6, ymax);
    console.log("ymax = ", ymax);
    console.log("sid = ", sid);
    
    // set-up the physics engine
    engine = Engine.create();
    world = engine.world;

    // initialise the ensemble
    ensemble = new Ensemble([],world);

    // intialise the boundaries
    boundaries = makeBoundaries(settings.boundary_positions, xmax, ymax,
				sid.width, sid.height, world);
    
};

function draw() {

    /* Draws background and img to the canvas.
       This function is continuously called for the
       lifetime of the scripts executions after setup()
       has completed. Effectively advances time. */

    sid = getImgScaledDimensions(my_image, 0.6, ymax);
    background(51);
    imageMode(CENTER);
    image(my_image, xmax/2 , ymax/2, sid.width, sid.height);
    if (particles_log) {
	ensemble.updateFeeds();
    };
    Engine.update(engine);
    ensemble.removeOutliers(xmax,ymax);
    ensemble.show();
    if (show_boundaries) {
	    for (var i = 0; i < boundaries.length; i++) {
		boundaries[i].show();
	    };
    };
    for (var i = 0; i < feed_blocks.length; i++) {
	feed_blocks[i].show();
    };
};


function deactivateAll() {
    deactiveAllBoundaries();
    deactivateAllFeedBlocks();
};


function deactiveAllBoundaries() {
    for (var i = 0; i < boundaries.length; i++) {
	boundaries[i].active = false;
    };
};


function deactivateAllFeedBlocks() {
    for (var i = 0; i < feed_blocks.length; i++) {
	feed_blocks[i].active = false;
    };
};


function mouseClicked() {
    if (is_on_canvas(mouseX, mouseY, canvas)) {
	deactivateAll();
	for (var i = 0; i < feed_blocks.length; i++) {
	    feed_blocks[i].mousePressed(mouseX, mouseY);
	    if (feed_blocks[i].active) {
		return; // only allow a single active feed block
	    };
	};
	
	for (var i = 0; i < boundaries.length; i++) {
	    boundaries[i].mousePressed(mouseX, mouseY);
	    if (boundaries[i].active) {
		return; // only allow a single active boundary
	    };
	};
    };
};

function mouseDragged() {
    if (is_on_canvas(mouseX, mouseY, canvas)) {
	for (var i = 0; i < boundaries.length; i++) {
	    boundaries[i].mouseDragged(mouseX, mouseY);
	};
    };
};<commit_msg>boundary builder: feed positions can now be dragged and dropped<commit_after>// VCE Project - boundary_builder.js
//
// This tool can be used to place vce_boundary.Boundary objects and
// particle feeds using the mouse and keys (as opposed to adjusting
// the coordinates through trial and error). Images can be imported
// and displayed on the canvas to aid placement of the boundaries.
//
// Note: This is a work in progress.
//
// Requires:
// - p5.js or p5.min.js
// - matter.js
// - vce_utils.js
// - vce_particle.js
// - vce_ensemble.js
// - vce_boundary.js
// - setting.js (temporarily for boundary positional info)
//
// <NAME> 2018
// <EMAIL>
//
// To do:
// - testing
// - allow user to place particle feed(s)
//
// --------------------------------------------------
//               set-up variables
// --------------------------------------------------
var debug = false;
var particles_log = false;
var ensemble;
var boundaries = [];
var Engine = Matter.Engine,
    World = Matter.World,
    Bodies = Matter.Bodies,
    Body = Matter.Body,
    Vector = Matter.Vector;
var sid;
var show_boundaries = true;
var my_image;
var y_max;
var feed_blocks = [];

// --------------------------------------------------
//             Visualisation functionality
// --------------------------------------------------
function preload() {
    // load the default image
    var my_image_url = "../../resources/reactor_ni.svg";
    my_image = loadImage(my_image_url, pic => print(pic), loadImgErrFix);
    $('#filename_input').val(my_image_url);
};

function setup(new_canvas) {

    /* This function is called upon entry to create the
       simulation canvas which we draw onto  */

    // set-up the canvas
    var dimensions = getSimBoxDimensions();
    xmax = dimensions.xmax;
    ymax = dimensions.ymax;
    var canvas= createCanvas(xmax, ymax);
    canvas.parent("sim_container");
    sid = getImgScaledDimensions(my_image, 0.6, ymax);
    console.log("ymax = ", ymax);
    console.log("sid = ", sid);
    
    // set-up the physics engine
    engine = Engine.create();
    world = engine.world;

    // initialise the ensemble
    ensemble = new Ensemble([],world);

    // intialise the boundaries
    boundaries = makeBoundaries(settings.boundary_positions, xmax, ymax,
				sid.width, sid.height, world);
    
};

function draw() {

    /* Draws background and img to the canvas.
       This function is continuously called for the
       lifetime of the scripts executions after setup()
       has completed. Effectively advances time. */

    sid = getImgScaledDimensions(my_image, 0.6, ymax);
    background(51);
    imageMode(CENTER);
    image(my_image, xmax/2 , ymax/2, sid.width, sid.height);
    if (particles_log) {
	ensemble.updateFeeds();
    };
    Engine.update(engine);
    ensemble.removeOutliers(xmax,ymax);
    ensemble.show();
    if (show_boundaries) {
	    for (var i = 0; i < boundaries.length; i++) {
		boundaries[i].show();
	    };
    };
    for (var i = 0; i < feed_blocks.length; i++) {
	feed_blocks[i].show();
    };
};


function deactivateAll() {
    deactiveAllBoundaries();
    deactivateAllFeedBlocks();
};


function deactiveAllBoundaries() {
    for (var i = 0; i < boundaries.length; i++) {
	boundaries[i].active = false;
    };
};


function deactivateAllFeedBlocks() {
    for (var i = 0; i < feed_blocks.length; i++) {
	feed_blocks[i].active = false;
    };
};


function mouseClicked() {
    if (is_on_canvas(mouseX, mouseY, canvas)) {
	deactivateAll();
	for (var i = 0; i < feed_blocks.length; i++) {
	    feed_blocks[i].mousePressed(mouseX, mouseY);
	    if (feed_blocks[i].active) {
		return; // only allow a single active feed block
	    };
	};
	
	for (var i = 0; i < boundaries.length; i++) {
	    boundaries[i].mousePressed(mouseX, mouseY);
	    if (boundaries[i].active) {
		return; // only allow a single active boundary
	    };
	};
    };
};

function mouseDragged() {
    if (is_on_canvas(mouseX, mouseY, canvas)) {
	for (var i = 0; i < feed_blocks.length; i++) {
	    feed_blocks[i].mouseDragged(mouseX, mouseY);
	    ensemble.feeds[i].x = feed_blocks[i].body.position.x;
	    ensemble.feeds[i].y = feed_blocks[i].body.position.y;
	};

	
	for (var i = 0; i < boundaries.length; i++) {
	    boundaries[i].mouseDragged(mouseX, mouseY);
	};
    };
};
{'fraction_non_alphanumeric': 0.18048721948877955, 'fraction_numerical': 0.00516020640825633, 'mean_word_length': 2.4113794514940645, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5703399', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2598, 'n_words': 708}