<commit_before>import Phaser from 'phaser'

export default class extends Phaser.Sprite {
    constructor ({ game, x, y, asset }) {
        super(game, x, y, asset);
        this.mapnodes = [
            [-1200,-300], [-900,300], [-300,100], [150,300], [800,-100],
            [600,-600], [900,-1000], [700,-1300], [-200,-1000],
            [-300,-300], [-700,-300], [-600,-1000], [-800,-1200],
            [-1100,-1200], [-1200,-700], [-1200,-300]
        ]
        this.outline = [];
    }

    initialize () {
        this.game.physics.p2.enable(this, true);
        this.body.static = true;
        this.anchor.set(0);
        this.body.clearShapes();
        this.outline = this.generateRoadBoundaries(this.mapnodes);
        var err = this.body.addPolygon({skipSimpleCheck: true, removeCollinearPoints: 0.1}, this.outline);
        this.body.setCollisionGroup(this.game.physics.p2.nothingCollisionGroup);
    }

    getXCoordinates () {
        return this.mapnodes.map( c=> c[0] );
    }

    getYCoordinates () {
        return this.mapnodes.map( c=> c[1] );
    }

    generateRoadBoundaries () {
        // At certain (uniform) points along the Catmull Rom curve of these points,
        //   - Find the current slope of curve
        //   - Generate collision points perpendicular to this slope 

        // In order to get a decent distribution of sample points, we need
        //   to find the distance of the track
        var distance = 0;
        for ( var i = 0; i < this.mapnodes.length - 1; i++ ) {
            var x = this.mapnodes[i][0];
            var y = this.mapnodes[i][1];
            var nx = this.mapnodes[i+1][0];
            var ny = this.mapnodes[i+1][1];
            distance += this.game.math.distance(x, y, nx, ny);
        }

        const DISTANCE_BETWEEN_SAMPLES = 70; // Measured in pixels
        const ROAD_WIDTH_FROM_CENTER = 100;   // Measured in pixels

        const STEP = 1/(distance/DISTANCE_BETWEEN_SAMPLES);<commit_msg>Add getPointOnTrack function<commit_after>import Phaser from 'phaser'

export default class extends Phaser.Sprite {
    constructor ({ game, x, y, asset }) {
        super(game, x, y, asset);
        this.mapnodes = [
            [-1200,-300], [-900,300], [-300,100], [150,300], [800,-100],
            [600,-600], [900,-1000], [700,-1300], [-200,-1000],
            [-300,-300], [-700,-300], [-600,-1000], [-800,-1200],
            [-1100,-1200], [-1200,-700], [-1200,-300]
        ]
        this.outline = [];
    }

    initialize () {
        this.game.physics.p2.enable(this, true);
        this.body.static = true;
        this.anchor.set(0);
        this.body.clearShapes();
        this.outline = this.generateRoadBoundaries(this.mapnodes);
        var err = this.body.addPolygon({skipSimpleCheck: true, removeCollinearPoints: 0.1}, this.outline);
        this.body.setCollisionGroup(this.game.physics.p2.nothingCollisionGroup);
    }

    getXCoordinates () {
        return this.mapnodes.map( c => c[0] );
    }

    getYCoordinates () {
        return this.mapnodes.map( c => c[1] );
    }

    getPointOnTrack ( percent ) {
        var pointsx = this.getXCoordinates();
        var pointsy = this.getYCoordinates();

        var xpos = this.game.math.catmullRomInterpolation(pointsx, percent);
        var ypos = this.game.math.catmullRomInterpolation(pointsy, percent);

        var dx = this.game.math.catmullRomInterpolation(pointsx, percent+0.001) - xpos;
        var dy = this.game.math.catmullRomInterpolation(pointsy, percent+0.001) - ypos;
        var angle = Math.atan(dy/dx) + Math.PI/2;
        console.log(dx, dy);

        xpos += this.x;
        ypos += this.y;

        return {x: xpos, y: ypos, a: angle};
    }

    generateRoadBoundaries () {
        // At certain (uniform) points along the Catmull Rom curve of these points,
        //   - Find the current slope of curve
        //   - Generate collision points perpendicular to this slope 

        // In order to get a decent distribution of sample points, we need
        //   to find the distance of the track
        var distance = 0;
        for ( var i = 0; i < this.mapnodes.length - 1; i++ ) {
            var x = this.mapnodes[i][0];
            var y = this.mapnodes[i][1];
            var nx = this.mapnodes[i+1][0];
            var ny = this.mapnodes[i+1][1];
            distance += this.game.math.distance(x, y, nx, ny);
        }

        const DISTANCE_BETWEEN_SAMPLES = 70; // Measured in pixels
        const ROAD_WIDTH_FROM_CENTER = 100;   // Measured in pixels

        const STEP = 1/(distance/DISTANCE_BETWEEN_SAMPLES);
{'fraction_non_alphanumeric': 0.1436656508489334, 'fraction_numerical': 0.057683935568132345, 'mean_word_length': 2.142954856361149, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '615849', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1450, 'n_words': 346}