<commit_before>package h3d.col;

@:allow(h3d.col)
class Plane {
	
	var nx : Float;
	var ny : Float;
	var nz : Float;
	var d : Float;
	
	inline function new(nx, ny, nz, d) {
		this.nx = nx;
		this.ny = ny;
		this.nz = nz;
		this.d = d;
	}
	
	/**
		Returns the plan normal, with the distance in the w value
	**/
	public inline function getNormal() {
		return new h3d.Vector(nx, ny, nz, d);
	}
	
	/**
		Normalize the plan, so we can use distance().
	**/
	public inline function normalize() {
		var len = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
		nx *= len;
		ny *= len;
		nz *= len;
		d *= len;
	}
	
	public function toString() {
		return "{" + FMath.fmt(nx) + "," + FMath.fmt(ny) + "," + FMath.fmt(nz) + "," + FMath.fmt(d) + "}";
	}
	
	/**
		Returns the signed distance between a point an the plane. This requires the plan to be normalized. If the distance is negative it means that we are "under" the plan.
	**/
	public inline function distance( p : Vector ) {
		return nx * p.x + ny * p.y + nz * p.z - d;
	}
	
	public inline function project( p : Vector ) : Vector {
		var d = distance(p);
		return new Vector(p.x + d * nx, p.y + d * ny, p.z + d * nz);
	}

	public static inline function fromPoints( p0 : Vector, p1 : Vector, p2 : Vector ) {
		var d1 = p1.sub(p0);
		var d2 = p2.sub(p0);
		var n = d1.cross(d2);
		return new Plane(n.x,n.y,n.z,n.dot3(p0));
	}
	
	public static inline function fromNormalPoint( n : Vector, p : Vector ) {
		return new Plane(n.x,n.y,n.z,n.dot3(p));
	}
	
	public static inline function X(v:Float) {
		return new Plane( 1, 0, 0, v );
	}
	
	public static inline function Y(v:Float) {
		return new Plane( 0, 1, 0, v );
	}

	public static inline function Z(v:Float) {
		return new Plane( 0, 0, 1, v );
	}
	
}<commit_msg>added projectTo<commit_after>package h3d.col;

@:allow(h3d.col)
class Plane {
	
	var nx : Float;
	var ny : Float;
	var nz : Float;
	var d : Float;
	
	inline function new(nx, ny, nz, d) {
		this.nx = nx;
		this.ny = ny;
		this.nz = nz;
		this.d = d;
	}
	
	/**
		Returns the plan normal, with the distance in the w value
	**/
	public inline function getNormal() {
		return new h3d.Vector(nx, ny, nz, d);
	}
	
	/**
		Normalize the plan, so we can use distance().
	**/
	public inline function normalize() {
		var len = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
		nx *= len;
		ny *= len;
		nz *= len;
		d *= len;
	}
	
	public function toString() {
		return "{" + FMath.fmt(nx) + "," + FMath.fmt(ny) + "," + FMath.fmt(nz) + "," + FMath.fmt(d) + "}";
	}
	
	/**
		Returns the signed distance between a point an the plane. This requires the plan to be normalized. If the distance is negative it means that we are "under" the plan.
	**/
	public inline function distance( p : Vector ) {
		return nx * p.x + ny * p.y + nz * p.z - d;
	}
	
	public inline function project( p : Vector ) : Vector {
		var d = distance(p);
		return new Vector(p.x + d * nx, p.y + d * ny, p.z + d * nz);
	}

	public inline function projectTo( p : Vector, out : Vector ) {
		var d = distance(p);
		out.x = p.x + d * nx;
		out.y = p.y + d * ny;
		out.z = p.z + d * nz;
	}
	
	public static inline function fromPoints( p0 : Vector, p1 : Vector, p2 : Vector ) {
		var d1 = p1.sub(p0);
		var d2 = p2.sub(p0);
		var n = d1.cross(d2);
		return new Plane(n.x,n.y,n.z,n.dot3(p0));
	}
	
	public static inline function fromNormalPoint( n : Vector, p : Vector ) {
		return new Plane(n.x,n.y,n.z,n.dot3(p));
	}
	
	public static inline function X(v:Float) {
		return new Plane( 1, 0, 0, v );
	}
	
	public static inline function Y(v:Float) {
		return new Plane( 0, 1, 0, v );
	}

	public static inline function Z(v:Float) {
		return new Plane( 0, 0, 1, v );
	}
	
}
{'fraction_non_alphanumeric': 0.15003927729772193, 'fraction_numerical': 0.014139827179890024, 'mean_word_length': 2.342082239720035, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3899417', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1475, 'n_words': 474}