<commit_before>package h2d.col;

class Poly {

	public var points : Array<Point>;
	var segments : Array<Seg>;
	
	public function new( points ) {
		this.points = points;
	}
		
	public function isConvex() {
		for( i in 0...points.length ) {
			var p1 = points[i];
			var p2 = points[(i + 1) % points.length];
			var p3 = points[(i + 2) % points.length];
			if( (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x) < 0 )
				return false;
		}
		return true;
	}

	public function getSegments() {
		if( segments != null )
			return segments;
		segments = [];
		for( i in 0...points.length ) {
			var s = new Seg(points[i], points[(i + 1) % points.length]);
			segments.push(s);
		}
		return segments;
	}
	
	public function hasPoint( p : Point ) {
		for( s in getSegments() )
			if( s.side(p) < 0 )
				return false;
		return true;
	}
	
	public function project( p : Point ) : Point {
		var dmin = 1e20, smin = null;
		for( s in getSegments() ) {
			var d = s.distanceSq(p);
			if( d < dmin ) {
				dmin = d;
				smin = s;
			}
		}
		return smin.project(p);
	}
	
	public function distanceSq( p : Point ) {
		var dmin = 1e20;
		for( s in getSegments() ) {
			var d = s.distanceSq(p);
			if( d < dmin ) dmin = d;
		}
		return dmin;
	}
	
	public inline function distance( p : Point ) {
		return h3d.FMath.sqrt(distanceSq(p));
	}
	
}<commit_msg>added calculateArea<commit_after>package h2d.col;

class Poly {

	public var points : Array<Point>;
	var segments : Array<Seg>;
	
	public function new( points ) {
		this.points = points;
	}
		
	public function isConvex() {
		for( i in 0...points.length ) {
			var p1 = points[i];
			var p2 = points[(i + 1) % points.length];
			var p3 = points[(i + 2) % points.length];
			if( (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x) < 0 )
				return false;
		}
		return true;
	}
	
	public function calculateArea() {
		var s = 0.;
		for( i in 0...points.length ) {
			var p = points[i];
			var n = points[(i + 1) % points.length];
			s += p.y * n.x - p.x * n.y;
		}
		return s * 0.5;
	}

	public function getSegments() {
		if( segments != null )
			return segments;
		segments = [];
		for( i in 0...points.length ) {
			var s = new Seg(points[i], points[(i + 1) % points.length]);
			segments.push(s);
		}
		return segments;
	}
	
	public function hasPoint( p : Point ) {
		for( s in getSegments() )
			if( s.side(p) < 0 )
				return false;
		return true;
	}
	
	public function project( p : Point ) : Point {
		var dmin = 1e20, smin = null;
		for( s in getSegments() ) {
			var d = s.distanceSq(p);
			if( d < dmin ) {
				dmin = d;
				smin = s;
			}
		}
		return smin.project(p);
	}
	
	public function distanceSq( p : Point ) {
		var dmin = 1e20;
		for( s in getSegments() ) {
			var d = s.distanceSq(p);
			if( d < dmin ) dmin = d;
		}
		return dmin;
	}
	
	public inline function distance( p : Point ) {
		return h3d.FMath.sqrt(distanceSq(p));
	}
	
}
{'fraction_non_alphanumeric': 0.15225254850378164, 'fraction_numerical': 0.018743834265044394, 'mean_word_length': 2.0603621730382295, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3462319', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1172, 'n_words': 321}