<commit_before>package luxe.tilemaps;

import luxe.Color;
import luxe.Rectangle;
import luxe.Vector;

import luxe.tilemaps.Tilemap;
import luxe.tilemaps.Isometric;

import phoenix.geometry.QuadGeometry;
import phoenix.Texture.FilterType;
import phoenix.geometry.Geometry;
import phoenix.Vector;

import luxe.options.TilemapOptions;

class Isometric {

    public static function worldpos_to_tile_coord( world_x:Float, world_y:Float, tile_width:Int, tile_height:Int, ?scale:Float=1.0 ) : Vector {

        var tile_pos = new Vector();

            var tile_width_half = tile_width / 2;
            var tile_height_half = tile_height / 2;

            tile_pos.x = ((world_x / tile_width_half) + (world_y / tile_height_half)) / 2;
            tile_pos.y = ((world_y / tile_height_half) - (world_x / tile_width_half)) / 2;

        return tile_pos;

    } //worldpos_to_tile_coord

    public static function tile_coord_to_worldpos(  tile_x:Int, tile_y:Int, tile_width:Int, tile_height:Int,
                                                   ?scale:Float=1.0, ?offset_x:TileOffset, ?offset_y:TileOffset ) : Vector {
        var world_pos = new Vector();

		var _scaled_tw = tile_width * scale;
		var _scaled_th = tile_height * scale;
		
		

		var tile_width_half = _scaled_tw / 2;
		var tile_height_half = _scaled_th / 2;
		
			//	Top left by default
		if(offset_x == null) { offset_x = TileOffset.left; };
		if (offset_y == null) { offset_y = TileOffset.top; };
		
		var tile_offset_x : Float = 0;
		var tile_offset_y : Float = 0;

			switch(offset_x) {
				case TileOffset.center:    { tile_offset_x += (_scaled_tw / 2); tile_offset_x /= tile_width; }
				case TileOffset.right:     { tile_offset_x += _scaled_tw; tile_offset_x /= tile_width; }
				default:
			}

			switch(offset_y) {
				case TileOffset.center:    { tile_offset_y += (_scaled_th/2); tile_offset_y /= tile_height; }
				case TileOffset.bottom:    { tile_offset_y += _scaled_th; tile_offset_y /= tile_height; }
				default:
			}
		
		tile_offset_x += tile_x;
		tile_offset_y += tile_y;

		world_pos.x = (tile_offset_x - tile_offset_y) * tile_width_half;
		world_pos.y = (tile_offset_x + tile_offset_y) * tile_height_half;
		
        return world_pos;

    } //tile_coord_to_worldpos


} //Ortho

class IsometricVisual extends TilemapVisual {

    public override function create() {

        for( layer in map ) {

            var _layer_geom : TilemapVisualLayerGeometry = [];

            for( y in 0 ... map.height ) {

                    //the geometry row
                var _geom_row : Array<Geometry> = [];

                for( x in 0 ... map.width ) {

                    var _tile_geom = create_tile_for_layer(layer, x, y);

                        //we want to push nulls into here,
                        //because otherwise the sizes won't match
                        //and because we use it to create tiles when
                        //changing the tile gid later
                    _geom_row.push( _tile_geom );

                } //for each tile in the x

                    //add the geometry to the bunches
                _layer_geom.push(_geom_row);

            } //for y

                //add the geometry to the list
            geometry.set( layer.name, _layer_geom );

        } //for each layer

        if(options.grid) {

            var color = new Color(1,1,1,0.8).rgb(0xcc0000);

            for(x in 0 ... map.width+1) {

                var ip = Isometric.tile_coord_to_worldpos(x, 0, map.tile_width, map.tile_height, options.scale);
                var ip_bot = Isometric.tile_coord_to_worldpos(x, map.height, map.tile_width, map.tile_height, options.scale);

                Luxe.draw.line({
                    p0 : new Vector(map.pos.x + ip.x, map.pos.y + ip.y ),
                    p1 : new Vector(map.pos.x + ip_bot.x, map.pos.y + ip_bot.y),
                    color : color,
                    depth : 2
                });
            }

            for(y in 0 ... map.height+1) {

                var ip = Isometric.tile_coord_to_worldpos(0, y, map.tile_width, map.tile_height, options.scale);
                var ip_bot = Isometric.tile_coord_to_worldpos(map.width, y, map.tile_width, map.tile_height, options.scale);

                Luxe.draw.line({
                    p0 : new Vector(map.pos.x + ip.x, map.pos.y + ip.y),
                    p1 : new Vector(map.pos.x + ip_bot.x, map.pos.y + ip_bot.y),
                    color : color,
                    depth : options.depth+0.001,
                    group : options.group,
                    batcher : options.batcher
                });
            }

        }

    } //create

    override function update_tile_id( _geom:Geometry, _layer_name:String, _x:Int, _y:Int, _id:Int ) {

        var tileset = map.tileset_from_id( _id );
        var image_coord = tileset.pos_in_texture( _id );

        var g : QuadGeometry = cast _geom;<commit_msg>Fixes isometric grid when using a custom batcher<commit_after>package luxe.tilemaps;

import luxe.Color;
import luxe.Rectangle;
import luxe.Vector;

import luxe.tilemaps.Tilemap;
import luxe.tilemaps.Isometric;

import phoenix.geometry.QuadGeometry;
import phoenix.Texture.FilterType;
import phoenix.geometry.Geometry;
import phoenix.Vector;

import luxe.options.TilemapOptions;

class Isometric {

    public static function worldpos_to_tile_coord( world_x:Float, world_y:Float, tile_width:Int, tile_height:Int, ?scale:Float=1.0 ) : Vector {

        var tile_pos = new Vector();

            var tile_width_half = tile_width / 2;
            var tile_height_half = tile_height / 2;

            tile_pos.x = ((world_x / tile_width_half) + (world_y / tile_height_half)) / 2;
            tile_pos.y = ((world_y / tile_height_half) - (world_x / tile_width_half)) / 2;

        return tile_pos;

    } //worldpos_to_tile_coord

    public static function tile_coord_to_worldpos(  tile_x:Int, tile_y:Int, tile_width:Int, tile_height:Int,
                                                   ?scale:Float=1.0, ?offset_x:TileOffset, ?offset_y:TileOffset ) : Vector {
        var world_pos = new Vector();

		var _scaled_tw = tile_width * scale;
		var _scaled_th = tile_height * scale;
		
		

		var tile_width_half = _scaled_tw / 2;
		var tile_height_half = _scaled_th / 2;
		
			//	Top left by default
		if(offset_x == null) { offset_x = TileOffset.left; };
		if (offset_y == null) { offset_y = TileOffset.top; };
		
		var tile_offset_x : Float = 0;
		var tile_offset_y : Float = 0;

			switch(offset_x) {
				case TileOffset.center:    { tile_offset_x += (_scaled_tw / 2); tile_offset_x /= tile_width; }
				case TileOffset.right:     { tile_offset_x += _scaled_tw; tile_offset_x /= tile_width; }
				default:
			}

			switch(offset_y) {
				case TileOffset.center:    { tile_offset_y += (_scaled_th/2); tile_offset_y /= tile_height; }
				case TileOffset.bottom:    { tile_offset_y += _scaled_th; tile_offset_y /= tile_height; }
				default:
			}
		
		tile_offset_x += tile_x;
		tile_offset_y += tile_y;

		world_pos.x = (tile_offset_x - tile_offset_y) * tile_width_half;
		world_pos.y = (tile_offset_x + tile_offset_y) * tile_height_half;
		
        return world_pos;

    } //tile_coord_to_worldpos


} //Ortho

class IsometricVisual extends TilemapVisual {

    public override function create() {

        for( layer in map ) {

            var _layer_geom : TilemapVisualLayerGeometry = [];

            for( y in 0 ... map.height ) {

                    //the geometry row
                var _geom_row : Array<Geometry> = [];

                for( x in 0 ... map.width ) {

                    var _tile_geom = create_tile_for_layer(layer, x, y);

                        //we want to push nulls into here,
                        //because otherwise the sizes won't match
                        //and because we use it to create tiles when
                        //changing the tile gid later
                    _geom_row.push( _tile_geom );

                } //for each tile in the x

                    //add the geometry to the bunches
                _layer_geom.push(_geom_row);

            } //for y

                //add the geometry to the list
            geometry.set( layer.name, _layer_geom );

        } //for each layer

        if(options.grid) {

            var color = new Color(1,1,1,0.8).rgb(0xcc0000);

            for(x in 0 ... map.width+1) {

                var ip = Isometric.tile_coord_to_worldpos(x, 0, map.tile_width, map.tile_height, options.scale);
                var ip_bot = Isometric.tile_coord_to_worldpos(x, map.height, map.tile_width, map.tile_height, options.scale);

                Luxe.draw.line({
                    p0 : new Vector(map.pos.x + ip.x, map.pos.y + ip.y ),
                    p1 : new Vector(map.pos.x + ip_bot.x, map.pos.y + ip_bot.y),
                    color : color,
                    depth : options.depth+0.001,
                    group : options.group,
                    batcher : options.batcher
                });
            }

            for(y in 0 ... map.height+1) {

                var ip = Isometric.tile_coord_to_worldpos(0, y, map.tile_width, map.tile_height, options.scale);
                var ip_bot = Isometric.tile_coord_to_worldpos(map.width, y, map.tile_width, map.tile_height, options.scale);

                Luxe.draw.line({
                    p0 : new Vector(map.pos.x + ip.x, map.pos.y + ip.y),
                    p1 : new Vector(map.pos.x + ip_bot.x, map.pos.y + ip_bot.y),
                    color : color,
                    depth : options.depth+0.001,
                    group : options.group,
                    batcher : options.batcher
                });
            }

        }

    } //create

    override function update_tile_id( _geom:Geometry, _layer_name:String, _x:Int, _y:Int, _id:Int ) {

        var tileset = map.tileset_from_id( _id );
        var image_coord = tileset.pos_in_texture( _id );

        var g : QuadGeometry = cast _geom;
{'fraction_non_alphanumeric': 0.1024897510248975, 'fraction_numerical': 0.0084991500849915, 'mean_word_length': 1.9041811846689896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6856779', 'n_tokens_mistral': 3456, 'n_tokens_neox': 3165, 'n_words': 714}