<commit_before>define(function (require, exports, module) {

    'use strict';

    var _        = require('underscore');
    var Backbone = require('backbone');

    var Simulation = require('common/simulation/simulation');
    var Vector2    = require('common/math/vector2');

    var Charge = require('models/charge');
    var Sensor = require('models/sensor');

    /**
     * Constants
     */
    var Constants = require('constants');

    /**
     * The simulation model here is based on the ChargeGroup class from the
     *   original sim.  All functionality of ChargeGroup is contained in
     *   this class as well as any additionally needed functionality.
     */
    var ChargesAndFieldsSimulation = Simulation.extend({

        defaults: _.extend(Simulation.prototype.defaults, {
            k: Constants.K,    // To be used in E-field equation: E = k*Q/r^2
            maxVoltage: 20000, // Voltage at which we would show total color saturation
            width:  100,
            height: 100
        }),
        
        initialize: function(attributes, options) {
            Simulation.prototype.initialize.apply(this, [attributes, options]);

            // Collections
            this.charges = new Backbone.Collection([], { model: Charge });
            this.sensors = new Backbone.Collection([], { model: Sensor });

            // Object caches
            this._efieldVec  = new Vector2();
            this._voltageLoc = new Vector2();
            this._nextPoint  = new Vector2();
        },

        /**
         * Initializes the models used in the simulation
         */
        initComponents: function() {
            
        },

        /**
         * Sets the simulation bounds' dimensions.
         */
        setBoundsDimensions: function(width, height) {
            this.set('width', width);
            this.set('height', height);
        },

        /**
         * This simulation does not make use of time and updates only when
         *   things change.  The view should listen for change events to
         *   trigger rendering.
         */
        update: function(time, deltaTime) {},

        /**
         * Adds a charge to the simulation
         */
        addCharge: function(charge) {
            this.charges.add(charge);
        },

        /**
         * Removes a charge from the simulation
         */
        removeCharge: function(charge) {
            this.charges.remove(charge);
        },

        /**
         * Returns whether or not there are any charges
         */
        hasCharges: function() {
            return this.charges.length !== 0;
        },

        /**
         * Adds a sensor to the simulation
         */
        addSensor: function(sensor) {
            this.sensors.add(sensor);
        },

        /**
         * Removes a sensor from the simulation
         */
        removeSensor: function(sensor) {
            this.sensors.remove(sensor);
        },

        /**
         * Returns the E-field vector at the given point
         */
        getE: function(x, y) {
            var sumX = 0;
            var sumY = 0;
            var charges = this.charges.models;

            var pos;
            var distSq;
            var distPow;

            for (var i = 0; i < charges.length; i++) {
                pos = charges[i].get('position');
                distSq = (x - pos.x) * (x - pos.x) + (y - pos.y) * (y - pos.y);
                distPow = Math.pow(distSq, 1.5);
                sumX += charges[i].get('q') * (x - pos.x) / distPow;
                sumY += charges[i].get('q') * (y - pos.y) / distPow;
            }

            this._efieldVec.x = this.get('k') * sumX;
            this._efieldVec.y = this.get('k') * sumY;

            return this._efieldVec;
        },

        /**
         * Returns the voltage at the given point
         */
        getV: function(x, y) {
            var sumV = 0;
            var charges = this.charges.models;

            var location = this._voltageLoc.set(x, y);
            var dist;

            for (var i = 0; i < charges.length; i++) {
                dist = location.distance(charges[i].get('position'));
                sumV += charges[i].get('q') / dist;
            }

            sumV *= this.get('k');

            return sumV;
        },

        /**
         * Starting at the given (x, y), move along the equipotential curve
         *   as far as the given displacement.
         */
        getNextEqualVoltagePoint: function(voltage, startX, startY, displacement) {
            var eVec = this.getE(startX, startY); // E-field vector
            var eMag = eVec.length();             // Magnitude of the e-field vector
            var xMid = startX - displacement * eVec.x / eMag;
            var yMid = startY + displacement * eVec.y / eMag;

            var eMidVec = this.getE(xMid, yMid);
            var vMid = this.getV(xMid, yMid);
            
            var dx = (vMid - voltage) * eMidVec.x / eMidVec.lengthSq();
            var xFinal = xMid + dx;
            var yFinal = yMid + dx * eMidVec.y / eMidVec.x;

            return this._nextPoint.set(xFinal, yFinal);
        }

    });<commit_msg>I fixed it!! This was all that was wrong. The x and y were supposed to be flipped. The equipotential plotter works now.<commit_after>define(function (require, exports, module) {

    'use strict';

    var _        = require('underscore');
    var Backbone = require('backbone');

    var Simulation = require('common/simulation/simulation');
    var Vector2    = require('common/math/vector2');

    var Charge = require('models/charge');
    var Sensor = require('models/sensor');

    /**
     * Constants
     */
    var Constants = require('constants');

    /**
     * The simulation model here is based on the ChargeGroup class from the
     *   original sim.  All functionality of ChargeGroup is contained in
     *   this class as well as any additionally needed functionality.
     */
    var ChargesAndFieldsSimulation = Simulation.extend({

        defaults: _.extend(Simulation.prototype.defaults, {
            k: Constants.K,    // To be used in E-field equation: E = k*Q/r^2
            maxVoltage: 20000, // Voltage at which we would show total color saturation
            width:  100,
            height: 100
        }),
        
        initialize: function(attributes, options) {
            Simulation.prototype.initialize.apply(this, [attributes, options]);

            // Collections
            this.charges = new Backbone.Collection([], { model: Charge });
            this.sensors = new Backbone.Collection([], { model: Sensor });

            // Object caches
            this._efieldVec  = new Vector2();
            this._voltageLoc = new Vector2();
            this._nextPoint  = new Vector2();
        },

        /**
         * Initializes the models used in the simulation
         */
        initComponents: function() {
            
        },

        /**
         * Sets the simulation bounds' dimensions.
         */
        setBoundsDimensions: function(width, height) {
            this.set('width', width);
            this.set('height', height);
        },

        /**
         * This simulation does not make use of time and updates only when
         *   things change.  The view should listen for change events to
         *   trigger rendering.
         */
        update: function(time, deltaTime) {},

        /**
         * Adds a charge to the simulation
         */
        addCharge: function(charge) {
            this.charges.add(charge);
        },

        /**
         * Removes a charge from the simulation
         */
        removeCharge: function(charge) {
            this.charges.remove(charge);
        },

        /**
         * Returns whether or not there are any charges
         */
        hasCharges: function() {
            return this.charges.length !== 0;
        },

        /**
         * Adds a sensor to the simulation
         */
        addSensor: function(sensor) {
            this.sensors.add(sensor);
        },

        /**
         * Removes a sensor from the simulation
         */
        removeSensor: function(sensor) {
            this.sensors.remove(sensor);
        },

        /**
         * Returns the E-field vector at the given point
         */
        getE: function(x, y) {
            var sumX = 0;
            var sumY = 0;
            var charges = this.charges.models;

            var pos;
            var distSq;
            var distPow;

            for (var i = 0; i < charges.length; i++) {
                pos = charges[i].get('position');
                distSq = (x - pos.x) * (x - pos.x) + (y - pos.y) * (y - pos.y);
                distPow = Math.pow(distSq, 1.5);
                sumX += charges[i].get('q') * (x - pos.x) / distPow;
                sumY += charges[i].get('q') * (y - pos.y) / distPow;
            }

            this._efieldVec.x = this.get('k') * sumX;
            this._efieldVec.y = this.get('k') * sumY;

            return this._efieldVec;
        },

        /**
         * Returns the voltage at the given point
         */
        getV: function(x, y) {
            var sumV = 0;
            var charges = this.charges.models;

            var location = this._voltageLoc.set(x, y);
            var dist;

            for (var i = 0; i < charges.length; i++) {
                dist = location.distance(charges[i].get('position'));
                sumV += charges[i].get('q') / dist;
            }

            sumV *= this.get('k');

            return sumV;
        },

        /**
         * Starting at the given (x, y), move along the equipotential curve
         *   as far as the given displacement.
         */
        getNextEqualVoltagePoint: function(voltage, startX, startY, displacement) {
            var eVec = this.getE(startX, startY); // E-field vector
            var eMag = eVec.length();             // Magnitude of the e-field vector
            var xMid = startX - displacement * eVec.y / eMag; // eVec.y is not a mistake
            var yMid = startY + displacement * eVec.x / eMag;

            var eMidVec = this.getE(xMid, yMid);
            var vMid = this.getV(xMid, yMid);
            
            var dx = (vMid - voltage) * eMidVec.x / eMidVec.lengthSq();
            var xFinal = xMid + dx;
            var yFinal = yMid + dx * eMidVec.y / eMidVec.x;

            return this._nextPoint.set(xFinal, yFinal);
        }

    });
{'fraction_non_alphanumeric': 0.11536624964186802, 'fraction_numerical': 0.004775093114315729, 'mean_word_length': 1.5058626465661642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2550307', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2839, 'n_words': 807}