<commit_before>#include "cinder/app/AppBasic.h"
#include "cinder/Font.h"
#include "cinder/TriMesh.h"
#include "cinder/Triangulate.h"
#include "cinder/gl/Vbo.h"
#include "cinder/params/Params.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class TriangulationApp : public AppBasic {
 public:
	void		setup();
	void		draw();

	void		keyDown( KeyEvent event ) { setRandomGlyph(); }

	void		recalcMesh();
	
	void		setRandomFont();
	void		setRandomGlyph();
	
	Font				mFont;
	Shape2d				mShape;
	vector<string>		mFontNames;
	gl::VboMesh			mVboMesh;
	params::InterfaceGl	mParams;
	bool				mDrawWireframe;
	int					mFontSize;
};

void TriangulationApp::setup()
{
	mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 400 ) );
	mFontSize = 256;
	mParams.addParam( "Font Size", &mFontSize, "min=1 max=2000 keyIncr== keyDecr=-" );
	mDrawWireframe = true;
	mParams.addParam( "Draw Wireframe", &mDrawWireframe, "min=1 max=2000 keyIncr== keyDecr=-" );
	mParams.addButton( "Random Font", bind( &TriangulationApp::setRandomFont, this ), "key=f" );
	mParams.addButton( "Random Glyph", bind( &TriangulationApp::setRandomGlyph, this ) );

	mFontNames = Font::getNames();
	mFont = Font( "Times", mFontSize );
	mShape = mFont.getGlyphShape( mFont.getGlyphChar( 'A' ) );
	
	// setup VBO
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	recalcMesh();
}

void TriangulationApp::recalcMesh()
{
	mVboMesh = gl::VboMesh( Triangulator( mShape ).calcMesh( Triangulator::WINDING_ODD ) ); 
}

void TriangulationApp::setRandomFont()
{
	// select a random font from those available on the system
	mFont = Font( mFontNames[rand() % mFontNames.size()], mFontSize );
	setRandomGlyph();
}

void TriangulationApp::setRandomGlyph()
{
	size_t glyphIndex = rand() % mFont.getNumGlyphs();
	try {
		mShape = mFont.getGlyphShape( glyphIndex );
		recalcMesh();
	}
	catch( FontGlyphFailureExc &exc  ) {
		console() << "Looks like glyph " << glyphIndex << " doesn't exist in this font." << std::endl;
	}
}

void TriangulationApp::draw()
{
	gl::clear();
	gl::pushModelView();
		gl::translate( getWindowCenter() );
		gl::color( Color( 0, 0, 0.8f ) );
		gl::draw( mVboMesh );
		if( mDrawWireframe ) {
			gl::enableWireframe();
			gl::color( Color::white() );
			gl::draw( mVboMesh );
			gl::disableWireframe();
		}
	gl::popModelView();
	
	mParams.draw();
}


CINDER_APP_BASIC( TriangulationApp, RendererGl )<commit_msg>Cleanup to triangulation sample<commit_after>#include "cinder/app/AppBasic.h"
#include "cinder/Font.h"
#include "cinder/TriMesh.h"
#include "cinder/Triangulate.h"
#include "cinder/gl/Vbo.h"
#include "cinder/params/Params.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class TriangulationApp : public AppBasic {
  public:
	void		setup();
	void		draw();

	void		keyDown( KeyEvent event ) { setRandomGlyph(); }

	void		recalcMesh();
	
	void		setRandomFont();
	void		setRandomGlyph();
	
	Font				mFont;
	Shape2d				mShape;
	vector<string>		mFontNames;
	gl::VboMesh			mVboMesh;
	params::InterfaceGl	mParams;
	bool				mDrawWireframe;
	int					mFontSize;
	float				mZoom;
	float				mPrecision, mOldPrecision;
	int					mNumPoints;
};

void TriangulationApp::setup()
{
	mParams = params::InterfaceGl( "Parameters", Vec2i( 220, 170 ) );
	mFontSize = 256;
	mDrawWireframe = true;
	mParams.addParam( "Draw Wireframe", &mDrawWireframe, "min=1 max=2000 keyIncr== keyDecr=-" );
	mParams.addButton( "Random Font", bind( &TriangulationApp::setRandomFont, this ), "key=f" );
	mParams.addButton( "Random Glyph", bind( &TriangulationApp::setRandomGlyph, this ) );
	mZoom = 1.0f;
	mParams.addParam( "Zoom", &mZoom, "min=0.01 max=20 keyIncr=z keyDecr=Z" );
	mOldPrecision = mPrecision = 1.0f;
	mParams.addParam( "Precision", &mPrecision, "min=0.01 max=20 keyIncr=p keyDecr=P" );
	mNumPoints = 0;
	mParams.addParam( "Num Points", &mNumPoints, "", true );

	mFontNames = Font::getNames();
	mFont = Font( "Times", mFontSize );
	mShape = mFont.getGlyphShape( mFont.getGlyphChar( 'A' ) );
	
	// setup VBO
	gl::VboMesh::Layout layout;
	layout.setStaticPositions();
	recalcMesh();
}

void TriangulationApp::recalcMesh()
{
	TriMesh2d mesh = Triangulator( mShape, mPrecision ).calcMesh( Triangulator::WINDING_ODD );
	mNumPoints = mesh.getNumIndices();
	mVboMesh = gl::VboMesh( mesh ); 
	mOldPrecision = mPrecision;
}

void TriangulationApp::setRandomFont()
{
	// select a random font from those available on the system
	mFont = Font( mFontNames[rand() % mFontNames.size()], mFontSize );
	setRandomGlyph();
}

void TriangulationApp::setRandomGlyph()
{
	size_t glyphIndex = rand() % mFont.getNumGlyphs();
	try {
		mShape = mFont.getGlyphShape( glyphIndex );
		recalcMesh();
	}
	catch( FontGlyphFailureExc &exc  ) {
		console() << "Looks like glyph " << glyphIndex << " doesn't exist in this font." << std::endl;
	}
}

void TriangulationApp::draw()
{
	if( mOldPrecision != mPrecision )
		recalcMesh();

	gl::clear();
	gl::pushModelView();
		gl::translate( getWindowCenter() * Vec2f( 0.8f, 1.2f ) );
		gl::scale( Vec3f( mZoom, mZoom, mZoom ) );
		gl::color( Color( 0.8f, 0.4f, 0.0f ) );
		gl::draw( mVboMesh );
		if( mDrawWireframe ) {
			gl::enableWireframe();
			gl::color( Color::white() );
			gl::draw( mVboMesh );
			gl::disableWireframe();
		}
	gl::popModelView();
	
	mParams.draw();
}


CINDER_APP_BASIC( TriangulationApp, RendererGl )
{'fraction_non_alphanumeric': 0.15361558636193332, 'fraction_numerical': 0.0129261895841139, 'mean_word_length': 4.886438809261301, 'pattern_counts': {'":': 0, '<': 21, '<?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': '362513', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2013, 'n_words': 426}