<commit_before>class PolygonCreationView extends View {

	final int finalClickThreshold = 20;

	Polygon polygon;
	Polygon outerTri;

	boolean isDemo;
	boolean isIntersecting;

	public PolygonCreationView( float x1, float y1, float x2, float y2 ) {
		super(x1, y1, x2, y2);
		this.cFill = color(255, 255, 255);
		createOuterTriangle();
		reset();
	}

	public void reset() {
		setText(sceneControl.create);
		this.polygon = compGeoHelper.createPoly();
		this.polygon.cFill = color(random(255), random(255), random(255));
		this.polygon.finalized = false;
		this.finalized = false;
		this.isDemo = false;
		this.isIntersecting = false;
	}

	private void createOuterTriangle() {
		outerTri = compGeoHelper.createPoly();
		outerTri.cHighlight = color(255);
		outerTri.cFill = color(200, 200, 200);
		// +10 to give a slight border
		outerTri.addPoint( x1 + (w/4.0), y1 + 10 );
		outerTri.addPoint( xCenter - 10, y2 - 10 );
		outerTri.addPoint( x1 + 10, y2 - 10 );
	}


	public void demo() {
		this.isDemo = true;
		this.polygon.points.clear();
		this.polygon.addPoint( 253, 206 );
		this.polygon.addPoint( 482, 146 );
		this.polygon.addPoint( 535, 406 );
		this.polygon.addPoint( 328, 552 );
		this.polygon.addPoint( 374, 304 );
		this.polygon.addPoint( 125, 604 );
		this.polygon.addPoint( 63,  281 );
		this.polygon.addPoint( 224, 343 );
		this.polygon.addPoint( 128, 104 );
		this.polygon.finalized = true;
		centerAndResizePolygon(false);
		update();
	}

	public void demoRect() {
		this.isDemo = true;
		this.polygon.points.clear();
		this.polygon.addPoint(250, 200);
		this.polygon.addPoint(500, 200);
		this.polygon.addPoint(500, 400);
		this.polygon.addPoint(250, 400);
		this.polygon.finalized = true;
		centerAndResizePolygon(false);
		update();
	}

	public void addPoint( float x, float y ) {
		// TODO: validate that new point does not create non crossing polygon
		// If user clicks within range of first point, try to complete the poly
		if ( this.polygon.points.size() >= 2 ) {
			float xDiff = Math.abs(this.polygon.points.get(0).x - x);
			float yDiff = Math.abs(this.polygon.points.get(0).y - y);
			if ( xDiff < finalClickThreshold && yDiff < finalClickThreshold ) {
				this.polygon.finalized = true;
			} else {
				if ( !intersectingPoint( x, y ) ) {
					this.polygon.addPoint(x, y);
				} else {
					isIntersecting = true;
				}
			}
		} else {
			this.polygon.addPoint(x, y);
		}
	}

	public boolean intersectingPoint(float newX, float newY) {
		PolyPoint lastAddedPoint = this.polygon.points.get(
				this.polygon.points.size() - 1);
		PolyPoint currentPoint = new PolyPoint(newX, newY);
		for ( int i = 0; i < this.polygon.points.size() - 1; i++ ) {
			if ( compGeoHelper.lineIntersectionCheck(
						this.polygon.points.get(i),
						this.polygon.points.get(i+1),
						lastAddedPoint, currentPoint) ) {
				return true;
			}
		}
		return false;
	}

	public void onMousePress() {
		if ( visible && !finalized ) {
			if ( !polygon.finalized ) {
				addPoint( mouseX, mouseY );
			}
		}
	}

	public void onMouseRelease() {
		if ( visible && !finalized ) {
			isIntersecting = false;
		}
	}

	public void centerAndResizePolygon(boolean animate) {
		// calculate percent to scale polygon to fit within the outer tri
		float ratioToScalePoly = 1.0;
		Polygon tmp = this.polygon.copy();
		tmp.move( outerTri.getCenter().x, outerTri.getCenter().y );
		while( !this.outerTri.containsPolygon( tmp ) ){
			tmp.scale( 0.90 );
			ratioToScalePoly *= 0.90;
		}
		if ( animate ) {
			polygon.animateMove( outerTri.getCenter().x, outerTri.getCenter().y );
			polygon.animateScale( ratioToScalePoly );
		} else {
			polygon.move( outerTri.getCenter().x, outerTri.getCenter().y );
			polygon.scale( ratioToScalePoly );
		}
	}

	public void update() {
		if ( !this.finalized ) {
			if( !polygon.finalized ) {
				return true;
			} else {
				setText(sceneControl.created);
				if (!isDemo) {
					centerAndResizePolygon(true);
				}<commit_msg>reduce size to prevent very thin side tris<commit_after>class PolygonCreationView extends View {

	final int finalClickThreshold = 20;

	Polygon polygon;
	Polygon outerTri;

	boolean isDemo;
	boolean isIntersecting;

	public PolygonCreationView( float x1, float y1, float x2, float y2 ) {
		super(x1, y1, x2, y2);
		this.cFill = color(255, 255, 255);
		createOuterTriangle();
		reset();
	}

	public void reset() {
		setText(sceneControl.create);
		this.polygon = compGeoHelper.createPoly();
		this.polygon.cFill = color(random(255), random(255), random(255));
		this.polygon.finalized = false;
		this.finalized = false;
		this.isDemo = false;
		this.isIntersecting = false;
	}

	private void createOuterTriangle() {
		outerTri = compGeoHelper.createPoly();
		outerTri.cHighlight = color(255);
		outerTri.cFill = color(200, 200, 200);
		// +10 to give a slight border
		outerTri.addPoint( x1 + (w/4.0), y1 + 10 );
		outerTri.addPoint( xCenter - 10, y2 - 10 );
		outerTri.addPoint( x1 + 10, y2 - 10 );
	}


	public void demo() {
		this.isDemo = true;
		this.polygon.points.clear();
		this.polygon.addPoint( 253, 206 );
		this.polygon.addPoint( 482, 146 );
		this.polygon.addPoint( 535, 406 );
		this.polygon.addPoint( 328, 552 );
		this.polygon.addPoint( 374, 304 );
		this.polygon.addPoint( 125, 604 );
		this.polygon.addPoint( 63,  281 );
		this.polygon.addPoint( 224, 343 );
		this.polygon.addPoint( 128, 104 );
		this.polygon.finalized = true;
		centerAndResizePolygon(false);
		update();
	}

	public void demoRect() {
		this.isDemo = true;
		this.polygon.points.clear();
		this.polygon.addPoint(250, 200);
		this.polygon.addPoint(500, 200);
		this.polygon.addPoint(500, 400);
		this.polygon.addPoint(250, 400);
		this.polygon.finalized = true;
		centerAndResizePolygon(false);
		update();
	}

	public void addPoint( float x, float y ) {
		// TODO: validate that new point does not create non crossing polygon
		// If user clicks within range of first point, try to complete the poly
		if ( this.polygon.points.size() >= 2 ) {
			float xDiff = Math.abs(this.polygon.points.get(0).x - x);
			float yDiff = Math.abs(this.polygon.points.get(0).y - y);
			if ( xDiff < finalClickThreshold && yDiff < finalClickThreshold ) {
				this.polygon.finalized = true;
			} else {
				if ( !intersectingPoint( x, y ) ) {
					this.polygon.addPoint(x, y);
				} else {
					isIntersecting = true;
				}
			}
		} else {
			this.polygon.addPoint(x, y);
		}
	}

	public boolean intersectingPoint(float newX, float newY) {
		PolyPoint lastAddedPoint = this.polygon.points.get(
				this.polygon.points.size() - 1);
		PolyPoint currentPoint = new PolyPoint(newX, newY);
		for ( int i = 0; i < this.polygon.points.size() - 1; i++ ) {
			if ( compGeoHelper.lineIntersectionCheck(
						this.polygon.points.get(i),
						this.polygon.points.get(i+1),
						lastAddedPoint, currentPoint) ) {
				return true;
			}
		}
		return false;
	}

	public void onMousePress() {
		if ( visible && !finalized ) {
			if ( !polygon.finalized ) {
				addPoint( mouseX, mouseY );
			}
		}
	}

	public void onMouseRelease() {
		if ( visible && !finalized ) {
			isIntersecting = false;
		}
	}

	public void centerAndResizePolygon(boolean animate) {
		// calculate percent to scale polygon to fit within the outer tri
		float ratioToScalePoly = 1.0;
		Polygon tmp = this.polygon.copy();
		tmp.move( outerTri.getCenter().x, outerTri.getCenter().y );
		while( !this.outerTri.containsPolygon( tmp ) ){
			tmp.scale( 0.90 );
			ratioToScalePoly *= 0.90;
		}
		ratioToScalePoly *= 0.90;
		if ( animate ) {
			polygon.animateMove( outerTri.getCenter().x, outerTri.getCenter().y );
			polygon.animateScale( ratioToScalePoly );
		} else {
			polygon.move( outerTri.getCenter().x, outerTri.getCenter().y );
			polygon.scale( ratioToScalePoly );
		}
	}

	public void update() {
		if ( !this.finalized ) {
			if( !polygon.finalized ) {
				return true;
			} else {
				setText(sceneControl.created);
				if (!isDemo) {
					centerAndResizePolygon(true);
				}
{'fraction_non_alphanumeric': 0.1377403544049265, 'fraction_numerical': 0.03833102928239286, 'mean_word_length': 3.3773377337733774, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6923515', 'n_tokens_mistral': 3433, 'n_tokens_neox': 2814, 'n_words': 637}