<commit_before>package h3d.parts;
import h3d.parts.Data;

private typedef History = {
	var state : String;
	var frames : Array<h2d.Tile>;
}

private typedef Curve = {
	var value : Value;
	var shape : Bool;
	var name : String;
	var incr : Float;
	var mode : Int;
	var min : Float;
	var max : Float;
	var pow : Float;
	var freq : Float;
	var prec : Float;
	var scaleY : Float;
	var points : Array<h2d.col.Point>;
	var active : Bool;
	var converge : Converge;
	var pointSelected : h2d.col.Point;
}

class Editor extends h2d.Sprite {
	
	var emit : Emitter;
	var state : State;
	var curState : String;
	var stateChanged : Null<Float>;
	var curTile : h2d.Tile;
	var width : Int;
	var height : Int;
	var ui : h2d.comp.Component;
	var stats : h2d.comp.Label;
	var cachedMode : BlendMode;
	var lastPartSeen : Null<Float>;
	var props : {
		startTime : Float,
		pause : Bool,
		slow : Bool,
	};
	var curve : Curve;
	var curveBG : h2d.Tile;
	var curveTexture : h2d.Tile;
	var grad : h2d.comp.GradientEditor;
	var cedit : h2d.Interactive;
	var undo : Array<History>;
	var redo : Array<History>;
	public var currentFilePath : String;
	public var autoLoop : Bool = true;
	public var moveEmitter(default,set) : Bool = false;
	
	static var CURVES : Array<{ name : String, f : Curve -> Data.Value }> = [
		{ name : "Const", f : function(c) return VConst(c.min) },
		{ name : "Linear", f : function(c) return VLinear(c.min, c.max - c.min) },
		{ name : "Pow", f : function(c) return VPow(c.min, c.max - c.min, c.pow) },
		{ name : "Sin", f : function(c) return VSin(c.freq * Math.PI, (c.max - c.min) * 0.5, (c.min + c.max) * 0.5) },
		{ name : "Cos", f : function(c) return VCos(c.freq * Math.PI, (c.max - c.min) * 0.5, (c.min + c.max) * 0.5) },
		{ name : "Curve", f : function(c) return solvePoly(c) },
		{ name : "Random", f : function(c) return VRandom(c.min, c.max - c.min, c.converge) },
	];

	
	static function solvePoly( c : Curve ) {

		if( c.points == null )
			c.points = [new h2d.col.Point(0, c.min/c.max), new h2d.col.Point(1, 1)];
		
		var xvals = [for( p in c.points ) p.x];
		var yvals = [for( p in c.points ) p.y * c.max];
		var pts = [];
		for( i in 0...c.points.length ) {
			pts.push(xvals[i]);
			pts.push(yvals[i]);
		}
		var p = Std.int(c.prec);
		var beta = h2d.col.Polynomial.regress(xvals, yvals, p <= 0 ? 0 : (p >= c.points.length ? c.points.length-1 : p));
		while( Math.abs(beta[beta.length - 1]) < 1e-3 )
			beta.pop();
		return VPoly(beta,pts);
	}
	
	public function new(emiter, ?parent) {
		super(parent);
		this.emit = emiter;
		init();
		setState(emit.state);
	}
	
	public dynamic function onTextureSelect() {
		hxd.File.browse(function(sel) {
			sel.load(function(bytes) {
				changeTexture(sel.fileName, hxd.res.Any.fromBytes(sel.fileName, bytes).toTile());
			});
		},{
			defaultPath : currentFilePath,
			title : "Please select the texture",
			relativePath : true,
			fileTypes : [{ name : "Images", extensions : ["png","jpg","jpeg","gif"] }],
		});
	}
	
	public function changeTexture( name : String, t : h2d.Tile ) {
		state.textureName = name;<commit_msg>always use absolute path for textures<commit_after>package h3d.parts;
import h3d.parts.Data;

private typedef History = {
	var state : String;
	var frames : Array<h2d.Tile>;
}

private typedef Curve = {
	var value : Value;
	var shape : Bool;
	var name : String;
	var incr : Float;
	var mode : Int;
	var min : Float;
	var max : Float;
	var pow : Float;
	var freq : Float;
	var prec : Float;
	var scaleY : Float;
	var points : Array<h2d.col.Point>;
	var active : Bool;
	var converge : Converge;
	var pointSelected : h2d.col.Point;
}

class Editor extends h2d.Sprite {
	
	var emit : Emitter;
	var state : State;
	var curState : String;
	var stateChanged : Null<Float>;
	var curTile : h2d.Tile;
	var width : Int;
	var height : Int;
	var ui : h2d.comp.Component;
	var stats : h2d.comp.Label;
	var cachedMode : BlendMode;
	var lastPartSeen : Null<Float>;
	var props : {
		startTime : Float,
		pause : Bool,
		slow : Bool,
	};
	var curve : Curve;
	var curveBG : h2d.Tile;
	var curveTexture : h2d.Tile;
	var grad : h2d.comp.GradientEditor;
	var cedit : h2d.Interactive;
	var undo : Array<History>;
	var redo : Array<History>;
	public var currentFilePath : String;
	public var autoLoop : Bool = true;
	public var moveEmitter(default,set) : Bool = false;
	
	static var CURVES : Array<{ name : String, f : Curve -> Data.Value }> = [
		{ name : "Const", f : function(c) return VConst(c.min) },
		{ name : "Linear", f : function(c) return VLinear(c.min, c.max - c.min) },
		{ name : "Pow", f : function(c) return VPow(c.min, c.max - c.min, c.pow) },
		{ name : "Sin", f : function(c) return VSin(c.freq * Math.PI, (c.max - c.min) * 0.5, (c.min + c.max) * 0.5) },
		{ name : "Cos", f : function(c) return VCos(c.freq * Math.PI, (c.max - c.min) * 0.5, (c.min + c.max) * 0.5) },
		{ name : "Curve", f : function(c) return solvePoly(c) },
		{ name : "Random", f : function(c) return VRandom(c.min, c.max - c.min, c.converge) },
	];

	
	static function solvePoly( c : Curve ) {

		if( c.points == null )
			c.points = [new h2d.col.Point(0, c.min/c.max), new h2d.col.Point(1, 1)];
		
		var xvals = [for( p in c.points ) p.x];
		var yvals = [for( p in c.points ) p.y * c.max];
		var pts = [];
		for( i in 0...c.points.length ) {
			pts.push(xvals[i]);
			pts.push(yvals[i]);
		}
		var p = Std.int(c.prec);
		var beta = h2d.col.Polynomial.regress(xvals, yvals, p <= 0 ? 0 : (p >= c.points.length ? c.points.length-1 : p));
		while( Math.abs(beta[beta.length - 1]) < 1e-3 )
			beta.pop();
		return VPoly(beta,pts);
	}
	
	public function new(emiter, ?parent) {
		super(parent);
		this.emit = emiter;
		init();
		setState(emit.state);
	}
	
	public dynamic function onTextureSelect() {
		hxd.File.browse(function(sel) {
			sel.load(function(bytes) {
				changeTexture(sel.fileName, hxd.res.Any.fromBytes(sel.fileName, bytes).toTile());
			});
		},{
			defaultPath : currentFilePath,
			title : "Please select the texture",
			fileTypes : [{ name : "Images", extensions : ["png","jpg","jpeg","gif"] }],
		});
	}
	
	public function changeTexture( name : String, t : h2d.Tile ) {
		state.textureName = name;
{'fraction_non_alphanumeric': 0.16596297499188048, 'fraction_numerical': 0.01136732705423839, 'mean_word_length': 3.2300824175824174, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '1159150', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2387, 'n_words': 630}